preservation-space-organizational-unit-archive-acl-list.routable.ts 10.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  ElementRef,
  OnInit,
  ViewChild,
} from "@angular/core";
import {MatDialog} from "@angular/material/dialog";
import {ActivatedRoute} from "@angular/router";
11
import {environment} from "@environments/environment";
12
import {Archive} from "@home/models/archive.model";
13
14
15
16
17
18
19
20
21
22
23
24
import {
  ArchiveACL,
  User,
} from "@models";
import {Navigate} from "@ngxs/router-plugin";
import {
  Actions,
  ofActionCompleted,
  Store,
} from "@ngxs/store";
import {PreservationSpaceOrganizationalUnitArchiveAclAction} from "@preservation-space/organizational-unit/stores/archive-acl/preservation-space-organizational-unit-archive-acl.action";
import {PreservationSpaceOrganizationalUnitArchiveAclState} from "@preservation-space/organizational-unit/stores/archive-acl/preservation-space-organizational-unit-archive-acl.state";
25
import {PreservationSpaceOrganizationalUnitAction} from "@preservation-space/organizational-unit/stores/preservation-space-organizational-unit.action";
26
27
28
29
30
31
32
33
34
35
36
37
import {SharedDeleteDialog} from "@shared/components/dialogs/shared-abstract-delete/shared-delete.dialog";
import {SharedDataTablePresentational} from "@shared/components/presentationals/shared-data-table/shared-data-table.presentational";
import {SharedAbstractListRoutableOption} from "@shared/components/routables/shared-abstract-list/shared-abstract-list.routable";
import {SharedAbstractRoutable} from "@shared/components/routables/shared-abstract/shared-abstract.routable";
import {DataTableComponentEnum} from "@shared/enums/data-table-component.enum";
import {FieldTypeEnum} from "@shared/enums/field-type.enum";
import {IconNameEnum} from "@shared/enums/icon-name.enum";
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
import {LocalStateEnum} from "@shared/enums/local-state.enum";
import {
  AppRoutesEnum,
  PreservationSpaceOrganizationalUnitRoutesEnum,
38
  PreservationSpaceRoutesEnum,
39
  RoutesEnum,
40
  urlSeparator,
41
42
43
44
45
46
} from "@shared/enums/routes.enum";
import {DataTableActions} from "@shared/models/data-table-actions.model";
import {DataTableColumns} from "@shared/models/data-table-columns.model";
import {RouterExtService} from "@shared/services/router-ext.service";
import {SharedArchiveAclAction} from "@shared/stores/archive-acl/shared-archive-acl.action";
import {sharedArchiveActionNameSpace} from "@shared/stores/archive/shared-archive.action";
47
import {
48
  PARAM_QUERY_ORGUNIT,
49
50
51
  PARAM_QUERY_SEARCH,
  SharedArchiveState,
} from "@shared/stores/archive/shared-archive.state";
52
53
54
55
56
57
import {sharedUserActionNameSpace} from "@shared/stores/user/shared-user.action";
import {SharedUserState} from "@shared/stores/user/shared-user.state";
import {StoreDialogUtil} from "@shared/utils/store-dialog.util";
import {Observable} from "rxjs";
import {tap} from "rxjs/operators";
import {
58
59
60
  isNullOrUndefined,
  MappingObject,
  MappingObjectUtil,
61
62
63
  MemoizedUtil,
  OrderEnum,
  QueryParameters,
64
  QueryParametersUtil,
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  ResourceNameSpace,
  Sort,
} from "solidify-frontend";

