@@ -36,6 +36,7 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
3636 @tracked endCurrentMeeting = false ;
3737 @tracked translationChannels = [ ] ;
3838 @tracked translationChannelsNew = [ ] ;
39+ @tracked translationChannelsRemoved = [ ] ;
3940
4041 @computed
4142 get currentLocale ( ) {
@@ -99,18 +100,28 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
99100
100101 async loadTranslationChannels ( ) {
101102 const videoStreamId = this . data . stream . get ( 'id' ) ; // Get the current video stream id from the route
102- const responseData = await this . loader . load ( `/video-streams/${ videoStreamId } /translation_channels` ) ;
103- this . translationChannels = responseData . data . map ( channel => channel . attributes ) ;
104- this . translationChannels = responseData . data . map ( channel => ( {
105- id : channel . id ,
106- ...channel . attributes
107- } ) ) ;
103+ if ( videoStreamId ) {
104+ const responseData = await this . loader . load ( `/video-streams/${ videoStreamId } /translation_channels` ) ;
105+ this . translationChannels = responseData . data . map ( channel => channel . attributes ) ;
106+ this . translationChannels = responseData . data . map ( channel => ( {
107+ id : channel . id ,
108+ ...channel . attributes
109+ } ) ) ;
110+ }
108111 }
109112
110113 @action
111114 async removeChannel ( index , id ) {
112- this . translationChannels = this . translationChannels . filter ( ( _ , i ) => i !== index ) ;
113- this . loader . delete ( `/translation_channels/${ id } ` ) ;
115+ if ( id ) {
116+ this . translationChannels = this . translationChannels . filter ( ( _ , i ) => i !== index ) ;
117+ this . translationChannelsRemoved . push ( id ) ;
118+ } else {
119+ this . translationChannelsNew = this . translationChannelsNew . filter ( ( _ , i ) => i !== index ) ;
120+ }
121+ }
122+
123+ async deletedChannels ( ) {
124+ this . translationChannelsRemoved . forEach ( id => this . loader . delete ( `/translation_channels/${ id } ` ) ) ;
114125 }
115126
116127 @action
@@ -129,7 +140,6 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
129140
130141 @action
131142 async updateChannel ( index , id ) {
132- event . preventDefault ( ) ;
133143 const channel = this . translationChannels [ index ] ;
134144 const payload = {
135145 data : {
@@ -149,7 +159,7 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
149159 channel : {
150160 data : {
151161 type : 'video_channel' ,
152- id : ` ${ channel . id } `
162+ id : this . data . stream . videoChannel . get ( 'id' )
153163 }
154164 }
155165 }
@@ -331,7 +341,6 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
331341
332342 @action
333343 addChannel ( ) {
334- event . preventDefault ( ) ;
335344 this . translationChannelsNew = [ ...this . translationChannelsNew , { id : '' , name : '' , url : '' } ] ;
336345 }
337346
@@ -410,7 +419,6 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
410419
411420 @action
412421 addNewChannel ( channel ) {
413- event . preventDefault ( ) ;
414422 const payload = {
415423 'data' : {
416424 'type' : 'translation_channel' ,
@@ -428,7 +436,7 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
428436 'channel' : {
429437 'data' : {
430438 'type' : 'video_channel' ,
431- 'id' : '1'
439+ 'id' : this . data . stream . videoChannel . get ( 'id' )
432440 }
433441 }
434442 }
@@ -446,6 +454,13 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
446454 this . onValid ( async ( ) => {
447455 try {
448456 this . set ( 'isLoading' , true ) ;
457+ if ( this . data . stream . extra ?. bbb_options ) {
458+ this . data . stream . extra . bbb_options . endCurrentMeeting = this
459+ . showUpdateOptions
460+ ? this . endCurrentMeeting
461+ : false ;
462+ }
463+ await this . data . stream . save ( ) ;
449464 for ( const channel of this . translationChannelsNew ) {
450465 this . addNewChannel ( channel ) ;
451466 }
@@ -454,13 +469,9 @@ export default class VideoroomForm extends Component.extend(FormMixin) {
454469 this . updateChannel ( index , channel . id ) ;
455470 } ) ;
456471
457- if ( this . data . stream . extra ?. bbb_options ) {
458- this . data . stream . extra . bbb_options . endCurrentMeeting = this
459- . showUpdateOptions
460- ? this . endCurrentMeeting
461- : false ;
472+ if ( this . translationChannelsRemoved . length > 0 ) {
473+ this . deletedChannels ( ) ;
462474 }
463- await this . data . stream . save ( ) ;
464475 const saveModerators = this . data . stream . moderators
465476 . toArray ( )
466477 . map ( moderator => {
0 commit comments