@@ -13,11 +13,13 @@ import {
1313 TranslateModule ,
1414 TranslateService ,
1515} from '@ngx-translate/core' ;
16+ import { Observable } from 'rxjs' ;
1617import {
17- combineLatest as observableCombineLatest ,
18- Observable ,
19- } from 'rxjs' ;
20- import { map } from 'rxjs/operators' ;
18+ filter ,
19+ map ,
20+ startWith ,
21+ switchMap ,
22+ } from 'rxjs/operators' ;
2123
2224import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
2325import { FeatureID } from '../../../core/data/feature-authorization/feature-id' ;
@@ -32,6 +34,7 @@ import {
3234} from '../../empty.util' ;
3335import { NotificationsService } from '../../notifications/notifications.service' ;
3436import { PaginatedSearchOptions } from '../models/paginated-search-options.model' ;
37+ import { SearchFilter } from '../models/search-filter.model' ;
3538
3639@Component ( {
3740 selector : 'ds-search-export-csv' ,
@@ -69,15 +72,11 @@ export class SearchExportCsvComponent implements OnInit {
6972 }
7073
7174 ngOnInit ( ) : void {
72- const scriptExists$ = this . scriptDataService . findById ( 'metadata-export-search' ) . pipe (
73- getFirstCompletedRemoteData ( ) ,
74- map ( ( rd ) => rd . isSuccess && hasValue ( rd . payload ) ) ,
75- ) ;
76-
77- const isAuthorized$ = this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) ;
78-
79- this . shouldShowButton$ = observableCombineLatest ( [ scriptExists$ , isAuthorized$ ] ) . pipe (
80- map ( ( [ scriptExists , isAuthorized ] : [ boolean , boolean ] ) => scriptExists && isAuthorized ) ,
75+ this . shouldShowButton$ = this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) . pipe (
76+ filter ( ( isAuthorized : boolean ) => isAuthorized ) ,
77+ switchMap ( ( ) => this . scriptDataService . scriptWithNameExistsAndCanExecute ( 'metadata-export-search' ) ) ,
78+ map ( ( canExecute : boolean ) => canExecute ) ,
79+ startWith ( false ) ,
8180 ) ;
8281 }
8382
@@ -97,19 +96,19 @@ export class SearchExportCsvComponent implements OnInit {
9796 parameters . push ( { name : '-c' , value : this . searchConfig . configuration } ) ;
9897 }
9998 if ( isNotEmpty ( this . searchConfig . filters ) ) {
100- this . searchConfig . filters . forEach ( ( filter ) => {
101- if ( hasValue ( filter . values ) ) {
102- filter . values . forEach ( ( value ) => {
99+ this . searchConfig . filters . forEach ( ( searchFilter : SearchFilter ) => {
100+ if ( hasValue ( searchFilter . values ) ) {
101+ searchFilter . values . forEach ( ( value : string ) => {
103102 let operator ;
104103 let filterValue ;
105- if ( hasValue ( filter . operator ) ) {
106- operator = filter . operator ;
104+ if ( hasValue ( searchFilter . operator ) ) {
105+ operator = searchFilter . operator ;
107106 filterValue = value ;
108107 } else {
109108 operator = value . substring ( value . lastIndexOf ( ',' ) + 1 ) ;
110109 filterValue = value . substring ( 0 , value . lastIndexOf ( ',' ) ) ;
111110 }
112- const valueToAdd = `${ filter . key . substring ( 2 ) } ,${ operator } =${ filterValue } ` ;
111+ const valueToAdd = `${ searchFilter . key . substring ( 2 ) } ,${ operator } =${ filterValue } ` ;
113112 parameters . push ( { name : '-f' , value : valueToAdd } ) ;
114113 } ) ;
115114 }
0 commit comments