From 27860954541c67110a3b38a41d0f52636b49ad0f Mon Sep 17 00:00:00 2001
From: pkupczyk <piotr.kupczyk@id.ethz.ch>
Date: Tue, 8 Nov 2022 11:14:04 +0100
Subject: [PATCH] SSDM-13152 : Exports for master data and metadata UI - make
 ELN sample, experiment and vocabulary tables use the new export

---
 .../html/js/config/StandardProfile.js         |  2 +-
 .../html/js/controllers/MainController.js     |  6 ++--
 .../AdvancedSearch/AdvancedSearchView.js      |  2 +-
 .../js/views/DataGrid/DataGridController.js   | 34 ++++++++++++++++---
 .../views/DataGrid/ExperimentDataGridUtil.js  | 18 ++++++++--
 .../js/views/DataGrid/SampleDataGridUtil.js   | 23 +++++++++++--
 .../HierarchyTable/HierarchyTableView.js      |  2 +-
 .../html/js/views/History/HistoryView.js      |  1 +
 .../SampleForm/widgets/StorageListView.js     |  2 +-
 .../js/views/TrashManager/TrashManagerView.js |  2 +-
 .../js/views/UserManager/UserManagerView.js   |  2 +-
 .../VocabularyManagerView.js                  |  8 +++--
 .../html/plugins/bbb-hub/snakemake-table.js   |  2 +-
 13 files changed, 82 insertions(+), 22 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/StandardProfile.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/StandardProfile.js
index e0f6bd66b1e..d676f925817 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/StandardProfile.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/StandardProfile.js
@@ -412,7 +412,7 @@ $.extend(StandardProfile.prototype, DefaultProfile.prototype, {
 							repTitle += " (as saved when ordered)"
 						}
 						
-						var orderSummary = new DataGridController(repTitle, columns, [], null, getDataRows, null, false, "ORDER_SUMMARY", false, 30);
+						var orderSummary = new DataGridController(repTitle, columns, [], null, getDataRows, null, false, "ORDER_SUMMARY", false, false, 30);
 						orderSummary.init(orderSummaryContainer);
 						
 						var totalsByCurrencyContainer = $("<div>").append($("<br>")).append($("<legend>").append("Total:"));
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
index 4cb7812153b..c177e7d734a 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
@@ -1542,7 +1542,7 @@ function MainController(profile) {
 									}
 								}
 								
-								var dataGrid = new DataGridController(searchDomainLabel + " Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_" + searchDomainLabel, false, 90);
+								var dataGrid = new DataGridController(searchDomainLabel + " Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_" + searchDomainLabel, false, false, 90);
 								localReference.currentView = dataGrid;
 								var content = localReference._getBackwardsCompatibleMainContainer();
 								dataGrid.init(content);
@@ -1670,7 +1670,7 @@ function MainController(profile) {
 										}
 									}
 									
-									var dataGrid = new DataGridController(searchDomainLabel + " Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_" + searchDomainLabel, false, 90);
+									var dataGrid = new DataGridController(searchDomainLabel + " Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_" + searchDomainLabel, false, false, 90);
 									localReference.currentView = dataGrid;
 									var content = localReference._getBackwardsCompatibleMainContainer();
 									dataGrid.init(content);
@@ -1843,7 +1843,7 @@ function MainController(profile) {
 				mainController.changeView('showViewSamplePageFromPermId', e.data.permId);
 			}
 			
-			var dataGrid = new DataGridController("Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_OPENBIS", false, 90);
+			var dataGrid = new DataGridController("Search Results", columns, [], null, getDataList, rowClick, true, "SEARCH_OPENBIS", false, false, 90);
 			localReference.currentView = dataGrid;
 			var content = localReference._getBackwardsCompatibleMainContainer();
 			dataGrid.init(content);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
index 702d7b55b68..3855177276d 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/AdvancedSearch/AdvancedSearchView.js
@@ -1292,7 +1292,7 @@ function AdvancedSearchView(advancedSearchController, advancedSearchModel) {
 
             var filterModes = isGlobalSearch ? [] : null
 			var getDataRows = this._advancedSearchController.searchWithPagination(criteria, isGlobalSearch);
-			var dataGrid = new DataGridController(this.resultsTitle, this._filterColumns(columns), columnsLast, dynamicColumnsFunc, getDataRows, null, false, this.configKeyPrefix + this._advancedSearchModel.criteria.entityKind, isMultiselectable, 70, filterModes);
+			var dataGrid = new DataGridController(this.resultsTitle, this._filterColumns(columns), columnsLast, dynamicColumnsFunc, getDataRows, null, false, this.configKeyPrefix + this._advancedSearchModel.criteria.entityKind, isMultiselectable, false, 70, filterModes);
 			return dataGrid;
 	}
 
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/DataGridController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/DataGridController.js
index 9da148d5242..f21fdfbb6e0 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/DataGridController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/DataGridController.js
@@ -24,6 +24,7 @@ function DataGridController(
     showAllColumns,
     configKey,
     isMultiselectable,
+    isExportable,
     heightPercentage,
     filterModes
 ) {
@@ -50,7 +51,7 @@ function DataGridController(
         $container.empty().append($element)
     }
 
-    this.setId = function(id){
+    this.setId = function (id) {
         this.id = id
     }
 
@@ -73,6 +74,9 @@ function DataGridController(
                     loadRows: _this._loadRows,
                     onSettingsChange: _this._onSettingsChange,
                     onRowClick: rowClickEventHandler,
+                    exportable: isExportable,
+                    scheduleExport: _this._scheduleExport,
+                    loadExported: _this._loadExported,
                     selectable: false,
                     multiselectable: isMultiselectable,
                     actions: _this._actions(extraOptions),
@@ -155,12 +159,12 @@ function DataGridController(
                         value = params.value
                     }
 
-                    if(value === null || value === undefined || value === ""){
+                    if (value === null || value === undefined || value === "") {
                         return
-                    }else{
-                        if(_.isString(value)){
+                    } else {
+                        if (_.isString(value)) {
                             $(params.container).empty().text(value)
-                        }else{
+                        } else {
                             $(params.container).empty().append(value)
                         }
                     }
@@ -191,6 +195,7 @@ function DataGridController(
                         index === columns.length - 1),
                 configurable: !column.hide && !column.canNotBeHidden,
                 exportable: column.isExportable,
+                exportableProperty: column.exportableProperty,
                 truncate: column.truncate,
                 metadata: column.metadata,
             }
@@ -274,6 +279,25 @@ function DataGridController(
         mainController.serverFacade.setSetting(configKey, elnGridSettingsStr)
     }
 
+	this._scheduleExport = function (parameters) {
+		let serviceParameters = {
+			"method" : "export",
+			"file_name" : "test",
+			"ids" : parameters.exportedIds,
+			"export_referred" : true,
+			"export_properties" : parameters.exportedProperties,
+			"text_formatting" : parameters.exportedValues
+		}
+
+		mainController.serverFacade.customASService(serviceParameters, function() {
+			alert("Export succeeded")
+		}, "xls-export", function(errorResult) {
+			Util.showError("Export failed: " + JSON.stringify(errorResult));
+		});
+	}
+
+    this._loadExported = function () {}
+
     this.refresh = function () {
         if (_this.controller) {
             _this.controller.load()
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
index 4dd22eb37e1..e352201072e 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
@@ -108,10 +108,14 @@ var ExperimentDataGridUtil = new function() {
 				var entity = entities[sIdx];
 				var model = {		
 									'id' : entity.permId,
+									'exportableId' : {
+										exportable_kind: 'EXPERIMENT',
+										perm_id: entity.permId
+									},
 									'code' : entity.code,
 									'identifier' : entity.identifier,
 									'permId' : entity.permId,
-                                    'type' : entity.experimentTypeCode,
+									'type' : entity.experimentTypeCode,
 									'registrator' : entity.registrationDetails.userId,
 									'registrationDate' : Util.getFormatedDate(new Date(entity.registrationDetails.registrationDate)),
 									'modifier' : entity.registrationDetails.modifierUserId,
@@ -147,12 +151,22 @@ var ExperimentDataGridUtil = new function() {
                     entityType: entity.type
                 }
             }))
+
+            propertyColumnsToSort.forEach(propertyColumn => {
+                propertyColumn.exportableProperty = {
+                    code: propertyColumn.property,
+                    types: {
+                        "EXPERIMENT": Object.keys(foundExperimentTypes)
+                    }
+                }
+            })
+
             return propertyColumnsToSort;
         }
 			
 		//Create and return a data grid controller
         var configKey = "EXPERIMENT_TABLE";
-        var dataGridController = new DataGridController(null, columns, [], dynamicColumnsFunc, getDataList, rowClick, false, configKey, null, heightPercentage);
+        var dataGridController = new DataGridController(null, columns, [], dynamicColumnsFunc, getDataList, rowClick, false, configKey, null, true, heightPercentage);
 		dataGridController.setId("experiment-grid")
 		return dataGridController;
 	}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
index 1f2968d4ed9..dbe49a7031a 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
@@ -128,7 +128,7 @@ var SampleDataGridUtil = new function() {
 				}
 			}
 			
-            var propertyColumnsToSort = SampleDataGridUtil.createPropertyColumns(foundPropertyCodes);
+			var propertyColumnsToSort = SampleDataGridUtil.createPropertyColumns(foundPropertyCodes);
 			FormUtil.sortPropertyColumns(propertyColumnsToSort, samples.map(function(sample){
 				return {
 					entityKind: "SAMPLE",
@@ -136,6 +136,15 @@ var SampleDataGridUtil = new function() {
 				}
 			}))
 
+			propertyColumnsToSort.forEach(propertyColumn => {
+				propertyColumn.exportableProperty = {
+					code: propertyColumn.property,
+					types: {
+						"SAMPLE": Object.keys(foundSampleTypes)
+					}
+				}
+			})
+
 			return propertyColumnsToSort;
 		}
 
@@ -341,7 +350,7 @@ var SampleDataGridUtil = new function() {
 			configKey += "_" + optionalConfigPostKey;
 		}
 		
-		var dataGridController = new DataGridController(null, columnsFirst, columnsLast, dynamicColumnsFunc, getDataList, rowClick, false, configKey, isMultiselectable, heightPercentage);
+		var dataGridController = new DataGridController(null, columnsFirst, columnsLast, dynamicColumnsFunc, getDataList, rowClick, false, configKey, isMultiselectable, true, heightPercentage);
 		dataGridController.setId("sample-grid")
 		return dataGridController;
 	}
@@ -415,8 +424,12 @@ var SampleDataGridUtil = new function() {
 						modificationDate = Util.getFormatedDate(new Date(sample.registrationDetails.modificationDate));
 					}
 					
-					var sampleModel = { 
+					var sampleModel = {
 										'id' : sample.permId,
+										'exportableId' : {
+											exportable_kind: 'SAMPLE',
+											perm_id: sample.permId
+										},
 										'$object' : sample,
 										'identifier' : sample.identifier, 
 										'code' : sample.code,
@@ -658,6 +671,10 @@ var SampleDataGridUtil = new function() {
 				
 				var sampleModel = {
 									'id' : sample.permId,
+									'exportableId' : {
+										exportable_kind: 'SAMPLE',
+										perm_id: sample.permId
+									},
 									'$object' : sample,
 									'identifier' : sample.identifier, 
 									'code' : sample.code,
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/HierarchyTableView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/HierarchyTableView.js
index f37cdca154e..9f803fa6aa3 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/HierarchyTableView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/HierarchyTableView.js
@@ -166,7 +166,7 @@ function HierarchyTableView(controller, model) {
 			callback(filteredData);
 		}
 		
-		this._dataGrid = new DataGridController(null, columns, [], null, getDataList, null, false, this._model.entity["@type"] + "_HIERARCHY_TABLE", false, 90);
+		this._dataGrid = new DataGridController(null, columns, [], null, getDataList, null, false, this._model.entity["@type"] + "_HIERARCHY_TABLE", false, false, 90);
 		this._dataGrid.init(this._container);
 		this._container.prepend($("<legend>").append(" " + ELNDictionary.Sample + " Hierarchy"));
 	}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/History/HistoryView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/History/HistoryView.js
index 35d5631110d..44c6b9d2886 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/History/HistoryView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/History/HistoryView.js
@@ -119,6 +119,7 @@ function HistoryView(controller, model) {
             null,
             false,
             this._model.entity["@type"] + "_HISTORY",
+            false,
             false
         )
 
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js
index 8a246b82917..364e676d1d2 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/StorageListView.js
@@ -145,7 +145,7 @@ function StorageListView(storageListController, storageListModel) {
 			}});
 		}
 
-		this._dataGrid = new DataGridController(null, columns, [], null, getDataList, rowClick, false, "STORAGE_WIDGET", isMultiselectable, 60);
+		this._dataGrid = new DataGridController(null, columns, [], null, getDataList, rowClick, false, "STORAGE_WIDGET", isMultiselectable, false, 60);
 
 		var $dataGridContainer = $("<div>");
 		this._dataGrid.init($dataGridContainer, extraOptions);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/TrashManager/TrashManagerView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/TrashManager/TrashManagerView.js
index e256e2119e7..a818988bf82 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/TrashManager/TrashManagerView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/TrashManager/TrashManagerView.js
@@ -209,7 +209,7 @@ function TrashManagerView(trashManagerController, trashManagerModel) {
 		}
 		
 		var dataGridContainer = $("<div>").css("margin-top", "-10px").css("margin-left", "-10px");
-		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, true, "TRASHCAN_TABLE", false, 90);
+		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, true, "TRASHCAN_TABLE", false, false, 90);
 		dataGrid.init(dataGridContainer);
 		$containerColumn.append(dataGridContainer);
 	}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserManager/UserManagerView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserManager/UserManagerView.js
