From 13644fb5d165f175554fcc813a529833f8280791 Mon Sep 17 00:00:00 2001
From: "ext.sopra.ncastejon" <castejon.nicolas@gmail.com>
Date: Thu, 19 Mar 2020 16:08:25 +0100
Subject: [PATCH] Display the correct formats in the Download tab.

---
 .../dataset-detail.component.ts               | 34 ++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/app/dataset-detail/components/dataset-detail/dataset-detail.component.ts b/src/app/dataset-detail/components/dataset-detail/dataset-detail.component.ts
index 8602c83d..cd910edb 100644
--- a/src/app/dataset-detail/components/dataset-detail/dataset-detail.component.ts
+++ b/src/app/dataset-detail/components/dataset-detail/dataset-detail.component.ts
@@ -109,15 +109,43 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
     return formatted;
   }
 
+  // Get the formats available to download
   get datasetFormatsList() {
 
     const links = this._datasetDetailService.datasetMetadata.link;
-    let list = links.map(l => l.formats);
+
+    let list = links.map((link) => {
+      let filteredList = link.formats;
+      if (link.formats) {
+        filteredList = link.formats.filter((f) => {
+          let validFormat = true;
+          if (!f) {
+            validFormat = false;
+          }
+          // If nongeographical dataset, there is no shapefile format
+          // tslint:disable-next-line: ter-indent
+          // tslint:disable-next-line: brace-style
+          else if (this._datasetDetailService.datasetMetadata.type === 'nonGeographicDataset'
+            && f === 'ShapeFile') {
+            validFormat = false;
+          } else if (f === 'PDF' && link.name.includes('Licence')) { // Remove PDF because it's Licence
+            validFormat = false;
+          }
+          return validFormat;
+        });
+      }
+      return filteredList;
+    });
+
     // Flat the arrays
     list = [].concat(...list);
     // Remove duplicates
     list = [...new Set(list)];
 
+    list = list.filter((el) => {
+      return el !== undefined;
+    });
+
     let formatted: string;
 
     if (list.length > 4) {
@@ -126,10 +154,6 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
       formatted = list.join(', ');
     }
 
-    if (links.length === 1 && links[0].name.includes('Licence')) {
-      formatted = null;
-    }
-
     return formatted;
   }
 
-- 
GitLab