Commit 55705ebe authored by Florent Poittevin's avatar Florent Poittevin Committed by Alicia.DeDiosFuente
Browse files

feat: 649 Add preservation policy to org unit and refacto component default value

Add preservation policy to org unit in admin page
Create component select with default value
Fix state admin org unit to manage update of sub resource
parent 227ddd46
......@@ -5,11 +5,13 @@ import {AdminLicenseDeleteDialog} from "@app/features/admin/components/dialogs/a
import {AdminOrgunitDeleteDialog} from "@app/features/admin/components/dialogs/admin-orgunit-delete/admin-orgunit-delete.dialog";
import {AdminPreservationPolicyDeleteDialog} from "@app/features/admin/components/dialogs/admin-preservation-policy-delete/admin-preservation-policy-delete.dialog";
import {AdminSubmissionPolicyDeleteDialog} from "@app/features/admin/components/dialogs/admin-submission-policy-delete/admin-submission-policy-delete.dialog";
import {AdminUserDeleteDialog} from "@app/features/admin/components/dialogs/admin-user-delete/admin-user-delete.dialog";
import {AdminInstitutionFormPresentational} from "@app/features/admin/components/presentationals/admin-institution-form/admin-institution-form.presentational";
import {AdminLicenseFormPresentational} from "@app/features/admin/components/presentationals/admin-license-form/admin-license-form.presentational";
import {AdminOrgunitFormPresentational} from "@app/features/admin/components/presentationals/admin-orgunit-form/admin-orgunit-form.presentational";
import {AdminPreservationPolicyFormPresentational} from "@app/features/admin/components/presentationals/admin-preservation-policy-form/admin-preservation-policy-form.presentational";
import {AdminSubmissionPolicyFormPresentational} from "@app/features/admin/components/presentationals/admin-submission-policy-form/admin-submission-policy-form.presentational";
import {AdminUserForm} from "@app/features/admin/components/presentationals/admin-user-form/admin-user-form";
import {AdminHomeRoutable} from "@app/features/admin/components/routables/admin-home/admin-home.routable";
import {AdminInstitutionCreateRoutable} from "@app/features/admin/components/routables/admin-institution-create/admin-institution-create.routable";
import {AdminInstitutionDetailRoutable} from "@app/features/admin/components/routables/admin-institution-detail/admin-institution-detail.routable";
......@@ -30,24 +32,23 @@ import {AdminPreservationPolicyListRoutable} from "@app/features/admin/component
import {AdminSubmissionPolicyCreateRoutable} from "@app/features/admin/components/routables/admin-submission-policy-create/admin-submission-policy-create.routable";
import {AdminSubmissionPolicyDetailRoutable} from "@app/features/admin/components/routables/admin-submission-policy-detail/admin-submission-policy-detail.routable";
import {AdminSubmissionPolicyEditRoutable} from "@app/features/admin/components/routables/admin-submission-policy-edit/admin-submission-policy-edit.routable";
import {AdminUserCreateRoutable} from "@app/features/admin/components/routables/admin-user-create/admin-user-create.routable";
import {AdminUserDetailRoutable} from "@app/features/admin/components/routables/admin-user-detail/admin-user-detail.routable";
import {AdminUserEditRoutable} from "@app/features/admin/components/routables/admin-user-edit/admin-user-edit.routable";
import {AdminUserListRoutable} from "@app/features/admin/components/routables/admin-user-list/admin-user-list-routable";
import {AdminState} from "@app/features/admin/stores/admin.state";
import {AdminInstitutionState} from "@app/features/admin/stores/institution/admin-institution.state";
import {AdminLicenseState} from "@app/features/admin/stores/license/admin-license.state";
import {AdminOrganizationalUnitState} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.state";
import {AdminOrganizationalUnitPreservationPolicyState} from "@app/features/admin/stores/organizational-unit/preservation-policy/admin-organizational-unit-preservation-policy.state";
import {AdminOrganizationalUnitSubmissionPolicyState} from "@app/features/admin/stores/organizational-unit/submission-policy/admin-organizational-unit-submission-policy.state";
import {AdminPreservationPolicyState} from "@app/features/admin/stores/preservation-policy/admin-preservation-policy.state";
import {AdminSubmissionPolicyState} from "@app/features/admin/stores/submission-policy/admin-submission-policy.state";
import {AdminUserState} from "@app/features/admin/stores/user/admin-user.state";
import {SharedModule} from "@app/shared/shared.module";
import {TranslateModule} from "@ngx-translate/core";
import {NgxsModule} from "@ngxs/store";
import {AdminSubmissionPolicyListRoutable} from "./components/routables/admin-submission-policy-list/admin-submission-policy-list.routable";
import {AdminUserState} from "@app/features/admin/stores/user/admin-user.state";
import {AdminUserListRoutable} from "@app/features/admin/components/routables/admin-user-list/admin-user-list-routable";
import {AdminUserDetailRoutable} from "@app/features/admin/components/routables/admin-user-detail/admin-user-detail.routable";
import {AdminUserForm} from "@app/features/admin/components/presentationals/admin-user-form/admin-user-form";
import {AdminUserDeleteDialog} from "@app/features/admin/components/dialogs/admin-user-delete/admin-user-delete.dialog";
import {AdminUserCreateRoutable} from "@app/features/admin/components/routables/admin-user-create/admin-user-create.routable";
import {AdminUserEditRoutable} from "@app/features/admin/components/routables/admin-user-edit/admin-user-edit.routable";
const routables = [
AdminHomeRoutable,
......@@ -91,7 +92,7 @@ const presentationals = [
AdminPreservationPolicyFormPresentational,
AdminOrgunitFormPresentational,
AdminInstitutionFormPresentational,
AdminUserForm
AdminUserForm,
];
@NgModule({
......@@ -113,6 +114,7 @@ const presentationals = [
AdminInstitutionState,
AdminOrganizationalUnitState,
AdminOrganizationalUnitSubmissionPolicyState,
AdminOrganizationalUnitPreservationPolicyState,
AdminUserState,
]),
],
......
......@@ -10,27 +10,25 @@
<mat-error *ngFor="let error of getFormControl(formDefinition.name).errors?.errorsFromBackend">{{error}}</mat-error>
</mat-form-field>
<dlcm-shared-searchable-multi-select [list]="listSubmissionPolicies"
[formControl]="form.get(formDefinition.submissionPolicies)"
[required]="isRequired(formDefinition.submissionPolicies)"
[labelKey]="'name'"
[valueKey]="'resId'"
[placeholder]="'admin.organizationalUnit.form.submissionPolicy' | translate"
<dlcm-shared-multi-select-default-value [list]="listSubmissionPolicies"
[formControl]="form.get(formDefinition.submissionPolicies)"
[formControlDefault]="form.get(formDefinition.defaultSubmissionPolicy)"
[required]="isRequired(formDefinition.submissionPolicies)"
[labelKey]="'name'"
[valueKey]="'resId'"
[placeholder]="'admin.organizationalUnit.form.submissionPolicy' | translate"
>
</dlcm-shared-searchable-multi-select>
</dlcm-shared-multi-select-default-value>
<mat-form-field>
<mat-label>{{'admin.organizationalUnit.form.submissionPolicyDefaultValue' | translate }}</mat-label>
<mat-select [formControlName]="formDefinition.defaultSubmissionPolicy"
[required]="isRequired(formDefinition.defaultSubmissionPolicy)">
<mat-option *ngFor="let submissionPolicy of listDefaultSubmissionPolicies"
[value]="submissionPolicy.resId">
{{submissionPolicy.name}}
</mat-option>
</mat-select>
<mat-error *ngIf="getFormControl(formDefinition.defaultSubmissionPolicy).invalid">{{'required' | translate}}</mat-error>
<mat-error *ngFor="let error of getFormControl(formDefinition.defaultSubmissionPolicy).errors?.errorsFromBackend">{{error}}</mat-error>
</mat-form-field>
<dlcm-shared-multi-select-default-value [list]="listPreservationPolicies"
[formControl]="form.get(formDefinition.preservationPolicies)"
[formControlDefault]="form.get(formDefinition.defaultPreservationPolicy)"
[required]="isRequired(formDefinition.preservationPolicies)"
[labelKey]="'name'"
[valueKey]="'resId'"
[placeholder]="'admin.organizationalUnit.form.preservationPolicy' | translate"
>
</dlcm-shared-multi-select-default-value>
<mat-form-field>
<input [formControlName]="formDefinition.description"
......
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges} from "@angular/core";
import {FormBuilder, Validators} from "@angular/forms";
import {OrganizationalUnitsExtended} from "@app/features/deposit/models/organizational-unit-extended.model";
import {OrganizationalUnits, PreservationPolicies, SubmissionPolicies} from "@app/generated-api";
......@@ -6,7 +6,6 @@ import {SharedAbstractFormPresentational} from "@app/shared/components/presentat
import {LocalModelAttributeEnum} from "@app/shared/enums/model-attribute.enum";
import {BaseFormDefinition} from "@app/shared/models/base-form-definition.model";
import _ from "lodash";
import {tap} from "rxjs/operators";
import {DateUtil, PropertyName, SolidifyValidator} from "solidify-frontend";
@Component({
......@@ -15,20 +14,21 @@ import {DateUtil, PropertyName, SolidifyValidator} from "solidify-frontend";
styleUrls: ["../../../../../shared/components/presentationals/shared-abstract-form/shared-abstract-form.presentational.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentational<OrganizationalUnits> implements OnChanges, OnInit {
export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentational<OrganizationalUnits> implements OnChanges {
formDefinition: FormComponentFormDefinition = new FormComponentFormDefinition();
@Input()
selectedSubmissionPolicies: SubmissionPolicies[];
@Input()
selectedPreservationPolicies: PreservationPolicies[];
@Input()
listSubmissionPolicies: SubmissionPolicies[];
@Input()
listPreservationPolicies: PreservationPolicies[];
listDefaultSubmissionPolicies: SubmissionPolicies[];
constructor(protected readonly _changeDetectorRef: ChangeDetectorRef,
private readonly _fb: FormBuilder) {
super(_changeDetectorRef);
......@@ -47,20 +47,6 @@ export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentati
}
}
ngOnInit(): void {
super.ngOnInit();
this.computeListDefaultSubmissionPolicies();
this.subscribe(this.form.get(this.formDefinition.submissionPolicies).valueChanges.pipe(
tap(v => {
this.computeListDefaultSubmissionPolicies();
if (this.listDefaultSubmissionPolicies.findIndex(s => s.resId === this.form.get(this.formDefinition.defaultSubmissionPolicy).value) === -1) {
this.form.get(this.formDefinition.defaultSubmissionPolicy).setValue(undefined);
}
}),
));
}
protected initNewForm(): void {
this.form = this._fb.group({
[this.formDefinition.name]: ["", [Validators.required, SolidifyValidator]],
......@@ -70,8 +56,9 @@ export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentati
[this.formDefinition.isEmpty]: [false],
[this.formDefinition.open]: [false],
[this.formDefinition.submissionPolicies]: [[], [Validators.required, SolidifyValidator]],
[this.formDefinition.preservationPolicies]: [[], [Validators.required, SolidifyValidator]],
[this.formDefinition.defaultSubmissionPolicy]: [undefined, [Validators.required, SolidifyValidator]],
[this.formDefinition.defaultPreservationPolicy]: [],
[this.formDefinition.defaultPreservationPolicy]: [undefined, [Validators.required, SolidifyValidator]],
});
}
......@@ -84,8 +71,9 @@ export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentati
[this.formDefinition.isEmpty]: [organizationalUnit.isEmpty],
[this.formDefinition.open]: [organizationalUnit.open],
[this.formDefinition.submissionPolicies]: [_.map(this.selectedSubmissionPolicies, LocalModelAttributeEnum.resId), [Validators.required, SolidifyValidator]],
[this.formDefinition.preservationPolicies]: [_.map(this.selectedPreservationPolicies, LocalModelAttributeEnum.resId), [Validators.required, SolidifyValidator]],
[this.formDefinition.defaultSubmissionPolicy]: [(organizationalUnit.defaultSubmissionPolicy ? organizationalUnit.defaultSubmissionPolicy.resId : undefined), [Validators.required, SolidifyValidator]],
[this.formDefinition.defaultPreservationPolicy]: [],
[this.formDefinition.defaultPreservationPolicy]: [(organizationalUnit.defaultPreservationPolicy ? organizationalUnit.defaultPreservationPolicy.resId : undefined), [Validators.required, SolidifyValidator]],
});
}
......@@ -93,12 +81,9 @@ export class AdminOrgunitFormPresentational extends SharedAbstractFormPresentati
organizationalUnit.openingDate = DateUtil.convertToLocalDateDateSimple(organizationalUnit.openingDate);
organizationalUnit.closingDate = DateUtil.convertToLocalDateDateSimple(organizationalUnit.closingDate);
organizationalUnit.defaultSubmissionPolicy = {resId: organizationalUnit[this.formDefinition.defaultSubmissionPolicy]};
organizationalUnit.defaultPreservationPolicy = {resId: organizationalUnit[this.formDefinition.defaultPreservationPolicy]};
return organizationalUnit;
}
computeListDefaultSubmissionPolicies(): void {
this.listDefaultSubmissionPolicies = this.listSubmissionPolicies.filter((s) => this.form.get(this.formDefinition.submissionPolicies).value.includes(s.resId));
}
}
class FormComponentFormDefinition extends BaseFormDefinition {
......@@ -108,6 +93,7 @@ class FormComponentFormDefinition extends BaseFormDefinition {
@PropertyName() closingDate: string;
@PropertyName() openingDate: string;
@PropertyName() submissionPolicies: string;
@PropertyName() preservationPolicies: string;
@PropertyName() open: string;
@PropertyName() defaultSubmissionPolicy: string;
@PropertyName() defaultPreservationPolicy: string;
......
......@@ -16,11 +16,13 @@
<div class="spinner-wrapper" *ngIf="isLoadingObs | async">
<mat-spinner></mat-spinner>
</div>
<dlcm-admin-orgunit-form *ngIf="!(isLoadingObs | async) && (currentObs | async) && !(isLoadingSubmissionPoliciesObs | async)"
[model]="currentObs| async"
[selectedSubmissionPolicies]="selectedSubmissionPoliciesObs | async"
[listSubmissionPolicies]="listSubmissionPoliciesObs | async"
[listPreservationPolicies]="listPreservationPoliciesObs | async"
[readonly]="true"
<dlcm-admin-orgunit-form
*ngIf="!(isLoadingObs | async) && (currentObs | async) && !(isLoadingSubmissionPoliciesObs | async) && !(isLoadingPreservationPoliciesObs | async)"
[model]="currentObs| async"
[selectedSubmissionPolicies]="selectedSubmissionPoliciesObs | async"
[selectedPreservationPolicies]="selectedPreservationPoliciesObs | async"
[listSubmissionPolicies]="listSubmissionPoliciesObs | async"
[listPreservationPolicies]="listPreservationPoliciesObs | async"
[readonly]="true"
></dlcm-admin-orgunit-form>
</div>
......@@ -3,6 +3,7 @@ import {MatDialog} from "@angular/material";
import {ActivatedRoute} from "@angular/router";
import {adminOrgUnitActionNameSpace} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.action";
import {AdminOrganizationalUnitStateModel} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.state";
import {AdminOrgUnitPreservationPolicyAction} from "@app/features/admin/stores/organizational-unit/preservation-policy/admin-organizational-unit-preservation-policy.action";
import {AdminOrgUnitSubmissionPolicyAction} from "@app/features/admin/stores/organizational-unit/submission-policy/admin-organizational-unit-submission-policy.action";
import {OrganizationalUnits, PreservationPolicies, SubmissionPolicies} from "@app/generated-api";
import {SharedAbstractDetailRoutable} from "@app/shared/components/routables/shared-abstract-detail/shared-abstract-detail.routable";
......@@ -20,7 +21,9 @@ import {StoreUtil, TRANSLATE} from "solidify-frontend";
})
export class AdminOrgunitDetailRoutable extends SharedAbstractDetailRoutable<OrganizationalUnits, AdminOrganizationalUnitStateModel> {
@Select((state: LocalStateModel) => StoreUtil.isLoadingState(state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_submissionPolicy])) isLoadingSubmissionPoliciesObs: Observable<boolean>;
@Select((state: LocalStateModel) => StoreUtil.isLoadingState(state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_preservationPolicy])) isLoadingPreservationPoliciesObs: Observable<boolean>;
@Select((state: LocalStateModel) => state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_submissionPolicy].selected) selectedSubmissionPoliciesObs: Observable<SubmissionPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_preservationPolicy].selected) selectedPreservationPoliciesObs: Observable<PreservationPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.shared][LocalStateEnum.shared_submissionPolicy].list) listSubmissionPoliciesObs: Observable<SubmissionPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.shared][LocalStateEnum.shared_preservationPolicy].list) listPreservationPoliciesObs: Observable<PreservationPolicies[]>;
......@@ -36,5 +39,6 @@ export class AdminOrgunitDetailRoutable extends SharedAbstractDetailRoutable<Org
getSubResourceWithParentId(id: string): void {
this.store.dispatch(new AdminOrgUnitSubmissionPolicyAction.GetAll(id));
this.store.dispatch(new AdminOrgUnitPreservationPolicyAction.GetAll(id));
}
}
<dlcm-admin-orgunit-form *ngIf="!(isLoadingObs | async) && (currentObs | async) && !(isLoadingSubmissionPoliciesObs | async)"
[model]="currentObs | async"
[selectedSubmissionPolicies]="selectedSubmissionPoliciesObs | async"
[listSubmissionPolicies]="listSubmissionPoliciesObs | async"
[listPreservationPolicies]="listPreservationPoliciesObs | async"
(submitChange)="update($event)">
<dlcm-admin-orgunit-form
*ngIf="!(isLoadingObs | async) && (currentObs | async) && !(isLoadingSubmissionPoliciesObs | async) && !(isLoadingPreservationPoliciesObs | async)"
[model]="currentObs | async"
[selectedSubmissionPolicies]="selectedSubmissionPoliciesObs | async"
[selectedPreservationPolicies]="selectedPreservationPoliciesObs | async"
[listSubmissionPolicies]="listSubmissionPoliciesObs | async"
[listPreservationPolicies]="listPreservationPoliciesObs | async"
(submitChange)="update($event)">
</dlcm-admin-orgunit-form>
<mat-spinner *ngIf="(isLoadingObs | async)"></mat-spinner>
......@@ -2,6 +2,7 @@ import {ChangeDetectionStrategy, Component} from "@angular/core";
import {ActivatedRoute} from "@angular/router";
import {adminOrgUnitActionNameSpace} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.action";
import {AdminOrganizationalUnitStateModel} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.state";
import {AdminOrgUnitPreservationPolicyAction} from "@app/features/admin/stores/organizational-unit/preservation-policy/admin-organizational-unit-preservation-policy.action";
import {AdminOrgUnitSubmissionPolicyAction} from "@app/features/admin/stores/organizational-unit/submission-policy/admin-organizational-unit-submission-policy.action";
import {OrganizationalUnits, PreservationPolicies, SubmissionPolicies} from "@app/generated-api";
import {SharedAbstractEditRoutable} from "@app/shared/components/routables/shared-abstract-edit/shared-abstract-edit.routable";
......@@ -19,7 +20,9 @@ import {StoreUtil} from "solidify-frontend";
})
export class AdminOrgunitEditRoutable extends SharedAbstractEditRoutable<OrganizationalUnits, AdminOrganizationalUnitStateModel> {
@Select((state: LocalStateModel) => StoreUtil.isLoadingState(state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_submissionPolicy])) isLoadingSubmissionPoliciesObs: Observable<boolean>;
@Select((state: LocalStateModel) => StoreUtil.isLoadingState(state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_preservationPolicy])) isLoadingPreservationPoliciesObs: Observable<boolean>;
@Select((state: LocalStateModel) => state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_submissionPolicy].selected) selectedSubmissionPoliciesObs: Observable<SubmissionPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.admin][LocalStateEnum.admin_organizationalUnit][LocalStateEnum.admin_organizationalUnit_preservationPolicy].selected) selectedPreservationPoliciesObs: Observable<SubmissionPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.shared][LocalStateEnum.shared_submissionPolicy].list) listSubmissionPoliciesObs: Observable<SubmissionPolicies[]>;
@Select((state: LocalStateModel) => state[LocalStateEnum.shared][LocalStateEnum.shared_preservationPolicy].list) listPreservationPoliciesObs: Observable<PreservationPolicies[]>;
......@@ -30,5 +33,6 @@ export class AdminOrgunitEditRoutable extends SharedAbstractEditRoutable<Organiz
getSubResourceWithParentId(id: string): void {
this.store.dispatch(new AdminOrgUnitSubmissionPolicyAction.GetAll(id));
this.store.dispatch(new AdminOrgUnitPreservationPolicyAction.GetAll(id));
}
}
import {OrganizationalUnitPreservationPolicy} from "@app/features/admin/models/organizational-unit-preservation-policy.model";
import {OrganizationalUnitSubmissionPolicy} from "@app/features/admin/models/organizational-unit-submission-policy.model";
import {
AdminOrgUnitAction,
adminOrgUnitActionNameSpace,
} from "@app/features/admin/stores/organizational-unit/admin-organizational-unit.action";
import {adminOrgUnitPreservationPolicyActionNameSpace} from "@app/features/admin/stores/organizational-unit/preservation-policy/admin-organizational-unit-preservation-policy.action";
import {
AdminOrganizationalUnitPreservationPolicyState,
AdminOrganizationalUnitPreservationPolicyStateModel,
} from "@app/features/admin/stores/organizational-unit/preservation-policy/admin-organizational-unit-preservation-policy.state";
import {adminOrgUnitSubmissionPolicyActionNameSpace} from "@app/features/admin/stores/organizational-unit/submission-policy/admin-organizational-unit-submission-policy.action";
import {
AdminOrganizationalUnitSubmissionPolicyState,
......@@ -10,11 +16,10 @@ import {
} from "@app/features/admin/stores/organizational-unit/submission-policy/admin-organizational-unit-submission-policy.state";
import {OrganizationalUnitsExtended} from "@app/features/deposit/models/organizational-unit-extended.model";
import {DepositStateModel} from "@app/features/deposit/stores/deposit.state";
import {AccessResourceApiEnum, AdminResourceApiEnum} from "@app/shared/enums/api.enum";
import {AdminResourceApiEnum} from "@app/shared/enums/api.enum";
import {LocalStateEnum} from "@app/shared/enums/local-state.enum";
import {LocalModelAttributeEnum} from "@app/shared/enums/model-attribute.enum";
import {RoutesEnum} from "@app/shared/enums/routes.enum";
import {LocalStateModel} from "@app/shared/models/local-state.model";
import {SharedPreservationPolicyAction} from "@app/shared/stores/preservation-policy/shared-preservation-policy.action";
import {SharedSubmissionPolicyAction} from "@app/shared/stores/submission-policy/shared-submission-policy.action";
import {Action, Actions, ofActionCompleted, State, StateContext, Store} from "@ngxs/store";
......@@ -33,6 +38,7 @@ import {
ObjectUtil,
OverrideDefaultAction,
Relation2TiersActionHelper,
Relation2TiersNameSpace,
ResourceApiEnum,
ResourceNameSpace,
ResourceState,
......@@ -43,6 +49,7 @@ import {environment} from "../../../../../environments/environment";
export interface AdminOrganizationalUnitStateModel extends ResourceStateModel<OrganizationalUnitsExtended> {
[LocalStateEnum.admin_organizationalUnit_submissionPolicy]?: AdminOrganizationalUnitSubmissionPolicyStateModel;
[LocalStateEnum.admin_organizationalUnit_preservationPolicy]?: AdminOrganizationalUnitPreservationPolicyStateModel;
}
@State<AdminOrganizationalUnitStateModel>({
......@@ -52,6 +59,7 @@ export interface AdminOrganizationalUnitStateModel extends ResourceStateModel<Or
},
children: [
AdminOrganizationalUnitSubmissionPolicyState,
AdminOrganizationalUnitPreservationPolicyState,
],
})
export class AdminOrganizationalUnitState extends ResourceState<OrganizationalUnitsExtended> {
......@@ -64,11 +72,7 @@ export class AdminOrganizationalUnitState extends ResourceState<OrganizationalUn
}
defineUrlResource(): ResourceApiEnum {
const isLoggedId = this.store.selectSnapshot((state: LocalStateModel) => state[LocalStateEnum.application].isLoggedIn);
if (isLoggedId) {
return AdminResourceApiEnum.organizationalUnits;
}
return AccessResourceApiEnum.organizationalUnits;
return AdminResourceApiEnum.organizationalUnits;
}
defineResourceNameSpace(): ResourceNameSpace {
......@@ -110,15 +114,12 @@ export class AdminOrganizationalUnitState extends ResourceState<OrganizationalUn
@Action(AdminOrgUnitAction.Create)
create(ctx: StateContext<AdminOrganizationalUnitStateModel>, action: AdminOrgUnitAction.Create): Observable<OrganizationalUnitsExtended> {
const oldDefaultSubmissionPolicyId = undefined;
const oldDefaultPreservationPolicyId = undefined;
return super.internalCreate(ctx, action)
.pipe(
tap(model => {
const parentResId = model.resId;
const oldSubmissionPolicies = [];
const newSubmissionPolicies = action.modelFormControlEvent.model[LocalModelAttributeEnum.submissionPolicies];
const updateSubResourceAction = Relation2TiersActionHelper.update(adminOrgUnitSubmissionPolicyActionNameSpace, parentResId, oldSubmissionPolicies, newSubmissionPolicies);
const listActionSubActionCompletionsWrapper = this.getUpdateRelationActionsWrapper(action, oldDefaultSubmissionPolicyId, parentResId);
StoreUtil.updateSubResource(ChangeModeEnum.create, this.actions$, ctx, updateSubResourceAction, adminOrgUnitActionNameSpace, adminOrgUnitSubmissionPolicyActionNameSpace, ...listActionSubActionCompletionsWrapper);
this.updateSubResourceSubmissionAndPreservationPolicy(ChangeModeEnum.create, action, ctx, oldDefaultSubmissionPolicyId, oldDefaultPreservationPolicyId, parentResId);
}),
);
}
......@@ -127,38 +128,86 @@ export class AdminOrganizationalUnitState extends ResourceState<OrganizationalUn
@Action(AdminOrgUnitAction.Update)
update(ctx: StateContext<AdminOrganizationalUnitStateModel>, action: AdminOrgUnitAction.Update): Observable<OrganizationalUnitsExtended> {
const oldDefaultSubmissionPolicyId = ObjectUtil.getValue(ctx.getState().current.defaultSubmissionPolicy, ModelAttributeEnum.resId) as string;
const oldDefaultPreservationPolicyId = ObjectUtil.getValue(ctx.getState().current.defaultPreservationPolicy, ModelAttributeEnum.resId) as string;
return super.internalUpdate(ctx, action)
.pipe(
tap(model => {
const parentResId = action.modelFormControlEvent.model.resId;
const oldSubmissionPolicies = _.map(ctx.getState()[LocalStateEnum.admin_organizationalUnit_submissionPolicy].selected, LocalModelAttributeEnum.resId);
const newSubmissionPolicies = action.modelFormControlEvent.model[LocalModelAttributeEnum.submissionPolicies];
const updateSubResourceAction = Relation2TiersActionHelper.update(adminOrgUnitSubmissionPolicyActionNameSpace, parentResId, oldSubmissionPolicies, newSubmissionPolicies);
const listActionSubActionCompletionsWrapper = this.getUpdateRelationActionsWrapper(action, oldDefaultSubmissionPolicyId, parentResId);
StoreUtil.updateSubResource(ChangeModeEnum.update, this.actions$, ctx, updateSubResourceAction, adminOrgUnitActionNameSpace, adminOrgUnitSubmissionPolicyActionNameSpace, ...listActionSubActionCompletionsWrapper);
this.updateSubResourceSubmissionAndPreservationPolicy(ChangeModeEnum.update, action, ctx, oldDefaultSubmissionPolicyId, oldDefaultPreservationPolicyId, parentResId);
}),
);
}
private getUpdateRelationActionsWrapper(action: AdminOrgUnitAction.Update, oldDefaultSubmissionPolicyId: string, parentResId: string): ActionSubActionCompletionsWrapper[] {
private updateSubResourceSubmissionAndPreservationPolicy(changeMode: ChangeModeEnum, action: AdminOrgUnitAction.Create | AdminOrgUnitAction.Update, ctx: StateContext<AdminOrganizationalUnitStateModel>, oldDefaultSubmissionPolicyId: string | undefined, oldDefaultPreservationPolicyId: string | undefined, parentResId: string): void {
const listSubmissionPoliciesActionSubActionCompletionsWrapper = this.getListSubresourceUpdateActionSubActionCompletionsWrapper(
changeMode,
adminOrgUnitSubmissionPolicyActionNameSpace,
action,
ctx,
oldDefaultSubmissionPolicyId,
parentResId,
LocalModelAttributeEnum.defaultSubmissionPolicy,
LocalModelAttributeEnum.submissionPolicies,
LocalStateEnum.admin_organizationalUnit_submissionPolicy);
const listPreservationPoliciesActionSubActionCompletionsWrapper = this.getListSubresourceUpdateActionSubActionCompletionsWrapper(
changeMode,
adminOrgUnitPreservationPolicyActionNameSpace,
action,
ctx,
oldDefaultPreservationPolicyId,
parentResId,
LocalModelAttributeEnum.defaultPreservationPolicy,
LocalModelAttributeEnum.preservationPolicies,
LocalStateEnum.admin_organizationalUnit_preservationPolicy);
StoreUtil.updateSubResourceCustom(changeMode, ctx, adminOrgUnitActionNameSpace, [...listSubmissionPoliciesActionSubActionCompletionsWrapper, ...listPreservationPoliciesActionSubActionCompletionsWrapper]);
}
private getListSubresourceUpdateActionSubActionCompletionsWrapper(changeMode: ChangeModeEnum,
nameSpace: Relation2TiersNameSpace,
action: AdminOrgUnitAction.Create | AdminOrgUnitAction.Update,
ctx: StateContext<AdminOrganizationalUnitStateModel>,
oldDefaultId: string | undefined,
parentResId: string,
defaultFormKey: string,
selectedFormKey: string,
subStateKey: LocalStateEnum): ActionSubActionCompletionsWrapper[] {
const newDefaultId = action.modelFormControlEvent.model[defaultFormKey].resId;
const oldSelectedValues = changeMode === ChangeModeEnum.create ? [] : _.map(ctx.getState()[subStateKey].selected, LocalModelAttributeEnum.resId);
const newSelectedValues = action.modelFormControlEvent.model[selectedFormKey];
return this.getUpdateRelationActionsWrapper(nameSpace, oldDefaultId, newDefaultId, parentResId, oldSelectedValues, newSelectedValues);
}
private getUpdateRelationActionsWrapper(nameSpace: Relation2TiersNameSpace, oldDefaultResId: string | undefined, newDefaultResId: string, parentResId: string, oldSelectedValuesId: string[], newSelectedValuesId: string[]): ActionSubActionCompletionsWrapper[] {
const listActionSubActionCompletionsWrapper: ActionSubActionCompletionsWrapper[] = [];
const newDefaultSubmissionPolicyId = action.modelFormControlEvent.model.defaultSubmissionPolicy.resId;
if (oldDefaultSubmissionPolicyId !== newDefaultSubmissionPolicyId) {
if (isNotNullNorUndefined(oldDefaultSubmissionPolicyId)) {
listActionSubActionCompletionsWrapper.push({
action: Relation2TiersActionHelper.update(nameSpace, parentResId, oldSelectedValuesId, newSelectedValuesId),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateSuccess)),
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateFail)),
],
});
if (oldDefaultResId !== newDefaultResId) {
if (isNotNullNorUndefined(oldDefaultResId) && newSelectedValuesId.includes(oldDefaultResId)) {
listActionSubActionCompletionsWrapper.push({
action: Relation2TiersActionHelper.updateRelation<OrganizationalUnitSubmissionPolicy>(adminOrgUnitSubmissionPolicyActionNameSpace, parentResId, oldDefaultSubmissionPolicyId, {defaultPolicy: false} as OrganizationalUnitSubmissionPolicy),
action: Relation2TiersActionHelper.updateRelation(nameSpace, parentResId, oldDefaultResId, {defaultPolicy: false} as OrganizationalUnitSubmissionPolicy | OrganizationalUnitPreservationPolicy),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(adminOrgUnitSubmissionPolicyActionNameSpace.UpdateRelationSuccess)),
this.actions$.pipe(ofActionCompleted(adminOrgUnitSubmissionPolicyActionNameSpace.UpdateRelationFail)),
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateRelationSuccess)),
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateRelationFail)),
],
});
}
if (isNotNullNorUndefined(newDefaultSubmissionPolicyId)) {
if (isNotNullNorUndefined(newDefaultResId)) {
listActionSubActionCompletionsWrapper.push({
action: Relation2TiersActionHelper.updateRelation<OrganizationalUnitSubmissionPolicy>(adminOrgUnitSubmissionPolicyActionNameSpace, parentResId, newDefaultSubmissionPolicyId, {defaultPolicy: true} as OrganizationalUnitSubmissionPolicy),
action: Relation2TiersActionHelper.updateRelation(nameSpace, parentResId, newDefaultResId, {defaultPolicy: true} as OrganizationalUnitSubmissionPolicy | OrganizationalUnitPreservationPolicy),
subActionCompletions: [
this.actions$.pipe(ofActionCompleted(adminOrgUnitSubmissionPolicyActionNameSpace.UpdateRelationSuccess)),
this.actions$.pipe(ofActionCompleted(adminOrgUnitSubmissionPolicyActionNameSpace.UpdateRelationFail)),
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateRelationSuccess)),
this.actions$.pipe(ofActionCompleted(nameSpace.UpdateRelationFail)),
],
});
}
......
import {OrganizationalUnitPreservationPolicy} from "@app/features/admin/models/organizational-unit-preservation-policy.model";
import {PreservationPolicies} from "@app/generated-api";
import {LocalStateEnum} from "@app/shared/enums/local-state.enum";
import {Relation2TiersAction, Relation2TiersNameSpace, TypeDefaultAction} from "solidify-frontend";
const state = LocalStateEnum.admin_organizationalUnit_preservationPolicy;
export namespace AdminOrgUnitPreservationPolicyAction {
@TypeDefaultAction(state)
export class GetAll extends Relation2TiersAction.GetAll {
}
@TypeDefaultAction(state)
export class GetAllSuccess extends Relation2TiersAction.GetAllSuccess<PreservationPolicies> {
}
@TypeDefaultAction(state)
export class GetAllFail extends Relation2TiersAction.GetAllFail {
}
@TypeDefaultAction(state)
export class GetById extends Relation2TiersAction.GetById {
}
@TypeDefaultAction(state)
export class GetByIdSuccess extends Relation2TiersAction.GetByIdSuccess<PreservationPolicies> {
}
@TypeDefaultAction(state)
export class GetByIdFail extends Relation2TiersAction.GetByIdFail {
}
@TypeDefaultAction(state)
export class Update extends Relation2TiersAction.Update {
}
@TypeDefaultAction(state)
export class UpdateSuccess extends Relation2TiersAction.UpdateSuccess {
}
@TypeDefaultAction(state)
export class UpdateFail extends Relation2TiersAction.UpdateFail {
}
@TypeDefaultAction(state)
export class UpdateRelation extends Relation2TiersAction.UpdateRelation<OrganizationalUnitPreservationPolicy> {
}
@TypeDefaultAction(state)
export class UpdateRelationSuccess extends Relation2TiersAction.UpdateRelationSuccess<OrganizationalUnitPreservationPolicy> {
}
@TypeDefaultAction(state)
export class UpdateRelationFail extends Relation2TiersAction.UpdateRelationFail<OrganizationalUnitPreservationPolicy> {
}
@TypeDefaultAction(state)