Commit 980602fe authored by Florent Poittevin's avatar Florent Poittevin
Browse files

Rename action relation 2 tiers

parent 915d0f9a
......@@ -2,51 +2,51 @@ import {Relation2TiersAction} from "@app/core/stores/relation-2-tiers/relation-2
import {Relation2TiersNameSpace} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
export class Relation2TiersActionHelper {
static getAllSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResource>): Relation2TiersAction.GetAllSubResource {
return new relation2TiersNameSpace.GetAllSubResource(...args);
static getAllSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAll>): Relation2TiersAction.GetAll {
return new relation2TiersNameSpace.GetAll(...args);
}
static getAllSubResourceSuccess<T>(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceSuccess>): Relation2TiersAction.GetAllSubResourceSuccess<T> {
return new relation2TiersNameSpace.GetAllSubResourceSuccess(...args);
static getAllSubResourceSuccess<T>(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSuccess>): Relation2TiersAction.GetAllSuccess<T> {
return new relation2TiersNameSpace.GetAllSuccess(...args);
}
static getAllSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
return new relation2TiersNameSpace.GetAllSubResourceFail(...args);
static getAllSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllFail>): Relation2TiersAction.GetAllFail {
return new relation2TiersNameSpace.GetAllFail(...args);
}
static createSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
return new relation2TiersNameSpace.CreateSubResource(...args);
static createSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.Create>): Relation2TiersAction.Create {
return new relation2TiersNameSpace.Create(...args);
}
static createSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
return new relation2TiersNameSpace.CreateSubResourceSuccess(...args);
static createSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSuccess>): Relation2TiersAction.CreateSuccess {
return new relation2TiersNameSpace.CreateSuccess(...args);
}
static createSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
return new relation2TiersNameSpace.CreateSubResourceFail(...args);
static createSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateFail>): Relation2TiersAction.CreateFail {
return new relation2TiersNameSpace.CreateFail(...args);
}
static deleteSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
return new relation2TiersNameSpace.DeleteSubResource(...args);
static deleteSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.Delete>): Relation2TiersAction.Delete {
return new relation2TiersNameSpace.Delete(...args);
}
static deleteSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
return new relation2TiersNameSpace.DeleteSubResourceSuccess(...args);
static deleteSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSuccess>): Relation2TiersAction.DeleteSuccess {
return new relation2TiersNameSpace.DeleteSuccess(...args);
}
static deleteSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
return new relation2TiersNameSpace.DeleteSubResourceFail(...args);
static deleteSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteFail>): Relation2TiersAction.DeleteFail {
return new relation2TiersNameSpace.DeleteFail(...args);
}
static updateSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
return new relation2TiersNameSpace.UpdateSubResource(...args);
static updateSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.Update>): Relation2TiersAction.Update {
return new relation2TiersNameSpace.Update(...args);
}
static updateSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
return new relation2TiersNameSpace.UpdateSubResourceSuccess(...args);
static updateSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSuccess>): Relation2TiersAction.UpdateSuccess {
return new relation2TiersNameSpace.UpdateSuccess(...args);
}
static updateSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceFail>): Relation2TiersAction.UpdateSubResourceFail {
return new relation2TiersNameSpace.UpdateSubResourceFail(...args);
static updateSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateFail>): Relation2TiersAction.UpdateFail {
return new relation2TiersNameSpace.UpdateFail(...args);
}
}
......@@ -2,16 +2,16 @@ import {BaseStoreNameSpace} from "@app/core/models/stores/base-store-namespace.m
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
export interface Relation2TiersNameSpace extends BaseStoreNameSpace {
GetAllSubResource: StoreActionClass;
GetAllSubResourceSuccess: StoreActionClass;
GetAllSubResourceFail: StoreActionClass;
CreateSubResource: StoreActionClass;
CreateSubResourceSuccess: StoreActionClass;
CreateSubResourceFail: StoreActionClass;
DeleteSubResource: StoreActionClass;
DeleteSubResourceSuccess: StoreActionClass;
DeleteSubResourceFail: StoreActionClass;
UpdateSubResource: StoreActionClass;
UpdateSubResourceSuccess: StoreActionClass;
UpdateSubResourceFail: StoreActionClass;
GetAll: StoreActionClass;
GetAllSuccess: StoreActionClass;
GetAllFail: StoreActionClass;
Create: StoreActionClass;
CreateSuccess: StoreActionClass;
CreateFail: StoreActionClass;
Delete: StoreActionClass;
DeleteSuccess: StoreActionClass;
DeleteFail: StoreActionClass;
Update: StoreActionClass;
UpdateSuccess: StoreActionClass;
UpdateFail: StoreActionClass;
}
......@@ -3,77 +3,70 @@ import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
export namespace Relation2TiersAction {
export class GetAllSubResource {
static readonly type: string = "[{0}] Get All SubResource";
export class GetAll {
static readonly type: string = "[{0}] Relation 2 Tiers : Get All";
constructor(public parentId: string, public queryParameters?: QueryParametersModel) {
}
}
export class GetAllSubResourceSuccess<T> {
static readonly type: string = "[{0}] Get All SubResource Success";
export class GetAllSuccess<T> {
static readonly type: string = "[{0}] Relation 2 Tiers : Get All Success";
constructor(public list: CollectionTypedModel<T>) {
}
}
export class GetAllSubResourceFail {
static readonly type: string = "[{0}] Get All SubResource Fail";
export class GetAllFail {
static readonly type: string = "[{0}] Relation 2 Tiers : Get All Fail";
}
export class CreateCompoSubResource<T> {
static readonly type: string = "[{0}] Create Compo SubResource";
constructor(public parentId: string, public model: T) {
}
}
export class CreateSubResource {
static readonly type: string = "[{0}] Create SubResource";
export class Create {
static readonly type: string = "[{0}] Relation 2 Tiers : Create";
constructor(public parentId: string, public listResId: string[]) {
}
}
export class CreateSubResourceSuccess {
static readonly type: string = "[{0}] Create SubResource Success";
export class CreateSuccess {
static readonly type: string = "[{0}] Relation 2 Tiers : Create Success";
}
export class CreateSubResourceFail {
static readonly type: string = "[{0}] Create SubResource Fail";
export class CreateFail {
static readonly type: string = "[{0}] Relation 2 Tiers : Create Fail";
}
export class DeleteSubResource {
static readonly type: string = "[{0}] Delete SubResource";
export class Delete {
static readonly type: string = "[{0}] Relation 2 Tiers : Delete";
constructor(public parentId: string, public listResId: string[]) {
}
}
export class DeleteSubResourceSuccess {
static readonly type: string = "[{0}] Delete SubResource Success";
export class DeleteSuccess {
static readonly type: string = "[{0}] Relation 2 Tiers : Delete Success";
}
export class DeleteSubResourceFail {
static readonly type: string = "[{0}] Delete SubResource Fail";
export class DeleteFail {
static readonly type: string = "[{0}] Relation 2 Tiers : Delete Fail";
}
export class UpdateSubResource {
static readonly type: string = "[{0}] Update SubResource";
export class Update {
static readonly type: string = "[{0}] Relation 2 Tiers : Update";
constructor(public parentId: string, public oldResId: string[], public newResId: string[]) {
}
}
export class UpdateSubResourceSuccess {
static readonly type: string = "[{0}] Update SubResource Success";
export class UpdateSuccess {
static readonly type: string = "[{0}] Relation 2 Tiers : Update Success";
constructor(public parentId: string) {
}
}
export class UpdateSubResourceFail {
static readonly type: string = "[{0}] Update SubResource Fail";
export class UpdateFail {
static readonly type: string = "[{0}] Relation 2 Tiers : Update Fail";
constructor(public parentId: string) {
}
......
......@@ -58,8 +58,8 @@ export abstract class Relation2TiersState<T> {
return this.urlResource + urlSeparator + parentId + urlSeparator + this.resourceName;
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResource)
getAll<U>(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResource): Observable<CollectionTypedModel<U>> {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAll)
getAll<U>(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAll): Observable<CollectionTypedModel<U>> {
const queryParameters = StoreUtil.getQueryParametersToApply(action.queryParameters, ctx);
const url = this.evaluateSubResourceUrl(action.parentId);
return this.apiService.get<U>(url, queryParameters)
......@@ -74,23 +74,23 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResourceSuccess)
getAllSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceSuccess<T>): void {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSuccess)
getAllSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSuccess<T>): void {
ctx.patchState({
selected: action.list._data,
isLoading: false,
});
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceFail): void {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllFail)
getAllFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.CreateSubResource)
create(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.CreateSubResource): Observable<string[]> {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.Create)
create(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.Create): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
......@@ -107,8 +107,8 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.DeleteSubResource)
delete(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.DeleteSubResource): Observable<string[]> {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.Delete)
delete(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.Delete): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
......@@ -125,30 +125,30 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResource)
update(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResource): void {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.Update)
update(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.Update): void {
const subResourceUpdate: SubResourceUpdateModel = this.determineSubResourceChange(action.oldResId, action.newResId);
const createAndUpdateActions = this.computeUpdatesActionsToDispatch(subResourceUpdate, action.parentId);
ctx.dispatch(createAndUpdateActions);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceSuccess): void {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSuccess)
updateSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSuccess): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.relation2TiersNameSpace, action.parentId));
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceFail): void {
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateFail)
updateFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateFail): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.relation2TiersNameSpace, action.parentId));
}
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): Relation2TiersAction.CreateSubResource[] | Relation2TiersAction.DeleteSubResource[] {
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): Relation2TiersAction.Create[] | Relation2TiersAction.Delete[] {
const actions = [];
const deleteAction = Relation2TiersActionHelper.deleteSubResource(this.relation2TiersNameSpace, parentId, subResourceUpdate.resourceToRemoved);
actions.push(deleteAction);
......
......@@ -35,6 +35,6 @@ export class DetailView extends AbstractDetailView<OrganizationalUnitsModel, Org
}
getSubResourceWithParentId(id: string): void {
this.store.dispatch(new OrgUnitSubmissionPolicyAction.GetAllSubResource(id));
this.store.dispatch(new OrgUnitSubmissionPolicyAction.GetAll(id));
}
}
......@@ -28,7 +28,7 @@ export class EditView extends AbstractEditView<OrganizationalUnitsModel, Organiz
}
getSubResourceWithParentId(id: string): void {
this.store.dispatch(new OrgUnitSubmissionPolicyAction.GetAllSubResource(id));
this.store.dispatch(new OrgUnitSubmissionPolicyAction.GetAll(id));
}
ngOnInit(): void {
......
......@@ -9,51 +9,51 @@ const state = StateEnum.organizationalUnitSubResourceSubmissionPolicy;
export namespace OrgUnitSubmissionPolicyAction {
@TypeDefaultAction(state)
export class GetAllSubResource extends Relation2TiersAction.GetAllSubResource {
export class GetAll extends Relation2TiersAction.GetAll {
}
@TypeDefaultAction(state)
export class GetAllSubResourceSuccess extends Relation2TiersAction.GetAllSubResourceSuccess<SubmissionPoliciesModel> {
export class GetAllSuccess extends Relation2TiersAction.GetAllSuccess<SubmissionPoliciesModel> {
}
@TypeDefaultAction(state)
export class GetAllSubResourceFail extends Relation2TiersAction.GetAllSubResourceFail {
export class GetAllFail extends Relation2TiersAction.GetAllFail {
}
@TypeDefaultAction(state)
export class UpdateSubResource extends Relation2TiersAction.UpdateSubResource {
export class Update extends Relation2TiersAction.Update {
}
@TypeDefaultAction(state)
export class UpdateSubResourceSuccess extends Relation2TiersAction.UpdateSubResourceSuccess {
export class UpdateSuccess extends Relation2TiersAction.UpdateSuccess {
}
@TypeDefaultAction(state)
export class UpdateSubResourceFail extends Relation2TiersAction.UpdateSubResourceFail {
export class UpdateFail extends Relation2TiersAction.UpdateFail {
}
@TypeDefaultAction(state)
export class CreateSubResource extends Relation2TiersAction.CreateSubResource {
export class Create extends Relation2TiersAction.Create {
}
@TypeDefaultAction(state)
export class CreateSubResourceSuccess extends Relation2TiersAction.CreateSubResourceSuccess {
export class CreateSuccess extends Relation2TiersAction.CreateSuccess {
}
@TypeDefaultAction(state)
export class CreateSubResourceFail extends Relation2TiersAction.CreateSubResourceFail {
export class CreateFail extends Relation2TiersAction.CreateFail {
}
@TypeDefaultAction(state)
export class DeleteSubResource extends Relation2TiersAction.DeleteSubResource {
export class Delete extends Relation2TiersAction.Delete {
}
@TypeDefaultAction(state)
export class DeleteSubResourceSuccess extends Relation2TiersAction.DeleteSubResourceSuccess {
export class DeleteSuccess extends Relation2TiersAction.DeleteSuccess {
}
@TypeDefaultAction(state)
export class DeleteSubResourceFail extends Relation2TiersAction.DeleteSubResourceFail {
export class DeleteFail extends Relation2TiersAction.DeleteFail {
}
}
......
......@@ -36,15 +36,15 @@ export class OrganizationalUnitSubmissionPolicyState extends Relation2TiersState
protected notificationService: NotificationService,
private actions$: Actions) {
super(apiService, store, notificationService);
zip(this.actions$.pipe(ofActionCompleted(OrgUnitSubmissionPolicyAction.CreateSubResource)),
this.actions$.pipe(ofActionCompleted(OrgUnitSubmissionPolicyAction.DeleteSubResource)))
zip(this.actions$.pipe(ofActionCompleted(OrgUnitSubmissionPolicyAction.Create)),
this.actions$.pipe(ofActionCompleted(OrgUnitSubmissionPolicyAction.Delete)))
.pipe(
tap((completions: ActionCompletion[]) => {
const parentId = (completions[0].action as OrgUnitSubmissionPolicyAction.CreateSubResource).parentId;
const parentId = (completions[0].action as OrgUnitSubmissionPolicyAction.Create).parentId;
if (completions.every(c => c.result.successful)) {
this.store.dispatch(new OrgUnitSubmissionPolicyAction.UpdateSubResourceSuccess(parentId));
this.store.dispatch(new OrgUnitSubmissionPolicyAction.UpdateSuccess(parentId));
} else {
this.store.dispatch(new OrgUnitSubmissionPolicyAction.UpdateSubResourceFail(parentId));
this.store.dispatch(new OrgUnitSubmissionPolicyAction.UpdateFail(parentId));
}
}),
).subscribe();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment