order-all-order-detail-edit.routable.ts 9.78 KB
Newer Older
Florent Poittevin's avatar
Florent Poittevin committed
1
2
3
4
5
6
7
import {
  ChangeDetectorRef,
  Component,
  OnDestroy,
  OnInit,
  ViewChild,
} from "@angular/core";
William Arsac's avatar
William Arsac committed
8
import {MatDialog} from "@angular/material/dialog";
Florent Poittevin's avatar
Florent Poittevin committed
9
10
11
12
import {
  ActivatedRoute,
  Router,
} from "@angular/router";
Florent POITTEVIN's avatar
Florent POITTEVIN committed
13
import {Enums} from "@enums";
William Arsac's avatar
William Arsac committed
14
import {environment} from "@environments/environment";
Florent Poittevin's avatar
Florent Poittevin committed
15
16
17
18
import {
  Aip,
  Dip,
  Order,
19
} from "@models";
Florent Poittevin's avatar
Florent Poittevin committed
20
21
22
import {Navigate} from "@ngxs/router-plugin";
import {
  Actions,
23
  ofActionCompleted,
Florent Poittevin's avatar
Florent Poittevin committed
24
25
26
  Select,
  Store,
} from "@ngxs/store";
27
28
29
30
31
import {OrderAllOrderFormPresentational} from "@order/features/all-order/components/presentationals/all-order-form/order-all-order-form.presentational";
import {OrderAllOrderAipAction} from "@order/features/all-order/stores/aip/order-all-order-aip.action";
import {OrderAllOrderAipState} from "@order/features/all-order/stores/aip/order-all-order-aip.state";
import {OrderAllOrderDipAction} from "@order/features/all-order/stores/dip/order-all-order-dip.action";
import {OrderAllOrderDipState} from "@order/features/all-order/stores/dip/order-all-order-dip.state";
Florent Poittevin's avatar
Florent Poittevin committed
32
import {
33
34
35
  OrderAllOrderAction,
  orderAllOrderActionNameSpace,
} from "@order/features/all-order/stores/order-all-order.action";
Florent Poittevin's avatar
Florent Poittevin committed
36
import {
37
38
39
40
41
42
43
  OrderAllOrderState,
  OrderAllOrderStateModel,
} from "@order/features/all-order/stores/order-all-order.state";
import {OrderAllOrderOrderArchiveAction} from "@order/features/all-order/stores/order-archive/order-all-order-order-archive.action";
import {OrderAllOrderOrderArchiveState} from "@order/features/all-order/stores/order-archive/order-all-order-order-archive.state";
import {OrderAllOrderStatusHistoryAction} from "@order/features/all-order/stores/status-history/order-all-order-status-history.action";
import {OrderAllOrderStatusHistoryState} from "@order/features/all-order/stores/status-history/order-all-order-status-history.state";
Florent Poittevin's avatar
Florent Poittevin committed
44
45
import {SharedHistoryDialog} from "@shared/components/dialogs/shared-history/shared-history.dialog";
import {SharedAbstractDetailEditCommonRoutable} from "@shared/components/routables/shared-abstract-detail-edit-common/shared-abstract-detail-edit-common.routable";
46
import {IconNameEnum} from "@shared/enums/icon-name.enum";
47
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
48
import {LocalStateEnum} from "@shared/enums/local-state.enum";
Florent Poittevin's avatar
Florent Poittevin committed
49
50
51
52
import {
  AppRoutesEnum,
  PreservationPlanningRoutesEnum,
  RoutesEnum,
53
  SharedAipRoutesEnum,
Florent Poittevin's avatar
Florent Poittevin committed
54
55
56
57
58
59
} from "@shared/enums/routes.enum";
import {OrderArchive} from "@shared/models/business/order-archive.model";
import {ExtraButtonToolbar} from "@shared/models/extra-button-toolbar.model";
import {StatusHistoryDialog} from "@shared/models/status-history-dialog.model";
import {StatusHistory} from "@shared/models/status-history.model";
import {SecurityService} from "@shared/services/security.service";
60
import {sharedOrderActionNameSpace} from "@shared/stores/order/shared-order.action";
Florent Poittevin's avatar
Florent Poittevin committed
61
62
import {MetadataUtil} from "@shared/utils/metadata.util";
import {Observable} from "rxjs";
63
64
65
66
import {
  take,
  tap,
} from "rxjs/operators";
Florent Poittevin's avatar
Florent Poittevin committed
67
68
import {
  AssociationState,
69
  EnumUtil,
Florent Poittevin's avatar
Florent Poittevin committed
70
71
  isNullOrUndefined,
  MemoizedUtil,
72
  OverrideProperty,
73
  Paging,
Florent Poittevin's avatar
Florent Poittevin committed
74
  QueryParameters,
75
  ResourceNameSpace,
Florent Poittevin's avatar
Florent Poittevin committed
76
77
78
} from "solidify-frontend";

