item-relationships.component.ts (dspace-angular-dspace-7.0) | : | item-relationships.component.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
import { ChangeDetectorRef, Component } from '@angular/core'; | import { ChangeDetectorRef, Component } from '@angular/core'; | |||
import { Item } from '../../../core/shared/item.model'; | import { Item } from '../../../core/shared/item.model'; | |||
import { | import { | |||
DeleteRelationship, | DeleteRelationship, | |||
FieldUpdate, | FieldUpdate, | |||
FieldUpdates, | FieldUpdates, | |||
RelationshipIdentifiable, | RelationshipIdentifiable, | |||
} from '../../../core/data/object-updates/object-updates.reducer'; | } from '../../../core/data/object-updates/object-updates.reducer'; | |||
import { Observable } from 'rxjs/internal/Observable'; | import { Observable } from 'rxjs/internal/Observable'; | |||
import { map, startWith, switchMap, take } from 'rxjs/operators'; | import { map, startWith, switchMap, take } from 'rxjs/operators'; | |||
import { | import { combineLatest as observableCombineLatest, of as observableOf, zip as ob | |||
combineLatest as observableCombineLatest, | servableZip } from 'rxjs'; | |||
of as observableOf, | ||||
zip as observableZip | ||||
} from 'rxjs'; | ||||
import { followLink } from '../../../shared/utils/follow-link-config.model'; | import { followLink } from '../../../shared/utils/follow-link-config.model'; | |||
import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-it em-update.component'; | import { AbstractItemUpdateComponent } from '../abstract-item-update/abstract-it em-update.component'; | |||
import { ItemDataService } from '../../../core/data/item-data.service'; | import { ItemDataService } from '../../../core/data/item-data.service'; | |||
import { ObjectUpdatesService } from '../../../core/data/object-updates/object-u pdates.service'; | import { ObjectUpdatesService } from '../../../core/data/object-updates/object-u pdates.service'; | |||
import { ActivatedRoute, Router } from '@angular/router'; | import { ActivatedRoute, Router } from '@angular/router'; | |||
import { NotificationsService } from '../../../shared/notifications/notification s.service'; | import { NotificationsService } from '../../../shared/notifications/notification s.service'; | |||
import { TranslateService } from '@ngx-translate/core'; | import { TranslateService } from '@ngx-translate/core'; | |||
import { RelationshipService } from '../../../core/data/relationship.service'; | import { RelationshipService } from '../../../core/data/relationship.service'; | |||
import { RemoteData } from '../../../core/data/remote-data'; | import { RemoteData } from '../../../core/data/remote-data'; | |||
import { ObjectCacheService } from '../../../core/cache/object-cache.service'; | import { ObjectCacheService } from '../../../core/cache/object-cache.service'; | |||
import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../core /shared/operators'; | import { getFirstSucceededRemoteData, getRemoteDataPayload } from '../../../core /shared/operators'; | |||
import { RequestService } from '../../../core/data/request.service'; | import { RequestService } from '../../../core/data/request.service'; | |||
import { RelationshipType } from '../../../core/shared/item-relationships/relati onship-type.model'; | import { RelationshipType } from '../../../core/shared/item-relationships/relati onship-type.model'; | |||
import { ItemType } from '../../../core/shared/item-relationships/item-type.mode l'; | import { ItemType } from '../../../core/shared/item-relationships/item-type.mode l'; | |||
import { EntityTypeService } from '../../../core/data/entity-type.service'; | import { EntityTypeService } from '../../../core/data/entity-type.service'; | |||
import { FieldChangeType } from '../../../core/data/object-updates/object-update s.actions'; | import { FieldChangeType } from '../../../core/data/object-updates/object-update s.actions'; | |||
import { Relationship } from '../../../core/shared/item-relationships/relationsh ip.model'; | import { Relationship } from '../../../core/shared/item-relationships/relationsh ip.model'; | |||
import { NoContent } from '../../../core/shared/NoContent.model'; | import { NoContent } from '../../../core/shared/NoContent.model'; | |||
import { hasValue } from '../../../shared/empty.util'; | import { hasValue } from '../../../shared/empty.util'; | |||
import { RelationshipTypeService } from '../../../core/data/relationship-type.se | ||||
rvice'; | ||||
import { PaginatedList } from '../../../core/data/paginated-list.model'; | ||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||||
@Component({ | @Component({ | |||
selector: 'ds-item-relationships', | selector: 'ds-item-relationships', | |||
styleUrls: ['./item-relationships.component.scss'], | styleUrls: ['./item-relationships.component.scss'], | |||
templateUrl: './item-relationships.component.html', | templateUrl: './item-relationships.component.html', | |||
}) | }) | |||
/** | /** | |||
* Component for displaying an item's relationships edit page | * Component for displaying an item's relationships edit page | |||
*/ | */ | |||
export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { | export class ItemRelationshipsComponent extends AbstractItemUpdateComponent { | |||
skipping to change at line 67 | skipping to change at line 66 | |||
public itemService: ItemDataService, | public itemService: ItemDataService, | |||
public objectUpdatesService: ObjectUpdatesService, | public objectUpdatesService: ObjectUpdatesService, | |||
public router: Router, | public router: Router, | |||
public notificationsService: NotificationsService, | public notificationsService: NotificationsService, | |||
public translateService: TranslateService, | public translateService: TranslateService, | |||
public route: ActivatedRoute, | public route: ActivatedRoute, | |||
public relationshipService: RelationshipService, | public relationshipService: RelationshipService, | |||
public objectCache: ObjectCacheService, | public objectCache: ObjectCacheService, | |||
public requestService: RequestService, | public requestService: RequestService, | |||
public entityTypeService: EntityTypeService, | public entityTypeService: EntityTypeService, | |||
protected relationshipTypeService: RelationshipTypeService, | ||||
public cdr: ChangeDetectorRef, | public cdr: ChangeDetectorRef, | |||
protected modalService: NgbModal, | ||||
) { | ) { | |||
super(itemService, objectUpdatesService, router, notificationsService, trans lateService, route); | super(itemService, objectUpdatesService, router, notificationsService, trans lateService, route); | |||
} | } | |||
/** | /** | |||
* Initialize the values and updates of the current item's relationship fields | * Initialize the values and updates of the current item's relationship fields | |||
*/ | */ | |||
public initializeUpdates(): void { | public initializeUpdates(): void { | |||
const label = this.item.firstMetadataValue('dspace.entity.type'); | const label = this.item.firstMetadataValue('dspace.entity.type'); | |||
if (label !== undefined) { | if (label !== undefined) { | |||
this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType( | ||||
label, true, true, ...this.getRelationshipTypeFollowLinks()) | ||||
.pipe( | ||||
map((relationshipTypes: PaginatedList<RelationshipType>) => relationship | ||||
Types.page) | ||||
); | ||||
this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe ( | this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe ( | |||
getFirstSucceededRemoteData(), | getFirstSucceededRemoteData(), | |||
getRemoteDataPayload(), | getRemoteDataPayload(), | |||
); | ); | |||
this.relationshipTypes$ = this.entityType$.pipe( | ||||
switchMap((entityType) => | ||||
this.entityTypeService.getEntityTypeRelationships( | ||||
entityType.id, | ||||
true, | ||||
true, | ||||
followLink('leftType'), | ||||
followLink('rightType')) | ||||
.pipe( | ||||
getFirstSucceededRemoteData(), | ||||
getRemoteDataPayload(), | ||||
map((relationshipTypes) => relationshipTypes.page), | ||||
) | ||||
), | ||||
); | ||||
} else { | } else { | |||
this.entityType$ = observableOf(undefined); | this.entityType$ = observableOf(undefined); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Initialize the prefix for notification messages | * Initialize the prefix for notification messages | |||
*/ | */ | |||
public initializeNotificationsPrefix(): void { | public initializeNotificationsPrefix(): void { | |||
this.notificationsPrefix = 'item.edit.relationships.notifications.'; | this.notificationsPrefix = 'item.edit.relationships.notifications.'; | |||
skipping to change at line 159 | skipping to change at line 149 | |||
const actions = [ | const actions = [ | |||
this.deleteRelationships(removeRelationshipIDs), | this.deleteRelationships(removeRelationshipIDs), | |||
this.addRelationships(addRelatedItems), | this.addRelationships(addRelatedItems), | |||
]; | ]; | |||
actions.forEach((action) => | actions.forEach((action) => | |||
action.subscribe((response) => { | action.subscribe((response) => { | |||
if (response.length > 0) { | if (response.length > 0) { | |||
this.initializeOriginalFields(); | this.initializeOriginalFields(); | |||
this.cdr.detectChanges(); | this.cdr.detectChanges(); | |||
this.displayNotifications(response); | this.displayNotifications(response); | |||
this.modalService.dismissAll(); | ||||
} | } | |||
}) | }) | |||
); | ); | |||
}); | }); | |||
} | } | |||
deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<R emoteData<NoContent>[]> { | deleteRelationships(deleteRelationshipIDs: DeleteRelationship[]): Observable<R emoteData<NoContent>[]> { | |||
return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => { | return observableZip(...deleteRelationshipIDs.map((deleteRelationship) => { | |||
let copyVirtualMetadata: string; | let copyVirtualMetadata: string; | |||
if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.kee pRightVirtualMetadata) { | if (deleteRelationship.keepLeftVirtualMetadata && deleteRelationship.kee pRightVirtualMetadata) { | |||
skipping to change at line 235 | skipping to change at line 226 | |||
/** | /** | |||
* Sends all initial values of this item to the object updates service | * Sends all initial values of this item to the object updates service | |||
*/ | */ | |||
public initializeOriginalFields() { | public initializeOriginalFields() { | |||
return this.relationshipService.getRelatedItems(this.item).pipe( | return this.relationshipService.getRelatedItems(this.item).pipe( | |||
take(1), | take(1), | |||
).subscribe((items: Item[]) => { | ).subscribe((items: Item[]) => { | |||
this.objectUpdatesService.initialize(this.url, items, this.item.lastModifi ed); | this.objectUpdatesService.initialize(this.url, items, this.item.lastModifi ed); | |||
}); | }); | |||
} | } | |||
getRelationshipTypeFollowLinks() { | ||||
return [ | ||||
followLink('leftType'), | ||||
followLink('rightType') | ||||
]; | ||||
} | ||||
} | } | |||
End of changes. 8 change blocks. | ||||
20 lines changed or deleted | 23 lines changed or added |