submission-import-external.component.ts (dspace-angular-dspace-7.0) | : | submission-import-external.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
import { SearchConfigurationService } from '../../core/shared/search/search-conf iguration.service'; | import { SearchConfigurationService } from '../../core/shared/search/search-conf iguration.service'; | |||
import { Context } from '../../core/shared/context.model'; | import { Context } from '../../core/shared/context.model'; | |||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-c omponent-options.model'; | import { PaginationComponentOptions } from '../../shared/pagination/pagination-c omponent-options.model'; | |||
import { RouteService } from '../../core/services/route.service'; | import { RouteService } from '../../core/services/route.service'; | |||
import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils '; | import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils '; | |||
import { SubmissionImportExternalPreviewComponent } from './import-external-prev iew/submission-import-external-preview.component'; | import { SubmissionImportExternalPreviewComponent } from './import-external-prev iew/submission-import-external-preview.component'; | |||
import { fadeIn } from '../../shared/animations/fade'; | import { fadeIn } from '../../shared/animations/fade'; | |||
import { PageInfo } from '../../core/shared/page-info.model'; | import { PageInfo } from '../../core/shared/page-info.model'; | |||
import { hasValue, isNotEmpty } from '../../shared/empty.util'; | import { hasValue, isNotEmpty } from '../../shared/empty.util'; | |||
import { getFinishedRemoteData } from '../../core/shared/operators'; | import { getFinishedRemoteData } from '../../core/shared/operators'; | |||
import { NONE_ENTITY_TYPE } from '../../core/shared/item-relationships/item-type .resource-type'; | ||||
/** | /** | |||
* This component allows to submit a new workspaceitem importing the data from a n external source. | * This component allows to submit a new workspaceitem importing the data from a n external source. | |||
*/ | */ | |||
@Component({ | @Component({ | |||
selector: 'ds-submission-import-external', | selector: 'ds-submission-import-external', | |||
styleUrls: ['./submission-import-external.component.scss'], | styleUrls: ['./submission-import-external.component.scss'], | |||
templateUrl: './submission-import-external.component.html', | templateUrl: './submission-import-external.component.html', | |||
animations: [fadeIn] | animations: [fadeIn] | |||
}) | }) | |||
skipping to change at line 48 | skipping to change at line 49 | |||
public routeData: ExternalSourceData; | public routeData: ExternalSourceData; | |||
/** | /** | |||
* The displayed list of entries | * The displayed list of entries | |||
*/ | */ | |||
public entriesRD$: BehaviorSubject<RemoteData<PaginatedList<ExternalSourceEntr y>>> = new BehaviorSubject<RemoteData<PaginatedList<ExternalSourceEntry>>>(null) ; | public entriesRD$: BehaviorSubject<RemoteData<PaginatedList<ExternalSourceEntr y>>> = new BehaviorSubject<RemoteData<PaginatedList<ExternalSourceEntry>>>(null) ; | |||
/** | /** | |||
* TRUE if the REST service is called to retrieve the external source items | * TRUE if the REST service is called to retrieve the external source items | |||
*/ | */ | |||
public isLoading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(fal se); | public isLoading$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(fal se); | |||
public reload$: BehaviorSubject<{ query: string, source: string }> = new Behav | public reload$: BehaviorSubject<ExternalSourceData> = new BehaviorSubject<Exte | |||
iorSubject<{ query: string; source: string }>({ | rnalSourceData>({ | |||
entity: '', | ||||
query: '', | query: '', | |||
source: '' | sourceId: '' | |||
}); | }); | |||
/** | /** | |||
* Configuration to use for the import buttons | * Configuration to use for the import buttons | |||
*/ | */ | |||
public importConfig: { buttonLabel: string }; | public importConfig: { buttonLabel: string }; | |||
/** | /** | |||
* Suffix for button label | * Suffix for button label | |||
*/ | */ | |||
public label: string; | public label: string; | |||
/** | /** | |||
skipping to change at line 112 | skipping to change at line 114 | |||
private routeService: RouteService, | private routeService: RouteService, | |||
private router: Router, | private router: Router, | |||
private modalService: NgbModal, | private modalService: NgbModal, | |||
) { | ) { | |||
} | } | |||
/** | /** | |||
* Get the entries for the selected external source and set initial configurat ion. | * Get the entries for the selected external source and set initial configurat ion. | |||
*/ | */ | |||
ngOnInit(): void { | ngOnInit(): void { | |||
this.label = 'Journal'; | ||||
this.listId = 'list-submission-external-sources'; | this.listId = 'list-submission-external-sources'; | |||
this.context = Context.EntitySearchModalWithNameVariants; | this.context = Context.EntitySearchModalWithNameVariants; | |||
this.repeatable = false; | this.repeatable = false; | |||
this.routeData = {sourceId: '', query: ''}; | this.routeData = {entity: '', sourceId: '', query: ''}; | |||
this.importConfig = { | this.importConfig = { | |||
buttonLabel: 'submission.sections.describe.relationship-lookup.external-so urce.import-button-title.' + this.label | buttonLabel: 'submission.sections.describe.relationship-lookup.external-so urce.import-button-title.' + this.label | |||
}; | }; | |||
this.entriesRD$ = new BehaviorSubject(createSuccessfulRemoteDataObject(build PaginatedList(new PageInfo(), []))); | this.entriesRD$ = new BehaviorSubject(createSuccessfulRemoteDataObject(build PaginatedList(new PageInfo(), []))); | |||
this.isLoading$ = new BehaviorSubject(false); | this.isLoading$ = new BehaviorSubject(false); | |||
this.subs.push(combineLatest( | this.subs.push(combineLatest( | |||
[ | [ | |||
this.routeService.getQueryParameterValue('source'), | this.routeService.getQueryParameterValue('entity'), | |||
this.routeService.getQueryParameterValue('sourceId'), | ||||
this.routeService.getQueryParameterValue('query') | this.routeService.getQueryParameterValue('query') | |||
]).pipe( | ]).pipe( | |||
take(1) | take(1) | |||
).subscribe(([source, query]: [string, string]) => { | ).subscribe(([entity, sourceId, query]: [string, string, string]) => { | |||
this.reload$.next({query: query, source: source}); | this.reload$.next({entity: entity || NONE_ENTITY_TYPE, query: query, sourc | |||
eId: sourceId}); | ||||
this.selectLabel(entity); | ||||
this.retrieveExternalSources(); | this.retrieveExternalSources(); | |||
})); | })); | |||
} | } | |||
/** | /** | |||
* Get the data from the searchbar and changes the router data. | * Get the data from the searchbar and changes the router data. | |||
*/ | */ | |||
public getExternalSourceData(event: ExternalSourceData): void { | public getExternalSourceData(event: ExternalSourceData): void { | |||
this.router.navigate( | this.router.navigate( | |||
[], | [], | |||
{ | { | |||
queryParams: {source: event.sourceId, query: event.query}, | queryParams: event, | |||
replaceUrl: true | replaceUrl: true | |||
} | } | |||
).then(() => { | ).then(() => { | |||
this.reload$.next({source: event.sourceId, query: event.query}); | this.reload$.next(event); | |||
this.retrieveExternalSources(); | this.retrieveExternalSources(); | |||
}); | }); | |||
} | } | |||
/** | /** | |||
* Display an item preview by opening up an import modal window. | * Display an item preview by opening up an import modal window. | |||
* @param entry The entry to import | * @param entry The entry to import | |||
*/ | */ | |||
public import(entry): void { | public import(entry): void { | |||
this.modalRef = this.modalService.open(SubmissionImportExternalPreviewCompon ent, { | this.modalRef = this.modalService.open(SubmissionImportExternalPreviewCompon ent, { | |||
size: 'lg', | size: 'lg', | |||
}); | }); | |||
const modalComp = this.modalRef.componentInstance; | const modalComp = this.modalRef.componentInstance; | |||
modalComp.externalSourceEntry = entry; | modalComp.externalSourceEntry = entry; | |||
modalComp.labelPrefix = this.label; | ||||
} | } | |||
/** | /** | |||
* Unsubscribe from all subscriptions | * Unsubscribe from all subscriptions | |||
*/ | */ | |||
ngOnDestroy(): void { | ngOnDestroy(): void { | |||
this.subs | this.subs | |||
.filter((sub) => hasValue(sub)) | .filter((sub) => hasValue(sub)) | |||
.forEach((sub) => sub.unsubscribe()); | .forEach((sub) => sub.unsubscribe()); | |||
if (hasValue(this.retrieveExternalSourcesSub)) { | if (hasValue(this.retrieveExternalSourcesSub)) { | |||
this.retrieveExternalSourcesSub.unsubscribe(); | this.retrieveExternalSourcesSub.unsubscribe(); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Retrieve external source entries | * Retrieve external source entries. | |||
* | ||||
* @param source The source tupe | ||||
* @param query The query string to search | ||||
*/ | */ | |||
private retrieveExternalSources(): void { | private retrieveExternalSources(): void { | |||
if (hasValue(this.retrieveExternalSourcesSub)) { | if (hasValue(this.retrieveExternalSourcesSub)) { | |||
this.retrieveExternalSourcesSub.unsubscribe(); | this.retrieveExternalSourcesSub.unsubscribe(); | |||
} | } | |||
this.retrieveExternalSourcesSub = this.reload$.pipe( | this.retrieveExternalSourcesSub = this.reload$.pipe( | |||
filter((sourceQueryObject: { source: string, query: string }) => isNotEmpt | filter((sourceQueryObject: ExternalSourceData) => isNotEmpty(sourceQueryOb | |||
y(sourceQueryObject.source) && isNotEmpty(sourceQueryObject.query)), | ject.sourceId) && isNotEmpty(sourceQueryObject.query)), | |||
switchMap((sourceQueryObject: { source: string, query: string }) => { | switchMap((sourceQueryObject: ExternalSourceData) => { | |||
const source = sourceQueryObject.source; | ||||
const query = sourceQueryObject.query; | const query = sourceQueryObject.query; | |||
this.routeData.sourceId = source; | this.routeData = sourceQueryObject; | |||
this.routeData.query = query; | ||||
return this.searchConfigService.paginatedSearchOptions.pipe( | return this.searchConfigService.paginatedSearchOptions.pipe( | |||
tap((v) => this.isLoading$.next(true)), | tap(() => this.isLoading$.next(true)), | |||
filter((searchOptions) => searchOptions.query === query), | filter((searchOptions) => searchOptions.query === query), | |||
mergeMap((searchOptions) => this.externalService.getExternalSourceEn tries(this.routeData.sourceId, searchOptions).pipe( | mergeMap((searchOptions) => this.externalService.getExternalSourceEn tries(this.routeData.sourceId, searchOptions).pipe( | |||
getFinishedRemoteData(), | getFinishedRemoteData(), | |||
)), | )) | |||
); | ); | |||
} | } | |||
), | ), | |||
).subscribe((rdData) => { | ).subscribe((rdData) => { | |||
this.entriesRD$.next(rdData); | this.entriesRD$.next(rdData); | |||
this.isLoading$.next(false); | this.isLoading$.next(false); | |||
}); | }); | |||
} | } | |||
/** | ||||
* Set the correct button label, depending on the entity. | ||||
* | ||||
* @param entity The entity name | ||||
*/ | ||||
private selectLabel(entity: string): void { | ||||
this.label = entity; | ||||
this.importConfig = { | ||||
buttonLabel: 'submission.sections.describe.relationship-lookup.external-so | ||||
urce.import-button-title.' + this.label | ||||
}; | ||||
} | ||||
} | } | |||
End of changes. 16 change blocks. | ||||
22 lines changed or deleted | 35 lines changed or added |