dynamic-lookup-relation-modal.component.ts (dspace-angular-dspace-7.0) | : | dynamic-lookup-relation-modal.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 15 | skipping to change at line 15 | |||
import { map, skip, switchMap, take } from 'rxjs/operators'; | import { map, skip, switchMap, take } from 'rxjs/operators'; | |||
import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-p age.component'; | import { SEARCH_CONFIG_SERVICE } from '../../../../../my-dspace-page/my-dspace-p age.component'; | |||
import { SearchConfigurationService } from '../../../../../core/shared/search/se arch-configuration.service'; | import { SearchConfigurationService } from '../../../../../core/shared/search/se arch-configuration.service'; | |||
import { SelectableListService } from '../../../../object-list/selectable-list/s electable-list.service'; | import { SelectableListService } from '../../../../object-list/selectable-list/s electable-list.service'; | |||
import { SelectableListState } from '../../../../object-list/selectable-list/sel ectable-list.reducer'; | import { SelectableListState } from '../../../../object-list/selectable-list/sel ectable-list.reducer'; | |||
import { ListableObject } from '../../../../object-collection/shared/listable-ob ject.model'; | import { ListableObject } from '../../../../object-collection/shared/listable-ob ject.model'; | |||
import { RelationshipOptions } from '../../models/relationship-options.model'; | import { RelationshipOptions } from '../../models/relationship-options.model'; | |||
import { SearchResult } from '../../../../search/search-result.model'; | import { SearchResult } from '../../../../search/search-result.model'; | |||
import { Item } from '../../../../../core/shared/item.model'; | import { Item } from '../../../../../core/shared/item.model'; | |||
import { | import { | |||
AddRelationshipAction, RemoveRelationshipAction, UpdateRelationshipNameVariant | AddRelationshipAction, | |||
Action, | RemoveRelationshipAction, | |||
UpdateRelationshipNameVariantAction, | ||||
} from './relationship.actions'; | } from './relationship.actions'; | |||
import { RelationshipService } from '../../../../../core/data/relationship.servi ce'; | import { RelationshipService } from '../../../../../core/data/relationship.servi ce'; | |||
import { RelationshipTypeService } from '../../../../../core/data/relationship-t ype.service'; | import { RelationshipTypeService } from '../../../../../core/data/relationship-t ype.service'; | |||
import { Store } from '@ngrx/store'; | import { Store } from '@ngrx/store'; | |||
import { AppState } from '../../../../../app.reducer'; | import { AppState } from '../../../../../app.reducer'; | |||
import { Context } from '../../../../../core/shared/context.model'; | import { Context } from '../../../../../core/shared/context.model'; | |||
import { LookupRelationService } from '../../../../../core/data/lookup-relation. service'; | import { LookupRelationService } from '../../../../../core/data/lookup-relation. service'; | |||
import { ExternalSource } from '../../../../../core/shared/external-source.model '; | import { ExternalSource } from '../../../../../core/shared/external-source.model '; | |||
import { ExternalSourceService } from '../../../../../core/data/external-source. service'; | import { ExternalSourceService } from '../../../../../core/data/external-source. service'; | |||
import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | |||
import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot e-data-build.service'; | import { RemoteDataBuildService } from '../../../../../core/cache/builders/remot e-data-build.service'; | |||
import { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/ope rators'; | import { getAllSucceededRemoteDataPayload } from '../../../../../core/shared/ope rators'; | |||
import { followLink } from '../../../../utils/follow-link-config.model'; | ||||
import { RelationshipType } from '../../../../../core/shared/item-relationships/ | ||||
relationship-type.model'; | ||||
@Component({ | @Component({ | |||
selector: 'ds-dynamic-lookup-relation-modal', | selector: 'ds-dynamic-lookup-relation-modal', | |||
styleUrls: ['./dynamic-lookup-relation-modal.component.scss'], | styleUrls: ['./dynamic-lookup-relation-modal.component.scss'], | |||
templateUrl: './dynamic-lookup-relation-modal.component.html', | templateUrl: './dynamic-lookup-relation-modal.component.html', | |||
providers: [ | providers: [ | |||
{ | { | |||
provide: SEARCH_CONFIG_SERVICE, | provide: SEARCH_CONFIG_SERVICE, | |||
useClass: SearchConfigurationService | useClass: SearchConfigurationService | |||
} | } | |||
skipping to change at line 117 | skipping to change at line 121 | |||
/** | /** | |||
* The total amount of internal items for the current options | * The total amount of internal items for the current options | |||
*/ | */ | |||
totalInternal$: Observable<number>; | totalInternal$: Observable<number>; | |||
/** | /** | |||
* The total amount of results for each external source using the current opti ons | * The total amount of results for each external source using the current opti ons | |||
*/ | */ | |||
totalExternal$: Observable<number[]>; | totalExternal$: Observable<number[]>; | |||
/** | ||||
* The type of relationship | ||||
*/ | ||||
relationshipType: RelationshipType; | ||||
/** | ||||
* Checks if relationship is left | ||||
*/ | ||||
currentItemIsLeftItem$: Observable<boolean>; | ||||
/** | ||||
* Relationship is left | ||||
*/ | ||||
isLeft = false; | ||||
/** | ||||
* Checks if modal is being used by edit relationship page | ||||
*/ | ||||
isEditRelationship = false; | ||||
/** | ||||
* Maintain the list of the related items to be added | ||||
*/ | ||||
toAdd = []; | ||||
/** | ||||
* Maintain the list of the related items to be removed | ||||
*/ | ||||
toRemove = []; | ||||
/** | ||||
* Disable buttons while the submit button is pressed | ||||
*/ | ||||
isPending = false; | ||||
constructor( | constructor( | |||
public modal: NgbActiveModal, | public modal: NgbActiveModal, | |||
private selectableListService: SelectableListService, | private selectableListService: SelectableListService, | |||
private relationshipService: RelationshipService, | private relationshipService: RelationshipService, | |||
private relationshipTypeService: RelationshipTypeService, | private relationshipTypeService: RelationshipTypeService, | |||
private externalSourceService: ExternalSourceService, | private externalSourceService: ExternalSourceService, | |||
private lookupRelationService: LookupRelationService, | private lookupRelationService: LookupRelationService, | |||
private searchConfigService: SearchConfigurationService, | private searchConfigService: SearchConfigurationService, | |||
private rdbService: RemoteDataBuildService, | private rdbService: RemoteDataBuildService, | |||
private zone: NgZone, | private zone: NgZone, | |||
private store: Store<AppState>, | private store: Store<AppState>, | |||
private router: Router, | private router: Router, | |||
) { | ) { | |||
} | } | |||
ngOnInit(): void { | ngOnInit(): void { | |||
if (!!this.currentItemIsLeftItem$) { | ||||
this.currentItemIsLeftItem$.subscribe((isLeft) => { | ||||
this.isLeft = isLeft; | ||||
}); | ||||
} | ||||
this.selection$ = this.selectableListService | this.selection$ = this.selectableListService | |||
.getSelectableList(this.listId) | .getSelectableList(this.listId) | |||
.pipe(map((listState: SelectableListState) => hasValue(listState) && hasVa lue(listState.selection) ? listState.selection : [])); | .pipe(map((listState: SelectableListState) => hasValue(listState) && hasVa lue(listState.selection) ? listState.selection : [])); | |||
this.selection$.pipe(take(1)).subscribe((selection) => | this.selection$.pipe(take(1)).subscribe((selection) => | |||
selection.map((s: SearchResult<Item>) => this.addNameVariantSubscription(s )) | selection.map((s: SearchResult<Item>) => this.addNameVariantSubscription(s )) | |||
); | ); | |||
if (this.relationshipOptions.nameVariants === 'true') { | if (this.relationshipOptions.nameVariants === 'true') { | |||
this.context = Context.EntitySearchModalWithNameVariants; | this.context = Context.EntitySearchModalWithNameVariants; | |||
} else { | } else { | |||
this.context = Context.EntitySearchModal; | this.context = Context.EntitySearchModal; | |||
} | } | |||
if (isNotEmpty(this.relationshipOptions.externalSources)) { | if (isNotEmpty(this.relationshipOptions.externalSources)) { | |||
this.externalSourcesRD$ = this.rdbService.aggregate( | this.externalSourcesRD$ = this.rdbService.aggregate( | |||
this.relationshipOptions.externalSources.map((source) => this.externalSo | this.relationshipOptions.externalSources.map((source) => { | |||
urceService.findById(source)) | return this.externalSourceService.findById( | |||
source, | ||||
true, | ||||
true, | ||||
followLink('entityTypes') | ||||
); | ||||
}) | ||||
).pipe( | ).pipe( | |||
getAllSucceededRemoteDataPayload() | getAllSucceededRemoteDataPayload() | |||
); | ); | |||
} | } | |||
this.setTotals(); | this.setTotals(); | |||
} | } | |||
close() { | close() { | |||
this.toAdd = []; | ||||
this.toRemove = []; | ||||
this.modal.close(); | this.modal.close(); | |||
} | } | |||
/** | /** | |||
* Select (a list of) objects and add them to the store | * Select (a list of) objects and add them to the store | |||
* @param selectableObjects | * @param selectableObjects | |||
*/ | */ | |||
select(...selectableObjects: SearchResult<Item>[]) { | select(...selectableObjects: SearchResult<Item>[]) { | |||
this.zone.runOutsideAngular( | this.zone.runOutsideAngular( | |||
() => { | () => { | |||
skipping to change at line 249 | skipping to change at line 303 | |||
this.totalExternal$ = externalSourcesAndOptions$.pipe( | this.totalExternal$ = externalSourcesAndOptions$.pipe( | |||
switchMap(([sources, options]) => | switchMap(([sources, options]) => | |||
observableCombineLatest(...sources.map((source: ExternalSource) => this. lookupRelationService.getTotalExternalResults(source, options)))) | observableCombineLatest(...sources.map((source: ExternalSource) => this. lookupRelationService.getTotalExternalResults(source, options)))) | |||
); | ); | |||
} | } | |||
ngOnDestroy() { | ngOnDestroy() { | |||
this.router.navigate([], {}); | this.router.navigate([], {}); | |||
Object.values(this.subMap).forEach((subscription) => subscription.unsubscrib e()); | Object.values(this.subMap).forEach((subscription) => subscription.unsubscrib e()); | |||
} | } | |||
/* tslint:disable:no-empty */ | ||||
/** | ||||
* Called when discard button is clicked, emit discard event to parent to conc | ||||
lude functionality | ||||
*/ | ||||
discardEv(): void { | ||||
} | ||||
/** | ||||
* Called when submit button is clicked, emit submit event to parent to conclu | ||||
de functionality | ||||
*/ | ||||
submitEv(): void { | ||||
} | ||||
/* tslint:enable:no-empty */ | ||||
} | } | |||
End of changes. 7 change blocks. | ||||
4 lines changed or deleted | 74 lines changed or added |