From 6dd50a734cd8bf89b9d1ce005eb6d1c9942c6f4e Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Fri, 31 Jan 2020 12:48:46 +0100
Subject: [PATCH] fix: aip statuses when data to display are not on the first
 storagion

---
 .../aip-status-home.routable.ts               |  7 ++-
 .../aip-status-name.presentational.html       |  1 +
 .../aip-status-name.presentational.scss       |  2 +
 .../aip-status-name.presentational.ts         | 55 +++++++++++++++++++
 ...ip-status-orgunit-name.presentational.html |  3 +
 ...ip-status-orgunit-name.presentational.scss |  3 +
 .../aip-status-orgunit-name.presentational.ts | 54 ++++++++++++++++++
 .../shared-data-table.presentational.html     |  8 +++
 .../shared/enums/data-table-component.enum.ts |  2 +
 src/app/shared/shared.module.ts               |  4 ++
 10 files changed, 136 insertions(+), 3 deletions(-)
 create mode 100644 src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.html
 create mode 100644 src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.scss
 create mode 100644 src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.ts
 create mode 100644 src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.html
 create mode 100644 src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.scss
 create mode 100644 src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.ts

diff --git a/src/app/features/preservation/aip-status/components/routables/aip-status-home/aip-status-home.routable.ts b/src/app/features/preservation/aip-status/components/routables/aip-status-home/aip-status-home.routable.ts
index 952965e1e..82d305b1e 100644
--- a/src/app/features/preservation/aip-status/components/routables/aip-status-home/aip-status-home.routable.ts
+++ b/src/app/features/preservation/aip-status/components/routables/aip-status-home/aip-status-home.routable.ts
@@ -55,19 +55,20 @@ export class AipStatusHomeRoutable extends SharedAbstractPresentational implemen
         isSortable: false,
       },
       {
-        field: "copies[0].aip.info.name" as any,
+        field: "copies",
         header: TRANSLATE("admin.preservation.aipStatuses.table.header.name"),
         type: FieldTypeEnum.string,
         order: OrderEnum.none,
         isFilterable: false,
         isSortable: false,
+        component: DataTableComponentEnum.aipStatusNamePresentational,
       },
       {
-        field: "copies[0].aip.info.organizationalUnitId" as any,
+        field: "copies",
         header: TRANSLATE("admin.preservation.aipStatuses.table.header.organizationalUnit"),
         type: FieldTypeEnum.string,
         order: OrderEnum.none,
-        component: DataTableComponentEnum.organizationalUnitName,
+        component: DataTableComponentEnum.aipStatusOrgUnitPresentational,
         isFilterable: false,
         isSortable: false,
       },
