From 1563c80b7bf8eb0a608cf6467b7171bc214312b4 Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Thu, 9 Oct 2014 12:35:02 +0000
Subject: [PATCH] SSDM-995 : Incorrect order of depths in the javascript image
 viewer

SVN: 32569
---
 .../imageviewer/ChannelStackManager.js        | 30 +++++++++++--------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/public/resources/components/imageviewer/ChannelStackManager.js b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/public/resources/components/imageviewer/ChannelStackManager.js
index c1f71f1af33..37a8b85dcd4 100644
--- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/public/resources/components/imageviewer/ChannelStackManager.js
+++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/web/public/resources/components/imageviewer/ChannelStackManager.js
@@ -30,9 +30,12 @@ define([ "jquery" ], function($) {
 					} else if (v2 == null) {
 						return 1;
 					} else {
-						if (v1 > v2) {
+						var v1Int = parseInt(v1);
+						var v2Int = parseInt(v2);
+
+						if (v1Int > v2Int) {
 							return 1;
-						} else if (v1 < v2) {
+						} else if (v1Int < v2Int) {
 							return -1;
 						} else {
 							return 0;
@@ -45,8 +48,7 @@ define([ "jquery" ], function($) {
 		},
 
 		isMatrix : function() {
-			return (!this.isSeriesNumberPresent() || this.getSeriesNumbers().length == 1) && !this.isTimePointMissing() && !this.isDepthMissing()
-					&& this.isDepthConsistent();
+			return (!this.isSeriesNumberPresent() || this.getSeriesNumbers().length == 1) && !this.isTimePointMissing() && !this.isDepthMissing() && this.isDepthConsistent();
 		},
 
 		isSeriesNumberPresent : function() {
@@ -90,9 +92,7 @@ define([ "jquery" ], function($) {
 					}
 				});
 
-				this.seriesNumbers = Object.keys(seriesNumbers).map(function(seriesNumber) {
-					return parseInt(seriesNumber);
-				}).sort();
+				this.seriesNumbers = this.sortAsNumbers(Object.keys(seriesNumbers));
 			}
 			return this.seriesNumbers;
 		},
@@ -111,9 +111,7 @@ define([ "jquery" ], function($) {
 					}
 				});
 
-				this.timePoints = Object.keys(timePoints).map(function(timePoint) {
-					return parseInt(timePoint);
-				}).sort();
+				this.timePoints = this.sortAsNumbers(Object.keys(timePoints));
 			}
 			return this.timePoints;
 		},
@@ -146,9 +144,7 @@ define([ "jquery" ], function($) {
 					}
 				});
 
-				this.depths = Object.keys(depths).map(function(depth) {
-					return parseInt(depth);
-				}).sort();
+				this.depths = this.sortAsNumbers(Object.keys(depths));
 			}
 			return this.depths;
 		},
@@ -227,6 +223,14 @@ define([ "jquery" ], function($) {
 
 		getChannelStacks : function() {
 			return this.channelStacks;
+		},
+
+		sortAsNumbers : function(array) {
+			return array.map(function(item) {
+				return parseInt(item);
+			}).sort(function(i1, i2) {
+				return i1 - i2;
+			});
 		}
 
 	});
-- 
GitLab