Commit 8c21f774 authored by Florent Poittevin's avatar Florent Poittevin
Browse files

Rename attribut of state

parent 5c3e72f2
import {Relation2TiersAction} from "@app/core/stores/relation-2-tiers/relation-2-tiers.action";
import {Relation2TiersNamespaceModel} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
export class Relation2TiersActionHelper {
static getAllSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResource>): Relation2TiersAction.GetAllSubResource {
static getAllSubResource(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResource>): Relation2TiersAction.GetAllSubResource {
return new crudTwoTiersNameSpace.GetAllSubResource(...args);
}
static getAllSubResourceSuccess<T>(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceSuccess>): Relation2TiersAction.GetAllSubResourceSuccess<T> {
static getAllSubResourceSuccess<T>(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceSuccess>): Relation2TiersAction.GetAllSubResourceSuccess<T> {
return new crudTwoTiersNameSpace.GetAllSubResourceSuccess(...args);
}
static getAllSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
static getAllSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
return new crudTwoTiersNameSpace.GetAllSubResourceFail(...args);
}
static createSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
static createSubResource(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
return new crudTwoTiersNameSpace.CreateSubResource(...args);
}
static createSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
static createSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
return new crudTwoTiersNameSpace.CreateSubResourceSuccess(...args);
}
static createSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
static createSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
return new crudTwoTiersNameSpace.CreateSubResourceFail(...args);
}
static deleteSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
static deleteSubResource(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
return new crudTwoTiersNameSpace.DeleteSubResource(...args);
}
static deleteSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
static deleteSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
return new crudTwoTiersNameSpace.DeleteSubResourceSuccess(...args);
}
static deleteSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
static deleteSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
return new crudTwoTiersNameSpace.DeleteSubResourceFail(...args);
}
static updateSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
static updateSubResource(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
return new crudTwoTiersNameSpace.UpdateSubResource(...args);
}
static updateSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
static updateSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
return new crudTwoTiersNameSpace.UpdateSubResourceSuccess(...args);
}
static updateSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceFail>): Relation2TiersAction.UpdateSubResourceFail {
static updateSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespace, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceFail>): Relation2TiersAction.UpdateSubResourceFail {
return new crudTwoTiersNameSpace.UpdateSubResourceFail(...args);
}
}
import {ResourceAction} from "@app/core/stores/resource/resource.action";
import {ResourceNamespaceModel} from "@app/core/stores/resource/resource-namespace.model";
import {ResourceNamespace} from "../stores/resource/resource.namespace";
export class ResourceActionHelper {
static loadResource(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResource>): ResourceAction.LoadResource {
static loadResource(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.LoadResource>): ResourceAction.LoadResource {
return new crudNameSpace.LoadResource(...args);
}
static loadResourceSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceSuccess>): ResourceAction.LoadResourceSuccess {
static loadResourceSuccess(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceSuccess>): ResourceAction.LoadResourceSuccess {
return new crudNameSpace.LoadResourceSuccess(...args);
}
static loadResourceFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceFail>): ResourceAction.LoadResourceFail {
static loadResourceFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceFail>): ResourceAction.LoadResourceFail {
return new crudNameSpace.LoadResourceFail(...args);
}
static changeQueryParameters(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.ChangeQueryParameters>): ResourceAction.ChangeQueryParameters {
static changeQueryParameters(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.ChangeQueryParameters>): ResourceAction.ChangeQueryParameters {
return new crudNameSpace.ChangeQueryParameters(...args);
}
static getAll(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetAll>): ResourceAction.GetAll {
static getAll(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetAll>): ResourceAction.GetAll {
return new crudNameSpace.GetAll(...args);
}
static getAllSuccess<T>(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetAllSuccess>): ResourceAction.GetAllSuccess<T> {
static getAllSuccess<T>(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetAllSuccess>): ResourceAction.GetAllSuccess<T> {
return new crudNameSpace.GetAllSuccess(...args);
}
static getAllFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetAllFail>): ResourceAction.GetAllFail {
static getAllFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetAllFail>): ResourceAction.GetAllFail {
return new crudNameSpace.GetAllFail(...args);
}
static getById(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetById>): ResourceAction.GetById {
static getById(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetById>): ResourceAction.GetById {
return new crudNameSpace.GetById(...args);
}
static getByIdSuccess<T>(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetByIdSuccess>): ResourceAction.GetByIdSuccess<T> {
static getByIdSuccess<T>(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetByIdSuccess>): ResourceAction.GetByIdSuccess<T> {
return new crudNameSpace.GetByIdSuccess(...args);
}
static getByIdFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetByIdFail>): ResourceAction.GetByIdFail {
static getByIdFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.GetByIdFail>): ResourceAction.GetByIdFail {
return new crudNameSpace.GetByIdFail(...args);
}
static create<T>(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.Create>): ResourceAction.Create<T> {
static create<T>(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.Create>): ResourceAction.Create<T> {
return new crudNameSpace.Create(...args);
}
static createSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.CreateSuccess>): ResourceAction.CreateSuccess {
static createSuccess(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.CreateSuccess>): ResourceAction.CreateSuccess {
return new crudNameSpace.CreateSuccess(...args);
}
static createFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.CreateFail>): ResourceAction.CreateFail {
static createFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.CreateFail>): ResourceAction.CreateFail {
return new crudNameSpace.CreateFail(...args);
}
static update<T>(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.Update>): ResourceAction.Update<T> {
static update<T>(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.Update>): ResourceAction.Update<T> {
return new crudNameSpace.Update(...args);
}
static updateSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.UpdateSuccess>): ResourceAction.UpdateSuccess {
static updateSuccess(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.UpdateSuccess>): ResourceAction.UpdateSuccess {
return new crudNameSpace.UpdateSuccess(...args);
}
static updateFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.UpdateFail>): ResourceAction.UpdateFail {
static updateFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.UpdateFail>): ResourceAction.UpdateFail {
return new crudNameSpace.UpdateFail(...args);
}
static delete(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.Delete>): ResourceAction.Delete {
static delete(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.Delete>): ResourceAction.Delete {
return new crudNameSpace.Delete(...args);
}
static deleteSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.DeleteSuccess>): ResourceAction.DeleteSuccess {
static deleteSuccess(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.DeleteSuccess>): ResourceAction.DeleteSuccess {
return new crudNameSpace.DeleteSuccess(...args);
}
static deleteFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.DeleteFail>): ResourceAction.DeleteFail {
static deleteFail(crudNameSpace: ResourceNamespace, ...args: ConstructorParameters<typeof ResourceAction.DeleteFail>): ResourceAction.DeleteFail {
return new crudNameSpace.DeleteFail(...args);
}
}
import {Relation2TiersNamespaceModel} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
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: Relation2TiersNamespaceModel = 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 {Relation2TiersNamespaceModel} from "@app/core/stores/relation-2-tiers/relation-2-tiers-namespace.model";
import {Relation2TiersNamespace} from "@app/core/stores/relation-2-tiers/relation2-tiers.namespace";
import {Relation2TiersActionHelper} from "@app/core/helpers/relation-2-tiers-action.helper";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {BaseResourceState} from "@app/core/models/stores/base-resource.state";
......@@ -32,49 +32,49 @@ export const defaultRelation2TiersStateInitValue: Relation2TiersStateModel<any>
export abstract class Relation2TiersState<T> {
protected readonly state: StateEnum;
protected readonly crudTwoTiersNameSpace: Relation2TiersNamespaceModel;
protected readonly relation2TiersNameSpace: Relation2TiersNamespace;
protected readonly urlResource: ResourceApiEnum;
private readonly subResource: ApiResourceNameEnum;
private readonly subResourceName: ApiResourceNameEnum;
protected constructor(protected apiService: ApiService,
protected store: Store,
protected notificationService: NotificationService) {
this.urlResource = this.defineUrlResource();
this.state = this.defineState();
this.crudTwoTiersNameSpace = this.defineCrudNameSpace();
this.subResource = this.defineSubResource();
StoreUtil.initState(Relation2TiersState, this.constructor, this.crudTwoTiersNameSpace);
this.relation2TiersNameSpace = this.defineCrudNameSpace();
this.subResourceName = this.defineSubResource();
StoreUtil.initState(Relation2TiersState, this.constructor, this.relation2TiersNameSpace);
}
abstract defineUrlResource(): ResourceApiEnum;
abstract defineState(): StateEnum;
abstract defineCrudNameSpace(): Relation2TiersNamespaceModel;
abstract defineCrudNameSpace(): Relation2TiersNamespace;
abstract defineSubResource(): ApiResourceNameEnum;
private evaluateSubResourceUrl(parentId: string): string {
return this.urlResource + urlSeparator + parentId + urlSeparator + this.subResource;
return this.urlResource + urlSeparator + parentId + urlSeparator + this.subResourceName;
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => 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);
return this.apiService.get<U>(url, queryParameters)
.pipe(
tap((collection: CollectionTypedModel<U>) => {
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceSuccess<U>(this.crudTwoTiersNameSpace, collection));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceSuccess<U>(this.relation2TiersNameSpace, collection));
}),
catchError(error => {
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceFail(this.relation2TiersNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => 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: Relation2TiersNamespaceModel) => relation2TiersNameSpace.GetAllSubResourceFail)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => relation2TiersNameSpace.CreateSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.CreateSubResource)
create(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.CreateSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
......@@ -98,16 +98,16 @@ export abstract class Relation2TiersState<T> {
return this.apiService.post<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(Relation2TiersActionHelper.createSubResourceSuccess(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.createSubResourceSuccess(this.relation2TiersNameSpace));
}),
catchError(error => {
ctx.dispatch(Relation2TiersActionHelper.createSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.createSubResourceFail(this.relation2TiersNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => relation2TiersNameSpace.DeleteSubResource)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.DeleteSubResource)
delete(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.DeleteSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
......@@ -116,43 +116,43 @@ export abstract class Relation2TiersState<T> {
return this.apiService.delete<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceSuccess(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceSuccess(this.relation2TiersNameSpace));
}),
catchError(error => {
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceFail(this.relation2TiersNameSpace));
throw error;
}),
);
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => 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: Relation2TiersNamespaceModel) => relation2TiersNameSpace.UpdateSubResourceSuccess)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceSuccess): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.relation2TiersNameSpace, action.parentId));
}
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespaceModel) => relation2TiersNameSpace.UpdateSubResourceFail)
@RegisterDefaultAction((relation2TiersNameSpace: Relation2TiersNamespace) => relation2TiersNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.relation2TiersNameSpace, action.parentId));
}
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): Relation2TiersAction.CreateSubResource[] | Relation2TiersAction.DeleteSubResource[] {
const actions = [];
const deleteAction = Relation2TiersActionHelper.deleteSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToRemoved);
const deleteAction = Relation2TiersActionHelper.deleteSubResource(this.relation2TiersNameSpace, parentId, subResourceUpdate.resourceToRemoved);
actions.push(deleteAction);
const createAction = Relation2TiersActionHelper.createSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToAdd);
const createAction = Relation2TiersActionHelper.createSubResource(this.relation2TiersNameSpace, parentId, subResourceUpdate.resourceToAdd);
actions.push(createAction);
return actions;
}
......
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
import {BaseStoreNameSpace} from "@app/core/models/stores/base-store-namespace.model";
export interface Relation2TiersNamespaceModel extends BaseStoreNameSpace {
export interface Relation2TiersNamespace extends BaseStoreNameSpace {
GetAllSubResource: StoreActionClass;
GetAllSubResourceSuccess: StoreActionClass;
GetAllSubResourceFail: StoreActionClass;
......
import {ResourceNamespaceModel} from "@app/core/stores/resource/resource-namespace.model";
import {ResourceNamespace} from "./resource.namespace";
import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
......@@ -104,4 +104,4 @@ export namespace ResourceAction {
}
}
export const crudActionNameSpace: ResourceNamespaceModel = ResourceAction;
export const crudActionNameSpace: ResourceNamespace = ResourceAction;
import {StoreActionClass} from "@app/core/models/stores/state-action.model";
import {BaseStoreNameSpace} from "@app/core/models/stores/base-store-namespace.model";
export interface ResourceNamespaceModel extends BaseStoreNameSpace {
export interface ResourceNamespace extends BaseStoreNameSpace {
LoadResource: StoreActionClass;
LoadResourceSuccess: StoreActionClass;
LoadResourceFail: StoreActionClass;
......
import {ResourceActionHelper} from "@app/core/helpers/resource-action.helper";
import {ApiService} from "@app/core/http/api.service";
import {NotificationService} from "@app/core/services/notification.service";
import {ResourceNamespaceModel} from "@app/core/stores/resource/resource-namespace.model";
import {BaseResourceState} from "@app/core/models/stores/base-resource.state";
import {NotificationService} from "@app/core/services/notification.service";
import {ResourceAction} from "@app/core/stores/resource/resource.action";
import {StoreRouteUtil} from "@app/core/utils/stores/store-route.util";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {TRANSLATE} from "@app/core/utils/translate.util";
import {RegisterDefaultAction} from "@app/shared/decorators/store.decorator";
import {ResourceApiEnum} from "@app/shared/enums/api.enum";
import {ModelAttributeEnum} from "@app/shared/enums/model-attribute.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 {ResourceActionHelper} from "@app/core/helpers/resource-action.helper";
import {StoreRouteUtil} from "@app/core/utils/stores/store-route.util";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {TRANSLATE} from "@app/core/utils/translate.util";
import {Navigate} from "@ngxs/router-plugin";
import {StateContext, Store} from "@ngxs/store";
import {Observable} from "rxjs";
import {catchError} from "rxjs/internal/operators/catchError";
import {tap} from "rxjs/operators";
import {ResourceNamespace} from "./resource.namespace";
export interface ResourceStateModel<T> extends BaseResourceState {
list: T[];
......@@ -34,7 +34,7 @@ export const defaultResourceStateInitValue: ResourceStateModel<any> = {
export abstract class ResourceState<T> {
protected readonly state: StateEnum;
protected readonly resourceNameSpace: ResourceNamespaceModel;
protected readonly resourceNameSpace: ResourceNamespace;
protected readonly urlResource: ResourceApiEnum;
protected constructor(protected apiService: ApiService,
......@@ -50,9 +50,9 @@ export abstract class ResourceState<T> {
abstract defineState(): StateEnum;
abstract defineResourceNameSpace(): ResourceNamespaceModel;
abstract defineResourceNameSpace(): ResourceNamespace;
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.ChangeQueryParameters)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.ChangeQueryParameters)
changeQueryParameters(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.ChangeQueryParameters): void {
ctx.patchState({
queryParameters: action.queryParameters,
......@@ -60,7 +60,7 @@ export abstract class ResourceState<T> {
ctx.dispatch(ResourceActionHelper.getAll(this.resourceNameSpace));
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetAll, {cancelUncompleted: true})
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetAll, {cancelUncompleted: true})
getAll(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetAll): Observable<CollectionTypedModel<T>> {
ctx.patchState({
......@@ -81,7 +81,7 @@ export abstract class ResourceState<T> {
);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetAllSuccess)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetAllSuccess)
getAllSuccess(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetAllSuccess<T>): void {
const queryParameters = StoreUtil.updateQueryParameters(ctx, action.list);
......@@ -93,14 +93,14 @@ export abstract class ResourceState<T> {
});
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetAllFail)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetAllFail)
getAllFail(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetAllFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetById)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetById)
getById(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetById): Observable<T> {
ctx.patchState({
isLoading: true,
......@@ -119,7 +119,7 @@ export abstract class ResourceState<T> {
);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetByIdSuccess)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetByIdSuccess)
getByIdSuccess(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetByIdSuccess<T>): void {
ctx.patchState({
current: action.model,
......@@ -127,14 +127,14 @@ export abstract class ResourceState<T> {
});
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.GetByIdFail)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.GetByIdFail)
getByIdFail(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.GetByIdFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.Create)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.Create)
create(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.Create<T>): Observable<T> {
ctx.patchState({
isLoading: true,
......@@ -152,7 +152,7 @@ export abstract class ResourceState<T> {
);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.CreateSuccess)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.CreateSuccess)
createSuccess(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.CreateSuccess): void {
ctx.patchState({
isLoading: false,
......@@ -163,14 +163,14 @@ export abstract class ResourceState<T> {
this.notificationService.showSuccess(TRANSLATE("notification.crud.create"), true);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.CreateFail)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.CreateFail)
createFail(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.CreateFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.Update)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.Update)
update(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.Update<T>): Observable<T> {
ctx.patchState({
isLoading: true,
......@@ -188,7 +188,7 @@ export abstract class ResourceState<T> {
);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.UpdateSuccess)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.UpdateSuccess)
updateSuccess(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.UpdateSuccess): void {
ctx.patchState({
isLoading: false,
......@@ -199,14 +199,14 @@ export abstract class ResourceState<T> {
this.notificationService.showSuccess(TRANSLATE("notification.crud.update"), true);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.UpdateFail)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.UpdateFail)
updateFail(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.UpdateFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterDefaultAction((crudNameSpace: ResourceNamespaceModel) => crudNameSpace.Delete)
@RegisterDefaultAction((crudNameSpace: ResourceNamespace) => crudNameSpace.Delete)
delete(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.Delete): Observable<T> {
ctx.patchState({
isLoading: true,
......@@ -224,7 +224,7 @@ export abstract class ResourceState<T> {
);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.DeleteSuccess)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.DeleteSuccess)
deleteSuccess(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.DeleteSuccess): void {
ctx.patchState({
isLoading: false,
......@@ -235,7 +235,7 @@ export abstract class ResourceState<T> {
this.notificationService.showSuccess(TRANSLATE("notification.crud.delete"), true);
}
@RegisterDefaultAction((resourceNameSpace: ResourceNamespaceModel) => resourceNameSpace.DeleteFail)
@RegisterDefaultAction((resourceNameSpace: ResourceNamespace) => resourceNameSpace.DeleteFail)
deleteFail(ctx: StateContext<ResourceStateModel<T>>, action: ResourceAction.DeleteFail): void {
ctx.patchState({
isLoading: false,
......
import {DepositDataFileModel} from "@app/deposit/models/deposit-data-file.model";
import {DepositsModel} from "@app/generated-api";
import {ResourceAction} from "@app/core/stores/resource/resource.action";
import {ResourceNamespaceModel} from "@app/core/stores/resource/resource-namespace.model";
import {ResourceNamespace} from "../../core/stores/resource/resource.namespace";
import {TypeDefaultAction} from "@app/shared/decorators/type-default-action.decorator";