Added more comments

This commit is contained in:
Giuseppe Digilio
2019-03-20 19:57:07 +01:00
parent 825464bb9c
commit 6335d61dda
26 changed files with 1505 additions and 123 deletions

View File

@@ -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));
}
}