11import { Component , OnDestroy , OnInit } from '@angular/core' ;
2- import { combineLatest as observableCombineLatest , Observable } from 'rxjs' ;
2+ import { Observable } from 'rxjs' ;
33import { RemoteData } from '../../../core/data/remote-data' ;
44import { PaginatedList } from '../../../core/data/paginated-list.model' ;
55import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model' ;
66import { BitstreamFormat } from '../../../core/shared/bitstream-format.model' ;
77import { BitstreamFormatDataService } from '../../../core/data/bitstream-format-data.service' ;
88import { map , mergeMap , switchMap , take , toArray } from 'rxjs/operators' ;
99import { NotificationsService } from '../../../shared/notifications/notifications.service' ;
10- import { Router } from '@angular/router' ;
1110import { TranslateService } from '@ngx-translate/core' ;
1211import { NoContent } from '../../../core/shared/NoContent.model' ;
1312import { PaginationService } from '../../../core/pagination/pagination.service' ;
@@ -26,7 +25,12 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
2625 /**
2726 * A paginated list of bitstream formats to be shown on the page
2827 */
29- bitstreamFormats : Observable < RemoteData < PaginatedList < BitstreamFormat > > > ;
28+ bitstreamFormats$ : Observable < RemoteData < PaginatedList < BitstreamFormat > > > ;
29+
30+ /**
31+ * The currently selected {@link BitstreamFormat} IDs
32+ */
33+ selectedBitstreamFormatIDs$ : Observable < string [ ] > ;
3034
3135 /**
3236 * The current pagination configuration for the page
@@ -39,7 +43,6 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
3943 } ) ;
4044
4145 constructor ( private notificationsService : NotificationsService ,
42- private router : Router ,
4346 private translateService : TranslateService ,
4447 private bitstreamFormatService : BitstreamFormatDataService ,
4548 private paginationService : PaginationService ,
@@ -94,14 +97,11 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
9497 }
9598
9699 /**
97- * Checks whether a given bitstream format is selected in the list (checkbox)
98- * @param bitstreamFormat
100+ * Returns the list of all the bitstream formats that are selected in the list (checkbox)
99101 */
100- isSelected ( bitstreamFormat : BitstreamFormat ) : Observable < boolean > {
102+ selectedBitstreamFormatIDs ( ) : Observable < string [ ] > {
101103 return this . bitstreamFormatService . getSelectedBitstreamFormats ( ) . pipe (
102- map ( ( bitstreamFormats : BitstreamFormat [ ] ) => {
103- return bitstreamFormats . find ( ( selectedFormat ) => selectedFormat . id === bitstreamFormat . id ) != null ;
104- } )
104+ map ( ( bitstreamFormats : BitstreamFormat [ ] ) => bitstreamFormats . map ( ( selectedFormat ) => selectedFormat . id ) ) ,
105105 ) ;
106106 }
107107
@@ -125,27 +125,23 @@ export class BitstreamFormatsComponent implements OnInit, OnDestroy {
125125 const prefix = 'admin.registries.bitstream-formats.delete' ;
126126 const suffix = success ? 'success' : 'failure' ;
127127
128- const messages = observableCombineLatest (
129- this . translateService . get ( `${ prefix } .${ suffix } .head` ) ,
130- this . translateService . get ( `${ prefix } .${ suffix } .amount` , { amount : amount } )
131- ) ;
132- messages . subscribe ( ( [ head , content ] ) => {
128+ const head : string = this . translateService . instant ( `${ prefix } .${ suffix } .head` ) ;
129+ const content : string = this . translateService . instant ( `${ prefix } .${ suffix } .amount` , { amount : amount } ) ;
133130
134- if ( success ) {
135- this . notificationsService . success ( head , content ) ;
136- } else {
137- this . notificationsService . error ( head , content ) ;
138- }
139- } ) ;
131+ if ( success ) {
132+ this . notificationsService . success ( head , content ) ;
133+ } else {
134+ this . notificationsService . error ( head , content ) ;
135+ }
140136 }
141137
142138 ngOnInit ( ) : void {
143-
144- this . bitstreamFormats = this . paginationService . getFindListOptions ( this . pageConfig . id , this . pageConfig ) . pipe (
139+ this . bitstreamFormats$ = this . paginationService . getFindListOptions ( this . pageConfig . id , this . pageConfig ) . pipe (
145140 switchMap ( ( findListOptions : FindListOptions ) => {
146141 return this . bitstreamFormatService . findAll ( findListOptions ) ;
147142 } )
148143 ) ;
144+ this . selectedBitstreamFormatIDs$ = this . selectedBitstreamFormatIDs ( ) ;
149145 }
150146
151147
0 commit comments