deposit-file.container.ts 19 KB
Newer Older
1
2
3
4
import {PersonRole} from "@admin/models/person-role.model";
import {
  ChangeDetectorRef,
  Component,
5
  Inject,
6
7
8
9
10
11
12
13
14
  OnInit,
  ViewChild,
} from "@angular/core";
import {
  MatDialog,
  MatDialogRef,
} from "@angular/material/dialog";
import {ActivatedRoute} from "@angular/router";
import {AppState} from "@app/stores/app.state";
15
16
17
18
import {
  DepositFileUploadDialog,
  DepositFileUploadDialogData,
} from "@deposit/components/dialogs/deposit-file-upload/deposit-file-upload.dialog";
19
20
import {DepositDataFileHelper} from "@deposit/helpers/deposit-data-file.helper";
import {DepositDataFile} from "@deposit/models/deposit-data-file.model";
21
import {FileUploadWrapper} from "@deposit/models/file-upload-wrapper.model";
22
23
24
25
26
27
28
29
30
31
import {DepositDataFileAction} from "@deposit/stores/data-file/deposit-data-file.action";
import {DepositDataFileState} from "@deposit/stores/data-file/deposit-data-file.state";
import {
  DepositAction,
  depositActionNameSpace,
} from "@deposit/stores/deposit.action";
import {
  DepositState,
  DepositStateModel,
} from "@deposit/stores/deposit.state";
32
import {DepositOrganizationalUnitState} from "@deposit/stores/organizational-unit/deposit-organizational-unit.state";
Florent POITTEVIN's avatar
Florent POITTEVIN committed
33
import {Enums} from "@enums";
34
import {Deposit} from "@models";
35
import {Navigate} from "@ngxs/router-plugin";
36
37
38
39
40
import {
  Actions,
  Select,
  Store,
} from "@ngxs/store";
41
import {SharedFileAndAipInformationContainer} from "@shared/components/containers/shared-file-and-aip-information/shared-file-and-aip-information.container";
42
43
44
45
import {
  SharedDeleteDialog,
  SharedDeleteDialogData,
} from "@shared/components/dialogs/shared-abstract-delete/shared-delete.dialog";
46
47
48
49
50
51
52
53
54
55
56
import {
  SharedConfirmDialog,
  SharedConfirmDialogData,
} from "@shared/components/dialogs/shared-confirm/shared-confirm.dialog";
import {SharedPreviewDialogData} from "@shared/components/dialogs/shared-preview/shared-preview-dialog-data.model";
import {SharedPreviewDialog} from "@shared/components/dialogs/shared-preview/shared-preview.dialog";
import {SharedDataTablePresentational} from "@shared/components/presentationals/shared-data-table/shared-data-table.presentational";
import {SharedAbstractDetailEditRoutable} from "@shared/components/routables/shared-abstract-detail-edit/shared-abstract-detail-edit.routable";
import {DataTableComponentEnum} from "@shared/enums/data-table-component.enum";
import {FieldTypeEnum} from "@shared/enums/field-type.enum";
import {FileViewModeEnum} from "@shared/enums/file-view-mode.enum";
57
import {IconNameEnum} from "@shared/enums/icon-name.enum";
58
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
59
import {LocalStateEnum} from "@shared/enums/local-state.enum";
60
61
62
63
import {
  AppRoutesEnum,
  DepositRoutesEnum,
} from "@shared/enums/routes.enum";
64
65
66
67
68
import {FileVisualizerHelper} from "@shared/filevisualizer/helpers/file-visualizer.helper";
import {
  AbstractFileVisualizer,
  FILE_VISUALIZERS,
} from "@shared/filevisualizer/services/abstract-file-visualizer.service";
69
70
71
72
73
74
75
import {DataTableActions} from "@shared/models/data-table-actions.model";
import {DataTableBulkActions} from "@shared/models/data-table-bulk-actions.model";
import {DataTableColumns} from "@shared/models/data-table-columns.model";
import {SecurityService} from "@shared/services/security.service";
import {Observable} from "rxjs";
import {
  distinctUntilChanged,
76
  filter,
77
  map,
78
79
80
81
  take,
  tap,
} from "rxjs/operators";
import {
82
  isNonEmptyArray,
83
84
85
  isNullOrUndefined,
  isTrue,
  isUndefined,
86
  MappingObjectUtil,
87
  MARK_AS_TRANSLATABLE,
88
89
90
  MemoizedUtil,
  OrderEnum,
  QueryParameters,
91
  QueryParametersUtil,
92
93
94
95
96
97
98
99
100
101
  ResourceActionHelper,
  StringUtil,
} from "solidify-frontend";

