mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
Added more comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectorRef, Component, Input, OnChanges, ViewChild } from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
|
||||
import { WorkspaceitemSectionUploadFileObject } from '../../../../../core/submission/models/workspaceitem-section-upload-file.model';
|
||||
import {
|
||||
DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER,
|
||||
DynamicDateControlModel,
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
DynamicFormGroupModel,
|
||||
DynamicSelectModel
|
||||
} from '@ng-dynamic-forms/core';
|
||||
|
||||
import { WorkspaceitemSectionUploadFileObject } from '../../../../../core/submission/models/workspaceitem-section-upload-file.model';
|
||||
import { FormBuilderService } from '../../../../../shared/form/builder/form-builder.service';
|
||||
import {
|
||||
BITSTREAM_ACCESS_CONDITIONS_FORM_ARRAY_CONFIG,
|
||||
@@ -35,37 +37,113 @@ import { AccessConditionOption } from '../../../../../core/config/models/config-
|
||||
import { SubmissionService } from '../../../../submission.service';
|
||||
import { FormService } from '../../../../../shared/form/form.service';
|
||||
import { FormComponent } from '../../../../../shared/form/form.component';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { Group } from '../../../../../core/eperson/models/group.model';
|
||||
|
||||
/**
|
||||
* This component represents the edit form for bitstream
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-submission-upload-section-file-edit',
|
||||
templateUrl: './section-upload-file-edit.component.html',
|
||||
})
|
||||
export class UploadSectionFileEditComponent implements OnChanges {
|
||||
|
||||
/**
|
||||
* The list of available access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionOptions: any[];
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
@Input() collectionId;
|
||||
@Input() collectionPolicyType;
|
||||
@Input() configMetadataForm: SubmissionFormsModel;
|
||||
@Input() fileData: WorkspaceitemSectionUploadFileObject;
|
||||
@Input() fileId;
|
||||
@Input() fileIndex;
|
||||
@Input() formId;
|
||||
@Input() sectionId;
|
||||
@Input() submissionId;
|
||||
|
||||
/**
|
||||
* The list of available groups for an access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() collectionId: string;
|
||||
|
||||
/**
|
||||
* Define if collection access conditions policy type :
|
||||
* POLICY_DEFAULT_NO_LIST : is not possible to define additional access group/s for the single file
|
||||
* POLICY_DEFAULT_WITH_LIST : is possible to define additional access group/s for the single file
|
||||
* @type {number}
|
||||
*/
|
||||
@Input() collectionPolicyType: number;
|
||||
|
||||
/**
|
||||
* The configuration for the bitstream's metadata form
|
||||
* @type {SubmissionFormsModel}
|
||||
*/
|
||||
@Input() configMetadataForm: SubmissionFormsModel;
|
||||
|
||||
/**
|
||||
* The bitstream's metadata data
|
||||
* @type {WorkspaceitemSectionUploadFileObject}
|
||||
*/
|
||||
@Input() fileData: WorkspaceitemSectionUploadFileObject;
|
||||
|
||||
/**
|
||||
* The bitstream id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() fileId: string;
|
||||
|
||||
/**
|
||||
* The bitstream array key
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() fileIndex: string;
|
||||
|
||||
/**
|
||||
* The form id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() formId: string;
|
||||
|
||||
/**
|
||||
* The section id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() sectionId: string;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() submissionId: string;
|
||||
|
||||
/**
|
||||
* The form model
|
||||
* @type {DynamicFormControlModel[]}
|
||||
*/
|
||||
public formModel: DynamicFormControlModel[];
|
||||
|
||||
/**
|
||||
* The FormComponent reference
|
||||
*/
|
||||
@ViewChild('formRef') public formRef: FormComponent;
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
* @param {ChangeDetectorRef} cdr
|
||||
* @param {FormBuilderService} formBuilderService
|
||||
* @param {FormService} formService
|
||||
* @param {SubmissionService} submissionService
|
||||
*/
|
||||
constructor(private cdr: ChangeDetectorRef,
|
||||
private formBuilderService: FormBuilderService,
|
||||
private formService: FormService,
|
||||
private submissionService: SubmissionService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch form model init
|
||||
*/
|
||||
ngOnChanges() {
|
||||
if (this.fileData && this.formId) {
|
||||
this.formModel = this.buildFileEditForm();
|
||||
@@ -73,8 +151,10 @@ export class UploadSectionFileEditComponent implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize form model
|
||||
*/
|
||||
protected buildFileEditForm() {
|
||||
// TODO check in the rest server configuration whether dc.description may be repeatable
|
||||
const configDescr: FormFieldModel = Object.assign({}, this.configMetadataForm.rows[0].fields[0]);
|
||||
configDescr.repeatable = false;
|
||||
const configForm = Object.assign({}, this.configMetadataForm, {
|
||||
@@ -107,7 +187,7 @@ export class UploadSectionFileEditComponent implements OnChanges {
|
||||
}
|
||||
accessConditionTypeModelConfig.options = accessConditionTypeOptions;
|
||||
|
||||
// Dynamic assign of relation in config. For startdate, endDate, groups.
|
||||
// Dynamically assign of relation in config. For startdate, endDate, groups.
|
||||
const hasStart = [];
|
||||
const hasEnd = [];
|
||||
const hasGroups = [];
|
||||
@@ -153,6 +233,12 @@ export class UploadSectionFileEditComponent implements OnChanges {
|
||||
return formModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize form model values
|
||||
*
|
||||
* @param formModel
|
||||
* The form model
|
||||
*/
|
||||
public initModelData(formModel: DynamicFormControlModel[]) {
|
||||
this.fileData.accessConditions.forEach((accessCondition, index) => {
|
||||
Array.of('name', 'groupUUID', 'startDate', 'endDate')
|
||||
@@ -183,22 +269,36 @@ export class UploadSectionFileEditComponent implements OnChanges {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch form model update when changing an access condition
|
||||
*
|
||||
* @param formModel
|
||||
* The form model
|
||||
*/
|
||||
public onChange(event: DynamicFormControlEvent) {
|
||||
if (event.model.id === 'name') {
|
||||
this.setOptions(event.model, event.control);
|
||||
}
|
||||
}
|
||||
|
||||
public setOptions(model, control) {
|
||||
/**
|
||||
* Update `startDate`, 'groupUUID' and 'endDate' model
|
||||
*
|
||||
* @param model
|
||||
* The [[DynamicFormControlModel]] object
|
||||
* @param control
|
||||
* The [[FormControl]] object
|
||||
*/
|
||||
public setOptions(model: DynamicFormControlModel, control: FormControl) {
|
||||
let accessCondition: AccessConditionOption = null;
|
||||
this.availableAccessConditionOptions.filter((element) => element.name === control.value)
|
||||
.forEach((element) => accessCondition = element);
|
||||
if (isNotEmpty(accessCondition)) {
|
||||
const showGroups: boolean = accessCondition.hasStartDate === true || accessCondition.hasEndDate === true;
|
||||
|
||||
const groupControl: FormControl = control.parent.get('groupUUID');
|
||||
const startDateControl: FormControl = control.parent.get('startDate');
|
||||
const endDateControl: FormControl = control.parent.get('endDate');
|
||||
const groupControl: FormControl = control.parent.get('groupUUID') as FormControl;
|
||||
const startDateControl: FormControl = control.parent.get('startDate') as FormControl;
|
||||
const endDateControl: FormControl = control.parent.get('endDate') as FormControl;
|
||||
|
||||
// Clear previous state
|
||||
groupControl.markAsUntouched();
|
||||
@@ -236,8 +336,8 @@ export class UploadSectionFileEditComponent implements OnChanges {
|
||||
const confGroup = { relation: groupModel.relation };
|
||||
const groupsConfig = Object.assign({}, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_CONFIG, confGroup);
|
||||
groupsConfig.options = groupOptions;
|
||||
model.parent.group.pop();
|
||||
model.parent.group.push(new DynamicSelectModel(groupsConfig, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT));
|
||||
(model.parent as DynamicFormGroupModel).group.pop();
|
||||
(model.parent as DynamicFormGroupModel).group.push(new DynamicSelectModel(groupsConfig, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectorRef, Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
|
||||
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { BehaviorSubject, Subscription } from 'rxjs';
|
||||
import { filter, first, flatMap, take } from 'rxjs/operators';
|
||||
import { DynamicFormControlModel, } from '@ng-dynamic-forms/core';
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
@@ -23,6 +23,9 @@ import { WorkspaceitemSectionUploadObject } from '../../../../core/submission/mo
|
||||
import { UploadSectionFileEditComponent } from './edit/section-upload-file-edit.component';
|
||||
import { Group } from '../../../../core/eperson/models/group.model';
|
||||
|
||||
/**
|
||||
* This component represents a single bitstream contained in the submission
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-submission-upload-section-file',
|
||||
styleUrls: ['./section-upload-file.component.scss'],
|
||||
@@ -30,28 +33,129 @@ import { Group } from '../../../../core/eperson/models/group.model';
|
||||
})
|
||||
export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
|
||||
/**
|
||||
* The list of available access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionOptions: any[];
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
@Input() collectionId;
|
||||
@Input() collectionPolicyType;
|
||||
@Input() configMetadataForm: SubmissionFormsModel;
|
||||
@Input() fileId;
|
||||
@Input() fileIndex;
|
||||
@Input() fileName;
|
||||
@Input() sectionId;
|
||||
@Input() submissionId;
|
||||
|
||||
/**
|
||||
* The list of available groups for an access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() collectionId: string;
|
||||
|
||||
/**
|
||||
* Define if collection access conditions policy type :
|
||||
* POLICY_DEFAULT_NO_LIST : is not possible to define additional access group/s for the single file
|
||||
* POLICY_DEFAULT_WITH_LIST : is possible to define additional access group/s for the single file
|
||||
* @type {number}
|
||||
*/
|
||||
@Input() collectionPolicyType: number;
|
||||
|
||||
/**
|
||||
* The configuration for the bitstream's metadata form
|
||||
* @type {SubmissionFormsModel}
|
||||
*/
|
||||
@Input() configMetadataForm: SubmissionFormsModel;
|
||||
|
||||
/**
|
||||
* The bitstream id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() fileId: string;
|
||||
|
||||
/**
|
||||
* The bitstream array key
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() fileIndex: string;
|
||||
|
||||
/**
|
||||
* The bitstream id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() fileName: string;
|
||||
|
||||
/**
|
||||
* The section id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() sectionId: string;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() submissionId: string;
|
||||
|
||||
/**
|
||||
* The bitstream's metadata data
|
||||
* @type {WorkspaceitemSectionUploadFileObject}
|
||||
*/
|
||||
public fileData: WorkspaceitemSectionUploadFileObject;
|
||||
public formId;
|
||||
public readMode;
|
||||
|
||||
/**
|
||||
* The form id
|
||||
* @type {string}
|
||||
*/
|
||||
public formId: string;
|
||||
|
||||
/**
|
||||
* A boolean representing if to show bitstream edit form
|
||||
* @type {boolean}
|
||||
*/
|
||||
public readMode: boolean;
|
||||
|
||||
/**
|
||||
* The form model
|
||||
* @type {DynamicFormControlModel[]}
|
||||
*/
|
||||
public formModel: DynamicFormControlModel[];
|
||||
|
||||
/**
|
||||
* A boolean representing if a submission delete operation is pending
|
||||
* @type {BehaviorSubject<boolean>}
|
||||
*/
|
||||
public processingDelete$ = new BehaviorSubject<boolean>(false);
|
||||
|
||||
/**
|
||||
* The [JsonPatchOperationPathCombiner] object
|
||||
* @type {JsonPatchOperationPathCombiner}
|
||||
*/
|
||||
protected pathCombiner: JsonPatchOperationPathCombiner;
|
||||
protected subscriptions = [];
|
||||
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
* @type {Array}
|
||||
*/
|
||||
protected subscriptions: Subscription[] = [];
|
||||
|
||||
/**
|
||||
* The [[UploadSectionFileEditComponent]] reference
|
||||
* @type {UploadSectionFileEditComponent}
|
||||
*/
|
||||
@ViewChild(UploadSectionFileEditComponent) fileEditComp: UploadSectionFileEditComponent;
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
* @param {ChangeDetectorRef} cdr
|
||||
* @param {FileService} fileService
|
||||
* @param {FormService} formService
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {NgbModal} modalService
|
||||
* @param {JsonPatchOperationsBuilder} operationsBuilder
|
||||
* @param {SubmissionJsonPatchOperationsService} operationsService
|
||||
* @param {SubmissionService} submissionService
|
||||
* @param {SectionUploadService} uploadService
|
||||
*/
|
||||
constructor(private cdr: ChangeDetectorRef,
|
||||
private fileService: FileService,
|
||||
private formService: FormService,
|
||||
@@ -64,6 +168,9 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
this.readMode = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve bitstream's metadata
|
||||
*/
|
||||
ngOnChanges() {
|
||||
if (this.availableAccessConditionOptions && this.availableAccessConditionGroups) {
|
||||
// Retrieve file state
|
||||
@@ -79,11 +186,17 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.formId = this.formService.getUniqueId(this.fileId);
|
||||
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionId, 'files', this.fileIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bitstream from submission
|
||||
*/
|
||||
protected deleteFile() {
|
||||
this.operationsBuilder.remove(this.pathCombiner.getPath());
|
||||
this.subscriptions.push(this.operationsService.jsonPatchByResourceID(
|
||||
@@ -97,6 +210,9 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show confirmation dialog for delete
|
||||
*/
|
||||
public confirmDelete(content) {
|
||||
this.modalService.open(content).result.then(
|
||||
(result) => {
|
||||
@@ -108,6 +224,9 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform bitstream download
|
||||
*/
|
||||
public downloadBitstreamFile() {
|
||||
this.halService.getEndpoint('bitstreams').pipe(
|
||||
first())
|
||||
@@ -117,9 +236,16 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Save bitstream metadata
|
||||
*
|
||||
* @param event
|
||||
* the click event emitted
|
||||
*/
|
||||
public saveBitstreamData(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// validate form
|
||||
this.formService.validateAllFormFields(this.fileEditComp.formRef.formGroup);
|
||||
this.subscriptions.push(this.formService.isValid(this.formId).pipe(
|
||||
take(1),
|
||||
@@ -127,6 +253,7 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
flatMap(() => this.formService.getFormData(this.formId)),
|
||||
take(1),
|
||||
flatMap((formData: any) => {
|
||||
// collect bitstream metadata
|
||||
Object.keys((formData.metadata))
|
||||
.filter((key) => isNotEmpty(formData.metadata[key]))
|
||||
.forEach((key) => {
|
||||
@@ -174,6 +301,7 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||
}
|
||||
|
||||
// dispatch a PATCH request to save metadata
|
||||
return this.operationsService.jsonPatchByResourceID(
|
||||
this.submissionService.getSubmissionObjectLinkName(),
|
||||
this.submissionId,
|
||||
@@ -194,11 +322,20 @@ export class UploadSectionFileComponent implements OnChanges, OnInit {
|
||||
}));
|
||||
}
|
||||
|
||||
private retrieveValueFromField(field) {
|
||||
/**
|
||||
* Retrieve field value
|
||||
*
|
||||
* @param field
|
||||
* the specified field object
|
||||
*/
|
||||
private retrieveValueFromField(field: any) {
|
||||
const temp = Array.isArray(field) ? field[0] : field;
|
||||
return (temp) ? temp.value : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch from edit form to metadata view
|
||||
*/
|
||||
public switchMode() {
|
||||
this.readMode = !this.readMode;
|
||||
this.cdr.detectChanges();
|
||||
|
@@ -5,17 +5,42 @@ import { isNotEmpty } from '../../../../../shared/empty.util';
|
||||
import { Metadata } from '../../../../../core/shared/metadata.utils';
|
||||
import { MetadataMap, MetadataValue } from '../../../../../core/shared/metadata.models';
|
||||
|
||||
/**
|
||||
* This component allow to show bitstream's metadata
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-submission-upload-section-file-view',
|
||||
templateUrl: './section-upload-file-view.component.html',
|
||||
})
|
||||
export class UploadSectionFileViewComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* The bitstream's metadata data
|
||||
* @type {WorkspaceitemSectionUploadFileObject}
|
||||
*/
|
||||
@Input() fileData: WorkspaceitemSectionUploadFileObject;
|
||||
|
||||
/**
|
||||
* The [[MetadataMap]] object
|
||||
* @type {MetadataMap}
|
||||
*/
|
||||
public metadata: MetadataMap = Object.create({});
|
||||
|
||||
/**
|
||||
* The bitstream's title key
|
||||
* @type {string}
|
||||
*/
|
||||
public fileTitleKey = 'Title';
|
||||
|
||||
/**
|
||||
* The bitstream's description key
|
||||
* @type {string}
|
||||
*/
|
||||
public fileDescrKey = 'Description';
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*/
|
||||
ngOnInit() {
|
||||
if (isNotEmpty(this.fileData.metadata)) {
|
||||
this.metadata[this.fileTitleKey] = Metadata.all(this.fileData.metadata, 'dc.title');
|
||||
@@ -23,7 +48,15 @@ export class UploadSectionFileViewComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
getAllMetadataValue(metadataKey): MetadataValue[] {
|
||||
/**
|
||||
* Gets all matching metadata in the map(s)
|
||||
*
|
||||
* @param metadataKey
|
||||
* The metadata key(s) in scope
|
||||
* @returns {MetadataValue[]}
|
||||
* The matching values
|
||||
*/
|
||||
getAllMetadataValue(metadataKey: string): MetadataValue[] {
|
||||
return Metadata.all(this.metadata, metadataKey);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user