From 0ae023d446563e342ec673e16dbfb52e802c21a6 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Wed, 28 May 2014 09:19:16 +0000
Subject: [PATCH] SSDM-306: Dropping ELN Experiment in favour of sub
 experiments. Step 1

SVN: 31610
---
 .../newbrowser/html/js/config/Profile.js      |   2 +-
 .../html/js/controllers/MainController.js     |  10 --
 .../newbrowser/html/js/server/ServerFacade.js |  49 ++++++---
 .../html/js/widgets/SideMenuWidget.js         | 100 ++++++++++++------
 4 files changed, 103 insertions(+), 58 deletions(-)

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js
index be624ddec6b..dc95fc56a1e 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/Profile.js
@@ -180,7 +180,7 @@ $.extend(DefaultProfile.prototype, {
 		// Utility methods used to navigate the configuration easily
 		//
 		this.isELNExperiment = function(sampleTypeCode) {
-			return $.inArray(sampleTypeCode, this.ELNExperiments) !== -1;
+			return false; //$.inArray(sampleTypeCode, this.ELNExperiments) !== -1;
 		}
 	
 		this.getPropertyType = function(propertyTypeCode) {
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js
index 631cdbba5c2..4b5ef43209c 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js
@@ -194,16 +194,6 @@ function MainController(profile) {
 					}
 				});
 				break;
-			case "showViewExperiment":
-				var _this = this;
-				this.serverFacade.getELNExperimentSampleIdForExperiment(arg, function(permId) {
-					if(!permId) {
-						Util.showError("1:1 Relation between experiment and sample missing. Probably not created with the ELN UI.");
-					} else {
-						_this.changeView("showViewSamplePageFromPermId", permId);
-					}
-				});
-				break;
 			case "showViewSamplePageFromPermId":
 				var _this = this;
 				this.serverFacade.searchWithUniqueId(arg, function(data) {
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
index 6facb1ede51..bf4218b96ee 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
@@ -65,29 +65,44 @@ function ServerFacade(openbisServer) {
 		this.openbisServer.listExperiments(projects, null, callbackFunction);
 	}
 	
+	this.listSamplesForExperiments = function(experiments, callbackFunction) {
+		var experimentsMatchClauses = []
+		
+		experiments.forEach(function(experiment){
+			experimentsMatchClauses.push({
+				"@type":"AttributeMatchClause",
+				fieldType : "ATTRIBUTE",			
+				attribute : "PERM_ID",
+				desiredValue : experiment.permId
+			});
+		});
+		
+		var experimentCriteria = {
+				matchClauses : experimentsMatchClauses,
+				operator : "MATCH_ANY_CLAUSES"
+		}
+		
+		var experimentSubCriteria = {
+				"@type" : "SearchSubCriteria",
+				"targetEntityKind" : "EXPERIMENT",	
+				"criteria" : experimentCriteria
+		}
+
+		var sampleCriteria = 
+		{
+			subCriterias : [ experimentSubCriteria ],
+			operator : "MATCH_ALL_CLAUSES"
+		};
+		
+		this.openbisServer.searchForSamples(sampleCriteria, callbackFunction)
+	}
+	
 	this.listPropertyTypes = function(callbackFunction) {
 		if(this.openbisServer.listPropertyTypes) { //If not present will not break, but annotations should not be used.
 			this.openbisServer.listPropertyTypes(false, callbackFunction);
 		}
 	}
 	
-	this.getELNExperimentSampleIdForExperiment = function(experimentIdentifier, callbackFunction) {
-		this.openbisServer.listSamplesForExperiment(experimentIdentifier, function(data) {
-			var permId = null;
-			if(data.result) {
-				var experimentIdentifierParts = experimentIdentifier.split("/");
-				for(var i = 0; i < data.result.length; i++) {
-					var sample = data.result[i];
-					var sampleIdentifierParts = sample.identifier.split("/");
-					if(sampleIdentifierParts[2] == experimentIdentifierParts[3]) {
-						permId = sample.permId;
-					}
-				}
-			}
-			callbackFunction(permId);
-		});
-	}
-	
 	//
 	// Others
 	//
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js
index 6b8469eaf57..71cea69d54c 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SideMenuWidget.js
@@ -49,6 +49,18 @@ function SideMenuWidget(mainController, containerId, serverFacade) {
 		return null;
 	}
 	
+	this._getExperimentNodeForCode = function(projectCode, experimentCode) {
+		var projectNode = this._getProjectNodeForCode(projectCode);
+		var experimentsFromProject = projectNode.newMenuIfSelected.children;
+		for(var eIdx = 0; eIdx < experimentsFromProject.length; eIdx++) {
+			var experimentNode = experimentsFromProject[eIdx];
+			if(experimentNode.displayName === experimentCode) {
+				return experimentNode;
+			}
+		}
+		return null;
+	}
+	
 	this.init = function() {
 		var _this = this;
 		
@@ -85,54 +97,82 @@ function SideMenuWidget(mainController, containerId, serverFacade) {
 			
 			//Fill Experiments
 			_this._serverFacade.listExperiments(projectsToAskForExperiments, function(experiments) {
+				var experimentsToAskForSamples = [];
 				for(var i = 0; i < experiments.result.length; i++) {
 					var experiment = experiments.result[i];
+					experimentsToAskForSamples.push(experiment);
 					var projectCode = experiment.identifier.split("/")[2];
 					var projectNode = _this._getProjectNodeForCode(projectCode);
 					
-					var menuItemExperiment = new SideMenuWidgetComponent(true, false, experiment.code, projectNode, null, "showViewExperiment", experiment.identifier);
-					projectNode.newMenuIfSelected.children.push(menuItemExperiment);
-				}
-				
-				//Fill Inventory
-				_this._menuStructure.newMenuIfSelected.children.push(
-						new SideMenuWidgetComponent(false, true, "Inventory", _this._menuStructure, null, null, null)
-				);
-				
-				var profile = _this._mainController.profile;
-				var typeGroups = _this._mainController.profile.typeGroups;
-				for(typeGroupCode in typeGroups) {
-					var newMenuIfSelectedTypeGroup = {
+					var newMenuIfSelectedExperiment = {
 							children : []
 					}
-				
-					for(var i = 0; i < typeGroups[typeGroupCode]["LIST"].length; i++) {
-						var sampleType = profile.getTypeForTypeCode(typeGroups[typeGroupCode]["LIST"][i]);
 					
-						if(sampleType !== null) {
-							var description = Util.getEmptyIfNull(sampleType.description);
-							if(description === "") {
-								description = sampleType.code;
-							}
+					var menuItemExperiment = new SideMenuWidgetComponent(true, false, experiment.code, projectNode, newMenuIfSelectedExperiment, null, null);
+					projectNode.newMenuIfSelected.children.push(menuItemExperiment);
+				}
+				
+				//Fill Sub Experiments
+				_this._serverFacade.listSamplesForExperiments(experimentsToAskForSamples, function(subExperiments) {
+					var a = 0;
+					for(var i = 0; i < subExperiments.result.length; i++) {
+						var subExperiment = subExperiments.result[i];
+						if(subExperiment.experimentIdentifierOrNull) {
+							var projectCode = subExperiment.experimentIdentifierOrNull.split("/")[2];
+							var experimentCode = subExperiment.experimentIdentifierOrNull.split("/")[3];
+							var experimentNode = _this._getExperimentNodeForCode(projectCode, experimentCode);
 							
-							var menuItemSampleType = new SideMenuWidgetComponent(true, false, description, _this._menuStructure, null, "showSamplesPage", sampleType.code)
-							newMenuIfSelectedTypeGroup.children.push(menuItemSampleType);
+							var menuItemSubExperiment = new SideMenuWidgetComponent(true, false, subExperiment.code, experimentNode, null, "showViewSamplePageFromPermId", subExperiment.permId);
+							experimentNode.newMenuIfSelected.children.push(menuItemSubExperiment);
 						}
 					}
 					
+					//Fill Inventory
 					_this._menuStructure.newMenuIfSelected.children.push(
-							new SideMenuWidgetComponent(true, false, typeGroups[typeGroupCode]["DISPLAY_NAME"], _this._menuStructure, newMenuIfSelectedTypeGroup, null, null)
+							new SideMenuWidgetComponent(false, true, "Inventory", _this._menuStructure, null, null, null)
 					);
-				}
-				
-				_this._repaint();
+					
+					var profile = _this._mainController.profile;
+					var typeGroups = _this._mainController.profile.typeGroups;
+					for(typeGroupCode in typeGroups) {
+						var newMenuIfSelectedTypeGroup = {
+								children : []
+						}
+					
+						for(var i = 0; i < typeGroups[typeGroupCode]["LIST"].length; i++) {
+							var sampleType = profile.getTypeForTypeCode(typeGroups[typeGroupCode]["LIST"][i]);
+						
+							if(sampleType !== null) {
+								var description = Util.getEmptyIfNull(sampleType.description);
+								if(description === "") {
+									description = sampleType.code;
+								}
+								
+								var menuItemSampleType = new SideMenuWidgetComponent(true, false, description, _this._menuStructure, null, "showSamplesPage", sampleType.code)
+								newMenuIfSelectedTypeGroup.children.push(menuItemSampleType);
+							}
+						}
+						
+						_this._menuStructure.newMenuIfSelected.children.push(
+								new SideMenuWidgetComponent(true, false, typeGroups[typeGroupCode]["DISPLAY_NAME"], _this._menuStructure, newMenuIfSelectedTypeGroup, null, null)
+						);
+					}
+					
+					_this._repaint();
+				});
+
 			});
 		});
 		
 		$(window).scroll(function(event){
-			var $element = $("#sideMenu");
-			var scrollTop = $(document).scrollTop();
-			$element.css('top', scrollTop + "px"); 
+			var sideMenuWidth = $("#sideMenu").width();
+			var windowWidth = $(window).width();
+			var ratio = sideMenuWidth / windowWidth;
+			if(ratio < 0.9) { //For small screens where the menu takes all the screen, we don't move it
+				var $element = $("#sideMenu");
+				var scrollTop = $(document).scrollTop();
+				$element.css('top', scrollTop + "px"); 
+			}
 		});
 		
 		$(window).resize(function(event){
-- 
GitLab