From f2700e9db291ee2d438fcf5c6ddf535c26ece9f8 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Tue, 28 Apr 2015 08:47:39 +0000
Subject: [PATCH] SSDM-1724 : Plate View (ongoing work)

SVN: 33916
---
 .../SampleForm/widgets/PlateController.js     | 13 ++++++----
 .../js/views/SampleForm/widgets/PlateModel.js |  7 +++---
 .../html/js/views/legacy/SampleHierarchy.js   | 24 +++++++++----------
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateController.js
index 846f015eefd..3af89c7ba11 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateController.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateController.js
@@ -42,9 +42,14 @@ function PlateController(sample) {
 		var _this = this;
 		$container.empty();
 		$container.append("Loading Wells ...");
-		mainController.serverFacade.searchContained(this._plateModel.sample.permId, function(contained) {
-			_this._plateModel.wells = contained;
-			_this._plateView.repaint($container);
-		});
+		if(this._plateModel.sample.contained) {
+			this._plateView.repaint($container);
+		} else {
+			mainController.serverFacade.searchContained(this._plateModel.sample.permId, function(contained) {
+				_this._plateModel.sample.contained = contained;
+				_this._plateView.repaint($container);
+			});
+		}
+		
 	}
 }
\ No newline at end of file
diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateModel.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateModel.js
index e0653b55c08..c29f25c412a 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateModel.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/widgets/PlateModel.js
@@ -16,7 +16,6 @@
 
 function PlateModel(sample) {
 	this.sample = sample;
-	this.wells = null;
 	
 	var getRowsAndColsFromPlateSample = function(sample) {
 		try {
@@ -37,9 +36,9 @@ function PlateModel(sample) {
 	
 	this.getWell = function(rowNum, colNum) {
 		var wellIdentifier = this.sample.identifier + ":" + this.getAlphabetLabel(rowNum) + colNum;
-		for(var wellIdx = 0; wellIdx < this.wells.length; wellIdx++) {
-			if(this.wells[wellIdx].identifier === wellIdentifier) {
-				var toReturn = this.wells[wellIdx];
+		for(var wellIdx = 0; wellIdx < this.sample.contained.length; wellIdx++) {
+			if(this.sample.contained[wellIdx].identifier === wellIdentifier) {
+				var toReturn = this.sample.contained[wellIdx];
 				return toReturn;
 			}
 		}
diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
index f9ed86a7d5d..8b76324c6f0 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/legacy/SampleHierarchy.js
@@ -81,8 +81,6 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 	}
 	
 	this.filterSampleAndUpdate = function() {
-		var newSample = jQuery.extend(true, {}, this.sample);
-		
 		//
 		// Used to remove the type label when rendering
 		//
@@ -111,7 +109,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 				}
 			}
 		}
-		selectedSampleTypesFilter(newSample, selectedSampleTypes);
+		selectedSampleTypesFilter(this.sample, selectedSampleTypes);
 		
 		//
 		// Used to cut the tree
@@ -120,15 +118,16 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 		var parentsLimitFilter = function(sample, depthLimit) {
 			if(sample.parents) {
 				if(depthLimit === 0) {
-					sample.parents = null;
+					sample.hideParents = true;
 				} else {
+					sample.hideParents = false;
 					for(var i = 0; i < sample.parents.length; i++) {
 						parentsLimitFilter(sample.parents[i], (depthLimit - 1));
 					}
 				}
 			}
 		}
-		parentsLimitFilter(newSample, parentsLimit);
+		parentsLimitFilter(this.sample, parentsLimit);
 		
 		//
 		// Used to cut the tree
@@ -137,17 +136,18 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 		var childrenLimitFilter = function(sample, depthLimit) {
 			if(sample.children) {
 				if(depthLimit === 0) {
-					sample.children = null;
+					sample.hideChildren = true;
 				} else {
+					sample.hideChildren = false;
 					for(var i = 0; i < sample.children.length; i++) {
 						childrenLimitFilter(sample.children[i], (depthLimit - 1));
 					}
 				}
 			}
 		}
-		childrenLimitFilter(newSample, childrenLimit);
+		childrenLimitFilter(this.sample, childrenLimit);
 		
-		this._repaintGraph(newSample);
+		this._repaintGraph(this.sample);
 	}
 	
 	this._addChildFor = function(permId) {
@@ -359,10 +359,10 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 				NODES[sample.permId] = true;
 			}
 			
-			if(sample.parents && !sample.hideGraphConnections) {
+			if(sample.parents && !sample.hideGraphConnections && !sample.hideParents) {
 				sample.parents.forEach(addSampleNodes, rootPermId);
 			}
-			if(sample.children && !sample.hideGraphConnections) {
+			if(sample.children && !sample.hideGraphConnections && !sample.hideChildren) {
 				sample.children.forEach(addSampleNodes, rootPermId);
 			}
 		}
@@ -370,7 +370,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 		var EDGES = {};
 		
 		function addSampleEdges(sample) {
-			if(sample.parents && !sample.hideGraphConnections) {
+			if(sample.parents && !sample.hideGraphConnections && !sample.hideParents) {
 				for(var i=0; i < sample.parents.length; i++) {
 					if(!EDGES[sample.parents[i].permId + ' -> ' + sample.permId]) {
 						g.addEdge(null, sample.parents[i].permId, sample.permId);
@@ -379,7 +379,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) {
 				}
 				sample.parents.forEach(addSampleEdges);
 			}
-			if(sample.children && !sample.hideGraphConnections) {
+			if(sample.children && !sample.hideGraphConnections && !sample.hideChildren) {
 				for(var i=0; i < sample.children.length; i++) {
 					if(!EDGES[sample.permId + ' -> ' + sample.children[i].permId]) {
 						g.addEdge(null, sample.permId, sample.children[i].permId);
-- 
GitLab