@Component({
  selector: "dlcm-deposit-file-container",
  templateUrl: "./deposit-file.container.html",
  styleUrls: ["./deposit-file.container.scss"],
})
export class DepositFileContainer extends SharedAbstractDetailEditRoutable<Deposit, DepositStateModel> implements OnInit {
102
  private readonly _KEY_QUERY_PARAMETERS: keyof DepositDataFile = "status";
103
  isLoadingDataFileObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, DepositDataFileState);
104
  listDataFileObs: Observable<DepositDataFile[]> = MemoizedUtil.list(this._store, DepositDataFileState);
105
106
107
  queryParametersObs: Observable<QueryParameters> = MemoizedUtil.queryParameters(this._store, DepositDataFileState).pipe(
    tap(queryParameters => this.isInErrorStatusFilter = MappingObjectUtil.get(QueryParametersUtil.getSearchItems(queryParameters), this._KEY_QUERY_PARAMETERS) === Enums.DataFile.StatusEnum.IN_ERROR),
  );
108
  draggingDepositDataFile: DepositDataFile | undefined = undefined;
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  intermediateFoldersObs: Observable<string[]> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.intermediateFolders);
  foldersWithIntermediateFoldersObs: Observable<string[]> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.foldersWithIntermediateFolders);
  currentFolderObs: Observable<string> = MemoizedUtil.select(this._store, DepositDataFileState, state => state.currentFolder);
  canEditObs: Observable<boolean> = MemoizedUtil.select(this._store, DepositState, state => state.canEdit).pipe(
    distinctUntilChanged(),
    tap(canEdit => this.actions = [...this.actions]), // Force method computeContext on datatable
  );

  @Select(AppState.currentOrgUnitPerson) currentPersonObs: Observable<PersonRole>;

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

  currentFileViewMode: FileViewModeEnum = FileViewModeEnum.FolderView;

  columns: DataTableColumns<DepositDataFile>[];

  actions: DataTableActions<DepositDataFile>[] = [
127
    {
128
129
130
131
      logo: IconNameEnum.notIgnore,
      callback: (depositDataFile: DepositDataFile) => this.validate(this._resId, depositDataFile),
      placeholder: current => LabelTranslateEnum.doNotIgnore,
      displayOnCondition: (depositDataFile: DepositDataFile) => depositDataFile.status === Enums.DataFile.StatusEnum.IGNORED_FILE,
132
    },
133
    {
134
      logo: IconNameEnum.download,
135
      callback: (depositDataFile: DepositDataFile) => this.downloadDataFile(this._resId, depositDataFile),
136
      placeholder: current => LabelTranslateEnum.download,
137
      displayOnCondition: current => current.status === Enums.DataFile.StatusEnum.PROCESSED || current.status === Enums.DataFile.StatusEnum.READY || current.status === Enums.DataFile.StatusEnum.VIRUS_CHECKED,
138
      isWrapped: false,
139
140
    },
    {
141
      logo: IconNameEnum.resume,
142
      callback: (depositDataFile: DepositDataFile) => this.resumeDataFile(this._resId, depositDataFile),
143
      placeholder: current => LabelTranslateEnum.resume,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
144
      displayOnCondition: (depositDataFile: DepositDataFile) => depositDataFile.status === Enums.DataFile.StatusEnum.IN_ERROR,
145
146
    },
    {
147
      logo: IconNameEnum.delete,
148
      callback: (depositDataFile: DepositDataFile) => this._deleteDataFile(this._resId, depositDataFile),
149
      placeholder: current => LabelTranslateEnum.delete,
150
151
152
      displayOnCondition: (depositDataFile: DepositDataFile) => MemoizedUtil.selectSnapshot(this._store, DepositState, state => state.canEdit),
    },
    {
153
      logo: IconNameEnum.preview,
154
      callback: (depositDataFile: DepositDataFile) => this._showPreview(depositDataFile),
155
      placeholder: current => LabelTranslateEnum.showPreview,
156
157
158
159
      displayOnCondition: (depositDataFile: DepositDataFile) => FileVisualizerHelper.canHandle(this._fileVisualizers, {
        dataFile: depositDataFile,
        fileExtension: FileVisualizerHelper.getFileExtension(depositDataFile.fileName),
      }),
160
161
162
    },
  ];

