@@ -175,12 +175,22 @@ export default Component.extend(EventWizardMixin, FormMixin, {
175175 } ;
176176 } ,
177177
178- tracks : computed ( 'data.tracks.@each.isDeleted' , function ( ) {
179- return this . data . tracks . filterBy ( 'isDeleted' , false ) ;
178+ tracks : computed ( 'data.tracks.@each.isDeleted' , 'data.tracks.@each.position' , function ( ) {
179+ const sortedRooms = this . data . event . tracks . sortBy ( 'position' ) . filterBy ( 'isDeleted' , false ) ;
180+ sortedRooms . forEach ( ( room , idx ) => {
181+ room . set ( 'position' , idx ) ;
182+ } ) ;
183+
184+ return sortedRooms ;
180185 } ) ,
181186
182- sessionTypes : computed ( 'data.sessionTypes.@each.isDeleted' , function ( ) {
183- return this . data . sessionTypes . filterBy ( 'isDeleted' , false ) ;
187+ sessionTypes : computed ( 'data.sessionTypes.@each.isDeleted' , 'data.sessionTypes.@each.position' , function ( ) {
188+ const sortedRooms = this . data . event . sessionTypes . sortBy ( 'position' ) . filterBy ( 'isDeleted' , false ) ;
189+ sortedRooms . forEach ( ( room , idx ) => {
190+ room . set ( 'position' , idx ) ;
191+ } ) ;
192+
193+ return sortedRooms ;
184194 } ) ,
185195
186196 hasCallForSpeaker : computed ( 'data.event.isCfsEnabled' , function ( ) {
@@ -229,16 +239,6 @@ export default Component.extend(EventWizardMixin, FormMixin, {
229239 } ,
230240
231241 actions : {
232- addItem ( type ) {
233- switch ( type ) {
234- case 'sessionType' :
235- this . data . sessionTypes . addObject ( this . store . createRecord ( 'session-type' ) ) ;
236- break ;
237- case 'track' :
238- this . data . tracks . addObject ( this . store . createRecord ( 'track' ) ) ;
239- break ;
240- }
241- } ,
242242 addCustomField ( ) {
243243 this . data . customForms . addObject ( this . store . createRecord ( 'customForm' , {
244244 event : this . data . event ,
@@ -260,24 +260,65 @@ export default Component.extend(EventWizardMixin, FormMixin, {
260260 removeField ( field ) {
261261 this . data . customForms . removeObject ( field ) ;
262262 } ,
263- addRoom ( index ) {
264- this . microlocations . forEach ( room => {
265- const pos = room . get ( 'position' ) ;
266- pos > index && room . set ( 'position' , pos + 1 ) ;
267- } ) ;
268- this . data . event . microlocations . addObject ( this . store . createRecord ( 'microlocation' , { position : index + 1 } ) ) ;
263+ addRoom ( type , index ) {
264+ switch ( type ) {
265+ case 'microlocation' :
266+ this . microlocations . forEach ( room => {
267+ const pos = room . get ( 'position' ) ;
268+ pos > index && room . set ( 'position' , pos + 1 ) ;
269+ } ) ;
270+ this . data . event . microlocations . addObject ( this . store . createRecord ( 'microlocation' , { position : index + 1 } ) ) ;
271+ break ;
272+ case 'sessionType' :
273+ this . sessionTypes . forEach ( room => {
274+ const pos = room . get ( 'position' ) ;
275+ pos > index && room . set ( 'position' , pos + 1 ) ;
276+ } ) ;
277+ this . data . event . sessionTypes . addObject ( this . store . createRecord ( 'session-type' , { position : index + 1 } ) ) ;
278+ break ;
279+ case 'track' :
280+ this . tracks . forEach ( room => {
281+ const pos = room . get ( 'position' ) ;
282+ pos > index && room . set ( 'position' , pos + 1 ) ;
283+ } ) ;
284+ this . data . event . tracks . addObject ( this . store . createRecord ( 'track' , { position : index + 1 } ) ) ;
285+ break ;
286+ }
269287 } ,
270- removeRoom ( room , index ) {
288+ removeRoom ( room , type , index ) {
271289 room . deleteRecord ( ) ;
272- this . microlocations . forEach ( item => {
273- const pos = item . get ( 'position' ) ;
274- pos > index && item . set ( 'position' , pos - 1 ) ;
275- } ) ;
290+ switch ( type ) {
291+ case 'microlocation' :
292+ this . microlocations . forEach ( item => {
293+ const pos = item . get ( 'position' ) ;
294+ pos > index && item . set ( 'position' , pos - 1 ) ;
295+ } ) ;
296+ break ;
297+ case 'sessionType' :
298+ this . sessionTypes . forEach ( item => {
299+ const pos = item . get ( 'position' ) ;
300+ pos > index && item . set ( 'position' , pos - 1 ) ;
301+ } ) ;
302+ break ;
303+ case 'track' :
304+ this . tracks . forEach ( item => {
305+ const pos = item . get ( 'position' ) ;
306+ pos > index && item . set ( 'position' , pos - 1 ) ;
307+ } ) ;
308+ break ;
309+ }
276310 } ,
277- moveRoom ( item , direction ) {
311+ moveRoom ( item , type , direction ) {
278312 const idx = item . get ( 'position' ) ;
279313 const otherIdx = direction === 'up' ? ( idx - 1 ) : ( idx + 1 ) ;
280- const other = this . microlocations . find ( item => item . get ( 'position' ) === otherIdx ) ;
314+ let other ;
315+ if ( type === 'microlocation' ) {
316+ other = this . microlocations . find ( item => item . get ( 'position' ) === otherIdx ) ;
317+ } else if ( type === 'sessionType' ) {
318+ other = this . sessionTypes . find ( item => item . get ( 'position' ) === otherIdx ) ;
319+ } else if ( type === 'track' ) {
320+ other = this . tracks . find ( item => item . get ( 'position' ) === otherIdx ) ;
321+ }
281322 other . set ( 'position' , idx ) ;
282323 item . set ( 'position' , otherIdx ) ;
283324 } ,
0 commit comments