From c7b7f578a059eefc9cdd68bc075994c123ff96d5 Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Tue, 11 Feb 2020 10:32:19 +0100
Subject: [PATCH] SSDM-9284: prettify type codes and use name for samples in
 HierarchyGraphs and tooltip for storage positions

---
 .../eln-lims/html/js/util/PrintUtil.js        | 56 ++++++-------------
 .../HierarchyTable/HierarchyTableView.js      |  9 +--
 .../widgets/HierarchyFilterView.js            |  2 +-
 .../views/StorageManager/widgets/GridView.js  |  4 +-
 .../html/js/views/legacy/SampleHierarchy.js   | 11 +---
 .../webapps/eln-lims/html/lib/grid/js/Grid.js |  2 +-
 6 files changed, 25 insertions(+), 59 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/PrintUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/PrintUtil.js
index 22821e3fb66..1c6fba5b79e 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/PrintUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/PrintUtil.js
@@ -66,7 +66,7 @@ var PrintUtil = new function() {
 		var samplesListOfCodes = "";
 		
 		for(var sampleTypeCode in allSamplesByType) {
-			samplesListOfCodes += sampleTypeCode + ": ";
+			samplesListOfCodes += Util.getDisplayNameFromCode(sampleTypeCode) + ": ";
 			var samples = allSamplesByType[sampleTypeCode];
 			for(var i = 0; i < samples.length; i++) {
 				var sample = samples[i];
@@ -76,13 +76,7 @@ var PrintUtil = new function() {
 				if(sampleTypeCode === "STORAGE_POSITION") {
 					samplesListOfCodes += Util.getStoragePositionDisplayName(sample);
 				} else {
-					var name = sample.properties[profile.propertyReplacingCode];
-					if(!name) {
-						samplesListOfCodes += sample.code;
-					} else {
-						samplesListOfCodes += sample.code + "(" + name + ")";
-					}
-					
+					samplesListOfCodes += Util.getDisplayNameForEntity(sample); 
 				}
 			}
 			samplesListOfCodes += "</br>";
@@ -127,6 +121,7 @@ var PrintUtil = new function() {
 		
 		var $newInspectorTable = $("<table>", { "class" : "properties table table-condensed" });
 		$newInspector.append($newInspectorTable);
+		this._addLabelAndValue($newInspectorTable, "Code", entity.code);
 		
 		if(extraProperties) {
 			for(code in extraProperties) {
@@ -136,11 +131,7 @@ var PrintUtil = new function() {
 				if(propLabel.length > 25) {
 					propLabel = propLabel.substring(0, 23) + "..."; 
 				}
-				$newInspectorTable
-				.append($("<tr>")
-							.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append(propLabel + ":")))
-							.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak"}).append(extraProp.value)))
-						);
+				this._addLabelAndValue($newInspectorTable, propLabel, extraProp.value);
 			}
 		}
 		
@@ -197,11 +188,7 @@ var PrintUtil = new function() {
 									.append($("<td>", { "class" : "property", "colspan" : "2" }).append($("<p>", { "class" : "inspectorLineBreak"}).append(propertyLabel + ":").append("<br>").append(propertyContent)))
 								);
 					} else {
-						$newInspectorTable
-						.append($("<tr>")
-									.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append(propertyLabel + ":")))
-									.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak" }).append(propertyContent)))
-								);
+						this._addLabelAndValue($newInspectorTable, propertyLabel, propertyContent);
 					}
 				}
 			}
