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

Rename crud class to match with backend controller name

parent 1462b717
import {AccessChangeQueryParameters, AccessSearch, AccessSearchFail, AccessSearchSuccess} from "@app/access/stores/access.action";
import {ApiService} from "@app/core/http/api.service";
import {isNullOrUndefined} from "@app/core/tools/is/is.tool";
import {CrudStateModel} from "@app/core/stores/crud/crud.state";
import {ResourceStateModel} from "@app/core/stores/resource/resource.state";
import {StoreUtil} from "@app/core/utils/stores/store.util";
import {AccessResourceApiEnum} from "@app/shared/enums/api.enum";
import {StateEnum} from "@app/shared/enums/state.enum";
import {ArchiveMetadataModel} from "@app/shared/models/business/archive-metadata.model";
import {CollectionTypedModel} from "@app/shared/models/collection-typed.model";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
import {CrudHelperUtil} from "@app/core/utils/crud-helper.util";
import {MapUtil} from "@app/core/utils/map.util";
import {StringUtil} from "@app/core/utils/string.util";
import {Action, State, StateContext, Store} from "@ngxs/store";
......@@ -15,7 +15,7 @@ import {Observable} from "rxjs";
import {tap} from "rxjs/internal/operators/tap";
import {catchError} from "rxjs/operators";
export interface AccessStateModel extends CrudStateModel<ArchiveMetadataModel> {
export interface AccessStateModel extends ResourceStateModel<ArchiveMetadataModel> {
search: string;
}
......@@ -53,7 +53,7 @@ export class AccessState {
});
const pathFilter = "query";
const queryParameters = CrudHelperUtil.getQueryParametersToApply(action.queryParameters, ctx);
const queryParameters = StoreUtil.getQueryParametersToApply(action.queryParameters, ctx);
MapUtil.addOrUpdate(queryParameters.search.searchItems, pathFilter, searchString);
if (searchString === StringUtil.stringEmpty) {
......@@ -86,7 +86,7 @@ export class AccessState {
@Action(AccessSearchSuccess)
searchDipSuccess(ctx: StateContext<AccessStateModel>, action: AccessSearchSuccess): void {
const queryParameters = CrudHelperUtil.updateQueryParameters(ctx, action.list);
const queryParameters = StoreUtil.updateQueryParameters(ctx, action.list);
ctx.patchState({
list: action.list === null || action.list === undefined ? [] : action.list._data,
......
import {Component, OnInit} from "@angular/core";
import {Router, RouterStateSnapshot} from "@angular/router";
import {ChangeAppLanguage, Logout} from "@app/app.action";
import {ChangeAppLanguage, Logout} from "@app/stores/app.action";
import {OAuth2Service} from "@app/core/auth/oauth2.service";
import {AbstractComponent} from "@app/shared/components/abstract/abstract.component";
import {LanguagesEnum} from "@app/shared/enums/languages.enum";
......
......@@ -3,7 +3,7 @@ import {APP_INITIALIZER, ErrorHandler, NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {AppRoutingModule} from "@app/app-routing.module";
import {AppState} from "@app/app.state";
import {AppState} from "@app/stores/app.state";
import {MainToolbarMobileComponent} from "@app/components/main-toolbar/main-toolbar-mobile/main-toolbar-mobile.component";
import {ApiModule} from "@app/generated-api/api.module";
import {GlobalErrorsHandlerService} from "@app/core/services/global-errors-handler.service";
......
import {Injectable} from "@angular/core";
import {CanActivate, Router} from "@angular/router";
import {AppStateModel} from "@app/app.state";
import {AppStateModel} from "@app/stores/app.state";
import {RoutesEnum} from "@app/shared/enums/routes.enum";
import {StateEnum} from "@app/shared/enums/state.enum";
import {Navigate} from "@ngxs/router-plugin";
......
import {CrudAction} from "@app/core/stores/crud/crud.action";
import {CrudNameSpace} from "@app/core/stores/crud.namespace";
export class CrudActionHelper {
static loadResource(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.LoadResource>): CrudAction.LoadResource {
return new crudNameSpace.LoadResource(...args);
}
static loadResourceSuccess(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.LoadResourceSuccess>): CrudAction.LoadResourceSuccess {
return new crudNameSpace.LoadResourceSuccess(...args);
}
static loadResourceFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.LoadResourceFail>): CrudAction.LoadResourceFail {
return new crudNameSpace.LoadResourceFail(...args);
}
static changeQueryParameters(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.ChangeQueryParameters>): CrudAction.ChangeQueryParameters {
return new crudNameSpace.ChangeQueryParameters(...args);
}
static getAll(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetAll>): CrudAction.GetAll {
return new crudNameSpace.GetAll(...args);
}
static getAllSuccess<T>(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetAllSuccess>): CrudAction.GetAllSuccess<T> {
return new crudNameSpace.GetAllSuccess(...args);
}
static getAllFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetAllFail>): CrudAction.GetAllFail {
return new crudNameSpace.GetAllFail(...args);
}
static getById(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetById>): CrudAction.GetById {
return new crudNameSpace.GetById(...args);
}
static getByIdSuccess<T>(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetByIdSuccess>): CrudAction.GetByIdSuccess<T> {
return new crudNameSpace.GetByIdSuccess(...args);
}
static getByIdFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.GetByIdFail>): CrudAction.GetByIdFail {
return new crudNameSpace.GetByIdFail(...args);
}
static create<T>(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.Create>): CrudAction.Create<T> {
return new crudNameSpace.Create(...args);
}
static createSuccess(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.CreateSuccess>): CrudAction.CreateSuccess {
return new crudNameSpace.CreateSuccess(...args);
}
static createFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.CreateFail>): CrudAction.CreateFail {
return new crudNameSpace.CreateFail(...args);
}
static update<T>(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.Update>): CrudAction.Update<T> {
return new crudNameSpace.Update(...args);
}
static updateSuccess(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.UpdateSuccess>): CrudAction.UpdateSuccess {
return new crudNameSpace.UpdateSuccess(...args);
}
static updateFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.UpdateFail>): CrudAction.UpdateFail {
return new crudNameSpace.UpdateFail(...args);
}
static delete(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.Delete>): CrudAction.Delete {
return new crudNameSpace.Delete(...args);
}
static deleteSuccess(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.DeleteSuccess>): CrudAction.DeleteSuccess {
return new crudNameSpace.DeleteSuccess(...args);
}
static deleteFail(crudNameSpace: CrudNameSpace, ...args: ConstructorParameters<typeof CrudAction.DeleteFail>): CrudAction.DeleteFail {
return new crudNameSpace.DeleteFail(...args);
}
}
import {Relation2TiersAction} from "@app/core/stores/crud-2-tiers/relation-2-tiers.action";
import {Relation2TiersNamespaceModel} from "@app/core/stores/crud-2-tiers/relation-2-tiers-namespace.model";
export class Relation2TiersActionHelper {
static getAllSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...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> {
return new crudTwoTiersNameSpace.GetAllSubResourceSuccess(...args);
}
static getAllSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.GetAllSubResourceFail>): Relation2TiersAction.GetAllSubResourceFail {
return new crudTwoTiersNameSpace.GetAllSubResourceFail(...args);
}
static createSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResource>): Relation2TiersAction.CreateSubResource {
return new crudTwoTiersNameSpace.CreateSubResource(...args);
}
static createSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceSuccess>): Relation2TiersAction.CreateSubResourceSuccess {
return new crudTwoTiersNameSpace.CreateSubResourceSuccess(...args);
}
static createSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.CreateSubResourceFail>): Relation2TiersAction.CreateSubResourceFail {
return new crudTwoTiersNameSpace.CreateSubResourceFail(...args);
}
static deleteSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResource>): Relation2TiersAction.DeleteSubResource {
return new crudTwoTiersNameSpace.DeleteSubResource(...args);
}
static deleteSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceSuccess>): Relation2TiersAction.DeleteSubResourceSuccess {
return new crudTwoTiersNameSpace.DeleteSubResourceSuccess(...args);
}
static deleteSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.DeleteSubResourceFail>): Relation2TiersAction.DeleteSubResourceFail {
return new crudTwoTiersNameSpace.DeleteSubResourceFail(...args);
}
static updateSubResource(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResource>): Relation2TiersAction.UpdateSubResource {
return new crudTwoTiersNameSpace.UpdateSubResource(...args);
}
static updateSubResourceSuccess(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...args: ConstructorParameters<typeof Relation2TiersAction.UpdateSubResourceSuccess>): Relation2TiersAction.UpdateSubResourceSuccess {
return new crudTwoTiersNameSpace.UpdateSubResourceSuccess(...args);
}
static updateSubResourceFail(crudTwoTiersNameSpace: Relation2TiersNamespaceModel, ...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";
export class ResourceActionHelper {
static loadResource(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResource>): ResourceAction.LoadResource {
return new crudNameSpace.LoadResource(...args);
}
static loadResourceSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceSuccess>): ResourceAction.LoadResourceSuccess {
return new crudNameSpace.LoadResourceSuccess(...args);
}
static loadResourceFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.LoadResourceFail>): ResourceAction.LoadResourceFail {
return new crudNameSpace.LoadResourceFail(...args);
}
static changeQueryParameters(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.ChangeQueryParameters>): ResourceAction.ChangeQueryParameters {
return new crudNameSpace.ChangeQueryParameters(...args);
}
static getAll(crudNameSpace: ResourceNamespaceModel, ...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> {
return new crudNameSpace.GetAllSuccess(...args);
}
static getAllFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.GetAllFail>): ResourceAction.GetAllFail {
return new crudNameSpace.GetAllFail(...args);
}
static getById(crudNameSpace: ResourceNamespaceModel, ...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> {
return new crudNameSpace.GetByIdSuccess(...args);
}
static getByIdFail(crudNameSpace: ResourceNamespaceModel, ...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> {
return new crudNameSpace.Create(...args);
}
static createSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.CreateSuccess>): ResourceAction.CreateSuccess {
return new crudNameSpace.CreateSuccess(...args);
}
static createFail(crudNameSpace: ResourceNamespaceModel, ...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> {
return new crudNameSpace.Update(...args);
}
static updateSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.UpdateSuccess>): ResourceAction.UpdateSuccess {
return new crudNameSpace.UpdateSuccess(...args);
}
static updateFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.UpdateFail>): ResourceAction.UpdateFail {
return new crudNameSpace.UpdateFail(...args);
}
static delete(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.Delete>): ResourceAction.Delete {
return new crudNameSpace.Delete(...args);
}
static deleteSuccess(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.DeleteSuccess>): ResourceAction.DeleteSuccess {
return new crudNameSpace.DeleteSuccess(...args);
}
static deleteFail(crudNameSpace: ResourceNamespaceModel, ...args: ConstructorParameters<typeof ResourceAction.DeleteFail>): ResourceAction.DeleteFail {
return new crudNameSpace.DeleteFail(...args);
}
}
import {BaseStateModel} from "@app/base.state";
import {BaseState} from "@app/core/models/stores/base.state";
import {QueryParametersModel} from "@app/shared/models/query-parameters.model";
export interface ResourceStateModel extends BaseStateModel {
export interface BaseResourceState extends BaseState {
total: number;
queryParameters: QueryParametersModel;
}
export interface BaseStoreNameSpace {
}
export interface BaseStateModel {
export interface BaseState {
isLoading: boolean;
}
export interface StoreActionClass extends Function {
new(...args: any[]): any;
type: string;
}
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 {
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 {CrudTwoTiersNameSpace} from "@app/core/stores/crud.namespace";
import {Relation2TiersNamespaceModel} from "@app/core/stores/crud-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";
export namespace CrudTwoTiersAction {
export namespace Relation2TiersAction {
export class GetAllSubResource {
static readonly type: string = "[{0}] Get All SubResource";
......@@ -80,4 +80,4 @@ export namespace CrudTwoTiersAction {
}
}
export const crudTwoTiersActionNameSpace: CrudTwoTiersNameSpace = CrudTwoTiersAction;
export const relation2TiersActionNameSpace: Relation2TiersNamespaceModel = Relation2TiersAction;
import {ApiService} from "@app/core/http/api.service";
import {NotificationService} from "@app/core/services/notification.service";
import {ResourceStateModel} from "@app/resource.state";
import {CrudTwoTiersAction} from "@app/core/stores/crud-two-tiers/crud-two-tiers.action";
import {CrudTwoTiersNameSpace} from "@app/core/stores/crud.namespace";
import {RegisterCrudAction} from "@app/shared/decorators/crud.decorator";
import {Relation2TiersAction} from "@app/core/stores/crud-2-tiers/relation-2-tiers.action";
import {Relation2TiersNamespaceModel} from "@app/core/stores/crud-2-tiers/relation-2-tiers-namespace.model";
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";
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";
......@@ -11,28 +13,26 @@ 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 {CrudHelperUtil} from "@app/core/utils/crud-helper.util";
import {CrudTwoTiersActionHelper} from "@app/core/utils/crud-two-tiers-action.helper";
import {CrudUtil} from "@app/core/utils/crud.util";
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 CrudTwoTiersStateModel<T> extends ResourceStateModel {
export interface Relation2TiersStateModel<T> extends BaseResourceState {
selected: T[];
}
export const defaultCrudTwoTiersStateInitValue: CrudTwoTiersStateModel<any> = {
export const defaultRelation2TiersStateInitValue: Relation2TiersStateModel<any> = {
total: 0,
isLoading: false,
selected: [],
queryParameters: new QueryParametersModel(),
};
export abstract class CrudTwoTiersState<T> {
export abstract class Relation2TiersState<T> {
protected readonly state: StateEnum;
protected readonly crudTwoTiersNameSpace: CrudTwoTiersNameSpace;
protected readonly crudTwoTiersNameSpace: Relation2TiersNamespaceModel;
protected readonly urlResource: ResourceApiEnum;
private readonly subResource: ApiResourceNameEnum;
......@@ -43,14 +43,14 @@ export abstract class CrudTwoTiersState<T> {
this.state = this.defineState();
this.crudTwoTiersNameSpace = this.defineCrudNameSpace();
this.subResource = this.defineSubResource();
CrudUtil.initState(CrudTwoTiersState, this.constructor, this.crudTwoTiersNameSpace);
StoreUtil.initState(Relation2TiersState, this.constructor, this.crudTwoTiersNameSpace);
}
abstract defineUrlResource(): ResourceApiEnum;
abstract defineState(): StateEnum;
abstract defineCrudNameSpace(): CrudTwoTiersNameSpace;
abstract defineCrudNameSpace(): Relation2TiersNamespaceModel;
abstract defineSubResource(): ApiResourceNameEnum;
......@@ -58,39 +58,39 @@ export abstract class CrudTwoTiersState<T> {
return this.urlResource + urlSeparator + parentId + urlSeparator + this.subResource;
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.GetAllSubResource)
getAll<U>(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.GetAllSubResource): Observable<CollectionTypedModel<U>> {
const queryParameters = CrudHelperUtil.getQueryParametersToApply(action.queryParameters, ctx);
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.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(CrudTwoTiersActionHelper.getAllSubResourceSuccess<U>(this.crudTwoTiersNameSpace, collection));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceSuccess<U>(this.crudTwoTiersNameSpace, collection));
}),
catchError(error => {
ctx.dispatch(CrudTwoTiersActionHelper.getAllSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResourceFail(this.crudTwoTiersNameSpace));
throw error;
}),
);
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.GetAllSubResourceSuccess)
getAllSuccess(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.GetAllSubResourceSuccess<T>): void {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.GetAllSubResourceSuccess)
getAllSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceSuccess<T>): void {
ctx.patchState({
selected: action.list._data,
isLoading: false,
});
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.GetAllSubResourceFail): void {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.GetAllSubResourceFail)
getAllFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.GetAllSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.CreateSubResource)
create(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.CreateSubResource): Observable<string[]> {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.CreateSubResource)
create(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.CreateSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
......@@ -98,17 +98,17 @@ export abstract class CrudTwoTiersState<T> {
return this.apiService.post<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(CrudTwoTiersActionHelper.createSubResourceSuccess(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.createSubResourceSuccess(this.crudTwoTiersNameSpace));
}),
catchError(error => {
ctx.dispatch(CrudTwoTiersActionHelper.createSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.createSubResourceFail(this.crudTwoTiersNameSpace));
throw error;
}),
);
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.DeleteSubResource)
delete(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.DeleteSubResource): Observable<string[]> {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.DeleteSubResource)
delete(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.DeleteSubResource): Observable<string[]> {
if (action.listResId.length === 0) {
return;
}
......@@ -116,43 +116,43 @@ export abstract class CrudTwoTiersState<T> {
return this.apiService.delete<string[]>(url, action.listResId)
.pipe(
tap(() => {
ctx.dispatch(CrudTwoTiersActionHelper.deleteSubResourceSuccess(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceSuccess(this.crudTwoTiersNameSpace));
}),
catchError(error => {
ctx.dispatch(CrudTwoTiersActionHelper.deleteSubResourceFail(this.crudTwoTiersNameSpace));
ctx.dispatch(Relation2TiersActionHelper.deleteSubResourceFail(this.crudTwoTiersNameSpace));
throw error;
}),
);
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.UpdateSubResource)
update(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.UpdateSubResource): void {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.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);
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.UpdateSubResourceSuccess): void {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.UpdateSubResourceSuccess)
updateSuccess(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceSuccess): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(CrudTwoTiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
}
@RegisterCrudAction((crudTwoTiersNameSpace: CrudTwoTiersNameSpace) => crudTwoTiersNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<CrudTwoTiersStateModel<T>>, action: CrudTwoTiersAction.UpdateSubResourceFail): void {
@RegisterDefaultAction((crudTwoTiersNameSpace: Relation2TiersNamespaceModel) => crudTwoTiersNameSpace.UpdateSubResourceFail)
updateFail(ctx: StateContext<Relation2TiersStateModel<T>>, action: Relation2TiersAction.UpdateSubResourceFail): void {
ctx.patchState({
isLoading: false,
});
ctx.dispatch(CrudTwoTiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
ctx.dispatch(Relation2TiersActionHelper.getAllSubResource(this.crudTwoTiersNameSpace, action.parentId));
}
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): CrudTwoTiersAction.CreateSubResource[] | CrudTwoTiersAction.DeleteSubResource[] {
private computeUpdatesActionsToDispatch(subResourceUpdate: SubResourceUpdateModel, parentId: string): Relation2TiersAction.CreateSubResource[] | Relation2TiersAction.DeleteSubResource[] {
const actions = [];
const deleteAction = CrudTwoTiersActionHelper.deleteSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToRemoved);
const deleteAction = Relation2TiersActionHelper.deleteSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToRemoved);
actions.push(deleteAction);
const createAction = CrudTwoTiersActionHelper.createSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToAdd);
const createAction = Relation2TiersActionHelper.createSubResource(this.crudTwoTiersNameSpace, parentId, subResourceUpdate.resourceToAdd);
actions.push(createAction);
return actions;
}
......
export interface BaseCrudNameSpace {
}
export interface CrudNameSpace extends BaseCrudNameSpace {
LoadResource: CrudActionClass;
LoadResourceSuccess: CrudActionClass;
LoadResourceFail: CrudActionClass;
ChangeQueryParameters: CrudActionClass;
GetAll: CrudActionClass;