163
  bulkActions: DataTableBulkActions<DepositDataFile>[] = [
164
    {
165
      logo: IconNameEnum.delete,
166
      callback: (list: DepositDataFile[]) => this._bulkDeleteDataFile(this._resId, list.map(s => s.resId)),
167
      label: LabelTranslateEnum.deleteSelection,
168
169
170
171
      displayOnCondition: (list: DepositDataFile[]) => this.canEditObs,
    },
    {
      logo: IconNameEnum.resume,
172
      callback: (list: DepositDataFile[]) => this._bulkResumeDataFile(this._resId, list.map(s => s.resId)),
173
174
      label: LabelTranslateEnum.resumeSelection,
      displayOnCondition: (list: DepositDataFile[]) => this.canEditObs && list.findIndex(d => d.status === Enums.DataFile.StatusEnum.IN_ERROR) !== -1,
175
    },
176
177
178
179
180
181
    {
      logo: IconNameEnum.notIgnore,
      callback: (list: DepositDataFile[]) => this._bulkValidateDataFile(this._resId, list.map(s => s.resId)),
      label: LabelTranslateEnum.doNotIgnoreSelection,
      displayOnCondition: (list: DepositDataFile[]) => this.canEditObs && list.findIndex(d => d.status === Enums.DataFile.StatusEnum.IGNORED_FILE) !== -1,
    },
182
183
184
185
186
187
188
  ];

  columnsToSkippedFilter: keyof DepositDataFile[] | string[] = [
    DepositDataFileHelper.RELATIVE_LOCATION,
    "status",
  ];

189
  dialogDataFileRef: MatDialogRef<SharedFileAndAipInformationContainer<DepositDataFile>>;
190
191
192
193
194

  get fileViewModeEnum(): typeof FileViewModeEnum {
    return FileViewModeEnum;
  }

Florent POITTEVIN's avatar
Florent POITTEVIN committed
195
196
  get depositEnum(): typeof Enums.Deposit.StatusEnum {
    return Enums.Deposit.StatusEnum;
197
198
  }

199
  readonly KEY_PARAM_NAME: keyof Deposit & string = undefined;
200
  isInErrorStatusFilter: boolean = false;
201
202
203
204
205
206

  constructor(protected readonly _store: Store,
              protected readonly _route: ActivatedRoute,
              protected readonly _actions$: Actions,
              protected readonly _changeDetector: ChangeDetectorRef,
              protected readonly _dialog: MatDialog,
207
208
              protected readonly _securityService: SecurityService,
              @Inject(FILE_VISUALIZERS) private readonly _fileVisualizers: AbstractFileVisualizer[]) {
209
210
211
212
213
    super(_store, _route, _actions$, _changeDetector, _dialog, LocalStateEnum.deposit, depositActionNameSpace);

    this.columns = [
      {
        field: "fileName",
214
        header: LabelTranslateEnum.fileName,
215
216
        type: FieldTypeEnum.string,
        order: OrderEnum.ascending,
217
218
        filterableField: "dataFile.sourceData" as any,
        sortableField: "dataFile.sourceData" as any,
David.Gold1's avatar
David.Gold1 committed
219
        isSortable: true,
David.Gold1's avatar
David.Gold1 committed
220
        isFilterable: true,
221
222
223
      },
      {
        field: "creation.when" as any,
224
        header: LabelTranslateEnum.created,
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
        type: FieldTypeEnum.datetime,
        order: OrderEnum.none,
        isFilterable: false,
        isSortable: true,
      },
      {
        field: "status",
        header: StringUtil.stringEmpty,
        type: FieldTypeEnum.singleSelect,
        order: OrderEnum.none,
        sortableField: "dataFile.status" as any,
        filterableField: "dataFile.status" as any,
        isSortable: false,
        isFilterable: false,
        translate: false,
        component: DataTableComponentEnum.dataFileQuickStatus,
        width: "35px",
        // filterEnum: ComplianceLevelEnumHelper.getListKeyValue(),
      },
      {
        field: "status",
246
        header: LabelTranslateEnum.status,
247
248
249
250
251
252
        type: FieldTypeEnum.singleSelect,
        order: OrderEnum.none,
        sortableField: "dataFile.status" as any,
        isSortable: true,
        isFilterable: true,
        translate: true,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
253
254
        tooltip: (value) => Enums.DataFile.getExplanation(value as Enums.DataFile.StatusEnum),
        filterEnum: Enums.DataFile.StatusEnumTranslate,
255
        component: DataTableComponentEnum.status,
256
257
258
      },
      {
        field: "complianceLevel",
259
        header: LabelTranslateEnum.complianceLevel,
260
261
262
263
264
265
266
        type: FieldTypeEnum.singleSelect,
        order: OrderEnum.none,
        sortableField: "dataFile.complianceLevel" as any,
        filterableField: "dataFile.complianceLevel" as any,
        isSortable: true,
        isFilterable: false,
        translate: true,
David.Gold1's avatar
David.Gold1 committed
267
        width: "185px",
268
        component: DataTableComponentEnum.conformityLevelStar,
Florent POITTEVIN's avatar
Florent POITTEVIN committed
269
        filterEnum: Enums.DataFile.ComplianceLevelEnumTranslate,
270
      },
271
      {
272
        field: "smartSize",
273
        header: LabelTranslateEnum.size,
274
        type: FieldTypeEnum.string,
275
276
277
278
279
280
        order: OrderEnum.none,
        sortableField: "dataFile.fileSize" as any,
        filterableField: "dataFile.fileSize" as any,
        isSortable: true,
        isFilterable: false,
        translate: true,
281
        width: "100px",
282
      },
283
284
285
    ];
  }