index 3bcccbb61f6..27c82ab7559 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserManager/UserManagerView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserManager/UserManagerView.js
@@ -124,7 +124,7 @@ function UserManagerView(userManagerController, userManagerModel) {
 			callback(dataList);
 		}
 		
-		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, false, "USER_MANAGER_TABLE", false, 90);
+		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, false, "USER_MANAGER_TABLE", false, false, 90);
 		dataGrid.setId("user-grid")
 		dataGrid.init(dataGridContainer);
 		
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/VocabularyManager/VocabularyManagerView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/VocabularyManager/VocabularyManagerView.js
index a37ca1064f2..a42c417fc55 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/VocabularyManager/VocabularyManagerView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/VocabularyManager/VocabularyManagerView.js
@@ -67,6 +67,10 @@ function VocabularyManagerView(vocabularyManagerController, vocabularyManagerMod
 				var codeDiv = "<div id= " + id +">" + vocabulary.code + "</did>";
 				dataList.push({
 					id: vocabulary.code,
+					exportableId : {
+						exportable_kind: 'VOCABULARY',
+						perm_id: vocabulary.code
+					},
 					code : codeDiv,
 					description : vocabulary.description,
 					object : vocabulary
@@ -79,7 +83,7 @@ function VocabularyManagerView(vocabularyManagerController, vocabularyManagerMod
 			_this._showVocabulary(e.data.object)
 		}
 		
-		var dataGrid = new DataGridController(null, columns, [], null, getDataList, rowClick, true, "VOCABULARY_TABLE", false, 90);
+		var dataGrid = new DataGridController(null, columns, [], null, getDataList, rowClick, true, "VOCABULARY_TABLE", false, true, 90);
 		dataGrid.setId("vocabulary-grid")
 		dataGrid.init(this._dataGridContainer);
 		
@@ -121,7 +125,7 @@ function VocabularyManagerView(vocabularyManagerController, vocabularyManagerMod
 			callback(dataList);
 		}
 		
-		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, true, "VOCABULARY_TERMS_TABLE", false, 90);
+		var dataGrid = new DataGridController(null, columns, [], null, getDataList, null, true, "VOCABULARY_TERMS_TABLE", false, false, 90);
 		dataGrid.setId("vocabulary-terms-table")
 		dataGrid.init(this._dataGridContainer);
 		
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/plugins/bbb-hub/snakemake-table.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/plugins/bbb-hub/snakemake-table.js
index 7dd2771de2e..3593dd1780c 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/plugins/bbb-hub/snakemake-table.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/plugins/bbb-hub/snakemake-table.js
@@ -70,7 +70,7 @@ var SnakemakeTable = new function() {
             callback(dataList);
         };
 
-        var dataGridController = new DataGridController(null, columns, [], null, getDataList, null, true, "ENTITY_TABLE_BBB", null, 90);
+        var dataGridController = new DataGridController(null, columns, [], null, getDataList, null, true, "ENTITY_TABLE_BBB", null, false, 90);
         dataGridController.init(container);
     }
 
-- 
GitLab