Commit c369f0e7 authored by Florent Poittevin's avatar Florent Poittevin
Browse files

Add Composition generic state

parent ca3df1b8
import {CompositionNameSpace} from "@app/core/stores/composition/composition-namespace.model";
import {CompositionAction} from "@app/core/stores/composition/composition.action";
export class CompositionActionHelper {
static getAllSubResource(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.GetAllSubResource>): CompositionAction.GetAllSubResource {
return new compositionNameSpace.GetAllSubResource(...args);
}
static getAllSubResourceSuccess<T>(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.GetAllSubResourceSuccess>): CompositionAction.GetAllSubResourceSuccess<T> {
return new compositionNameSpace.GetAllSubResourceSuccess(...args);
}
static getAllSubResourceFail(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.GetAllSubResourceFail>): CompositionAction.GetAllSubResourceFail {
return new compositionNameSpace.GetAllSubResourceFail(...args);
}
static createSubResource(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.CreateSubResource>): CompositionAction.CreateSubResource {
return new compositionNameSpace.CreateSubResource(...args);
}
static createSubResourceSuccess(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.CreateSubResourceSuccess>): CompositionAction.CreateSubResourceSuccess {
return new compositionNameSpace.CreateSubResourceSuccess(...args);
}
static createSubResourceFail(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.CreateSubResourceFail>): CompositionAction.CreateSubResourceFail {
return new compositionNameSpace.CreateSubResourceFail(...args);
}
static deleteSubResource(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.DeleteSubResource>): CompositionAction.DeleteSubResource {
return new compositionNameSpace.DeleteSubResource(...args);
}
static deleteSubResourceSuccess(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.DeleteSubResourceSuccess>): CompositionAction.DeleteSubResourceSuccess {
return new compositionNameSpace.DeleteSubResourceSuccess(...args);
}
static deleteSubResourceFail(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.DeleteSubResourceFail>): CompositionAction.DeleteSubResourceFail {
return new compositionNameSpace.DeleteSubResourceFail(...args);
}
static updateSubResource(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.UpdateSubResource>): CompositionAction.UpdateSubResource {
return new compositionNameSpace.UpdateSubResource(...args);
}
static updateSubResourceSuccess(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.UpdateSubResourceSuccess>): CompositionAction.UpdateSubResourceSuccess {
return new compositionNameSpace.UpdateSubResourceSuccess(...args);
}
static updateSubResourceFail(compositionNameSpace: CompositionNameSpace, ...args: ConstructorParameters<typeof CompositionAction.UpdateSubResourceFail>): CompositionAction.UpdateSubResourceFail {
return new compositionNameSpace.UpdateSubResourceFail(...args);
}
}
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
import {BaseStoreNameSpace} from "@app/core/models/stores/base-store-namespace.model";
export interface CompositionNameSpace 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;
}
import {CompositionNameSpace} from "@app/core/stores/composition/composition-namespace.model";
import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
export namespace CompositionAction {
export class GetAllSubResource {
static readonly type: string = "[{0}] Get All SubResource";
constructor(public parentId: string, public queryParameters?: QueryParametersModel) {
}
}
export class GetAllSubResourceSuccess<T> {
static readonly type: string = "[{0}] Get All SubResource Success";
constructor(public list: CollectionTypedModel<T>) {
}
}
export class GetAllSubResourceFail {
static readonly type: string = "[{0}] Get All SubResource 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";
constructor(public parentId: string, public listResId: string[]) {
}
}
export class CreateSubResourceSuccess {
static readonly type: string = "[{0}] Create SubResource Success";
}
export class CreateSubResourceFail {
static readonly type: string = "[{0}] Create SubResource Fail";
}
export class DeleteSubResource {
static readonly type: string = "[{0}] Delete SubResource";
constructor(public parentId: string, public listResId: string[]) {
}
}
export class DeleteSubResourceSuccess {
static readonly type: string = "[{0}] Delete SubResource Success";
}
export class DeleteSubResourceFail {
static readonly type: string = "[{0}] Delete SubResource Fail";
}
export class UpdateSubResource {
static readonly type: string = "[{0}] Update SubResource";
constructor(public parentId: string, public oldResId: string[], public newResId: string[]) {
}
}
export class UpdateSubResourceSuccess {
static readonly type: string = "[{0}] Update SubResource Success";
constructor(public parentId: string) {
}
}
export class UpdateSubResourceFail {
static readonly type: string = "[{0}] Update SubResource Fail";
constructor(public parentId: string) {
}
}
}
export const compositionActionNameSpace: CompositionNameSpace = CompositionAction;
import {CompositionActionHelper} from "@app/core/stores/composition/composition-action.helper";
import {ApiService} from "@app/core/http/api.service";
import {BaseResourceState} from "@app/core/models/stores/base-resource.state";
import {NotificationService} from "@app/core/services/notification.service";
import {CompositionNameSpace} from "@app/core/stores/composition/composition-namespace.model";
import {CompositionAction} from "@app/core/stores/composition/composition.action";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {RegisterDefaultAction} from "@app/shared/decorators/store.decorator";
import {ApiResourceNameEnum} from "@app/shared/enums/api-resource-name.enum";
import {ResourceApiEnum} from "@app/shared/enums/api.enum";
import {urlSeparator} from "@app/shared/enums/routes.enum";
import {StateEnum} from "@app/shared/enums/state.enum";
import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
import {SubResourceUpdateModel} from "@app/shared/models/sub-resource-update.model";
import {StateContext, Store} from "@ngxs/store";
import _ from "lodash";
import {Observable} from "rxjs";
import {catchError} from "rxjs/internal/operators/catchError";
import {tap} from "rxjs/internal/operators/tap";
export interface CompositionStateModel<T> extends BaseResourceState {
selected: T[];
}
export const defaultCompositionStateInitValue: CompositionStateModel<any> = {
total: 0,
isLoading: false,
selected: [],
queryParameters: new QueryParametersModel(),
};
export abstract class CompositionState<T> {
protected readonly state: StateEnum;
protected readonly compositionNameSpace: CompositionNameSpace;
protected readonly urlResource: ResourceApiEnum;
private readonly resourceName: ApiResourceNameEnum;
protected constructor(protected apiService: ApiService,
protected store: Store,
protected notificationService: NotificationService) {
this.urlResource = this.defineUrlResource();
this.state = this.defineState();
this.compositionNameSpace = this.defineCompositionNameSpace();
this.resourceName = this.defineResourceName();
StoreUtil.initState(CompositionState, this.constructor, this.compositionNameSpace);
}
abstract defineUrlResource(): ResourceApiEnum;
abstract defineState(): StateEnum;
abstract defineCompositionNameSpace(): CompositionNameSpace;
abstract defineResourceName(): ApiResourceNameEnum;
private evaluateSubResourceUrl(parentId: string): string {
return this.urlResource + urlSeparator + parentId + urlSeparator + this.resourceName;
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.GetAllSubResource)
getAll<U>(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.GetAllSubResource): Observable<CollectionTypedModel<U>> {
const queryParameters = StoreUtil.getQueryParametersToApply(action.queryParameters, ctx);
const url = this.evaluateSubResourceUrl(action.parentId);
return this.apiService.get<U>(url, queryParameters)
.pipe(
tap((collection: CollectionTypedModel<U>) => {
ctx.dispatch(CompositionActionHelper.getAllSubResourceSuccess<U>(this.compositionNameSpace, collection));
}),
catchError(error => {
ctx.dispatch(CompositionActionHelper.getAllSubResourceFail(this.compositionNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.GetAllSubResourceSuccess)
getAllSuccess(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.GetAllSubResourceSuccess<T>): void {
ctx.patchState({
selected: action.list._data,
isLoading: false,
});
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.GetAllSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.CreateSubResource)
create(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.CreateSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
const url = this.evaluateSubResourceUrl(action.parentId);
return this.apiService.post<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(CompositionActionHelper.createSubResourceSuccess(this.compositionNameSpace));
}),
catchError(error => {
ctx.dispatch(CompositionActionHelper.createSubResourceFail(this.compositionNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.DeleteSubResource)
delete(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.DeleteSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
const url = this.evaluateSubResourceUrl(action.parentId);
return this.apiService.delete<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(CompositionActionHelper.deleteSubResourceSuccess(this.compositionNameSpace));
}),
catchError(error => {
ctx.dispatch(CompositionActionHelper.deleteSubResourceFail(this.compositionNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.UpdateSubResource)
update(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.UpdateSubResource): void {
const subResourceUpdate: SubResourceUpdateModel = this.determineSubResourceChange(action.oldResId, action.newResId);
const createAndUpdateActions = this.computeUpdatesActionsToDispatch(subResourceUpdate, action.parentId);
ctx.dispatch(createAndUpdateActions);
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.UpdateSubResourceSuccess): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(CompositionActionHelper.getAllSubResource(this.compositionNameSpace, action.parentId));
}
@RegisterDefaultAction((compositionNameSpace: CompositionNameSpace) => compositionNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<CompositionStateModel<T>>, action: CompositionAction.UpdateSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(CompositionActionHelper.getAllSubResource(this.compositionNameSpace, action.parentId));
}
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): CompositionAction.CreateSubResource[] | CompositionAction.DeleteSubResource[] {
const actions = [];
const deleteAction = CompositionActionHelper.deleteSubResource(this.compositionNameSpace, parentId, subResourceUpdate.resourceToRemoved);
actions.push(deleteAction);
const createAction = CompositionActionHelper.createSubResource(this.compositionNameSpace, parentId, subResourceUpdate.resourceToAdd);
actions.push(createAction);
return actions;
}
private determineSubResourceChange(oldList: string[], newList: string[]): SubResourceUpdateModel {
const subResourceUpdate: SubResourceUpdateModel = new SubResourceUpdateModel();
const diff: string[] = _.xor(oldList, newList);
diff.forEach(d => {
if (_.includes(oldList, d)) {
subResourceUpdate.resourceToRemoved.push(d);
} else {
subResourceUpdate.resourceToAdd.push(d);
}
});
return subResourceUpdate;
}
}
import {Relation2TiersAction} from "@app/core/stores/relation-2-tiers/relation-2-tiers.action";
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
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 {
static getAllSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResource>): Relation2TiersAction.GetAllSubResource {
return new relation2TiersNameSpace.GetAllSubResource(...args);
}
static getAllSubResourceSuccess<T>(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceSuccess>): Relation2TiersAction.GetAllSubResourceSuccess<T> {
static getAllSubResourceSuccess<T>(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceSuccess>): Relation2TiersAction.GetAllSubResourceSuccess<T> {
return new relation2TiersNameSpace.GetAllSubResourceSuccess(...args);
}
static getAllSubResourceFail(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
static getAllSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
return new relation2TiersNameSpace.GetAllSubResourceFail(...args);
}
static createSubResource(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
static createSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
return new relation2TiersNameSpace.CreateSubResource(...args);
}
static createSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
static createSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
return new relation2TiersNameSpace.CreateSubResourceSuccess(...args);
}
static createSubResourceFail(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
static createSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
return new relation2TiersNameSpace.CreateSubResourceFail(...args);
}
static deleteSubResource(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
static deleteSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
return new relation2TiersNameSpace.DeleteSubResource(...args);
}
static deleteSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
static deleteSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
return new relation2TiersNameSpace.DeleteSubResourceSuccess(...args);
}
static deleteSubResourceFail(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
static deleteSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
return new relation2TiersNameSpace.DeleteSubResourceFail(...args);
}
static updateSubResource(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
static updateSubResource(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
return new relation2TiersNameSpace.UpdateSubResource(...args);
}
static updateSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
static updateSubResourceSuccess(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
return new relation2TiersNameSpace.UpdateSubResourceSuccess(...args);
}
static updateSubResourceFail(relation2TiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceFail>): Relation2TiersAction.UpdateSubResourceFail {
static updateSubResourceFail(relation2TiersNameSpace: Relation2TiersNameSpace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceFail>): Relation2TiersAction.UpdateSubResourceFail {
return new relation2TiersNameSpace.UpdateSubResourceFail(...args);
}
}
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
import {BaseStoreNameSpace} from "@app/core/models/stores/base-store-namespace.model";
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
export interface Relation2TiersNamespace extends BaseStoreNameSpace {
export interface Relation2TiersNameSpace extends BaseStoreNameSpace {
GetAllSubResource: StoreActionClass;
GetAllSubResourceSuccess: StoreActionClass;
GetAllSubResourceFail: StoreActionClass;
......
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
import {Relation2TiersNameSpace} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
......@@ -80,4 +80,4 @@ export namespace Relation2TiersAction {
}
}
export const relation2TiersActionNameSpace: Relation2TiersNamespace = Relation2TiersAction;
export const relation2TiersActionNameSpace: Relation2TiersNameSpace = Relation2TiersAction;
import {ApiService} from "@app/core/http/api.service";
import {NotificationService} from "@app/core/services/notification.service";
import {Relation2TiersAction} from "@app/core/stores/relation-2-tiers/relation-2-tiers.action";
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
import {Relation2TiersActionHelper} from "@app/core/helpers/relation-2-tiers-action.helper";
import {Relation2TiersNameSpace} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
import {Relation2TiersActionHelper} from "@app/core/stores/relation-2-tiers/relation-2-tiers-action.helper";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {BaseResourceState} from "@app/core/models/stores/base-resource.state";
import {RegisterDefaultAction} from "@app/shared/decorators/store.decorator";
......@@ -32,7 +32,7 @@ export const defaultRelation2TiersStateInitValue: Relation2TiersStateModel<any>
export abstract class Relation2TiersState<T> {
protected readonly state: StateEnum;
protected readonly relation2TiersNameSpace: Relation2TiersNamespace;
protected readonly relation2TiersNameSpace: Relation2TiersNameSpace;
protected readonly urlResource: ResourceApiEnum;
private readonly resourceName: ApiResourceNameEnum;
......@@ -50,7 +50,7 @@ export abstract class Relation2TiersState<T> {
abstract defineState(): StateEnum;
abstract defineRelation2TiersNameSpace(): Relation2TiersNamespace;
abstract defineRelation2TiersNameSpace(): Relation2TiersNameSpace;
abstract defineResourceName(): ApiResourceNameEnum;
......@@ -58,7 +58,7 @@ export abstract class Relation2TiersState<T> {
return this.urlResource + urlSeparator + parentId + urlSeparator + this.resourceName;
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.GetAllSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResource)
getAll<U>(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResource): Observable<CollectionTypedModel<U>> {
const queryParameters = StoreUtil.getQueryParametersToApply(action.queryParameters, ctx);
const url = this.evaluateSubResourceUrl(action.parentId);
......@@ -74,7 +74,7 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.GetAllSubResourceSuccess)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResourceSuccess)
getAllSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceSuccess<T>): void {
ctx.patchState({
selected: action.list._data,
......@@ -82,14 +82,14 @@ export abstract class Relation2TiersState<T> {
});
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.GetAllSubResourceFail)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.CreateSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.CreateSubResource)
create(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.CreateSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
......@@ -107,7 +107,7 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.DeleteSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.DeleteSubResource)
delete(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.DeleteSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
......@@ -125,14 +125,14 @@ export abstract class Relation2TiersState<T> {
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.UpdateSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResource)
update(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResource): 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)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceSuccess): void {
ctx.patchState({
isLoading: false,
......@@ -140,7 +140,7 @@ export abstract class Relation2TiersState<T> {
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.relation2TiersNameSpace, action.parentId));
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.UpdateSubResourceFail)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNameSpace) => relation2TiersNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceFail): void {
ctx.patchState({
isLoading: false,
......
import {Relation3TiersNamespace} from "@app/core/stores/relation-3-tiers/relation-3-tiers-namespace.model";
import {Relation3TiersNameSpace} from "@app/core/stores/relation-3-tiers/relation-3-tiers-namespace.model";
import {Relation3TiersAction} from "@app/core/stores/relation-3-tiers/relation-3-tiers.action";
export class Relation3TiersActionHelper {
static getAllSubResource(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResource>): Relation3TiersAction.GetAllSubResource {
return new relation3TiersNamespace.GetAllSubResource(...args);
static getAllSubResource(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResource>): Relation3TiersAction.GetAllSubResource {
return new relation3TiersNameSpace.GetAllSubResource(...args);
}
static getAllSubResourceSuccess<T>(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResourceSuccess>): Relation3TiersAction.GetAllSubResourceSuccess<T> {
return new relation3TiersNamespace.GetAllSubResourceSuccess(...args);
static getAllSubResourceSuccess<T>(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResourceSuccess>): Relation3TiersAction.GetAllSubResourceSuccess<T> {
return new relation3TiersNameSpace.GetAllSubResourceSuccess(...args);
}
static getAllSubResourceFail(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResourceFail>): Relation3TiersAction.GetAllSubResourceFail {
return new relation3TiersNamespace.GetAllSubResourceFail(...args);
static getAllSubResourceFail(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.GetAllSubResourceFail>): Relation3TiersAction.GetAllSubResourceFail {
return new relation3TiersNameSpace.GetAllSubResourceFail(...args);
}
static createSubResource(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResource>): Relation3TiersAction.CreateSubResource {
return new relation3TiersNamespace.CreateSubResource(...args);
static createSubResource(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResource>): Relation3TiersAction.CreateSubResource {
return new relation3TiersNameSpace.CreateSubResource(...args);
}
static createSubResourceSuccess(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResourceSuccess>): Relation3TiersAction.CreateSubResourceSuccess {
return new relation3TiersNamespace.CreateSubResourceSuccess(...args);
static createSubResourceSuccess(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResourceSuccess>): Relation3TiersAction.CreateSubResourceSuccess {
return new relation3TiersNameSpace.CreateSubResourceSuccess(...args);
}
static createSubResourceFail(relation3TiersNamespace: Relation3TiersNamespace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResourceFail>): Relation3TiersAction.CreateSubResourceFail {
return new relation3TiersNamespace.CreateSubResourceFail(...args);
static createSubResourceFail(relation3TiersNameSpace: Relation3TiersNameSpace, ...args: ConstructorParameters<typeof Relation3TiersAction.CreateSubResourceFail>): Relation3TiersAction.CreateSubResourceFail {
return new relation3TiersNameSpace.CreateSubResourceFail(...args);
} <