11import { Component , Input , OnInit } from '@angular/core' ;
2- import { combineLatest as observableCombineLatest , Observable } from 'rxjs' ;
2+ import { Observable } from 'rxjs' ;
33import { ScriptDataService } from '../../../core/data/processes/script-data.service' ;
44import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
5- import { map } from 'rxjs/operators' ;
5+ import { map , switchMap , filter , startWith } from 'rxjs/operators' ;
66import { FeatureID } from '../../../core/data/feature-authorization/feature-id' ;
77import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
88import { hasValue , isNotEmpty } from '../../empty.util' ;
@@ -13,6 +13,7 @@ import { NotificationsService } from '../../notifications/notifications.service'
1313import { TranslateService } from '@ngx-translate/core' ;
1414import { Router } from '@angular/router' ;
1515import { PaginatedSearchOptions } from '../models/paginated-search-options.model' ;
16+ import { SearchFilter } from '../models/search-filter.model' ;
1617
1718@Component ( {
1819 selector : 'ds-search-export-csv' ,
@@ -48,15 +49,11 @@ export class SearchExportCsvComponent implements OnInit {
4849 }
4950
5051 ngOnInit ( ) : void {
51- const scriptExists$ = this . scriptDataService . findById ( 'metadata-export-search' ) . pipe (
52- getFirstCompletedRemoteData ( ) ,
53- map ( ( rd ) => rd . isSuccess && hasValue ( rd . payload ) )
54- ) ;
55-
56- const isAuthorized$ = this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) ;
57-
58- this . shouldShowButton$ = observableCombineLatest ( [ scriptExists$ , isAuthorized$ ] ) . pipe (
59- map ( ( [ scriptExists , isAuthorized ] : [ boolean , boolean ] ) => scriptExists && isAuthorized )
52+ this . shouldShowButton$ = this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) . pipe (
53+ filter ( ( isAuthorized : boolean ) => isAuthorized ) ,
54+ switchMap ( ( ) => this . scriptDataService . scriptWithNameExistsAndCanExecute ( 'metadata-export-search' ) ) ,
55+ map ( ( canExecute : boolean ) => canExecute ) ,
56+ startWith ( false ) ,
6057 ) ;
6158 }
6259
@@ -76,19 +73,19 @@ export class SearchExportCsvComponent implements OnInit {
7673 parameters . push ( { name : '-c' , value : this . searchConfig . configuration } ) ;
7774 }
7875 if ( isNotEmpty ( this . searchConfig . filters ) ) {
79- this . searchConfig . filters . forEach ( ( filter ) => {
80- if ( hasValue ( filter . values ) ) {
81- filter . values . forEach ( ( value ) => {
76+ this . searchConfig . filters . forEach ( ( searchFilter : SearchFilter ) => {
77+ if ( hasValue ( searchFilter . values ) ) {
78+ searchFilter . values . forEach ( ( value : string ) => {
8279 let operator ;
8380 let filterValue ;
84- if ( hasValue ( filter . operator ) ) {
85- operator = filter . operator ;
81+ if ( hasValue ( searchFilter . operator ) ) {
82+ operator = searchFilter . operator ;
8683 filterValue = value ;
8784 } else {
8885 operator = value . substring ( value . lastIndexOf ( ',' ) + 1 ) ;
8986 filterValue = value . substring ( 0 , value . lastIndexOf ( ',' ) ) ;
9087 }
91- const valueToAdd = `${ filter . key . substring ( 2 ) } ,${ operator } =${ filterValue } ` ;
88+ const valueToAdd = `${ searchFilter . key . substring ( 2 ) } ,${ operator } =${ filterValue } ` ;
9289 parameters . push ( { name : '-f' , value : valueToAdd } ) ;
9390 } ) ;
9491 }
0 commit comments