mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-6174] Fix issue with item access condition which doesn't consider the maxStartDate/maxEndDate
This commit is contained in:
@@ -41,7 +41,9 @@ import {
|
||||
FORM_ACCESS_CONDITION_TYPE_LAYOUT
|
||||
} from './section-accesses.model';
|
||||
import { hasValue, isNotEmpty, isNotNull } from '../../../shared/empty.util';
|
||||
import { WorkspaceitemSectionAccessesObject } from '../../../core/submission/models/workspaceitem-section-accesses.model';
|
||||
import {
|
||||
WorkspaceitemSectionAccessesObject
|
||||
} from '../../../core/submission/models/workspaceitem-section-accesses.model';
|
||||
import { SubmissionAccessesConfigService } from '../../../core/config/submission-accesses-config.service';
|
||||
import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
|
||||
import { FormComponent } from '../../../shared/form/form.component';
|
||||
@@ -50,8 +52,12 @@ import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder
|
||||
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 { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
||||
import {
|
||||
SubmissionJsonPatchOperationsService
|
||||
} from '../../../core/submission/submission-json-patch-operations.service';
|
||||
import { dateToISOFormat } from '../../../shared/date.util';
|
||||
import { DynamicFormControlCondition } from '@ng-dynamic-forms/core/lib/model/misc/dynamic-form-control-relation.model';
|
||||
import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynamic-date-control.model';
|
||||
|
||||
/**
|
||||
* This component represents a section for managing item's access conditions.
|
||||
@@ -322,40 +328,61 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
|
||||
}
|
||||
accessConditionTypeModelConfig.options = accessConditionTypeOptions;
|
||||
|
||||
// Dynamically assign of relation in config. For startdate, endDate, groups.
|
||||
const hasStart = [];
|
||||
const hasEnd = [];
|
||||
const hasGroups = [];
|
||||
// Dynamically assign of relation in config. For startDate and endDate.
|
||||
const startDateCondition: DynamicFormControlCondition[] = [];
|
||||
const endDateCondition: DynamicFormControlCondition[] = [];
|
||||
let maxStartDate: DynamicDateControlValue;
|
||||
let maxEndDate: DynamicDateControlValue;
|
||||
this.availableAccessConditionOptions.forEach((condition) => {
|
||||
const showStart: boolean = condition.hasStartDate === true;
|
||||
const showEnd: boolean = condition.hasEndDate === true;
|
||||
const showGroups: boolean = showStart || showEnd;
|
||||
if (showStart) {
|
||||
hasStart.push({ id: 'name', value: condition.name });
|
||||
|
||||
if (condition.hasStartDate) {
|
||||
startDateCondition.push({ id: 'name', value: condition.name });
|
||||
if (condition.maxStartDate) {
|
||||
const min = new Date(condition.maxStartDate);
|
||||
maxStartDate = {
|
||||
year: min.getUTCFullYear(),
|
||||
month: min.getUTCMonth() + 1,
|
||||
day: min.getUTCDate()
|
||||
};
|
||||
}
|
||||
}
|
||||
if (showEnd) {
|
||||
hasEnd.push({ id: 'name', value: condition.name });
|
||||
}
|
||||
if (showGroups) {
|
||||
hasGroups.push({ id: 'name', value: condition.name });
|
||||
if (condition.hasEndDate) {
|
||||
endDateCondition.push({ id: 'name', value: condition.name });
|
||||
if (condition.maxEndDate) {
|
||||
const max = new Date(condition.maxEndDate);
|
||||
maxEndDate = {
|
||||
year: max.getUTCFullYear(),
|
||||
month: max.getUTCMonth() + 1,
|
||||
day: max.getUTCDate()
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
const confStart = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: hasStart }] };
|
||||
const confEnd = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: hasEnd }] };
|
||||
const confStart = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: startDateCondition }] };
|
||||
const confEnd = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: endDateCondition }] };
|
||||
const hasStartDate = startDateCondition.length > 0;
|
||||
const hasEndDate = endDateCondition.length > 0;
|
||||
|
||||
accessConditionsArrayConfig.groupFactory = () => {
|
||||
const type = new DynamicSelectModel(accessConditionTypeModelConfig, FORM_ACCESS_CONDITION_TYPE_LAYOUT);
|
||||
const startDateConfig = Object.assign({}, FORM_ACCESS_CONDITION_START_DATE_CONFIG, confStart);
|
||||
if (maxStartDate) {
|
||||
startDateConfig.max = maxStartDate;
|
||||
}
|
||||
|
||||
const endDateConfig = Object.assign({}, FORM_ACCESS_CONDITION_END_DATE_CONFIG, confEnd);
|
||||
if (maxEndDate) {
|
||||
endDateConfig.max = maxEndDate;
|
||||
}
|
||||
|
||||
const startDate = new DynamicDatePickerModel(startDateConfig, FORM_ACCESS_CONDITION_START_DATE_LAYOUT);
|
||||
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) {
|
||||
if (hasStartDate) {
|
||||
accessConditionGroupConfig.group.push(startDate);
|
||||
}
|
||||
if (hasEnd.length > 0) {
|
||||
if (hasEndDate) {
|
||||
accessConditionGroupConfig.group.push(endDate);
|
||||
}
|
||||
return [new DynamicFormGroupModel(accessConditionGroupConfig, ACCESS_CONDITION_GROUP_LAYOUT)];
|
||||
|
Reference in New Issue
Block a user