@Component({
79
80
81
  selector: "dlcm-order-all-order-detail-edit-routable",
  templateUrl: "./order-all-order-detail-edit.routable.html",
  styleUrls: ["./order-all-order-detail-edit.routable.scss"],
Florent Poittevin's avatar
Florent Poittevin committed
82
})
83
84
85
export class OrderAllOrderDetailEditRoutable extends SharedAbstractDetailEditCommonRoutable<Order, OrderAllOrderStateModel> implements OnInit, OnDestroy {
  @Select(OrderAllOrderState.isLoadingWithDependency) isLoadingWithDependencyObs: Observable<boolean>;
  @Select(OrderAllOrderState.isReadyToBeDisplayed) isReadyToBeDisplayedObs: Observable<boolean>;
Florent Poittevin's avatar
Florent Poittevin committed
86

87
  historyObs: Observable<StatusHistory[]> = MemoizedUtil.select(this._store, OrderAllOrderStatusHistoryState, state => state.history);
88
  isLoadingHistoryObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, OrderAllOrderStatusHistoryState);
89
  queryParametersObs: Observable<QueryParameters> = MemoizedUtil.select(this._store, OrderAllOrderStatusHistoryState, state => state.queryParameters);
Florent Poittevin's avatar
Florent Poittevin committed
90

91
92
93
94
  listAipObs: Observable<Aip[]> = AssociationState.selected(this._store, OrderAllOrderAipState);
  isLoadingAipObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, OrderAllOrderAipState);
  listDipObs: Observable<Aip[]> = AssociationState.selected(this._store, OrderAllOrderDipState);
  isLoadingDipObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, OrderAllOrderDipState);
Florent Poittevin's avatar
Florent Poittevin committed
95

96
  listOrderArchivesObs: Observable<OrderArchive[]> = MemoizedUtil.list(this._store, OrderAllOrderOrderArchiveState);
97
  isLoadingOrderArchivesObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, OrderAllOrderOrderArchiveState);
Florent Poittevin's avatar
Florent Poittevin committed
98

99
  queryParametersAipObs: Observable<QueryParameters> = MemoizedUtil.queryParameters(this._store, OrderAllOrderAipState);
100
  queryParametersOrderArchivesObs: Observable<QueryParameters> = MemoizedUtil.queryParameters(this._store, OrderAllOrderOrderArchiveState);
101
  queryParametersDipObs: Observable<QueryParameters> = MemoizedUtil.queryParameters(this._store, OrderAllOrderDipState);
102

William Arsac's avatar
William Arsac committed
103
  @ViewChild("formPresentational")
104
  readonly formPresentational: OrderAllOrderFormPresentational;
Florent Poittevin's avatar
Florent Poittevin committed
105

106
107
108
  @OverrideProperty()
  checkAvailableResourceNameSpace: ResourceNameSpace = sharedOrderActionNameSpace;

109
110
  get enumUtil(): typeof EnumUtil {
    return EnumUtil;
111
112
  }

Florent Poittevin's avatar
Florent Poittevin committed
113
114
115
116
  readonly KEY_PARAM_NAME: keyof Order & string = "name";

  listExtraButtons: ExtraButtonToolbar<Order>[] = [
    {
117
      color: "primary",
118
      icon: IconNameEnum.done,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
119
      displayCondition: current => !this.isEdit && !isNullOrUndefined(current) && current.status === Enums.Order.StatusEnum.INPROGRESS,
Florent Poittevin's avatar
Florent Poittevin committed
120
      callback: () => this.save(),
121
      labelToTranslate: (current) => LabelTranslateEnum.save,
122
      order: 40,
Florent Poittevin's avatar
Florent Poittevin committed
123
124
    },
    {
125
      color: "primary",
126
      icon: IconNameEnum.submit,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
127
      displayCondition: current => !this.isEdit && !isNullOrUndefined(current) && current.status === Enums.Order.StatusEnum.INPROGRESS && current.aipNumber > 0,
Florent Poittevin's avatar
Florent Poittevin committed
128
      callback: () => this.submit(),
129
      labelToTranslate: (current) => LabelTranslateEnum.submit,
130
      order: 40,
Florent Poittevin's avatar
Florent Poittevin committed
131
132
133
    },
    {
      color: "primary",
134
      icon: IconNameEnum.resume,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
135
      displayCondition: current => !this.isEdit && !isNullOrUndefined(current) && current.status === Enums.Order.StatusEnum.INERROR,
Florent Poittevin's avatar
Florent Poittevin committed
136
      callback: () => this.resume(),
137
      labelToTranslate: (current) => LabelTranslateEnum.resume,
138
      order: 40,
Florent Poittevin's avatar
Florent Poittevin committed
139
140
141
    },
  ];

Florent POITTEVIN's avatar
Florent POITTEVIN committed
142
143
  get orderStatusEnum(): typeof Enums.Order.StatusEnum {
    return Enums.Order.StatusEnum;
Florent Poittevin's avatar
Florent Poittevin committed
144
145
146
147
148
149
  }

  get metadataUtil(): typeof MetadataUtil {
    return MetadataUtil;
  }

