mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
63669: Content Source valid check + JSDocs
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
class="fas fa-undo-alt"></i>
|
class="fas fa-undo-alt"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary" [disabled]="!(hasChanges() | async)"
|
<button class="btn btn-primary" [disabled]="!(hasChanges() | async) || !isValid()"
|
||||||
(click)="onSubmit()"><i
|
(click)="onSubmit()"><i
|
||||||
class="fas fa-save"></i>
|
class="fas fa-save"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
class="fas fa-undo-alt"></i>
|
class="fas fa-undo-alt"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.reinstate-button" | translate}}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary" [disabled]="!(hasChanges() | async)"
|
<button class="btn btn-primary" [disabled]="!(hasChanges() | async) || !isValid()"
|
||||||
(click)="onSubmit()"><i
|
(click)="onSubmit()"><i
|
||||||
class="fas fa-save"></i>
|
class="fas fa-save"></i>
|
||||||
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
<span class="d-none d-sm-inline"> {{"item.edit.metadata.save-button" | translate}}</span>
|
||||||
|
@@ -194,6 +194,9 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
super(objectUpdatesService, notificationsService, translate);
|
super(objectUpdatesService, notificationsService, translate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize properties to setup the Field Update and Form
|
||||||
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.notificationsPrefix = 'collection.edit.tabs.source.notifications.';
|
this.notificationsPrefix = 'collection.edit.tabs.source.notifications.';
|
||||||
this.discardTimeOut = this.EnvConfig.collection.edit.undoTimeout;
|
this.discardTimeOut = this.EnvConfig.collection.edit.undoTimeout;
|
||||||
@@ -216,6 +219,9 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
this.initializeOriginalContentSource();
|
this.initializeOriginalContentSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the Field Update and subscribe on it to fire updates to the form whenever it changes
|
||||||
|
*/
|
||||||
initializeOriginalContentSource() {
|
initializeOriginalContentSource() {
|
||||||
const initialContentSource = cloneDeep(this.contentSource);
|
const initialContentSource = cloneDeep(this.contentSource);
|
||||||
this.objectUpdatesService.initialize(this.url, [initialContentSource], new Date());
|
this.objectUpdatesService.initialize(this.url, [initialContentSource], new Date());
|
||||||
@@ -272,21 +278,41 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired whenever the form receives an update and makes sure the Content Source and field update is up-to-date with the changes
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
onChange(event) {
|
onChange(event) {
|
||||||
this.updateContentSourceField(event.model);
|
this.updateContentSourceField(event.model);
|
||||||
this.saveFieldUpdate();
|
this.saveFieldUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit the edited Content Source to the REST API, re-initialize the field update and display a notification
|
||||||
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
// TODO: Fetch field update and send to REST API
|
// TODO: Fetch field update and send to REST API
|
||||||
this.initializeOriginalContentSource();
|
this.initializeOriginalContentSource();
|
||||||
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
|
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the edit and return to the previous page
|
||||||
|
*/
|
||||||
onCancel() {
|
onCancel() {
|
||||||
this.location.back();
|
this.location.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the current form valid to be submitted ?
|
||||||
|
*/
|
||||||
|
isValid(): boolean {
|
||||||
|
return !this.contentSource.enabled || this.formGroup.valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch the external source on or off and fire a field update
|
||||||
|
*/
|
||||||
changeExternalSource() {
|
changeExternalSource() {
|
||||||
this.contentSource.enabled = !this.contentSource.enabled;
|
this.contentSource.enabled = !this.contentSource.enabled;
|
||||||
this.updateContentSource();
|
this.updateContentSource();
|
||||||
@@ -303,6 +329,9 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loop over all inputs and update the Content Source with their value
|
||||||
|
*/
|
||||||
updateContentSource() {
|
updateContentSource() {
|
||||||
this.formModel.forEach(
|
this.formModel.forEach(
|
||||||
(fieldModel: DynamicFormGroupModel | DynamicInputModel) => {
|
(fieldModel: DynamicFormGroupModel | DynamicInputModel) => {
|
||||||
@@ -318,16 +347,26 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
this.saveFieldUpdate();
|
this.saveFieldUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the Content Source with the value from a DynamicInputModel
|
||||||
|
* @param fieldModel
|
||||||
|
*/
|
||||||
updateContentSourceField(fieldModel: DynamicInputModel) {
|
updateContentSourceField(fieldModel: DynamicInputModel) {
|
||||||
if (hasValue(fieldModel)) {
|
if (hasValue(fieldModel.value)) {
|
||||||
this.contentSource[fieldModel.id] = fieldModel.value;
|
this.contentSource[fieldModel.id] = fieldModel.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the current Content Source to the Object Updates cache
|
||||||
|
*/
|
||||||
saveFieldUpdate() {
|
saveFieldUpdate() {
|
||||||
this.objectUpdatesService.saveAddFieldUpdate(this.url, cloneDeep(this.contentSource));
|
this.objectUpdatesService.saveAddFieldUpdate(this.url, cloneDeep(this.contentSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure open subscriptions are closed
|
||||||
|
*/
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.updateSub.unsubscribe();
|
this.updateSub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model class that holds information about the Content Source of a Collection
|
||||||
|
*/
|
||||||
export class ContentSource {
|
export class ContentSource {
|
||||||
/**
|
/**
|
||||||
* Unique identifier
|
* Unique identifier
|
||||||
@@ -32,6 +35,7 @@ export class ContentSource {
|
|||||||
harvest = 3;
|
harvest = 3;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// TODO: Remove this once the Content Source is fetched from the REST API and a custom generated UUID is not necessary anymore
|
||||||
this.uuid = uuid();
|
this.uuid = uuid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user