mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
61142: Renaming and refactoring item-relationships
This commit is contained in:
@@ -24,7 +24,8 @@ export abstract class AbstractItemUpdateComponent implements OnInit {
|
||||
*/
|
||||
protected item: Item;
|
||||
/**
|
||||
* The current values and updates for all this item's metadata fields
|
||||
* The current values and updates for all this item's fields
|
||||
* Should be initialized in the initializeUpdates method of the child component
|
||||
*/
|
||||
protected updates$: Observable<FieldUpdates>;
|
||||
/**
|
||||
@@ -33,6 +34,7 @@ export abstract class AbstractItemUpdateComponent implements OnInit {
|
||||
protected url: string;
|
||||
/**
|
||||
* Prefix for this component's notification translate keys
|
||||
* Should be initialized in the initializeNotificationsPrefix method of the child component
|
||||
*/
|
||||
protected notificationsPrefix;
|
||||
/**
|
||||
@@ -78,8 +80,14 @@ export abstract class AbstractItemUpdateComponent implements OnInit {
|
||||
});
|
||||
|
||||
this.initializeNotificationsPrefix();
|
||||
this.initializeUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the values and updates of the current item's fields
|
||||
*/
|
||||
abstract initializeUpdates(): void;
|
||||
|
||||
/**
|
||||
* Initialize the prefix for notification messages
|
||||
*/
|
||||
|
@@ -16,7 +16,7 @@ import { ItemMetadataComponent } from './item-metadata/item-metadata.component';
|
||||
import { EditInPlaceFieldComponent } from './item-metadata/edit-in-place-field/edit-in-place-field.component';
|
||||
import { ItemBitstreamsComponent } from './item-bitstreams/item-bitstreams.component';
|
||||
import { ItemRelationshipsComponent } from './item-relationships/item-relationships.component';
|
||||
import { EditInPlaceRelationshipComponent } from './item-relationships/edit-in-place-relationship/edit-in-place-relationship.component';
|
||||
import { EditRelationshipComponent } from './item-relationships/edit-relationship/edit-relationship.component';
|
||||
|
||||
/**
|
||||
* Module that contains all components related to the Edit Item page administrator functionality
|
||||
@@ -42,7 +42,7 @@ import { EditInPlaceRelationshipComponent } from './item-relationships/edit-in-p
|
||||
ItemRelationshipsComponent,
|
||||
ItemBitstreamsComponent,
|
||||
EditInPlaceFieldComponent,
|
||||
EditInPlaceRelationshipComponent
|
||||
EditRelationshipComponent
|
||||
]
|
||||
})
|
||||
export class EditItemPageModule {
|
||||
|
@@ -54,6 +54,12 @@ export class ItemMetadataComponent extends AbstractItemUpdateComponent {
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.metadataFields$ = this.findMetadataFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the values and updates of the current item's metadata fields
|
||||
*/
|
||||
public initializeUpdates(): void {
|
||||
this.updates$ = this.objectUpdatesService.getFieldUpdates(this.url, this.item.metadataAsList);
|
||||
}
|
||||
|
||||
|
@@ -5,16 +5,14 @@ import { Item } from '../../../../core/shared/item.model';
|
||||
import { VIEW_MODE_ELEMENT } from '../../../simple/related-items/related-items-component';
|
||||
import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service';
|
||||
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
// tslint:disable-next-line:component-selector
|
||||
selector: '[ds-edit-in-place-relationship]',
|
||||
styleUrls: ['./edit-in-place-relationship.component.scss'],
|
||||
templateUrl: './edit-in-place-relationship.component.html',
|
||||
selector: '[ds-edit-relationship]',
|
||||
styleUrls: ['./edit-relationship.component.scss'],
|
||||
templateUrl: './edit-relationship.component.html',
|
||||
})
|
||||
export class EditInPlaceRelationshipComponent implements OnChanges {
|
||||
export class EditRelationshipComponent implements OnChanges {
|
||||
/**
|
||||
* The current field, value and state of the relationship
|
||||
*/
|
||||
@@ -45,18 +43,30 @@ export class EditInPlaceRelationshipComponent implements OnChanges {
|
||||
this.item = cloneDeep(this.fieldUpdate.field) as Item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a new remove update for this field to the object updates service
|
||||
*/
|
||||
remove(): void {
|
||||
this.objectUpdatesService.saveRemoveFieldUpdate(this.url, this.item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the current update for this field in the object updates service
|
||||
*/
|
||||
undo(): void {
|
||||
this.objectUpdatesService.removeSingleFieldUpdate(this.url, this.item.uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user should be allowed to remove this field
|
||||
*/
|
||||
canRemove(): boolean {
|
||||
return this.fieldUpdate.changeType !== FieldChangeType.REMOVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user should be allowed to cancel the update to this field
|
||||
*/
|
||||
canUndo(): boolean {
|
||||
return this.fieldUpdate.changeType >= 0;
|
||||
}
|
@@ -20,7 +20,7 @@
|
||||
<div *ngFor="let label of relationLabels$ | async" class="mb-2">
|
||||
<h5>{{label}}</h5>
|
||||
<div *ngFor="let updateValue of ((getUpdatesByLabel(label) | async)| dsObjectValues); trackBy: trackUpdate"
|
||||
ds-edit-in-place-relationship
|
||||
ds-edit-relationship
|
||||
[fieldUpdate]="updateValue || {}"
|
||||
[url]="url"
|
||||
[ngClass]="{
|
||||
|
@@ -38,13 +38,11 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
*/
|
||||
resolvedRelsAndTypes$: Observable<[Relationship[], RelationshipType[]]>;
|
||||
|
||||
/**
|
||||
* Set up and initialize all fields
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
|
||||
this.updates$ = this.getRelationships().pipe(
|
||||
relationsToItems(this.item.id, this.itemService),
|
||||
switchMap((items: Item[]) => this.objectUpdatesService.getFieldUpdates(this.url, items))
|
||||
);
|
||||
this.initRelationshipObservables();
|
||||
}
|
||||
|
||||
@@ -72,6 +70,16 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the values and updates of the current item's relationship fields
|
||||
*/
|
||||
public initializeUpdates(): void {
|
||||
this.updates$ = this.getRelationships().pipe(
|
||||
relationsToItems(this.item.id, this.itemService),
|
||||
switchMap((items: Item[]) => this.objectUpdatesService.getFieldUpdates(this.url, items))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the prefix for notification messages
|
||||
*/
|
||||
|
Reference in New Issue
Block a user