mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-4506] fix absolute paths
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
import { SectionAccessesService } from './section-accesses.service';
|
||||
import { Component, OnInit, ChangeDetectorRef, Inject, ViewChild } from '@angular/core';
|
||||
import { renderSectionFor } from 'src/app/submission/sections/sections-decorator';
|
||||
import { SectionsType } from 'src/app/submission/sections/sections-type';
|
||||
import { SubmissionService } from 'src/app/submission/submission.service';
|
||||
import { SectionDataObject } from 'src/app/submission/sections/models/section-data.model';
|
||||
import { SectionsService } from 'src/app/submission/sections/sections.service';
|
||||
import { SectionModelComponent } from 'src/app/submission/sections/models/section.model';
|
||||
import { Observable, of, Subscription, combineLatest as observableCombineLatest, BehaviorSubject, combineLatest } from 'rxjs';
|
||||
import { DynamicFormControlModel, MATCH_ENABLED, OR_OPERATOR, DynamicSelectModel, DynamicDatePickerModel, DynamicFormGroupModel, DynamicFormArrayModel, DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER, DynamicCheckboxModel, DynamicFormControlEvent } from '@ng-dynamic-forms/core';
|
||||
import { FormBuilderService } from 'src/app/shared/form/builder/form-builder.service';
|
||||
import { findIndex, isEqual } from 'lodash';
|
||||
import { Component, Inject, ViewChild } from '@angular/core';
|
||||
import { renderSectionFor } from '../sections-decorator';
|
||||
import { SectionsType } from '../sections-type';
|
||||
import { SectionDataObject } from '../models/section-data.model';
|
||||
import { SectionsService } from '../sections.service';
|
||||
import { SectionModelComponent } from '../models/section.model';
|
||||
import { BehaviorSubject, combineLatest, Observable, of, Subscription } from 'rxjs';
|
||||
import {
|
||||
DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX,
|
||||
DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER,
|
||||
DynamicCheckboxModel,
|
||||
DynamicDatePickerModel,
|
||||
DynamicFormArrayModel,
|
||||
DynamicFormControlEvent,
|
||||
DynamicFormControlModel,
|
||||
DynamicFormGroupModel,
|
||||
DynamicSelectModel,
|
||||
MATCH_ENABLED,
|
||||
OR_OPERATOR
|
||||
} from '@ng-dynamic-forms/core';
|
||||
import { FormBuilderService } from '../../../shared/form/builder/form-builder.service';
|
||||
|
||||
import {
|
||||
ACCESS_CONDITION_GROUP_CONFIG,
|
||||
@@ -21,26 +31,22 @@ import {
|
||||
FORM_ACCESS_CONDITION_START_DATE_CONFIG,
|
||||
FORM_ACCESS_CONDITION_START_DATE_LAYOUT,
|
||||
FORM_ACCESS_CONDITION_TYPE_CONFIG,
|
||||
FORM_ACCESS_CONDITION_TYPE_LAYOUT,
|
||||
ACCESS_FORM_CHECKBOX_LAYOUT
|
||||
FORM_ACCESS_CONDITION_TYPE_LAYOUT
|
||||
} from './section-accesses.model';
|
||||
import { isNotEmpty, isNotUndefined, isUndefined, hasValue, isNotNull } from 'src/app/shared/empty.util';
|
||||
import { hasValue, isNotEmpty, isNotNull } from '../../../shared/empty.util';
|
||||
import { WorkspaceitemSectionAccessesObject } from '../../../core/submission/models/workspaceitem-section-accesses.model';
|
||||
import { SubmissionAccessesConfigService } from 'src/app/core/config/submission-accesses-config.service';
|
||||
import { getFirstSucceededRemoteData } from 'src/app/core/shared/operators';
|
||||
import { map, take, filter, mergeMap } from 'rxjs/operators';
|
||||
import { FormComponent } from 'src/app/shared/form/form.component';
|
||||
import { FormService } from 'src/app/shared/form/form.service';
|
||||
import { JsonPatchOperationPathCombiner } from 'src/app/core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { SectionFormOperationsService } from 'src/app/submission/sections/form/section-form-operations.service';
|
||||
import { JsonPatchOperationsBuilder } from 'src/app/core/json-patch/builder/json-patch-operations-builder';
|
||||
import { AccessesConditionOption } from 'src/app/core/config/models/config-accesses-conditions-options.model';
|
||||
import { SubmissionAccessesConfigService } from '../../../core/config/submission-accesses-config.service';
|
||||
import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { filter, map, mergeMap, take } from 'rxjs/operators';
|
||||
import { FormComponent } from '../../../shared/form/form.component';
|
||||
import { FormService } from '../../../shared/form/form.service';
|
||||
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { SectionFormOperationsService } from '../form/section-form-operations.service';
|
||||
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
|
||||
import { AccessesConditionOption } from '../../../core/config/models/config-accesses-conditions-options.model';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { FormFieldPreviousValueObject } from 'src/app/shared/form/builder/models/form-field-previous-value-object';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { SubmissionObject } from 'src/app/core/submission/models/submission-object.model';
|
||||
import { SubmissionJsonPatchOperationsService } from 'src/app/core/submission/submission-json-patch-operations.service';
|
||||
import { dateToISOFormat } from 'src/app/shared/date.util';
|
||||
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
||||
import { dateToISOFormat } from '../../../shared/date.util';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-section-accesses',
|
||||
@@ -71,49 +77,41 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
* @type {WorkspaceitemSectionAccessesObject}
|
||||
*/
|
||||
public accessesData: WorkspaceitemSectionAccessesObject;
|
||||
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
* @type {Array}
|
||||
*/
|
||||
protected subs: Subscription[] = [];
|
||||
|
||||
|
||||
/**
|
||||
* The collection name this submission belonging to
|
||||
* @type {string}
|
||||
*/
|
||||
public collectionName: string;
|
||||
|
||||
/**
|
||||
* Is the upload required
|
||||
* @type {boolean}
|
||||
*/
|
||||
public required$ = new BehaviorSubject<boolean>(true);
|
||||
|
||||
/**
|
||||
* The [[JsonPatchOperationPathCombiner]] object
|
||||
* @type {JsonPatchOperationPathCombiner}
|
||||
*/
|
||||
protected pathCombiner: JsonPatchOperationPathCombiner;
|
||||
|
||||
/**
|
||||
* A map representing all field prevous values
|
||||
* @type {Map}
|
||||
*/
|
||||
protected previousValue: Map<string, number[]> = new Map();
|
||||
|
||||
/**
|
||||
* A map representing all field on their way to be removed
|
||||
* @type {Map}
|
||||
*/
|
||||
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
|
||||
|
||||
/**
|
||||
* The form model
|
||||
* @type {DynamicFormControlModel[]}
|
||||
*/
|
||||
formModel: DynamicFormControlModel[];
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
* @type {Array}
|
||||
*/
|
||||
protected subs: Subscription[] = [];
|
||||
/**
|
||||
* The [[JsonPatchOperationPathCombiner]] object
|
||||
* @type {JsonPatchOperationPathCombiner}
|
||||
*/
|
||||
protected pathCombiner: JsonPatchOperationPathCombiner;
|
||||
/**
|
||||
* A map representing all field prevous values
|
||||
* @type {Map}
|
||||
*/
|
||||
protected previousValue: Map<string, number[]> = new Map();
|
||||
/**
|
||||
* A map representing all field on their way to be removed
|
||||
* @type {Map}
|
||||
*/
|
||||
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
@@ -124,6 +122,7 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
* @param {JsonPatchOperationsBuilder} operationsBuilder
|
||||
* @param {SectionFormOperationsService} formOperationsService
|
||||
* @param {FormBuilderService} formBuilderService
|
||||
* @param {TranslateService} translate
|
||||
* @param {SubmissionAccessesConfigService} accessesConfigService
|
||||
* @param {SectionAccessesService} accessesService
|
||||
* @param {SubmissionJsonPatchOperationsService} operationsService
|
||||
@@ -144,6 +143,129 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
super(undefined, injectedSectionData, injectedSubmissionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize form model values
|
||||
*
|
||||
* @param formModel
|
||||
* The form model
|
||||
*/
|
||||
public initModelData(formModel: DynamicFormControlModel[]) {
|
||||
this.accessesData.accessConditions.forEach((accessCondition, index) => {
|
||||
Array.of('name', 'startDate', 'endDate')
|
||||
.filter((key) => accessCondition.hasOwnProperty(key) && isNotEmpty(accessCondition[key]))
|
||||
.forEach((key) => {
|
||||
const metadataModel: any = this.formBuilderService.findById(key, formModel, index);
|
||||
if (metadataModel) {
|
||||
if (metadataModel.type === DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER) {
|
||||
const date = new Date(accessCondition[key]);
|
||||
metadataModel.value = {
|
||||
year: date.getUTCFullYear(),
|
||||
month: date.getUTCMonth() + 1,
|
||||
day: date.getUTCDate()
|
||||
};
|
||||
} else {
|
||||
metadataModel.value = accessCondition[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when a form dfChange event is fired.
|
||||
* Dispatch form operations based on changes.
|
||||
*/
|
||||
onChange(event: DynamicFormControlEvent) {
|
||||
if (event.model.type === DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX) {
|
||||
const path = this.formOperationsService.getFieldPathSegmentedFromChangeEvent(event);
|
||||
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
|
||||
this.operationsBuilder.replace(this.pathCombiner.getPath(path), value.value, true);
|
||||
} else {
|
||||
// validate form
|
||||
this.formService.validateAllFormFields(this.formRef.formGroup);
|
||||
this.formService.isValid(this.formId).pipe(
|
||||
take(1),
|
||||
filter((isValid) => isValid),
|
||||
mergeMap(() => this.formService.getFormData(this.formId)),
|
||||
take(1)
|
||||
).subscribe((formData: any) => {
|
||||
const accessConditionsToSave = [];
|
||||
formData.accessCondition
|
||||
.map((accessConditions) => accessConditions.accessConditionGroup)
|
||||
.filter((accessCondition) => isNotEmpty(accessCondition))
|
||||
.forEach((accessCondition) => {
|
||||
let accessConditionOpt;
|
||||
|
||||
this.availableAccessConditionOptions
|
||||
.filter((element) => isNotNull(accessCondition.name) && element.name === accessCondition.name[0].value)
|
||||
.forEach((element) => accessConditionOpt = element);
|
||||
|
||||
if (accessConditionOpt) {
|
||||
const currentAccessCondition = Object.assign({}, accessCondition);
|
||||
currentAccessCondition.name = this.retrieveValueFromField(accessCondition.name);
|
||||
|
||||
/* When start and end date fields are deactivated, their values may be still present in formData,
|
||||
therefore it is necessary to delete them if they're not allowed by the current access condition option. */
|
||||
if (!accessConditionOpt.hasStartDate) {
|
||||
delete currentAccessCondition.startDate;
|
||||
} else if (accessCondition.startDate) {
|
||||
const startDate = this.retrieveValueFromField(accessCondition.startDate);
|
||||
currentAccessCondition.startDate = dateToISOFormat(startDate);
|
||||
}
|
||||
if (!accessConditionOpt.hasEndDate) {
|
||||
delete currentAccessCondition.endDate;
|
||||
} else if (accessCondition.endDate) {
|
||||
const endDate = this.retrieveValueFromField(accessCondition.endDate);
|
||||
currentAccessCondition.endDate = dateToISOFormat(endDate);
|
||||
}
|
||||
accessConditionsToSave.push(currentAccessCondition);
|
||||
}
|
||||
});
|
||||
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified form field has already a value stored
|
||||
*
|
||||
* @param fieldId
|
||||
* the section data retrieved from the serverù
|
||||
* @param index
|
||||
* the section data retrieved from the server
|
||||
*/
|
||||
hasStoredValue(fieldId, index): boolean {
|
||||
if (isNotEmpty(this.sectionData.data)) {
|
||||
return this.sectionData.data.hasOwnProperty(fieldId) &&
|
||||
isNotEmpty(this.sectionData.data[fieldId][index]) &&
|
||||
!this.isFieldToRemove(fieldId, index);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified field is on the way to be removed
|
||||
*
|
||||
* @param fieldId
|
||||
* the section data retrieved from the serverù
|
||||
* @param index
|
||||
* the section data retrieved from the server
|
||||
*/
|
||||
isFieldToRemove(fieldId, index) {
|
||||
return this.fieldsOnTheirWayToBeRemoved.has(fieldId) && this.fieldsOnTheirWayToBeRemoved.get(fieldId).includes(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from all subscriptions
|
||||
*/
|
||||
onSectionDestroy() {
|
||||
this.subs
|
||||
.filter((subscription) => hasValue(subscription))
|
||||
.forEach((subscription) => subscription.unsubscribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all instance variables and retrieve collection default access conditions
|
||||
*/
|
||||
@@ -174,7 +296,6 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
* the section status
|
||||
*/
|
||||
protected getSectionStatus(): Observable<boolean> {
|
||||
console.log('Method not implemented.');
|
||||
return of(true);
|
||||
}
|
||||
|
||||
@@ -237,8 +358,12 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
const endDate = new DynamicDatePickerModel(endDateConfig, FORM_ACCESS_CONDITION_END_DATE_LAYOUT);
|
||||
const accessConditionGroupConfig = Object.assign({}, ACCESS_CONDITION_GROUP_CONFIG);
|
||||
accessConditionGroupConfig.group = [type];
|
||||
if (hasStart.length > 0) { accessConditionGroupConfig.group.push(startDate); }
|
||||
if (hasEnd.length > 0) { accessConditionGroupConfig.group.push(endDate); }
|
||||
if (hasStart.length > 0) {
|
||||
accessConditionGroupConfig.group.push(startDate);
|
||||
}
|
||||
if (hasEnd.length > 0) {
|
||||
accessConditionGroupConfig.group.push(endDate);
|
||||
}
|
||||
return [new DynamicFormGroupModel(accessConditionGroupConfig, ACCESS_CONDITION_GROUP_LAYOUT)];
|
||||
};
|
||||
|
||||
@@ -252,153 +377,8 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
return formModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize form model values
|
||||
*
|
||||
* @param formModel
|
||||
* The form model
|
||||
*/
|
||||
public initModelData(formModel: DynamicFormControlModel[]) {
|
||||
this.accessesData.accessConditions.forEach((accessCondition, index) => {
|
||||
Array.of('name', 'startDate', 'endDate')
|
||||
.filter((key) => accessCondition.hasOwnProperty(key) && isNotEmpty(accessCondition[key]))
|
||||
.forEach((key) => {
|
||||
const metadataModel: any = this.formBuilderService.findById(key, formModel, index);
|
||||
if (metadataModel) {
|
||||
if (metadataModel.type === DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER) {
|
||||
const date = new Date(accessCondition[key]);
|
||||
metadataModel.value = {
|
||||
year: date.getUTCFullYear(),
|
||||
month: date.getUTCMonth() + 1,
|
||||
day: date.getUTCDate()
|
||||
};
|
||||
} else {
|
||||
metadataModel.value = accessCondition[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
// this.formService.validateAllFormFields(this.formRef.formGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called when a form dfChange event is fired.
|
||||
* Dispatch form operations based on changes.
|
||||
*/
|
||||
onChange(event: DynamicFormControlEvent) {
|
||||
if (event.model.type === 'CHECKBOX') {
|
||||
const path = this.formOperationsService.getFieldPathSegmentedFromChangeEvent(event);
|
||||
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
|
||||
this.operationsBuilder.replace(this.pathCombiner.getPath(path), value.value, true);
|
||||
} else {
|
||||
// validate form
|
||||
this.formService.validateAllFormFields(this.formRef.formGroup);
|
||||
this.formService.isValid(this.formId).pipe(
|
||||
take(1),
|
||||
filter((isValid) => isValid),
|
||||
mergeMap(() => this.formService.getFormData(this.formId)),
|
||||
take(1),
|
||||
mergeMap((formData: any) => {
|
||||
console.log(formData);
|
||||
const accessConditionsToSave = [];
|
||||
formData.accessCondition
|
||||
.map((accessConditions) => accessConditions.accessConditionGroup)
|
||||
.filter((accessCondition) => isNotEmpty(accessCondition))
|
||||
.forEach((accessCondition) => {
|
||||
let accessConditionOpt;
|
||||
|
||||
this.availableAccessConditionOptions
|
||||
.filter((element) => isNotNull(accessCondition.name) && element.name === accessCondition.name[0].value)
|
||||
.forEach((element) => accessConditionOpt = element);
|
||||
|
||||
if (accessConditionOpt) {
|
||||
const currentAccessCondition = Object.assign({}, accessCondition);
|
||||
currentAccessCondition.name = this.retrieveValueFromField(accessCondition.name);
|
||||
|
||||
/* When start and end date fields are deactivated, their values may be still present in formData,
|
||||
therefore it is necessary to delete them if they're not allowed by the current access condition option. */
|
||||
if (!accessConditionOpt.hasStartDate) {
|
||||
delete currentAccessCondition.startDate;
|
||||
} else if (accessCondition.startDate) {
|
||||
const startDate = this.retrieveValueFromField(accessCondition.startDate);
|
||||
currentAccessCondition.startDate = dateToISOFormat(startDate);
|
||||
}
|
||||
if (!accessConditionOpt.hasEndDate) {
|
||||
delete currentAccessCondition.endDate;
|
||||
} else if (accessCondition.endDate) {
|
||||
const endDate = this.retrieveValueFromField(accessCondition.endDate);
|
||||
currentAccessCondition.endDate = dateToISOFormat(endDate);
|
||||
}
|
||||
accessConditionsToSave.push(currentAccessCondition);
|
||||
}
|
||||
});
|
||||
|
||||
this.operationsBuilder.add(this.pathCombiner.getPath('accessConditions'), accessConditionsToSave, true);
|
||||
|
||||
return this.formService.getFormData(this.formId);
|
||||
|
||||
})
|
||||
).subscribe((result: SubmissionObject[]) => {
|
||||
console.log(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected retrieveValueFromField(field: any) {
|
||||
const temp = Array.isArray(field) ? field[0] : field;
|
||||
return (temp) ? temp.value : undefined;
|
||||
}
|
||||
/**
|
||||
* Check if the specified form field has already a value stored
|
||||
*
|
||||
* @param fieldId
|
||||
* the section data retrieved from the serverù
|
||||
* @param index
|
||||
* the section data retrieved from the server
|
||||
*/
|
||||
hasStoredValue(fieldId, index): boolean {
|
||||
if (isNotEmpty(this.sectionData.data)) {
|
||||
return this.sectionData.data.hasOwnProperty(fieldId) &&
|
||||
isNotEmpty(this.sectionData.data[fieldId][index]) &&
|
||||
!this.isFieldToRemove(fieldId, index);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private hasRelatedCustomError(medatata): boolean {
|
||||
const index = findIndex(this.sectionData.errorsToShow, { path: this.pathCombiner.getPath(medatata).path });
|
||||
if (index !== -1) {
|
||||
const error = this.sectionData.errorsToShow[index];
|
||||
const validator = error.message.replace('error.validation.', '');
|
||||
return !environment.form.validatorMap.hasOwnProperty(validator);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the specified field is on the way to be removed
|
||||
*
|
||||
* @param fieldId
|
||||
* the section data retrieved from the serverù
|
||||
* @param index
|
||||
* the section data retrieved from the server
|
||||
*/
|
||||
isFieldToRemove(fieldId, index) {
|
||||
return this.fieldsOnTheirWayToBeRemoved.has(fieldId) && this.fieldsOnTheirWayToBeRemoved.get(fieldId).includes(index);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unsubscribe from all subscriptions
|
||||
*/
|
||||
onSectionDestroy() {
|
||||
this.subs
|
||||
.filter((subscription) => hasValue(subscription))
|
||||
.forEach((subscription) => subscription.unsubscribe());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user