@@ -211,38 +198,22 @@ var PrintUtil = new function() {
 			//Show Parent Codes
 			var allParentCodesAsText = this._getCodesFromSamples(entity.parents);
 			if(allParentCodesAsText.length > 0) {
-				$newInspectorTable
-					.append($("<tr>")
-								.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append("Parents:")))
-								.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak" }).append(allParentCodesAsText)))
-							);
+				this._addLabelAndValue($newInspectorTable, "Parents", allParentCodesAsText);
 			}
 				
 			//Show Children Codes
 			var allChildrenCodesAsText = this._getCodesFromSamples(entity.children);
 			if(allChildrenCodesAsText.length > 0) {
-				$newInspectorTable
-				.append($("<tr>")
-							.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append("Children:")))
-							.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak"}).append(allChildrenCodesAsText)))
-						);
+				this._addLabelAndValue($newInspectorTable, "Children", allChildrenCodesAsText);
 			}
 		}
 		
 		//Show Modification Date
 		if(entity.registrationDetails) {
-			$newInspectorTable
-			.append($("<tr>")
-						.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append("Modification Date:")))
-						.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak"}).append(new Date(entity.registrationDetails["modificationDate"]))))
-					);
+			this._addLabelAndValue($newInspectorTable, "Modification Date", new Date(entity.registrationDetails["modificationDate"]));
 			
 			//Show Creation Date