150
  get accessLevelEnumTranslate(): typeof Enums.Deposit.AccessEnumTranslate {
Florent POITTEVIN's avatar
Florent POITTEVIN committed
151
    return Enums.Deposit.AccessEnumTranslate;
Florent Poittevin's avatar
Florent Poittevin committed
152
153
154
155
156
157
158
159
160
  }

  constructor(protected readonly _store: Store,
              protected readonly _route: ActivatedRoute,
              protected readonly _actions$: Actions,
              protected readonly _changeDetector: ChangeDetectorRef,
              protected readonly _dialog: MatDialog,
              protected readonly _router: Router,
              private readonly _securityService: SecurityService) {
161
    super(_store, _route, _actions$, _changeDetector, _dialog, LocalStateEnum.order_allOrder, orderAllOrderActionNameSpace, LocalStateEnum.order);
Florent Poittevin's avatar
Florent Poittevin committed
162
163
164
165
166
167
168
169
  }

  ngOnDestroy(): void {
    super.ngOnDestroy();
    this.cleanState();
  }

  getSubResourceWithParentId(id: string): void {
170
171
    this._store.dispatch(new OrderAllOrderAipAction.GetAll(id));
    this._store.dispatch(new OrderAllOrderDipAction.GetAll(id));
Florent Poittevin's avatar
Florent Poittevin committed
172
173
174
175
    this.view();
  }

  showHistory(): void {
176
    this._dialog.open(SharedHistoryDialog, {
177
      width: environment.modalWidth,
Florent Poittevin's avatar
Florent Poittevin committed
178
179
180
181
182
      data: {
        parentId: null,
        resourceResId: this._resId,
        name: this._state,
        statusHistory: this.historyObs,
183
        isLoading: this.isLoadingHistoryObs,
Florent Poittevin's avatar
Florent Poittevin committed
184
        queryParametersObs: this.queryParametersObs,
185
        state: OrderAllOrderStatusHistoryAction,
Florent Poittevin's avatar
Florent Poittevin committed
186
187
188
189
190
      } as StatusHistoryDialog,
    });
  }

  private submit(): void {
191
    this._store.dispatch(new OrderAllOrderAction.Submit(this._resId));
Florent Poittevin's avatar
Florent Poittevin committed
192
193
194
  }

  private resume(): void {
195
    this._store.dispatch(new OrderAllOrderAction.Resume(this._resId));
Florent Poittevin's avatar
Florent Poittevin committed
196
197
198
  }

  private view(): void {
199
    this._store.dispatch(new OrderAllOrderOrderArchiveAction.GetAll(this._resId));
Florent Poittevin's avatar
Florent Poittevin committed
200
201
202
  }

  private save(): void {
203
    this._store.dispatch(new OrderAllOrderAction.Save(this._resId));
204
205
    this.subscribe(this._actions$.pipe(ofActionCompleted(OrderAllOrderAction.SaveSuccess))
      .pipe(
206
        take(1),
207
208
209
210
211
        tap(result => {
          if (result.result.successful) {
            this._store.dispatch(new OrderAllOrderAipAction.GetAll(this._resId));
          }
        }),
212
      ));
Florent Poittevin's avatar
Florent Poittevin committed
213
214
215
  }

  goToDip(dip: Dip): void {
216
    this._store.dispatch(new Navigate([RoutesEnum.preservationPlanningDipDetail, dip.resId]));
Florent Poittevin's avatar
Florent Poittevin committed
217
218
219
220
221
222
223
224
225
  }

  goToAipDownloaded(aip: Aip): void {
    // TODO When aip downloaded page done
    this.goToAip(aip.resId);
  }

  goToAip(aipId: string): void {
    const storagionNode = 1;
226
    this._store.dispatch(new Navigate([AppRoutesEnum.preservationPlanning, PreservationPlanningRoutesEnum.aip, storagionNode, SharedAipRoutesEnum.aipDetail, aipId]));
Florent Poittevin's avatar
Florent Poittevin committed
227
  }
228

229
230
231
232
233
234
235
  pageChangeMatchingArchives($event: Paging): void {
    const queryParameters = new QueryParameters();
    queryParameters.paging = $event;
    this._store.dispatch(new OrderAllOrderOrderArchiveAction.GetAll(this._resId, queryParameters));
  }

  pageChangeAipsSelected($event: Paging): void {
236
237
238
239
    const queryParameters = new QueryParameters();
    queryParameters.paging = $event;
    this._store.dispatch(new OrderAllOrderAipAction.GetAll(this._resId, queryParameters));
  }
240

241
  pageChangeDipsAvailable($event: Paging): void {
242
243
    const queryParameters = new QueryParameters();
    queryParameters.paging = $event;
244
    this._store.dispatch(new OrderAllOrderDipAction.GetAll(this._resId, queryParameters));
245
  }
Florent Poittevin's avatar
Florent Poittevin committed
246
}