@Component({
  selector: "dlcm-preservation-space-organizational-unit-acl-list-routable",
  templateUrl: "../../../../../../shared/components/routables/shared-abstract-list/shared-abstract-list.routable.html",
  styleUrls: ["../../../../../../shared/components/routables/shared-abstract-list/shared-abstract-list.routable.scss"],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PreservationSpaceOrganizationalUnitArchiveAclListRoutable extends SharedAbstractRoutable implements OnInit {
  readonly KEY_CREATE_BUTTON: string = LabelTranslateEnum.create;
  readonly KEY_BACK_BUTTON: string | undefined = LabelTranslateEnum.backToOrganizationalUnit;
  readonly KEY_PARAM_NAME: keyof ArchiveACL & string = "aipId";

  skipInitialQuery: boolean = false;
81
  stickyTopPosition: number = environment.defaultStickyDatatableHeight;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  columnsSkippedToClear: string[] = [];

  actions: DataTableActions<ArchiveACL>[] = [
    {
      logo: IconNameEnum.edit,
      callback: (model: ArchiveACL) => this.goToEdit(model),
      placeholder: current => LabelTranslateEnum.edit,
      displayOnCondition: (model: ArchiveACL) => this.conditionDisplayEditButton(model),
    },
    {
      logo: IconNameEnum.delete,
      callback: (model: ArchiveACL) => this.delete(model),
      placeholder: current => LabelTranslateEnum.delete,
      displayOnCondition: (model: ArchiveACL) => this.conditionDisplayDeleteButton(model),
    },
  ];
  listNewId: string[];

  @ViewChild("dataTablePresentational")
  readonly dataTablePresentational: SharedDataTablePresentational<ArchiveACL>;

  sharedArchiveNameSpace: ResourceNameSpace = sharedArchiveActionNameSpace;
  sharedArchiveState: typeof SharedArchiveState = SharedArchiveState;

  sharedUserSort: Sort<User> = {
    field: "lastName",
    order: OrderEnum.ascending,
  };
  sharedUserNameSpace: ResourceNameSpace = sharedUserActionNameSpace;
  sharedUserState: typeof SharedUserState = SharedUserState;
112
  extraQueryParameters: MappingObject;
113

114
  columns: DataTableColumns<ArchiveACL>[];
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

  options: SharedAbstractListRoutableOption<ArchiveACL> = {
    canCreate: true,
    canGoBack: true,
    canRefresh: true,
  };

  isLoadingObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, PreservationSpaceOrganizationalUnitArchiveAclState);
  listObs: Observable<ArchiveACL[]> = MemoizedUtil.list(this._store, PreservationSpaceOrganizationalUnitArchiveAclState);
  queryParametersObs: Observable<QueryParameters> = MemoizedUtil.queryParameters(this._store, PreservationSpaceOrganizationalUnitArchiveAclState);
  private _orgUnitId: string;

  constructor(private readonly _store: Store,
              private readonly _changeDetector: ChangeDetectorRef,
              private readonly _route: ActivatedRoute,
              private readonly _routerExt: RouterExtService,
              private readonly _actions$: Actions,
              private readonly _dialog: MatDialog) {
    super();
  }

  ngOnInit(): void {
    super.ngOnInit();
    this.retrieveResIdFromUrl();
139
    this._store.dispatch(new PreservationSpaceOrganizationalUnitAction.GetById(this._orgUnitId));
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180

    this.extraQueryParameters = {[PARAM_QUERY_ORGUNIT]: this._orgUnitId};
    this.columns = [
      {
        field: "aipId",
        header: LabelTranslateEnum.archive,
        type: FieldTypeEnum.searchableSingleSelect,
        order: OrderEnum.none,
        isFilterable: true,
        isSortable: true,
        resourceNameSpace: this.sharedArchiveNameSpace,
        resourceState: this.sharedArchiveState as any,
        resourceLabelCallback: (value: Archive) => value.title,
        resourceLabelKey: PARAM_QUERY_SEARCH,
        component: DataTableComponentEnum.archive,
        extraSearchQueryParam: this.extraQueryParameters,
      },
      {
        field: "user.person.fullName",
        header: LabelTranslateEnum.user,
        type: FieldTypeEnum.searchableSingleSelect,
        order: OrderEnum.none,
        isFilterable: true,
        isSortable: true,
        resourceNameSpace: this.sharedUserNameSpace,
        resourceState: this.sharedUserState as any,
        resourceLabelKey: "lastName",
        resourceLabelCallback: (value: User) => value.lastName + ", " + value.firstName,
        searchableSingleSelectSort: this.sharedUserSort,
        filterableField: "user.resId",
        sortableField: "user.resId",
      },
      {
        field: "expiration",
        header: LabelTranslateEnum.expiration,
        type: FieldTypeEnum.datetime,
        order: OrderEnum.none,
        isFilterable: true,
        isSortable: true,
      },
    ];
181
182
183
  }

  protected retrieveResIdFromUrl(): void {
184
    this._orgUnitId = this._route.snapshot.parent.parent.paramMap.get(AppRoutesEnum.paramIdWithoutPrefixParam);
185
186
187
188
189
190
191
192
193
194
195
  }

  conditionDisplayEditButton(model: ArchiveACL | undefined): boolean {
    return true;
  }

  conditionDisplayDeleteButton(model: ArchiveACL | undefined): boolean {
    return true;
  }

  goToEdit(model: ArchiveACL): void {
196
    this._store.dispatch(new Navigate([RoutesEnum.preservationSpaceOrganizationalUnitDetail, this._orgUnitId, PreservationSpaceOrganizationalUnitRoutesEnum.manageAcl, PreservationSpaceOrganizationalUnitRoutesEnum.manageAclDetail, model.resId, PreservationSpaceOrganizationalUnitRoutesEnum.manageAclEdit], {}, {skipLocationChange: true}));
197
198
199
200
201
202
203
  }

  delete(model: ArchiveACL): void {
    const datas = StoreDialogUtil.deleteData(LocalStateEnum.preservationSpace_organizationalUnit_archiveAcl);
    datas.name = model[this.KEY_PARAM_NAME]?.toString();
    datas.resId = model.resId;

204
    this._dialog.open(SharedDeleteDialog, {
205
206
207
208
209
210
211
212
213
214
215
216
217
218
      width: "400px",
      data: datas,
    });
    this.subscribe(this._actions$.pipe(ofActionCompleted(SharedArchiveAclAction.DeleteSuccess))
      .pipe(
        tap(result => {
          if (result.result.successful) {
            this.getAll();
          }
        }),
      ));
  }

  create(element: ElementRef): void {
219
220
221
222
223
224
225
    this._store.dispatch(new Navigate([
      AppRoutesEnum.preservationSpace,
      PreservationSpaceRoutesEnum.organizationalUnit,
      PreservationSpaceOrganizationalUnitRoutesEnum.detail,
      this._orgUnitId,
      PreservationSpaceOrganizationalUnitRoutesEnum.manageAcl,
      PreservationSpaceOrganizationalUnitRoutesEnum.manageAclCreate], {} /*{skipLocationChange: true}*/));
226
227
228
  }

  getAll(queryParameters?: QueryParameters): void {
229
    this._store.dispatch(new PreservationSpaceOrganizationalUnitArchiveAclAction.GetAll(queryParameters, true));
230
231
232
  }

  showDetail(model: ArchiveACL): void {
233
    this._store.dispatch(new Navigate([RoutesEnum.preservationSpaceOrganizationalUnitDetail, this._orgUnitId, PreservationSpaceOrganizationalUnitRoutesEnum.manageAcl, PreservationSpaceOrganizationalUnitRoutesEnum.manageAclDetail, model.resId]));
234
235
236
  }

  onQueryParametersEvent(queryParameters: QueryParameters): void {
237
238
239
240
241
242
    if (isNullOrUndefined(queryParameters)) {
      queryParameters = new QueryParameters();
    }
    const searchItem = QueryParametersUtil.getSearchItems(queryParameters);
    MappingObjectUtil.set(searchItem, "organizationalUnit.resId", this._orgUnitId);
    this._store.dispatch(new PreservationSpaceOrganizationalUnitArchiveAclAction.ChangeQueryParameters(queryParameters, true));
243
244
245
246
247
248
249
250
251
252
253
    this._changeDetector.detectChanges(); // Allow to display spinner the first time
  }

  back(): void {
    this._store.dispatch(new Navigate([RoutesEnum.preservationSpaceOrganizationalUnitDetail, this._orgUnitId]));
  }

  navigateNavigate(navigate: Navigate): void {
    this._store.dispatch(navigate);
  }
}