286
287
288
289
290
  ngOnInit(): void {
    super.ngOnInit();
    this.getCurrentModelOnParent();
  }

291
292
293
294
295
296
  private getCurrentModelOnParent(): void {
    this._resId = this._route.snapshot.parent.paramMap.get(AppRoutesEnum.paramIdWithoutPrefixParam);
    this.getDepositById(this._resId);
  }

  private getDepositById(id: string): void {
297
    const depositInState = MemoizedUtil.currentSnapshot(this._store, DepositState);
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
    if (isNullOrUndefined(depositInState) || id !== depositInState.resId) {
      this._store.dispatch(ResourceActionHelper.getById(depositActionNameSpace, id, true));
    }
    this.getSubResourceWithParentId(id);
  }

  getSubResourceWithParentId(id: string): void {
    this._store.dispatch(new DepositDataFileAction.GetAll(id, undefined, true));
    this._store.dispatch(new DepositDataFileAction.GetListFolder(id));
  }

  onQueryParametersEvent(queryParameters: QueryParameters, withRefresh: boolean = true): void {
    this._store.dispatch(new DepositDataFileAction.ChangeQueryParameters(this._resId, queryParameters, true, withRefresh));
    // this._changeDetector.detectChanges(); // Allow to display spinner the first time
  }

  refresh(): void {
    this._store.dispatch(new DepositDataFileAction.Refresh(this._resId));
  }

  download($event: DepositDataFile): void {
    this._store.dispatch(new DepositDataFileAction.Download(this._resId, $event));
  }

  selectFolder(folderFullName: string | undefined): void {
    if (isUndefined(folderFullName)) {
      this.currentFileViewMode = FileViewModeEnum.FlatView;
    } else {
      this.currentFileViewMode = FileViewModeEnum.FolderView;
    }
    this._store.dispatch(new DepositDataFileAction.ChangeCurrentFolder(folderFullName, true));
  }

  downloadFolder(folderName: string): void {
    this._store.dispatch(new DepositAction.Download(this._resId, folderName));
  }

335
  deleteFolder(folderName: string): void {
336
    this.subscribe(this._dialog.open(SharedDeleteDialog, {
337
338
339
      minWidth: "500px",
      data: {
        name: folderName,
340
341
342
        resourceNameSpace: depositActionNameSpace,
        message: MARK_AS_TRANSLATABLE("deposit.dialog.deleteFolder.message"),
      } as SharedDeleteDialogData,
343
344
345
346
347
348
349
350
351
352
353
354
    }).afterClosed().pipe(
      tap((isConfirmed: boolean | undefined) => {
        if (isNullOrUndefined(isConfirmed)) {
          return;
        }
        if (isTrue(isConfirmed)) {
          this._store.dispatch(new DepositDataFileAction.DeleteFolder(this._resId, folderName));
        }
      }),
    ));
  }

355
  showDetail(depositDataFile: DepositDataFile): void {
356
357
    const orgUnitId = MemoizedUtil.currentSnapshot(this._store, DepositOrganizationalUnitState)?.resId;
    this._store.dispatch(new Navigate([AppRoutesEnum.deposit, orgUnitId, DepositRoutesEnum.detail, this._resId, DepositRoutesEnum.files, depositDataFile.resId]));
358
359
  }

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
  private _bulkDeleteDataFile(parentId: string, listId: string[]): Observable<boolean> {
    return this._dialog.open(SharedDeleteDialog, {
      minWidth: "500px",
      data: {
        name: undefined,
        resourceNameSpace: depositActionNameSpace,
        message: MARK_AS_TRANSLATABLE("deposit.dialog.deleteList.message"),
      } as SharedDeleteDialogData,
    }).afterClosed().pipe(
      take(1),
      map((isConfirmed: boolean | undefined) => {
        if (isNullOrUndefined(isConfirmed)) {
          return false;
        }
        if (isTrue(isConfirmed)) {
          this._bulkDeleteDataFileWithoutConfirmation(parentId, listId);
        }
        return true;
      }),
    );
  }

  private _bulkDeleteDataFileWithoutConfirmation(parentId: string, listId: string[]): void {
383
384
385
    this._store.dispatch(new DepositDataFileAction.DeleteAll(parentId, listId));
  }