diff --git a/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.html b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.html
new file mode 100644
index 000000000..7e6613293
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.html
@@ -0,0 +1 @@
+{{name}}
diff --git a/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.scss b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.scss
new file mode 100644
index 000000000..92ad54f14
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.scss
@@ -0,0 +1,2 @@
+@import "../sass/abstracts/variables";
+@import "../sass/abstracts/mixins";
diff --git a/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.ts b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.ts
new file mode 100644
index 000000000..2b2f43785
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-name/aip-status-name.presentational.ts
@@ -0,0 +1,55 @@
+import {
+  ChangeDetectionStrategy,
+  Component,
+  Input,
+} from "@angular/core";
+import {SharedAbstractPresentational} from "@app/shared/components/presentationals/shared-abstract/shared-abstract.presentational";
+import {AipCopyList} from "@shared/models/business/aip-copy-list.model";
+import {
+  isEmptyArray,
+  isNullOrUndefined,
+} from "solidify-frontend";
+
+@Component({
+  selector: "dlcm-aip-status-name",
+  templateUrl: "./aip-status-name.presentational.html",
+  styleUrls: ["./aip-status-name.presentational.scss"],
+  changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class AipStatusNamePresentational extends SharedAbstractPresentational {
+  private _aipCopyList: AipCopyList;
+
+  @Input()
+  set aipCopyList(value: AipCopyList) {
+    this._aipCopyList = value;
+    this.computeName();
+  }
+
+  get aipCopyList(): AipCopyList {
+    return this._aipCopyList;
+  }
+
+  name: string | undefined;
+
+  private computeName(): void {
+    if (isNullOrUndefined(this.aipCopyList) || isEmptyArray(this.aipCopyList)) {
+      this.name = undefined;
+      return;
+    }
+
+    let copyWithDataProvided = undefined;
+    this.aipCopyList.copies.some(copy => {
+      if (!isNullOrUndefined(copy.aip)) {
+        copyWithDataProvided = copy.aip;
+        return true;
+      }
+    });
+
+    if (isNullOrUndefined(copyWithDataProvided)) {
+      this.name = undefined;
+      return;
+    }
+
+    this.name = copyWithDataProvided.info.name;
+  }
+}
diff --git a/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.html b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.html
new file mode 100644
index 000000000..7e6fc8daa
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.html
@@ -0,0 +1,3 @@
+<dlcm-shared-organizational-unit-name-container *ngIf="!(orgUnitId | isNullOrUndefined)"
+                                                [id]="orgUnitId"
+></dlcm-shared-organizational-unit-name-container>
diff --git a/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.scss b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.scss
new file mode 100644
index 000000000..01cfa9a54
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.scss
@@ -0,0 +1,3 @@
+@import "../sass/abstracts/variables";
+@import "../sass/abstracts/mixins";
+
diff --git a/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.ts b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.ts
new file mode 100644
index 000000000..001eab975
--- /dev/null
+++ b/src/app/shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational.ts
@@ -0,0 +1,54 @@
+import {
+  ChangeDetectionStrategy,
+  Component,
+  Input,
+} from "@angular/core";
+import {SharedAbstractPresentational} from "@app/shared/components/presentationals/shared-abstract/shared-abstract.presentational";
+import {AipCopyList} from "@shared/models/business/aip-copy-list.model";
+import {
+  isEmptyArray,
+  isNullOrUndefined,
+} from "solidify-frontend";
+
+@Component({
+  selector: "dlcm-aip-status-orgunit-name",
+  templateUrl: "./aip-status-orgunit-name.presentational.html",
+  styleUrls: ["./aip-status-orgunit-name.presentational.scss"],
+  changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class AipStatusOrgunitNamePresentational extends SharedAbstractPresentational {
+  private _aipCopyList: AipCopyList;
+
+  @Input()
+  set aipCopyList(value: AipCopyList) {
+    this._aipCopyList = value;
+    this.computeOrgUnitId();
+  }
+
+  get aipCopyList(): AipCopyList {
+    return this._aipCopyList;
+  }
+
+  orgUnitId: string | undefined;
+
+  private computeOrgUnitId(): void {
+    if (isNullOrUndefined(this.aipCopyList) || isEmptyArray(this.aipCopyList)) {
+      this.orgUnitId = undefined;
+      return;
+    }
+
+    let copyWithDataProvided = undefined;
+    this.aipCopyList.copies.some(copy => {
+      if (!isNullOrUndefined(copy.aip)) {
+        copyWithDataProvided = copy.aip;
+        return true;
+      }
+    });
+
+    if (isNullOrUndefined(copyWithDataProvided)) {
+      this.orgUnitId = undefined;
+      return;
+    }
+    this.orgUnitId = copyWithDataProvided.info.organizationalUnitId;
+  }
+}
diff --git a/src/app/shared/components/presentationals/shared-data-table/shared-data-table.presentational.html b/src/app/shared/components/presentationals/shared-data-table/shared-data-table.presentational.html
index 5fda235a5..944e8bac0 100644
--- a/src/app/shared/components/presentationals/shared-data-table/shared-data-table.presentational.html
+++ b/src/app/shared/components/presentationals/shared-data-table/shared-data-table.presentational.html
@@ -158,6 +158,14 @@
                                        [aipCopyList]="rowData"
               ></dlcm-aip-status-summary>
 
+              <dlcm-aip-status-name *ngSwitchCase="dataTableComponentEnum.aipStatusNamePresentational"
+                                    [aipCopyList]="rowData"
+              ></dlcm-aip-status-name>
+
+              <dlcm-aip-status-orgunit-name *ngSwitchCase="dataTableComponentEnum.aipStatusOrgUnitPresentational"
+                                            [aipCopyList]="rowData"
+              ></dlcm-aip-status-orgunit-name>
+
               <dlcm-shared-compliance-level-rating *ngSwitchCase="dataTableComponentEnum.conformityLevelStar"
                                                    [withLabel]="false"
                                                    [center]="true"
diff --git a/src/app/shared/enums/data-table-component.enum.ts b/src/app/shared/enums/data-table-component.enum.ts
index 1dc1a1439..4d502296b 100644
--- a/src/app/shared/enums/data-table-component.enum.ts
+++ b/src/app/shared/enums/data-table-component.enum.ts
@@ -1,5 +1,7 @@
 export enum DataTableComponentEnum {
   aipStatusSummaryPresentational = 1,
+  aipStatusNamePresentational,
+  aipStatusOrgUnitPresentational,
   conformityLevelStar,
   dataFileQuickStatus,
   jobExecutionProgression,
diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts
index 2e0a18ade..2fcb05de7 100644
--- a/src/app/shared/shared.module.ts
+++ b/src/app/shared/shared.module.ts
@@ -39,6 +39,8 @@ import {SharedBaseActionDialog} from "@shared/components/dialogs/shared-base-act
 import {SharedBaseInfoDialog} from "@shared/components/dialogs/shared-base-info/shared-base-info.dialog";
 import {SharedFileDetailDialog} from "@shared/components/dialogs/shared-file-detail/shared-file-detail.dialog";
 import {SharedHistoryDialog} from "@shared/components/dialogs/shared-history/shared-history.dialog";
+import {AipStatusNamePresentational} from "@shared/components/presentationals/aip-status-name/aip-status-name.presentational";
+import {AipStatusOrgunitNamePresentational} from "@shared/components/presentationals/aip-status-orgunit-name/aip-status-orgunit-name.presentational";
 import {AipStatusSummaryPresentational} from "@shared/components/presentationals/aip-status-summary/aip-status-summary.presentational";
 import {ButtonToolbarDetailPresentational} from "@shared/components/presentationals/button-toolbar-detail/button-toolbar-detail.presentational";
 import {SharedBannerEditModePresentational} from "@shared/components/presentationals/shared-banner-edit-mode/shared-banner-edit-mode.presentational";
@@ -112,6 +114,8 @@ const presentationals = [
   SharedPersonOrgunitRolePresentational,
   SharedSnackbarPresentational,
   AipStatusSummaryPresentational,
+  AipStatusNamePresentational,
+  AipStatusOrgunitNamePresentational,
   SharedStarRatingPresentational,
   SharedDoiMenuPresentational,
   SharedButtonIdPresentational,
-- 
GitLab