diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/HierarchyUtil.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/HierarchyUtil.js index 3649b875b2db77116c8d4f1d3a19f80a271796d2..c9dffd9f3e1741f399275a74c40d7a1ddd8e2bdd 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/HierarchyUtil.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/HierarchyUtil.js @@ -14,157 +14,6 @@ * limitations under the License. */ var HierarchyUtil = new function() { - var getSampleTypes = function(sample) { - var sampleTypes = {}; - - var getSampleTypesWithQueueRecursion = function(sample, sampleTypes) { - if(!sampleTypes[sample.sampleTypeCode]) { - sampleTypes[sample.sampleTypeCode] = true; - } - - if(sample.parents) { - for(var i = 0; i < sample.parents.length; i++) { - getSampleTypesWithQueueRecursion(sample.parents[i], sampleTypes); - } - } - - if(sample.children) { - for(var i = 0; i < sample.children.length; i++) { - getSampleTypesWithQueueRecursion(sample.children[i], sampleTypes); - } - } - } - - getSampleTypesWithQueueRecursion(sample, sampleTypes); - return sampleTypes; - } - - var getMaxChildrenDepth = function(sample) { - var getMaxChildrenDepthWithQueueRecurion = function(sample, max) { - if(sample.children) { - var posibleNextMax = []; - - for(var i = 0; i < sample.children.length; i++) { - var nextMax = getMaxChildrenDepthWithQueueRecurion(sample.children[i], (max + 1)); - posibleNextMax.push(nextMax); - } - - for(var i = 0; i < posibleNextMax.length; i++) { - if(posibleNextMax[i] > max) { - max = posibleNextMax[i]; - } - } - } - - return max; - } - - return getMaxChildrenDepthWithQueueRecurion(sample, 0); - } - - var getMaxParentsDepth = function(sample) { - var getMaxParentsDepthWithQueueRecurion = function(sample, max) { - if(sample.parents) { - var posibleNextMax = []; - - for(var i = 0; i < sample.parents.length; i++) { - var nextMax = getMaxParentsDepthWithQueueRecurion(sample.parents[i], (max + 1)); - posibleNextMax.push(nextMax); - } - - for(var i = 0; i < posibleNextMax.length; i++) { - if(posibleNextMax[i] > max) { - max = posibleNextMax[i]; - } - } - } - - return max; - } - - return getMaxParentsDepthWithQueueRecurion(sample, 0); - } - - - var getSliderValue = function(id) { - var element = $('#' + id) - return element.length > 0 ? element.data('slider').getValue() : 0; - } - - this.getParentsLimit = function() { - return getSliderValue("parentsLimit"); - } - - this.getChildrenLimit = function() { - return getSliderValue("childrenLimit"); - } - - this.getSelectedSampleTypes = function() { - var selectedSampleTypes = $('#sampleTypesSelector').val(); - if(selectedSampleTypes === null) { - selectedSampleTypes = []; - } - return selectedSampleTypes; - } - - /* - * Creates a hierarchy filter widget for the specified sample and adds it to the specified container. - * The specified updater object should have a function filterSampleAndUpdate(). - */ - this.addHierarchyFilterWidget = function(container, sample, updater) { - var $filtersForm = $('<form>' , { class : 'form-inline'}); - container.append($filtersForm); - $filtersForm.submit(function(event) {updater.filterSampleAndUpdate(); event.preventDefault();}); - - var maxChildren = getMaxChildrenDepth(sample); - var $filtersFormSliderChildren = null; - if(maxChildren > 0) { - $filtersFormSliderChildren = $('<input>' , { 'id' : 'childrenLimit' , 'type' : 'text' , 'class' : 'span2', 'value' : '' , 'data-slider-max' : maxChildren , 'data-slider-value' : maxChildren}); - } else { - $filtersFormSliderChildren = 'No Children'; - } - - var maxParents = getMaxParentsDepth(sample); - var $filtersFormSliderParents = null; - if(maxParents > 0) { - $filtersFormSliderParents = $('<input>' , { 'id' : 'parentsLimit' , 'type' : 'text' , 'class' : 'span2', 'value' : '' , 'data-slider-max' : maxParents , 'data-slider-value' : maxParents}); - } else { - $filtersFormSliderParents = 'No Parents'; - } - - var sampleTypes = getSampleTypes(sample); - var $filtersFormSampleTypes = $('<select>', { 'id' : 'sampleTypesSelector' , class : 'multiselect' , 'multiple' : 'multiple'}); - for (var sampleType in sampleTypes) { - $filtersFormSampleTypes.append($('<option>', { 'value' : sampleType , 'selected' : ''}).html(sampleType)); - } - - $filtersForm - .append('<b>Filters</b>') - .append("<span style='padding-right:15px;'></span>") - .append('Children: ') - .append($filtersFormSliderChildren) - .append("<span style='padding-right:15px;'></span>") - .append(' Parents: ') - .append($filtersFormSliderParents) - .append("<span style='padding-right:15px;'></span>") - .append(' Show Types: ') - .append($filtersFormSampleTypes) - .append("<span style='position:absolute; left:30px; top:80px;'><svg height='100' width='100'><g id='svgControls'/></svg></span>"); - - $('#childrenLimit').slider().on('slideStop', function(event){ - updater.filterSampleAndUpdate(); - }); - - $('#parentsLimit').slider().on('slideStop', function(event){ - updater.filterSampleAndUpdate(); - }); - - $('#sampleTypesSelector').multiselect(); - $('#sampleTypesSelector').change(function(event){ - updater.filterSampleAndUpdate(); - }); - } - /* * Creates a map (sample identifiers as keys) for all ancestors and descendants of the specified sample. * The values of the map are the children and parents of the sample specified by the key.. diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/SampleHierarchyTableView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/SampleHierarchyTableView.js index 146ab8b7905d3445907da97cb50b155d8290c132..3d01a1da6d6f419e04518fa6a3e223b40327cc98 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/SampleHierarchyTableView.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/SampleHierarchyTableView.js @@ -19,6 +19,7 @@ function SampleHierarchyTableView(controller, model) { this._controller = controller; this._container = $("<div>"); this._dataGrid; + this._hierarchyFilterController; this.repaint = function($container) { var _this = this; @@ -32,11 +33,10 @@ function SampleHierarchyTableView(controller, model) { $container.append($containerColumn); $containerColumn.append($("<h1>").append("Sample Hierarchy Table for " + this._model.sample.identifier)); - HierarchyUtil.addHierarchyFilterWidget($containerColumn, this._model.sample, { - filterSampleAndUpdate : function() { - _this._dataGrid.refresh(); - } - }); + this._hierarchyFilterController = new HierarchyFilterController(this._model.sample, function() { + _this._dataGrid.refresh(); + }); + this._hierarchyFilterController.init($containerColumn); this._showHierarchy(); $containerColumn.append(this._container); } @@ -78,9 +78,9 @@ function SampleHierarchyTableView(controller, model) { var getDataList = function(callback) { var data = _this._model.getData(); - var parentsLimit = HierarchyUtil.getParentsLimit(); - var childrenLimit = HierarchyUtil.getChildrenLimit(); - var sampleTypes = HierarchyUtil.getSelectedSampleTypes(); + var parentsLimit = _this._hierarchyFilterController.getParentsLimit(); + var childrenLimit = _this._hierarchyFilterController.getChildrenLimit(); + var sampleTypes = _this._hierarchyFilterController.getSelectedSampleTypes(); var filteredData = []; for (var i = 0; i < data.length; i++) { var row = data[i]; diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterController.js new file mode 100644 index 0000000000000000000000000000000000000000..7810b53f6779273d5ffe4b0e766cd51333690aee --- /dev/null +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterController.js @@ -0,0 +1,57 @@ +/* + * Copyright 2015 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function HierarchyFilterController(sample, action) { + this._model = new HierarchyFilterModel(sample, action); + this._view = new HierarchyFilterView(this, this._model); + + this.init = function(container) { + this._view.init(container); + $('#childrenLimit').slider().on('slideStop', function(event){ + action(); + }); + + $('#parentsLimit').slider().on('slideStop', function(event){ + action(); + }); + + $('#sampleTypesSelector').multiselect(); + $('#sampleTypesSelector').change(function(event){ + action(); + }); + } + + this.getParentsLimit = function() { + return getSliderValue("parentsLimit"); + } + + this.getChildrenLimit = function() { + return getSliderValue("childrenLimit"); + } + + this.getSelectedSampleTypes = function() { + var selectedSampleTypes = $('#sampleTypesSelector').val(); + if(selectedSampleTypes === null) { + selectedSampleTypes = []; + } + return selectedSampleTypes; + } + + var getSliderValue = function(id) { + var element = $('#' + id) + return element.length > 0 ? element.data('slider').getValue() : 0; + } + +} \ No newline at end of file diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterModel.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterModel.js new file mode 100644 index 0000000000000000000000000000000000000000..329c6f2a6ac2336da24d05d730fad45d88c0e373 --- /dev/null +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterModel.js @@ -0,0 +1,79 @@ +/* + * Copyright 2015 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function HierarchyFilterModel(sample) { + this._sample = sample; + + this.getSampleTypes = function() { + var sampleTypes = {}; + var getSampleTypesWithQueueRecursion = function(sample, sampleTypes) { + if (!sampleTypes[sample.sampleTypeCode]) { + sampleTypes[sample.sampleTypeCode] = true; + } + if(sample.parents) { + for (var i = 0; i < sample.parents.length; i++) { + getSampleTypesWithQueueRecursion(sample.parents[i], sampleTypes); + } + } + if (sample.children) { + for (var i = 0; i < sample.children.length; i++) { + getSampleTypesWithQueueRecursion(sample.children[i], sampleTypes); + } + } + } + getSampleTypesWithQueueRecursion(this._sample, sampleTypes); + return sampleTypes; + } + + this.getMaxChildrenDepth = function() { + var getMaxChildrenDepthWithQueueRecurion = function(sample, max) { + if (sample.children) { + var posibleNextMax = []; + for (var i = 0; i < sample.children.length; i++) { + var nextMax = getMaxChildrenDepthWithQueueRecurion(sample.children[i], (max + 1)); + posibleNextMax.push(nextMax); + } + for (var i = 0; i < posibleNextMax.length; i++) { + if (posibleNextMax[i] > max) { + max = posibleNextMax[i]; + } + } + } + return max; + } + return getMaxChildrenDepthWithQueueRecurion(this._sample, 0); + } + + this.getMaxParentsDepth = function(sample) { + var getMaxParentsDepthWithQueueRecurion = function(sample, max) { + if (sample.parents) { + var posibleNextMax = []; + for (var i = 0; i < sample.parents.length; i++) { + var nextMax = getMaxParentsDepthWithQueueRecurion(sample.parents[i], (max + 1)); + posibleNextMax.push(nextMax); + } + for (var i = 0; i < posibleNextMax.length; i++) { + if (posibleNextMax[i] > max) { + max = posibleNextMax[i]; + } + } + } + return max; + } + return getMaxParentsDepthWithQueueRecurion(this._sample, 0); + } + + +} diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterView.js new file mode 100644 index 0000000000000000000000000000000000000000..4d21e9ef4dbb8de886922dea47ae4d0d0a73522a --- /dev/null +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleHierarchyTable/widgets/HierarchyFilterView.js @@ -0,0 +1,61 @@ +/* + * Copyright 2015 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function HierarchyFilterView(controller, model) { + this._controller = controller; + this._model = model; + + this.init = function(container) { + var $filtersForm = $('<form>' , { class : 'form-inline'}); + container.append($filtersForm); + $filtersForm.submit(function(event) {this._model.action(); event.preventDefault();}); + + var maxChildren = this._model.getMaxChildrenDepth(); + var $filtersFormSliderChildren = null; + if(maxChildren > 0) { + $filtersFormSliderChildren = $('<input>' , { 'id' : 'childrenLimit' , 'type' : 'text' , 'class' : 'span2', 'value' : '' , 'data-slider-max' : maxChildren , 'data-slider-value' : maxChildren}); + } else { + $filtersFormSliderChildren = 'No Children'; + } + + var maxParents = this._model.getMaxParentsDepth(); + var $filtersFormSliderParents = null; + if(maxParents > 0) { + $filtersFormSliderParents = $('<input>' , { 'id' : 'parentsLimit' , 'type' : 'text' , 'class' : 'span2', 'value' : '' , 'data-slider-max' : maxParents , 'data-slider-value' : maxParents}); + } else { + $filtersFormSliderParents = 'No Parents'; + } + + var sampleTypes = this._model.getSampleTypes(); + var $filtersFormSampleTypes = $('<select>', { 'id' : 'sampleTypesSelector' , class : 'multiselect' , 'multiple' : 'multiple'}); + for (var sampleType in sampleTypes) { + $filtersFormSampleTypes.append($('<option>', { 'value' : sampleType , 'selected' : ''}).html(sampleType)); + } + + $filtersForm + .append('<b>Filters</b>') + .append("<span style='padding-right:15px;'></span>") + .append('Children: ') + .append($filtersFormSliderChildren) + .append("<span style='padding-right:15px;'></span>") + .append(' Parents: ') + .append($filtersFormSliderParents) + .append("<span style='padding-right:15px;'></span>") + .append(' Show Types: ') + .append($filtersFormSampleTypes) + .append("<span style='position:absolute; left:30px; top:80px;'><svg height='100' width='100'><g id='svgControls'/></svg></span>"); + + } +} \ No newline at end of file diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleHierarchy.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleHierarchy.js index 3966955f63fd7d2bd90e91e375b03fcd7e9338d0..a597d669adf1b869ec130a095e6b356e04fcf643 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleHierarchy.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleHierarchy.js @@ -20,6 +20,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) { this.containerId = containerId; this.profile = profile; this.sample = sample; + this.hierarchyFilterController = null; this.init = function() { this.repaint(); @@ -33,7 +34,11 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) { $('#'+this.containerId).append($form); var $formColumn = $("<div>", { "class" : "col-md-12"}); $form.append($formColumn); - HierarchyUtil.addHierarchyFilterWidget($formColumn, this.sample, localInstance); + localInstance.hierarchyFilterController = new HierarchyFilterController(this.sample, function() { + localInstance.filterSampleAndUpdate(); + }); + localInstance.hierarchyFilterController.init($formColumn); + $formColumn.append($('<div>', { 'id' : 'graphContainer' })); $('#graphContainer').append("<svg id='svgMapContainer'><g id='svgMap' transform='translate(20,20) scale(1)'/></svg>"); @@ -81,7 +86,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) { // // Used to remove the type label when rendering // - var selectedSampleTypes = HierarchyUtil.getSelectedSampleTypes(); + var selectedSampleTypes = this.hierarchyFilterController.getSelectedSampleTypes(); var inArray = function(value, array) { for(var i = 0; i < array.length; i++) { if(array[i] === value) { @@ -111,7 +116,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) { // // Used to cut the tree // - var parentsLimit = HierarchyUtil.getParentsLimit(); + var parentsLimit = this.hierarchyFilterController.getParentsLimit(); var parentsLimitFilter = function(sample, depthLimit) { if(sample.parents) { if(depthLimit === 0) { @@ -128,7 +133,7 @@ function SampleHierarchy(serverFacade, containerId, profile, sample) { // // Used to cut the tree // - var childrenLimit = HierarchyUtil.getChildrenLimit(); + var childrenLimit = this.hierarchyFilterController.getChildrenLimit(); var childrenLimitFilter = function(sample, depthLimit) { if(sample.children) { if(depthLimit === 0) {