-			$newInspectorTable
-			.append($("<tr>")
-						.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append("Registration Date:")))
-						.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak"}).append(new Date(entity.registrationDetails["registrationDate"]))))
-					);
+			this._addLabelAndValue($newInspectorTable, "Registration Date", new Date(entity.registrationDetails["registrationDate"]));
 		}
 		
 		if(extraCustomId && extraContent) {
@@ -251,6 +222,15 @@ var PrintUtil = new function() {
 		
 		return $newInspector;
 	};
+	
+	this._addLabelAndValue = function($newInspectorTable, label, value) {
+		$newInspectorTable
+		.append($("<tr>")
+					.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLabel"}).append(label + ":")))
+					.append($("<td>", { "class" : "property", "colspan" : "1" }).append($("<p>", { "class" : "inspectorLineBreak" }).append(value)))
+				);
+
+	}
 
 	this._convertJsonToHtml = function(json) {
 		data = json["data"];
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 24877303093..9835090f459 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
@@ -32,14 +32,7 @@ function HierarchyTableView(controller, model) {
 		$containerColumn.append(this._container);
 		views.content.append($containerColumn);
 		
-		switch(this._model.entity["@type"]) {
-				case "as.dto.dataset.DataSet":
-					views.header.append($("<h1>").append("Dataset Hierarchy Table for " + this._model.entity.code));
-					break;
-				case "as.dto.sample.Sample":
-					views.header.append($("<h1>").append("" + ELNDictionary.Sample + " Hierarchy Table for " + this._model.entity.identifier));
-					break;
-		}
+		views.header.append($("<h1>").append("Dataset Hierarchy Table: " + Util.getDisplayNameForEntity(this._model.entity)));
 		
 		this._hierarchyFilterController = new HierarchyFilterController(this._model.entity, function() { _this._dataGrid.refresh(); });
 		this._hierarchyFilterController.init(views.header);
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/widgets/HierarchyFilterView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/widgets/HierarchyFilterView.js
index 0b85ab4e579..58b169b00e3 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/widgets/HierarchyFilterView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/HierarchyTable/widgets/HierarchyFilterView.js
@@ -41,7 +41,7 @@ function HierarchyFilterView(controller, model) {
 		var types = this._model.getTypes();
 		var $filtersFormEntityTypes = $('<select>', { 'id' : 'entityTypesSelector' , class : 'multiselect' , 'multiple' : 'multiple'});
 		for (var type in types) {
-			$filtersFormEntityTypes.append($('<option>', { 'value' : type , 'selected' : ''}).html(type));
+			$filtersFormEntityTypes.append($('<option>', { 'value' : type , 'selected' : ''}).html(Util.getDisplayNameFromCode(type)));
 		}
 		
 		$filtersForm
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/StorageManager/widgets/GridView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/StorageManager/widgets/GridView.js
index 59b4cf6a5a7..012e32325cc 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/StorageManager/widgets/GridView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/StorageManager/widgets/GridView.js
@@ -147,7 +147,6 @@ function GridView(gridModel) {
 						sample = jQuery.extend(true, {}, labels[i].data.samples[0]);
 					}
 					
-					extraProperties = null;
 					if(sample && sample.sampleTypeCode === "STORAGE_POSITION" && sample.parents && sample.parents[0]) {
 						if(profile.propertyReplacingCode &&  sample.parents[0].properties &&  sample.parents[0].properties[profile.propertyReplacingCode]) {
 							// Label
@@ -158,7 +157,6 @@ function GridView(gridModel) {
 						}
 						
 						sample = sample.parents[0];
-						extraProperties = {code : {label : "Code", value : sample.code}};
 							
 						var href = Util.getURLFor(null, "showViewSamplePageFromPermId", sample.permId);
 						optSampleTitle = $("<a>", { "href" : href, "class" : "browser-compatible-javascript-link" }).text(labels[i].displayName);
@@ -175,7 +173,7 @@ function GridView(gridModel) {
 					var labelContainer = $("<div>", { class: "storageBox", id : storageBoxId }).text(labels[i].displayName);
 					if (sample) {
 						var tooltip = PrintUtil.getTable(sample, false, optSampleTitle, 'inspectorWhiteFont', 
-								'colorEncodedWellAnnotations-holder-' + sample.permId, null, extraProperties);
+								'colorEncodedWellAnnotations-holder-' + sample.permId, null, null);
 						labelContainer.tooltipster({
 							content: $(tooltip),
 							interactive: true,
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
index b9dbfc5f1c3..f9cd29ef828 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
@@ -43,7 +43,7 @@ function SampleHierarchy(serverFacade, views, profile, sample) {
 		$form.append($formColumn);
 		
 		
-		views.header.append($("<h1>").append("" + ELNDictionary.Sample + " Hierarchy Graph for " + this.sample.identifier));
+		views.header.append($("<h1>").append("Hierarchy Graph: " + Util.getDisplayNameForEntity(this.sample)));
 		localInstance.hierarchyFilterController = new HierarchyFilterController(this.sample, function() { localInstance.filterSampleAndUpdate(); });
 		localInstance.hierarchyFilterController.init(views.header);
 
@@ -311,12 +311,7 @@ function SampleHierarchy(serverFacade, views, profile, sample) {
 							'style' : 'cursor:pointer; width:13px; height:18px;',
 						}));
 				
-				var nameLabel = null;
-				if(sample.properties[profile.propertyReplacingCode]) {
-					nameLabel = sample.code + "(" + sample.properties[profile.propertyReplacingCode] + ")";
-				} else {
-					nameLabel = sample.code;
-				}
+				var nameLabel = Util.getDisplayNameForEntity(sample);
 				
 				var $sampleLink = $('<a>', { 'href' : "javascript:mainController.changeView('showViewSamplePageFromPermId', '" + sample.permId + "')"}).text(nameLabel);
 				
@@ -326,7 +321,7 @@ function SampleHierarchy(serverFacade, views, profile, sample) {
 						.append($hideLink)
 						.append($dataLink)
 						.append($addChildLink)
-						.append(sample.sampleTypeCode + ':')
+						.append(' ' + Util.getDisplayNameFromCode(sample.sampleTypeCode) + ':')
 						.append($sampleLink);
 				
 				if(sample.showDataOnGraph) {
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js
index 8857fff7a15..aac6da56a85 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/lib/grid/js/Grid.js
@@ -754,7 +754,7 @@ $.extend(Grid.prototype, {
 //				$(thisGrid.panel).find(".repeater").width(newWidth);
 
 				var headerHeight = $(thisGrid.panel).find(".repeater-header").outerHeight(true);
-				var listHeight = Math.max(100, $(thisGrid.panel).find(".repeater-list").outerHeight(true));
+				var listHeight = Math.max(144, $(thisGrid.panel).find(".repeater-list").outerHeight(true));
 				var footerHeight = $(thisGrid.panel).find(".repeater-footer").outerHeight(true);
 				var viewport = $(thisGrid.panel).find(".repeater-canvas")[0];
 				var scrollbarHeight = viewport.scrollWidth > viewport.offsetWidth ? thisGrid.scrollbarWidth : 0;
-- 
GitLab