admin-preservation-policy.state.ts 2.88 KB
Newer Older
1
import {PreservationPolicy} from "@app/generated-api";
2
3
import {
  Actions,
4
  Selector,
5
6
7
  State,
  Store,
} from "@ngxs/store";
8
9
10
import {AdminResourceApiEnum} from "@shared/enums/api.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {RoutesEnum} from "@shared/enums/routes.enum";
11
12
import {
  ApiService,
13
  defaultResourceStateInitValue,
14
  isNullOrUndefined,
15
16
17
  NotificationService,
  ResourceState,
  ResourceStateModel,
18
  StoreUtil,
19
  TRANSLATE,
20
  urlSeparator,
21
22
23
} from "solidify-frontend";
import {adminPreservationPolicyActionNameSpace} from "./admin-preservation-policy.action";

24
export interface AdminPreservationPolicyStateModel extends ResourceStateModel<PreservationPolicy> {
25
26
27
28
29
}

@State<AdminPreservationPolicyStateModel>({
  name: LocalStateEnum.admin_preservationPolicy,
  defaults: {
30
    ...defaultResourceStateInitValue(),
31
32
  },
})
33
export class AdminPreservationPolicyState extends ResourceState<AdminPreservationPolicyStateModel, PreservationPolicy> {
34
35
36
37
  constructor(protected apiService: ApiService,
              protected store: Store,
              protected notificationService: NotificationService,
              protected actions$: Actions) {
38
39
    super(apiService, store, notificationService, actions$, {
      nameSpace: adminPreservationPolicyActionNameSpace,
40
41
42
      routeRedirectUrlAfterSuccessCreateAction: (resId: string) => RoutesEnum.adminPreservationPolicyDetail + urlSeparator + resId,
      routeRedirectUrlAfterSuccessUpdateAction: (resId: string) => RoutesEnum.adminPreservationPolicyDetail + urlSeparator + resId,
      routeRedirectUrlAfterSuccessDeleteAction: RoutesEnum.adminPreservationPolicy,
43
44
45
      notificationResourceCreateSuccessTextToTranslate: TRANSLATE("admin.preservationPolicy.notification.resource.create"),
      notificationResourceDeleteSuccessTextToTranslate: TRANSLATE("admin.preservationPolicy.notification.resource.delete"),
      notificationResourceUpdateSuccessTextToTranslate: TRANSLATE("admin.preservationPolicy.notification.resource.update"),
46
    });
47
  }
48

49
50
51
52
  protected get _urlResource(): string {
    return AdminResourceApiEnum.preservationPolicies;
  }

53
54
55
56
57
58
59
60
61
62
  @Selector()
  static isLoading(state: AdminPreservationPolicyStateModel): boolean {
    return StoreUtil.isLoadingState(state);
  }

  @Selector()
  static isLoadingWithDependency(state: AdminPreservationPolicyStateModel): boolean {
    return this.isLoading(state);
  }

63
64
65
66
67
68
69
70
  @Selector()
  static currentTitle(state: AdminPreservationPolicyStateModel): string | undefined {
    if (isNullOrUndefined(state.current)) {
      return undefined;
    }
    return state.current.name;
  }

71
72
73
74
75
76
77
78
  @Selector()
  static isReadyToBeDisplayed(state: AdminPreservationPolicyStateModel): boolean {
    return this.isReadyToBeDisplayedInCreateMode
      && !isNullOrUndefined(state.current);
  }

  @Selector()
  static isReadyToBeDisplayedInCreateMode(state: AdminPreservationPolicyStateModel): boolean {
79
    return true;
80
  }
81
}