386
  private _bulkResumeDataFile(parentId: string, listId: string[]): void {
387
388
389
    this._store.dispatch(new DepositDataFileAction.ResumeAll(parentId, listId));
  }

390
391
392
393
  private _bulkValidateDataFile(parentId: string, listId: string[]): void {
    this._store.dispatch(new DepositDataFileAction.ValidateAll(parentId, listId));
  }

394
  private _deleteDataFile(parentId: string, dataFile: DepositDataFile): void {
395
    this._store.dispatch(new DepositDataFileAction.Delete(parentId, dataFile.resId));
396
397
  }

398
  private _showPreview(dataFile: DepositDataFile): void {
399
    this._dialog.open(SharedPreviewDialog, {
400
401
      width: "max-content",
      maxWidth: "90vw",
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
      height: "min-content",
      data: {
        fileInput: {
          dataFile: dataFile,
        },

      } as SharedPreviewDialogData,
    });
  }

  moveDataFile(dataFile: DepositDataFile): void {
    this._store.dispatch(new DepositDataFileAction.Move(this._resId, {
      resId: dataFile.resId,
      relativeLocation: dataFile.relativeLocation,
    }));
  }

  validate(parentId: string, dataFile: DepositDataFile): void {
    this._store.dispatch(new DepositDataFileAction.Validate(parentId, dataFile));
  }

  downloadDataFile(parentId: string, dataFile: DepositDataFile): void {
    this._store.dispatch(new DepositDataFileAction.Download(parentId, dataFile));
  }

  resumeDataFile(parentId: string, dataFile: DepositDataFile): void {
428
    this._store.dispatch(new DepositDataFileAction.Resume(parentId, dataFile));
429
430
431
432
433
  }

  selectAndDelete(): void {
    this.subscribe(this._dialog.open(SharedConfirmDialog, {
      data: {
434
435
        titleToTranslate: MARK_AS_TRANSLATABLE("deposit.file.bulkDelete.title"),
        messageToTranslate: MARK_AS_TRANSLATABLE("deposit.file.bulkDelete.message"),
436
437
        confirmButtonToTranslate: LabelTranslateEnum.yesImSure,
        cancelButtonToTranslate: LabelTranslateEnum.cancel,
438
        colorConfirm: "warn",
439
440
441
442
443
444
445
446
447
448
      } as SharedConfirmDialogData,
    }).afterClosed().pipe(
      tap((isConfirmed: boolean | undefined) => {
        if (isNullOrUndefined(isConfirmed)) {
          return;
        }
        if (isTrue(isConfirmed)) {
          this.subscribe(this.dataTablePresentational.selectAllResult().pipe(
            take(1),
            tap(selection => {
449
              this._bulkDeleteDataFileWithoutConfirmation(this._resId, selection);
450
451
452
453
454
455
456
              this.dataTablePresentational.cleanSelection();
            }),
          ));
        }
      }),
    ));
  }
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

  uploadInFolder(fullFolderPath: string): void {
    const dialogRef = this._dialog.open(DepositFileUploadDialog, {
      width: "500px",
      data: {
        subDirectory: fullFolderPath,
      } as DepositFileUploadDialogData,
    });
    this.subscribe(dialogRef.afterClosed().pipe(
      filter((listFilesUploadWrapper: FileUploadWrapper[]) => isNonEmptyArray(listFilesUploadWrapper)),
      tap((listFilesUploadWrapper: FileUploadWrapper[]) => {
        listFilesUploadWrapper.forEach(f => this.upload(f));
      }),
    ));
  }

  upload($event: FileUploadWrapper): void {
    this._store.dispatch(new DepositAction.UploadDataFile(this._resId, $event));
  }
476
477
478
479
480

  selectAndResumeAll(): void {
    this.subscribe(this.dataTablePresentational.selectAllResult().pipe(
      take(1),
      tap(selectionList => {
481
        this._bulkResumeDataFile(this._resId, selectionList);
482
483
484
485
        this.dataTablePresentational.cleanSelection();
      }),
    ));
  }
486
487
488
489
490
491
492
493

  dragStart($event: DepositDataFile): void {
    this.draggingDepositDataFile = $event;
  }

  dragEnd($event: DepositDataFile): void {
    this.draggingDepositDataFile = undefined;
  }
494
}