From e92ff7bc2be2c2739f3e18be1f81ff0ba8c7cba2 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Wed, 2 Oct 2013 23:38:18 +0300 Subject: [PATCH 01/14] JARVIS-332 Updated package.json (bugs) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 1839a00..01ef0df 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "type": "git", "url": "https://github.com/joola/joola.io.sdk.git" }, + "bugs": "https://joolatech.atlassian.net/browse/JARVIS", "contributors": [ { "name": "Itay Weinberger", From 09a1c5f76c98ac72c8378db1cb481389f6b929b2 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 3 Oct 2013 14:42:20 +0300 Subject: [PATCH 02/14] JARVIS-373 Fixed issue with null ref to timeline --- lib/joolaio.visualisation.report.MetricBox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/joolaio.visualisation.report.MetricBox.js b/lib/joolaio.visualisation.report.MetricBox.js index 94ce7fd..3cc053e 100644 --- a/lib/joolaio.visualisation.report.MetricBox.js +++ b/lib/joolaio.visualisation.report.MetricBox.js @@ -401,7 +401,7 @@ joolaio.visualisation.report.MetricBox.prototype.draw = function (Container) { $(joolaio).trigger('report-metricbox-draw', [$metric, true, joolaio.colors[0]]); } - if (joolaio.visualisation.report.timeline.secondaryMetric != null) { + if (joolaio.visualisation.report.timeline && joolaio.visualisation.report.timeline.secondaryMetric != null) { var metric = joolaio.visualisation.report.timeline.secondaryMetric; var $metric = $(_this.Container).find('.jmetricbox[data-metric="' + metric.id + '"]'); $('.jmetricbox').removeClass('secondaryactive'); From 36534672afb30f0f8945128b8ae65e1fb2a10e2a Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 3 Oct 2013 14:42:35 +0300 Subject: [PATCH 03/14] JARVIS-372 Fixed issue with null ref timeline and table. --- lib/joolaio.visualisation.report.Table.js | 3880 +++++++++++---------- 1 file changed, 1941 insertions(+), 1939 deletions(-) diff --git a/lib/joolaio.visualisation.report.Table.js b/lib/joolaio.visualisation.report.Table.js index 664c8e7..8e98f3a 100644 --- a/lib/joolaio.visualisation.report.Table.js +++ b/lib/joolaio.visualisation.report.Table.js @@ -19,48 +19,48 @@ joolaio.require('joolaio.string'); joolaio.require('joolaio.visualisation.report'); joolaio.visualisation.report.Table = function (options, container) { - var _this = this; - var start = new Date().getMilliseconds(); + var _this = this; + var start = new Date().getMilliseconds(); - this._this = this; - this.ChartType = 'line'; - this.Resolution = 'Day'; - this.primaryMetric = null; //joolaio.dataaccess.metrics[0]; - this.secondaryMetric = null; - this.Filters = []; + this._this = this; + this.ChartType = 'line'; + this.Resolution = 'Day'; + this.primaryMetric = null; //joolaio.dataaccess.metrics[0]; + this.secondaryMetric = null; + this.Filters = []; - this.drilldownlevel = 0; - this.isother = false; - this.levels = []; + this.drilldownlevel = 0; + this.isother = false; + this.levels = []; - this.sortColumnIndex = -1; - this.ColumnIndex = -1; - this.compareColumnIndex = -1; - this.sortDir = 'DESC'; - this.currentPage = 1; - this.pageSize = 10; + this.sortColumnIndex = -1; + this.ColumnIndex = -1; + this.compareColumnIndex = -1; + this.sortDir = 'DESC'; + this.currentPage = 1; + this.pageSize = 10; - this.mode = 'table'; + this.mode = 'table'; - this.dimensions = []; - this.metrics = []; - this.Container = null; + this.dimensions = []; + this.metrics = []; + this.Container = null; - this.Filters = []; + this.Filters = []; - this.colors = joolaio.colors; //['#058DC7', '#ED7E17', '#50B432', '#AF49C5', '#EDEF00', '#8080FF', '#A0A424', '#E3071C', '#6AF9C4', '#B2DEFF', '#64E572', '#CCCCCC' ]; + this.colors = joolaio.colors; //['#058DC7', '#ED7E17', '#50B432', '#AF49C5', '#EDEF00', '#8080FF', '#A0A424', '#E3071C', '#6AF9C4', '#B2DEFF', '#64E572', '#CCCCCC' ]; - this.DateBox = joolaio.visualisation.picker.DateBox; - this.initialLoad = 0; + this.DateBox = joolaio.visualisation.picker.DateBox; + this.initialLoad = 0; - joolaio.objects.Dimensions.List(); - joolaio.objects.Metrics.List(); + joolaio.objects.Dimensions.List(); + joolaio.objects.Metrics.List(); - _this.getState(_this); - var executionTime = new Date().getMilliseconds() - start; - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 5, '...init (' + executionTime + 'ms)'); + _this.getState(_this); + var executionTime = new Date().getMilliseconds() - start; + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 5, '...init (' + executionTime + 'ms)'); - return this; + return this; } @@ -69,2198 +69,2200 @@ joolaio.visualisation.report.Table = function (options, container) { * @param {string=} container An optional container to apply the class to. */ joolaio.visualisation.report.Table.prototype.init = function (options, container) { - var _this = this; - var start = new Date().getMilliseconds(); - - //this._this = this; - - //lookup any containers relevant for the timeline - var matchedContainers = null; - if (container) - matchedContainers = $(container); - else - matchedContainers = $('.joolaio.report.jtable'); - if (matchedContainers.length == 0) - return; - - this.options = $.extend({ - pageSize: 10, - minSelected: 0, - maxSelected: 3, - defaultSelected: 0, - excludeDimensions: [] - }, options); - - _this.pageSize = this.options.pageSize; - _this.excludeDimensions = this.options.excludeDimensions; - $('.joolaio.breadcrumbs').empty(); - $(matchedContainers).each(function (index, item) { - if (!$(this).parent().hasClass('prettyprint')) { - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Applying to container (\'' + this.id + '\')'); - - //apply html and bind methods/events - _this.Container = item; - - if (_this.dimensions.length == 0) { - - var _dimensions = $(item).attr('data-dimensions'); - if (!_dimensions) - return; - - try { - - _this.levels = eval(_dimensions); - $(_this.levels).each(function (index, level) { - $(level).each(function (index2, dimension) { - $(joolaio.objects.Dimensions).each(function (index3, item) { - if (dimension == item.id) { - if (index == _this.drilldownlevel) { - _this.dimensions.push(item); - } - _this.levels[index][index2] = item; - } - }); - }); - }); - - + var _this = this; + var start = new Date().getMilliseconds(); + + //this._this = this; + + //lookup any containers relevant for the timeline + var matchedContainers = null; + if (container) + matchedContainers = $(container); + else + matchedContainers = $('.joolaio.report.jtable'); + if (matchedContainers.length == 0) + return; + + this.options = $.extend({ + pageSize: 10, + minSelected: 0, + maxSelected: 3, + defaultSelected: 0, + excludeDimensions: [] + }, options); + + _this.pageSize = this.options.pageSize; + _this.excludeDimensions = this.options.excludeDimensions; + $('.joolaio.breadcrumbs').empty(); + $(matchedContainers).each(function (index, item) { + if (!$(this).parent().hasClass('prettyprint')) { + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Applying to container (\'' + this.id + '\')'); + + //apply html and bind methods/events + _this.Container = item; + + if (_this.dimensions.length == 0) { + + var _dimensions = $(item).attr('data-dimensions'); + if (!_dimensions) + return; + + try { + + _this.levels = eval(_dimensions); + $(_this.levels).each(function (index, level) { + $(level).each(function (index2, dimension) { + $(joolaio.objects.Dimensions).each(function (index3, item) { + if (dimension == item.id) { + if (index == _this.drilldownlevel) { + _this.dimensions.push(item); + } + _this.levels[index][index2] = item; } - catch (e) { - _this.levels = []; - _this.levels.push([_dimensions]); - - _dimensions = _dimensions.split(','); - $(_dimensions).each(function (index, item) { - _dimensions[index] = $.trim(_dimensions[index]); - _this.dimensions.push(_dimensions[index]); - }); - $(joolaio.objects.Dimensions).each(function (index, item) { - if (_dimensions.indexOf(item.id) > -1) - _this.dimensions[_dimensions.indexOf(item.id)] = item; - }); - } - } - else { - - } - - _.each(_this.levels, function (level, ilevel) { - _.each(level, function (d, id) { - - if (typeof(d) != 'object') { - d = _.find(joolaio.objects.Dimensions, function (_d) { - return _d.id == d; - }); - if (d) { - _this.levels[ilevel][id] = d; - } - - } - }) + }); }); + }); - var _metrics = $(item).attr('data-metrics'); - if (!_metrics) - return; - _metrics = _metrics.split(','); - $(_metrics).each(function (index, item) { - _metrics[index] = $.trim(_metrics[index]); - _this.metrics.push(_metrics[index]); - }); - $(joolaio.objects.Metrics).each(function (index, item) { - if (_metrics.indexOf(item.id) > -1) - _this.metrics[_metrics.indexOf(item.id)] = item; - }); + } + catch (e) { + _this.levels = []; + _this.levels.push([_dimensions]); + + _dimensions = _dimensions.split(','); + $(_dimensions).each(function (index, item) { + _dimensions[index] = $.trim(_dimensions[index]); + _this.dimensions.push(_dimensions[index]); + }); + $(joolaio.objects.Dimensions).each(function (index, item) { + if (_dimensions.indexOf(item.id) > -1) + _this.dimensions[_dimensions.indexOf(item.id)] = item; + }); + } + } + else { + } - $(item).empty(); - _this.draw(item); - _this.fetch(_this, item); + _.each(_this.levels, function (level, ilevel) { + _.each(level, function (d, id) { - $(_this).unbind('data'); - $(_this).bind('data', function (evt, ret) { - ret.data = $(_this).data().data; + if (typeof(d) != 'object') { + d = _.find(joolaio.objects.Dimensions, function (_d) { + return _d.id == d; }); + if (d) { + _this.levels[ilevel][id] = d; + } - $(_this).unbind('click'); - $(_this).bind('click', function (evt) { - $(_this).trigger('clicked', $(this).data().data); - }); + } + }) + }); - //$(_this.DateBox).unbind('datechange'); - $(_this.DateBox).bind('datechange', function () { - //joolaio.visualisation.report.clearFilter(); - _this.fetch(_this); + var _metrics = $(item).attr('data-metrics'); + if (!_metrics) + return; + _metrics = _metrics.split(','); + $(_metrics).each(function (index, item) { + _metrics[index] = $.trim(_metrics[index]); + _this.metrics.push(_metrics[index]); + }); + + $(joolaio.objects.Metrics).each(function (index, item) { + if (_metrics.indexOf(item.id) > -1) + _this.metrics[_metrics.indexOf(item.id)] = item; + }); + + + $(item).empty(); + _this.draw(item); + _this.fetch(_this, item); + + $(_this).unbind('data'); + $(_this).bind('data', function (evt, ret) { + ret.data = $(_this).data().data; + }); + + $(_this).unbind('click'); + $(_this).bind('click', function (evt) { + $(_this).trigger('clicked', $(this).data().data); + }); + + //$(_this.DateBox).unbind('datechange'); + $(_this.DateBox).bind('datechange', function () { + //joolaio.visualisation.report.clearFilter(); + _this.fetch(_this); - if (_this.DateBox.comparePeriod) { - $('button.btn_pie').attr('disabled', 'true'); - $('button.btn_pie').addClass('disabled'); - $('button.btn_perf').attr('disabled', 'true'); - $('button.btn_perf').addClass('disabled'); + if (_this.DateBox.comparePeriod) { + $('button.btn_pie').attr('disabled', 'true'); + $('button.btn_pie').addClass('disabled'); + $('button.btn_perf').attr('disabled', 'true'); + $('button.btn_perf').addClass('disabled'); - _this.mode = 'table'; - } - else { - $('button.btn_pie').removeAttr('disabled'); - $('button.btn_pie').removeClass('disabled'); - $('button.btn_perf').removeAttr('disabled'); - $('button.btn_perf').removeClass('disabled'); + _this.mode = 'table'; + } + else { + $('button.btn_pie').removeAttr('disabled'); + $('button.btn_pie').removeClass('disabled'); + $('button.btn_perf').removeAttr('disabled'); + $('button.btn_perf').removeClass('disabled'); - } - }); + } + }); - $(joolaio.visualisation.report).bind('filter', function (e, options) { + $(joolaio.visualisation.report).bind('filter', function (e, options) { - if (!options || (options && !options.dontrunfetch)) - _this.fetch(_this); + if (!options || (options && !options.dontrunfetch)) + _this.fetch(_this); - }); + }); - _this.destroy = function () { - $(_this.DateBox).unbind('datechange'); - $(_this).unbind('data'); - $(_this).unbind('click'); - $(joolaio.visualisation.report).unbind('filter'); + _this.destroy = function () { + $(_this.DateBox).unbind('datechange'); + $(_this).unbind('data'); + $(_this).unbind('click'); + $(joolaio.visualisation.report).unbind('filter'); - try { - joolaio.state[_this.uid()].Filters = []; - } - catch (e) { - } - } + try { + joolaio.state[_this.uid()].Filters = []; + } + catch (e) { + } + } + } + }); + + $(joolaio.visualisation.report).bind('filter', function (e, options) { + + var parts = joolaio.visualisation.report.globalfilter.split('[AND]'); + var path = []; + $(parts).each(function (index, part) { + if (part != '') { + + if (part.indexOf('*=') > -1) { + var dID = part.split('*=')[0]; + var value = part.split('*=')[1]; + var dim; + + var _d = _.filter(joolaio.objects.Dimensions, function (d) { + return d.id == dID; + }); + if (_d) { + _d = _d[0]; + dim = _d.name; + } + else + throw 'Dimension not found'; + + path.push({name: dim, value: value, filter: part}); + } else { + var dID = part.split('=')[0]; + var value = part.split('=')[1]; + var dim; + + var _d = _.filter(joolaio.objects.Dimensions, function (d) { + return d.id == dID; + }); + if (_d) { + _d = _d[0]; + dim = _d.name;//$('.dimension[data-sortindex="0"]').text(); + } + else + throw 'Dimension not found'; + path.push({name: dim, value: value, filter: part}); } + } }); - $(joolaio.visualisation.report).bind('filter', function (e, options) { - - var parts = joolaio.visualisation.report.globalfilter.split('[AND]'); - var path = []; - $(parts).each(function (index, part) { - if (part != '') { - - if (part.indexOf('*=') > -1) { - var dID = part.split('*=')[0]; - var value = part.split('*=')[1]; - var dim; - - var _d = _.filter(joolaio.objects.Dimensions, function (d) { - return d.id == dID; - }); - if (_d) { - _d = _d[0]; - dim = _d.name; - } - else - throw 'Dimension not found'; - - path.push({name: dim, value: value, filter: part}); - } else { - var dID = part.split('=')[0]; - var value = part.split('=')[1]; - var dim; - - var _d = _.filter(joolaio.objects.Dimensions, function (d) { - return d.id == dID; - }); - if (_d) { - _d = _d[0]; - dim = _d.name;//$('.dimension[data-sortindex="0"]').text(); - } - else - throw 'Dimension not found'; - path.push({name: dim, value: value, filter: part}); - } - } - }); + if ($('.joolaio.breadcrumbs').length == 0) { + var $breadcrumbsAppend = $('.secondary.btn-group').after(''); + //$('.tablecontrol').append(''); + } + var $breadcrumbs = $('.joolaio.breadcrumbs'); + $breadcrumbs.empty(); - if ($('.joolaio.breadcrumbs').length == 0) { - var $breadcrumbsAppend = $('.secondary.btn-group').after(''); - //$('.tablecontrol').append(''); - } - var $breadcrumbs = $('.joolaio.breadcrumbs'); - $breadcrumbs.empty(); - - if (path.length > 0) { - var $crumb = $('
'); - var $caption = $(''); - var $value = $(''); - var $sep = $('/'); - var filter = ''; + if (path.length > 0) { + var $crumb = $('
'); + var $caption = $(''); + var $value = $(''); + var $sep = $('/'); + var filter = ''; - $value.text('ALL'); + $value.text('ALL'); - //$crumb.append($caption); - $crumb.append($value); - $crumb.append($sep); + //$crumb.append($caption); + $crumb.append($value); + $crumb.append($sep); - $breadcrumbs.append($crumb); - $crumb.attr('data-filter', filter); - } - $(path).each(function (index, item) { - var $crumb = $('
'); - var $caption = $(''); - var $value = $(''); + $breadcrumbs.append($crumb); + $crumb.attr('data-filter', filter); + } + $(path).each(function (index, item) { + var $crumb = $('
'); + var $caption = $(''); + var $value = $(''); - var $sep = $('/'); - $caption.text(item.name + ': '); - $value.text(item.value); + var $sep = $('/'); + $caption.text(item.name + ': '); + $value.text(item.value); - filter += item.filter + '[AND]'; + filter += item.filter + '[AND]'; - $crumb.append($caption); - $crumb.append($value); + $crumb.append($caption); + $crumb.append($value); - if (index < path.length - 1) - $crumb.append($sep); + if (index < path.length - 1) + $crumb.append($sep); - $crumb.attr('data-filter', filter); + $crumb.attr('data-filter', filter); - $breadcrumbs.append($crumb); - }); + $breadcrumbs.append($crumb); + }); - $('.joolaio.breadcrumbs .crumb').each(function (index, item) { - if (index < $('.joolaio.breadcrumbs .crumb').length - 1) { - var $this = $(item); - var $link = $($this.find('.value')); - $link.off('click'); - $link.on('click', function (e) { - if ($this.attr('data-filter') == '') { - joolaio.visualisation.report.table.Filters = []; - joolaio.visualisation.report.timeline.Filters = []; - } - joolaio.visualisation.report.setFilter($this.attr('data-filter')); - }); - } + $('.joolaio.breadcrumbs .crumb').each(function (index, item) { + if (index < $('.joolaio.breadcrumbs .crumb').length - 1) { + var $this = $(item); + var $link = $($this.find('.value')); + $link.off('click'); + $link.on('click', function (e) { + if ($this.attr('data-filter') == '') { + if (joolaio.visualisation.report.table) + joolaio.visualisation.report.table.Filters = []; + if (joolaio.visualisation.report.timeline) + joolaio.visualisation.report.timeline.Filters = []; + } + joolaio.visualisation.report.setFilter($this.attr('data-filter')); }); + } }); - var executionTime = new Date().getMilliseconds() - start; - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 5, '...init (' + executionTime + 'ms)'); + }); + var executionTime = new Date().getMilliseconds() - start; + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 5, '...init (' + executionTime + 'ms)'); - return this; + return this; }; joolaio.visualisation.report.Table.prototype.fetch = function (sender, container) { - if (!sender) { - sender = joolaio.visualisation.report.Table; - } - - var _this = sender; - _this.currentPage = 1; - var startdate = joolaio.visualisation.picker.DateBox.getDate().base_fromdate; - var enddate = joolaio.visualisation.picker.DateBox.getDate().base_todate; - if (_this.DateBox.comparePeriod) { - var compare_startdate = joolaio.visualisation.picker.DateBox.getDate().compare_fromdate; - var compare_enddate = joolaio.visualisation.picker.DateBox.getDate().compare_todate; - } - - var dimensionslist = ''; - $(_this.dimensions).each(function (index, item) { - dimensionslist += item.id + ', '; - }); - dimensionslist = dimensionslist.substring(0, dimensionslist.length - 2); - - var metricslist = ''; - $(_this.metrics).each(function (index, item) { - metricslist += item.id + ', '; - }); - metricslist = metricslist.substring(0, metricslist.length - 2); - - - var queryOptions = []; - var _queryOptions = { - id: 'primary', - startdate: joolaio.date.formatDate(startdate, 'yyyy-mm-dd hh:nn:ss.000'), - enddate: joolaio.date.formatDate(enddate, 'yyyy-mm-dd hh:nn:ss.999'), - dimensions: dimensionslist, - metrics: metricslist, - resolution: _this.Resolution, - omitDate: true, - filter: joolaio.visualisation.report.globalfilter, - sortKey: _this.metrics[0].id, - sortDir: 'DESC' + if (!sender) { + sender = joolaio.visualisation.report.Table; + } + + var _this = sender; + _this.currentPage = 1; + var startdate = joolaio.visualisation.picker.DateBox.getDate().base_fromdate; + var enddate = joolaio.visualisation.picker.DateBox.getDate().base_todate; + if (_this.DateBox.comparePeriod) { + var compare_startdate = joolaio.visualisation.picker.DateBox.getDate().compare_fromdate; + var compare_enddate = joolaio.visualisation.picker.DateBox.getDate().compare_todate; + } + + var dimensionslist = ''; + $(_this.dimensions).each(function (index, item) { + dimensionslist += item.id + ', '; + }); + dimensionslist = dimensionslist.substring(0, dimensionslist.length - 2); + + var metricslist = ''; + $(_this.metrics).each(function (index, item) { + metricslist += item.id + ', '; + }); + metricslist = metricslist.substring(0, metricslist.length - 2); + + + var queryOptions = []; + var _queryOptions = { + id: 'primary', + startdate: joolaio.date.formatDate(startdate, 'yyyy-mm-dd hh:nn:ss.000'), + enddate: joolaio.date.formatDate(enddate, 'yyyy-mm-dd hh:nn:ss.999'), + dimensions: dimensionslist, + metrics: metricslist, + resolution: _this.Resolution, + omitDate: true, + filter: joolaio.visualisation.report.globalfilter, + sortKey: _this.metrics[0].id, + sortDir: 'DESC' + }; + queryOptions.push(_queryOptions); + + if (_this.DateBox.comparePeriod) { + _queryOptions = { + id: 'compare_primary', + startdate: joolaio.date.formatDate(compare_startdate, 'yyyy-mm-dd hh:nn:ss.000'), + enddate: joolaio.date.formatDate(compare_enddate, 'yyyy-mm-dd hh:nn:ss.999'), + dimensions: dimensionslist, + metrics: metricslist, + resolution: _this.Resolution, + omitDate: true, + filter: joolaio.visualisation.report.globalfilter, + sortKey: _this.metrics[0].id, + sortDir: 'DESC' }; queryOptions.push(_queryOptions); + } - if (_this.DateBox.comparePeriod) { - _queryOptions = { - id: 'compare_primary', - startdate: joolaio.date.formatDate(compare_startdate, 'yyyy-mm-dd hh:nn:ss.000'), - enddate: joolaio.date.formatDate(compare_enddate, 'yyyy-mm-dd hh:nn:ss.999'), - dimensions: dimensionslist, - metrics: metricslist, - resolution: _this.Resolution, - omitDate: true, - filter: joolaio.visualisation.report.globalfilter, - sortKey: _this.metrics[0].id, - sortDir: 'DESC' - }; - queryOptions.push(_queryOptions); - } + joolaio.dataaccess.multifetch(_this, '/query/fetch', queryOptions, function (sender, data, error) { - joolaio.dataaccess.multifetch(_this, '/query/fetch', queryOptions, function (sender, data, error) { - - var series = []; - $(data).each(function (index, item) { - var result = item.data.Result; - var request = item.data.Request; - var _data = item.data.Result.Rows; - if (index == 0) { - if (_this.initialLoad == 0) - _this.initialLoad = 1; - - if (_this.options.defaultSelected && _this.initialLoad == 1) { - var _limit = _this.options.defaultSelected; - if (_limit > _data.length) - _limit = _data.length; - for (var i = 0; i < _limit; i++) { - var filter = ''; - _.each(_this.dimensions, function (d, di) { - filter += d.id + '=' + [_data[i].Values[di]] + '[AND]'; - }); - - $(joolaio.visualisation.report).trigger('addpartialfilter-quick', filter); - _this.Filters.push(filter); - } - - $(joolaio.visualisation.report).trigger('filter', [ - {dontrunfetch: true} - ]); - _this.initialLoad = 2; - } + var series = []; + $(data).each(function (index, item) { + var result = item.data.Result; + var request = item.data.Request; + var _data = item.data.Result.Rows; + if (index == 0) { + if (_this.initialLoad == 0) + _this.initialLoad = 1; + if (_this.options.defaultSelected && _this.initialLoad == 1) { + var _limit = _this.options.defaultSelected; + if (_limit > _data.length) + _limit = _data.length; + for (var i = 0; i < _limit; i++) { + var filter = ''; + _.each(_this.dimensions, function (d, di) { + filter += d.id + '=' + [_data[i].Values[di]] + '[AND]'; + }); - } - // - // } + $(joolaio.visualisation.report).trigger('addpartialfilter-quick', filter); + _this.Filters.push(filter); + } + + $(joolaio.visualisation.report).trigger('filter', [ + {dontrunfetch: true} + ]); + _this.initialLoad = 2; + } - series.push({dimensions: _this.dimensions, metrics: _this.metrics, data: result}); - }); - sender.datatable = series; + } + // + // } - _this.update(sender, dimensionslist, metricslist, series); + series.push({dimensions: _this.dimensions, metrics: _this.metrics, data: result}); }); -}; -joolaio.visualisation.report.Table.prototype.update = function (sender) { + sender.datatable = series; - var _this = sender; + _this.update(sender, dimensionslist, metricslist, series); + }); +}; - var series = _this.datatable[0];//series[0]; - var series_compare; - var _data_compare; - var _data_compare_toshow; - if (_this.DateBox.comparePeriod) { - series_compare = _this.datatable[1]; - _data_compare = series_compare.data.Rows; - } +joolaio.visualisation.report.Table.prototype.update = function (sender) { - var _columns = series.data.Columns; - var _allcolumns = _columns; - var _data = series.data.Rows; - var _totalsum_base = 0; - var _totalsumcompare_base = 0; - var _totalsum = 0; - var _totalsumcompare = 0; - - var $table = $($(_this.Container).find('.table')); - $table.find('tr').remove(); - - if (_this.sortColumnIndex == -1) { - $(_columns).each(function (index, column) { - if (column.aggregation) { - } else - _this.sortColumnIndex = index + 1; - }); + var _this = sender; + + var series = _this.datatable[0];//series[0]; + var series_compare; + var _data_compare; + var _data_compare_toshow; + if (_this.DateBox.comparePeriod) { + series_compare = _this.datatable[1]; + _data_compare = series_compare.data.Rows; + } + + var _columns = series.data.Columns; + var _allcolumns = _columns; + var _data = series.data.Rows; + var _totalsum_base = 0; + var _totalsumcompare_base = 0; + var _totalsum = 0; + var _totalsumcompare = 0; + + var $table = $($(_this.Container).find('.table')); + $table.find('tr').remove(); + + if (_this.sortColumnIndex == -1) { + $(_columns).each(function (index, column) { + if (column.aggregation) { + } else + _this.sortColumnIndex = index + 1; + }); - } - if (_this.ColumnIndex == -1) { - $(_columns).each(function (index, column) { - if (column.aggregation) { - } else - _this.ColumnIndex = index + 1; - }); - _this.compareColumnIndex = _this.ColumnIndex; + } + if (_this.ColumnIndex == -1) { + $(_columns).each(function (index, column) { + if (column.aggregation) { + } else + _this.ColumnIndex = index + 1; + }); + _this.compareColumnIndex = _this.ColumnIndex; - } + } // if (_this.mode == 'pie') // _this.sortColumnIndex = 1; - _data = $(_data).sort(function (a, b) { - var valuea = a.Values[_this.sortColumnIndex]; - var valueb = b.Values[_this.sortColumnIndex]; - if (_columns[_this.sortColumnIndex].aggregation) { - valuea = parseFloat(valuea); - valueb = parseFloat(valueb) - } + _data = $(_data).sort(function (a, b) { + var valuea = a.Values[_this.sortColumnIndex]; + var valueb = b.Values[_this.sortColumnIndex]; + if (_columns[_this.sortColumnIndex].aggregation) { + valuea = parseFloat(valuea); + valueb = parseFloat(valueb) + } - if (_this.sortDir == 'DESC') - return valuea < valueb ? 1 : -1; - else - return valuea > valueb ? 1 : -1; - }); + if (_this.sortDir == 'DESC') + return valuea < valueb ? 1 : -1; + else + return valuea > valueb ? 1 : -1; + }); + + _data_compare = $(_data_compare).sort(function (a, b) { + var valuea = a.Values[_this.sortColumnIndex]; + var valueb = b.Values[_this.sortColumnIndex]; + if (_columns[_this.sortColumnIndex].aggregation) { + valuea = parseFloat(valuea); + valueb = parseFloat(valueb) + } - _data_compare = $(_data_compare).sort(function (a, b) { - var valuea = a.Values[_this.sortColumnIndex]; - var valueb = b.Values[_this.sortColumnIndex]; - if (_columns[_this.sortColumnIndex].aggregation) { - valuea = parseFloat(valuea); - valueb = parseFloat(valueb) + if (_this.sortDir == 'DESC') + return valuea < valueb ? 1 : -1; + else + return valuea > valueb ? 1 : -1; + }); + + var _datatoshow = _data; + _datatoshow = _datatoshow.slice((_this.currentPage - 1) * (_this.pageSize), _this.currentPage * _this.pageSize); + + _data_compare_toshow = _data_compare; + if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { + var _temp2 = []; + var comparecolumnname = ''; + $(_datatoshow).each(function (pi, po) { + var point = { + FormattedValues: [], + Values: [] + }; + + $(_columns).each(function (ci, co) { + if (!co.aggregation) { + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); } + }); - if (_this.sortDir == 'DESC') - return valuea < valueb ? 1 : -1; - else - return valuea > valueb ? 1 : -1; - }); + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.ColumnIndex) { + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); + //_totalsum += parseFloat(po.Values[ci]); + } + }); - var _datatoshow = _data; - _datatoshow = _datatoshow.slice((_this.currentPage - 1) * (_this.pageSize), _this.currentPage * _this.pageSize); - - _data_compare_toshow = _data_compare; - if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { - var _temp2 = []; - var comparecolumnname = ''; - $(_datatoshow).each(function (pi, po) { - var point = { - FormattedValues: [], - Values: [] - }; - - $(_columns).each(function (ci, co) { - if (!co.aggregation) { - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); - } - }); - - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.ColumnIndex) { - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); - //_totalsum += parseFloat(po.Values[ci]); - } - }); + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.compareColumnIndex) { + comparecolumnname = co.name; - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.compareColumnIndex) { - comparecolumnname = co.name; + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); + //_totalsumcompare += parseFloat(po.Values[ci]); + //point.FormattedValues.push(-1); + //point.Values.push(-1); + //_temp.push(point); - //_totalsumcompare += parseFloat(po.Values[ci]); - //point.FormattedValues.push(-1); - //point.Values.push(-1); - //_temp.push(point); + } + }); - } - }); + _temp2.push(point); + }); + _datatoshow = _temp2; + $(_data).each(function (pi, po) { + var point = { + FormattedValues: [], + Values: [] + }; + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.ColumnIndex) { + _totalsum += parseFloat(po.Values[ci]); + } + if (co.aggregation && ci == _this.compareColumnIndex) { + comparecolumnname = co.name; + _totalsumcompare += parseFloat(po.Values[ci]); + } + }); + }); - _temp2.push(point); - }); - _datatoshow = _temp2; - $(_data).each(function (pi, po) { - var point = { - FormattedValues: [], - Values: [] - }; - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.ColumnIndex) { - _totalsum += parseFloat(po.Values[ci]); - } - if (co.aggregation && ci == _this.compareColumnIndex) { - comparecolumnname = co.name; - _totalsumcompare += parseFloat(po.Values[ci]); - } - }); - }); + $(_datatoshow).each(function (pi, po) { + _datatoshow[pi].FormattedValues[po.FormattedValues.length - 1] = po.Values[po.FormattedValues.length - 1] / _totalsumcompare * 100; + _datatoshow[pi].Values[po.Values.length - 1] = po.Values[po.Values.length - 1] / _totalsumcompare * 100; + }); + //_datatoshow = _temp; + } + + _totalsum_base = _totalsum; + _totalsumcompare_base = _totalsumcompare; + + if ((_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare' ) && _this.DateBox.comparePeriod) { + var _temp = []; + var comparecolumnname = ''; + $(_data_compare_toshow).each(function (pi, po) { + var point = { + FormattedValues: [], + Values: [] + }; + $(_columns).each(function (ci, co) { + if (!co.aggregation) { + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); + } + }); - $(_datatoshow).each(function (pi, po) { - _datatoshow[pi].FormattedValues[po.FormattedValues.length - 1] = po.Values[po.FormattedValues.length - 1] / _totalsumcompare * 100; - _datatoshow[pi].Values[po.Values.length - 1] = po.Values[po.Values.length - 1] / _totalsumcompare * 100; - }); - //_datatoshow = _temp; - } + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.ColumnIndex) { + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); + //_totalsum += parseFloat(po.Values[ci]); + } + }); - _totalsum_base = _totalsum; - _totalsumcompare_base = _totalsumcompare; - - if ((_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare' ) && _this.DateBox.comparePeriod) { - var _temp = []; - var comparecolumnname = ''; - $(_data_compare_toshow).each(function (pi, po) { - var point = { - FormattedValues: [], - Values: [] - }; - $(_columns).each(function (ci, co) { - if (!co.aggregation) { - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); - } - }); - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.ColumnIndex) { - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); - //_totalsum += parseFloat(po.Values[ci]); - } - }); + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.compareColumnIndex) { + comparecolumnname = co.name; + point.FormattedValues.push(po.FormattedValues[ci]); + point.Values.push(po.Values[ci]); - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.compareColumnIndex) { - comparecolumnname = co.name; + //_totalsumcompare += parseFloat(po.Values[ci]); + //point.FormattedValues.push(-1); + //point.Values.push(-1); + //_temp.push(point); - point.FormattedValues.push(po.FormattedValues[ci]); - point.Values.push(po.Values[ci]); + } + }); - //_totalsumcompare += parseFloat(po.Values[ci]); - //point.FormattedValues.push(-1); - //point.Values.push(-1); - //_temp.push(point); + _temp.push(point); + }); + _data_compare_toshow = _temp; - } - }); - _temp.push(point); - }); - _data_compare_toshow = _temp; + _totalsum = 0; + _totalsumcompare = 0; + $(_data_compare).each(function (pi, po) { + var point = { + FormattedValues: [], + Values: [] + }; + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.ColumnIndex) { + _totalsum += parseFloat(po.Values[ci]); + } + if (co.aggregation && ci == _this.compareColumnIndex) { + comparecolumnname = co.name; + _totalsumcompare += parseFloat(po.Values[ci]); + } + }); + }); - _totalsum = 0; - _totalsumcompare = 0; + $(_data_compare_toshow).each(function (pi, po) { + if (_totalsumcompare == 0) { + _data_compare_toshow[pi].FormattedValues[po.FormattedValues.length - 1] = 0; + _data_compare_toshow[pi].Values[po.Values.length - 1] = 0; + } + else { + _data_compare_toshow[pi].FormattedValues[po.FormattedValues.length - 1] = po.Values[po.FormattedValues.length - 1] / _totalsumcompare * 100; + _data_compare_toshow[pi].Values[po.Values.length - 1] = po.Values[po.Values.length - 1] / _totalsumcompare * 100; + } - $(_data_compare).each(function (pi, po) { - var point = { - FormattedValues: [], - Values: [] - }; - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.ColumnIndex) { - _totalsum += parseFloat(po.Values[ci]); - } - if (co.aggregation && ci == _this.compareColumnIndex) { - comparecolumnname = co.name; - _totalsumcompare += parseFloat(po.Values[ci]); - } - }); - }); - $(_data_compare_toshow).each(function (pi, po) { - if (_totalsumcompare == 0) { - _data_compare_toshow[pi].FormattedValues[po.FormattedValues.length - 1] = 0; - _data_compare_toshow[pi].Values[po.Values.length - 1] = 0; - } - else { - _data_compare_toshow[pi].FormattedValues[po.FormattedValues.length - 1] = po.Values[po.FormattedValues.length - 1] / _totalsumcompare * 100; - _data_compare_toshow[pi].Values[po.Values.length - 1] = po.Values[po.Values.length - 1] / _totalsumcompare * 100; + }); + } + if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { + _temp = []; + $(_columns).each(function (ci, co) { + if (co.aggregation && ci == _this.ColumnIndex) { + _temp.push(co); + } + else if (!co.aggregation) { + _temp.push(co); + } + }); + _columns = _temp; + _columns.push({name: comparecolumnname, aggregation: 'Special'}) + } + + //build columns + var $tr = $(""); + var $th = $(''); + $tr.append($th); + + $th = $(''); + $tr.append($th); + + var sortIndex = 0; + $(_columns).each(function (index, column) { + if (column.aggregation) { + var metric = column; + if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { + if (index == _columns.length - 2) { + $th = $('' + + ''); + + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation && (ao.aggregation == 'sum' || ao.aggregation == 'count')) { + $th.find('.metricpicker').append('') + + $th.addClass('sortkey'); + $th.addClass(_this.sortDir); } + }); + $th.find('.metricpicker').off('click'); + $th.find('.metricpicker').on('click', function (e) { - }); - } - if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { - _temp = []; - $(_columns).each(function (ci, co) { - if (co.aggregation && ci == _this.ColumnIndex) { - _temp.push(co); - } - else if (!co.aggregation) { - _temp.push(co); - } - }); - _columns = _temp; - _columns.push({name: comparecolumnname, aggregation: 'Special'}) - } - //build columns - var $tr = $(""); - var $th = $(''); - $tr.append($th); + e.stopPropagation(); + }); + $th.find('.metricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.ColumnIndex = ai; + } + }); + _this.update(_this); + }); - $th = $(''); - $tr.append($th); + } + else { + $th = $('' + _columns[_columns.length - 1].name + ''); + } + } + else if (_this.mode != 'pie') { + $th = $('' + metric.name + ''); + if (sortIndex == _this.sortColumnIndex) { + $th.addClass('sortkey'); + $th.addClass(_this.sortDir); + } + } + + if ($th) { + if ((_this.mode != 'pie' && _this.mode != 'perf' && _this.mode != 'compare') || + ((_this.mode == 'pie' && index < _columns.length - 1) || + ((_this.mode == 'perf' || _this.mode == 'compare') && index < _columns.length - 1))) { + $th.off('click'); + $th.on('click', function (e) { + e.stopPropagation(); + if (_this.sortColumnIndex == $(this).attr('data-sortindex')) + _this.sortDir = (_this.sortDir == 'DESC' ? 'ASC' : 'DESC'); + else + _this.sortDir = 'DESC'; + _this.sortColumnIndex = $(this).attr('data-sortindex'); - var sortIndex = 0; - $(_columns).each(function (index, column) { - if (column.aggregation) { - var metric = column; - if (_this.mode == 'pie' || _this.mode == 'perf' || _this.mode == 'compare') { - if (index == _columns.length - 2) { - $th = $('' + - ''); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation && (ao.aggregation == 'sum' || ao.aggregation == 'count')) { - $th.find('.metricpicker').append('') - - $th.addClass('sortkey'); - $th.addClass(_this.sortDir); - } - }); - - $th.find('.metricpicker').off('click'); - $th.find('.metricpicker').on('click', function (e) { - - - e.stopPropagation(); - }); - $th.find('.metricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.ColumnIndex = ai; - } - }); - _this.update(_this); - }); + $tr.find('th').removeClass('sortkey'); + $tr.find('th').removeClass('ASC'); + $tr.find('th').removeClass('DESC'); - } - else { - $th = $('' + _columns[_columns.length - 1].name + ''); - } - } - else if (_this.mode != 'pie') { - $th = $('' + metric.name + ''); - if (sortIndex == _this.sortColumnIndex) { - $th.addClass('sortkey'); - $th.addClass(_this.sortDir); - } - } + $(this).addClass('sortkey'); + $(this).addClass(_this.sortDir); - if ($th) { - if ((_this.mode != 'pie' && _this.mode != 'perf' && _this.mode != 'compare') || - ((_this.mode == 'pie' && index < _columns.length - 1) || - ((_this.mode == 'perf' || _this.mode == 'compare') && index < _columns.length - 1))) { - $th.off('click'); - $th.on('click', function (e) { - e.stopPropagation(); - if (_this.sortColumnIndex == $(this).attr('data-sortindex')) - _this.sortDir = (_this.sortDir == 'DESC' ? 'ASC' : 'DESC'); - else - _this.sortDir = 'DESC'; - _this.sortColumnIndex = $(this).attr('data-sortindex'); - - $tr.find('th').removeClass('sortkey'); - $tr.find('th').removeClass('ASC'); - $tr.find('th').removeClass('DESC'); - - $(this).addClass('sortkey'); - $(this).addClass(_this.sortDir); - - - _this.update(_this); - }); - } - else - $th.addClass('special'); - $tr.append($th); - } - sortIndex++; + _this.update(_this); + }); } - else { - var dimension = column; + else + $th.addClass('special'); + $tr.append($th); - if (index == 0) - $th = $('' + dimension.name + ''); - else { - $th = $('' + dimension.name + '' + - '' + - '' + - ''); - $($th.find('.removesecondarydimension')).off('click'); - $($th.find('.removesecondarydimension')).on('click', function (e) { + } + sortIndex++; + } + else { + var dimension = column; - _this.Filters = []; - $(joolaio.visualisation.report).trigger('joolaio-clearfilter'); + if (index == 0) + $th = $('' + dimension.name + ''); + else { + $th = $('' + dimension.name + '' + + '' + + '' + + ''); + $($th.find('.removesecondarydimension')).off('click'); + $($th.find('.removesecondarydimension')).on('click', function (e) { - var dindex = -1; - $(_this.dimensions).each(function (i, d) { + _this.Filters = []; + $(joolaio.visualisation.report).trigger('joolaio-clearfilter'); + var dindex = -1; + $(_this.dimensions).each(function (i, d) { - if (d.name == dimension.name) { - dindex = i; - } - }); - if (dindex > -1) { - _this.dimensions.splice(dindex, 1); + if (d.name == dimension.name) { + dindex = i; + } + }); + if (dindex > -1) { - _this.sortColumnIndex = parseInt(_this.sortColumnIndex) - 1; - _this.ColumnIndex = parseInt(_this.ColumnIndex) - 1; - _this.compareColumnIndex = parseInt(_this.compareColumnIndex) - 1; + _this.dimensions.splice(dindex, 1); - _this.currentPage = 1; + _this.sortColumnIndex = parseInt(_this.sortColumnIndex) - 1; + _this.ColumnIndex = parseInt(_this.ColumnIndex) - 1; + _this.compareColumnIndex = parseInt(_this.compareColumnIndex) - 1; - _this.fetch(_this); + _this.currentPage = 1; - } - e.stopPropagation(); - }); - } + _this.fetch(_this); - if (sortIndex == _this.sortColumnIndex) { - $th.addClass('sortkey'); - $th.addClass(_this.sortDir); - } - $th.off('click'); - $th.on('click', function (e) { - e.stopPropagation(); - if (_this.sortColumnIndex == $(this).attr('data-sortindex')) - _this.sortDir = (_this.sortDir == 'DESC' ? 'ASC' : 'DESC'); - else - _this.sortDir = 'DESC'; - _this.sortColumnIndex = $(this).attr('data-sortindex'); + } + e.stopPropagation(); + }); + } + + if (sortIndex == _this.sortColumnIndex) { + $th.addClass('sortkey'); + $th.addClass(_this.sortDir); + } + $th.off('click'); + $th.on('click', function (e) { + e.stopPropagation(); + if (_this.sortColumnIndex == $(this).attr('data-sortindex')) + _this.sortDir = (_this.sortDir == 'DESC' ? 'ASC' : 'DESC'); + else + _this.sortDir = 'DESC'; + _this.sortColumnIndex = $(this).attr('data-sortindex'); - $tr.find('th').removeClass('sortkey'); - $tr.find('th').removeClass('ASC'); - $tr.find('th').removeClass('DESC'); + $tr.find('th').removeClass('sortkey'); + $tr.find('th').removeClass('ASC'); + $tr.find('th').removeClass('DESC'); - $(this).addClass('sortkey'); - $(this).addClass(_this.sortDir); + $(this).addClass('sortkey'); + $(this).addClass(_this.sortDir); - _this.update(_this); - }); - $tr.append($th); - sortIndex++; + _this.update(_this); + }); + $tr.append($th); + sortIndex++; + } + + }); + $table.append($tr); + + if (_data.length == 0) { + $table.append('There is no data to display.'); + } + + if (!_this.DateBox.comparePeriod) { + $(_datatoshow).each(function (index, row) { + + var allowCheck = true; + //if (_this.dimensions[1] && _this.dimensions[1].type == 'date') + //allowCheck = false; + $tr = $(''); + $td = $(''); + if (_this.mode == 'pie') + $td.append('
'); + else + $td.append(''); + + $tr.append($td); + $td = $('' + parseInt((_this.currentPage - 1) * (_this.pageSize) + index + 1) + '.'); + $tr.append($td); + + var filter = ''; + var shortfilter = ''; + + $(_columns).each(function (i, cell) { + $td = $(''); + if (_columns[i].aggregation) + $td.addClass('metricvalue'); + else { + if (i == 0) { + $td.addClass('dimensionvalue'); + shortfilter = _columns[i].id + '=' + row.Values[i] + '[AND]'; + } + filter += _columns[i].id + '=' + row.Values[i] + '[AND]' + } + if (i == _this.sortColumnIndex) + $td.addClass('sortkey'); + + if (_this.mode != 'pie') + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i != _columns.length - 1) + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); } - }); - $table.append($tr); + $tr.append($td); + }); - if (_data.length == 0) { - $table.append('There is no data to display.'); - } + var $checkbox = $tr.find('.checkfilter'); - if (!_this.DateBox.comparePeriod) { - $(_datatoshow).each(function (index, row) { + $checkbox.attr('data-filter', filter); + $checkbox.off('click'); + $checkbox.on('click', function (e) { - var allowCheck = true; - //if (_this.dimensions[1] && _this.dimensions[1].type == 'date') - //allowCheck = false; - $tr = $(''); - $td = $(''); - if (_this.mode == 'pie') - $td.append('
'); - else - $td.append(''); + if ($checkbox.is(':checked')) { - $tr.append($td); - $td = $('' + parseInt((_this.currentPage - 1) * (_this.pageSize) + index + 1) + '.'); - $tr.append($td); + joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); + _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); + } + else { + joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); + if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { + _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); + //_this.fetch(_this); + } + } - var filter = ''; - var shortfilter = ''; - - $(_columns).each(function (i, cell) { - $td = $(''); - if (_columns[i].aggregation) - $td.addClass('metricvalue'); - else { - if (i == 0) { - $td.addClass('dimensionvalue'); - shortfilter = _columns[i].id + '=' + row.Values[i] + '[AND]'; - } - filter += _columns[i].id + '=' + row.Values[i] + '[AND]' - } - if (i == _this.sortColumnIndex) - $td.addClass('sortkey'); - - if (_this.mode != 'pie') - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i != _columns.length - 1) - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); - } + if (_this.options.minSelected > 0) { + var count = $('.checkfilter:checked').length; + if (count <= _this.options.minSelected) + $('.checkfilter:checked').attr('disabled', 'disabled'); + else + $('.checkfilter:checked').removeAttr('disabled'); + } - $tr.append($td); - }); + }); + if (_this.options.minSelected > 0) { + var count = $('.checkfilter:checked').length; - var $checkbox = $tr.find('.checkfilter'); + if (count <= _this.options.minSelected) + $('.checkfilter:checked').attr('disabled', 'disabled'); + else + $('.checkfilter:checked').removeAttr('disabled'); + } - $checkbox.attr('data-filter', filter); - $checkbox.off('click'); - $checkbox.on('click', function (e) { - if ($checkbox.is(':checked')) { + if (_this.Filters.indexOf(filter) > -1) + $checkbox.attr('checked', true); + else + $checkbox.attr('checked', false); - joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); - _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); - } - else { - joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); - if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { - _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); - //_this.fetch(_this); - } - } - if (_this.options.minSelected > 0) { - var count = $('.checkfilter:checked').length; - if (count <= _this.options.minSelected) - $('.checkfilter:checked').attr('disabled', 'disabled'); - else - $('.checkfilter:checked').removeAttr('disabled'); - } + if (_this.drilldownlevel <= _this.levels.length - 1) { + $tr.find('.drilldownlink').attr('data-filter', shortfilter); + $tr.find('.dimensionvalue .drilldownlink').off('click'); + $tr.find('.dimensionvalue .drilldownlink').on('click', function (e) { + $(this).off('click'); - }); - if (_this.options.minSelected > 0) { - var count = $('.checkfilter:checked').length; + if (_this.drilldownlevel < _this.levels.length - 1) + _this.drilldownlevel++; - if (count <= _this.options.minSelected) - $('.checkfilter:checked').attr('disabled', 'disabled'); - else - $('.checkfilter:checked').removeAttr('disabled'); - } + _this.dimensions.splice(0, _this.dimensions.length); + $(_this.levels[_this.drilldownlevel]).each(function (index, dimension) { + _this.dimensions.push(dimension); + }); - if (_this.Filters.indexOf(filter) > -1) - $checkbox.attr('checked', true); - else - $checkbox.attr('checked', false); + /* + $(_this.Filters).each(function (fi, f) { + joolaio.visualisation.report.removePartial(f); + }); + */ + _this.Filters = []; + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Drilldown to level ' + _this.drilldownlevel + ': ' + shortfilter); + joolaio.visualisation.report.setFilter(joolaio.visualisation.report.globalfilter + shortfilter); + }); + } + + if (_this.drilldownlevel == _this.levels.length - 1 && joolaio.visualisation.report.globalfilter != '' && (_datatoshow.length == 1 || (_datatoshow.length > 1 && _datatoshow[0].FormattedValues[0] == _datatoshow[1].FormattedValues[0]))) { + var $td = $tr.find('.dimensionvalue'); + var $link = $tr.find('.dimensionvalue .drilldownlink') + $link.off('click'); + $link.removeClass('drilldownlink'); + $td.removeClass('dimensionvalue'); + } + + if (_this.mode == 'pie') { + if (index == 0) { + //add the + var $th = $('Contribution to total: '); + + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation && (ao.aggregation == 'sum' || ao.aggregation == 'count')) { + $th.find('.comparemetricpicker').append('') + } + }); + + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; + } - if (_this.drilldownlevel <= _this.levels.length - 1) { - $tr.find('.drilldownlink').attr('data-filter', shortfilter); - $tr.find('.dimensionvalue .drilldownlink').off('click'); - $tr.find('.dimensionvalue .drilldownlink').on('click', function (e) { - $(this).off('click'); + }); + _this.update(_this); + }); - if (_this.drilldownlevel < _this.levels.length - 1) - _this.drilldownlevel++; + $($table.find('tr')[0]).append($th); - _this.dimensions.splice(0, _this.dimensions.length); - $(_this.levels[_this.drilldownlevel]).each(function (index, dimension) { - _this.dimensions.push(dimension); - }); + //special cell + $td = $(''); + if (!_this.DateBox.comparePeriod) + $td.attr('rowspan', _this.pageSize); + else + $td.attr('rowspan', _this.pageSize * 3); - /* - $(_this.Filters).each(function (fi, f) { - joolaio.visualisation.report.removePartial(f); - }); - */ - _this.Filters = []; + $tr.append($td); - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Drilldown to level ' + _this.drilldownlevel + ': ' + shortfilter); - joolaio.visualisation.report.setFilter(joolaio.visualisation.report.globalfilter + shortfilter); - }); + _this.drawPieChart(_this, $td, _columns, _datatoshow, _data, _totalsum_base, _totalsumcompare_base); + } + } + else if (_this.mode == 'perf') { + if (index == 0) { + //add the + var $th = $(''); + + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation) { + $th.find('.comparemetricpicker').append('') } + }); + + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; + } - if (_this.drilldownlevel == _this.levels.length - 1 && joolaio.visualisation.report.globalfilter != '' && (_datatoshow.length == 1 || (_datatoshow.length > 1 && _datatoshow[0].FormattedValues[0] == _datatoshow[1].FormattedValues[0]))) { - var $td = $tr.find('.dimensionvalue'); - var $link = $tr.find('.dimensionvalue .drilldownlink') - $link.off('click'); - $link.removeClass('drilldownlink'); - $td.removeClass('dimensionvalue'); - } + }); + _this.update(_this); + }); + $($table.find('tr')[0]).append($th); + var $header = $($table.find('tr')[0]); + $($header.find('th')[$header.find('th').length - 2]).remove(); + } + //special cell - if (_this.mode == 'pie') { - if (index == 0) { - //add the - var $th = $('Contribution to total: '); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation && (ao.aggregation == 'sum' || ao.aggregation == 'count')) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - - $($table.find('tr')[0]).append($th); - - - //special cell - $td = $(''); - if (!_this.DateBox.comparePeriod) - $td.attr('rowspan', _this.pageSize); - else - $td.attr('rowspan', _this.pageSize * 3); - - $tr.append($td); - - _this.drawPieChart(_this, $td, _columns, _datatoshow, _data, _totalsum_base, _totalsumcompare_base); - } - } - else if (_this.mode == 'perf') { - if (index == 0) { - //add the - var $th = $(''); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - $($table.find('tr')[0]).append($th); - var $header = $($table.find('tr')[0]); - $($header.find('th')[$header.find('th').length - 2]).remove(); - } - //special cell + $($tr.find('td')[$tr.find('td').length - 1]).remove(); - $($tr.find('td')[$tr.find('td').length - 1]).remove(); + var valIndex = row.FormattedValues.length - 1; + $td = $('' + row.FormattedValues[valIndex] + ''); - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row.FormattedValues[valIndex] + ''); + var value = +row.Values[valIndex]; - var value = +row.Values[valIndex]; + var width = (Math.floor(row.Values[valIndex]) ) + '%'; + var $_bar = $('
' + + '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); - var width = (Math.floor(row.Values[valIndex]) ) + '%'; - var $_bar = $('
' + - '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); + $td.html($_bar); - $td.html($_bar); + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); + } + else if (_this.mode == 'compare') { + if (index == 0) { + //add the + var $th = $(''); - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation) { + $th.find('.comparemetricpicker').append('') } - else if (_this.mode == 'compare') { - if (index == 0) { - //add the - var $th = $(''); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - $($table.find('tr')[0]).append($th); - var $header = $($table.find('tr')[0]); - $($header.find('th')[$header.find('th').length - 2]).remove(); - } - //special cell + }); + + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; + } - $($tr.find('td')[$tr.find('td').length - 1]).remove(); + }); + _this.update(_this); + }); + $($table.find('tr')[0]).append($th); + var $header = $($table.find('tr')[0]); + $($header.find('th')[$header.find('th').length - 2]).remove(); + } + //special cell - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row.FormattedValues[valIndex] + ''); + $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var value = +row.Values[valIndex]; + var valIndex = row.FormattedValues.length - 1; + $td = $('' + row.FormattedValues[valIndex] + ''); + var value = +row.Values[valIndex]; - var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; - var $_bar = $('
' + - '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); - $td.html($_bar); + var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; + var $_bar = $('
' + + '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); + $td.html($_bar); + + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); + } + else { + $($table.find('tr')[0]).find('.special').remove(); + } + + $table.append($tr); + }); + } + else { + $(_datatoshow).each(function (index, row) { + $tr = $(''); + $td = $(''); + if (_this.mode == 'pie') + $td.append('
'); + else + $td.append(''); + $tr.append($td); + $td = $('' + parseInt((_this.currentPage - 1) * (_this.pageSize) + index + 1) + '.'); + $tr.append($td); + + var filter = ''; + var shortfilter = ''; + + $(_columns).each(function (i, cell) { + $td = $(''); + + if (_columns[i].aggregation) + $td.addClass('metricvalue'); + else { + //$td.html(row.FormattedValues[i]); + $td.html('' + row.FormattedValues[i] + ''); + + if (_this.mode != 'pie') + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i != _columns.length - 1) + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); } - else { - $($table.find('tr')[0]).find('.special').remove(); + if (i == 0) { + $td.addClass('dimensionvalue'); + shortfilter = _columns[i].id + '=' + row.Values[i] + '[AND]'; } - $table.append($tr); - }); - } - else { - $(_datatoshow).each(function (index, row) { - $tr = $(''); - $td = $(''); - if (_this.mode == 'pie') - $td.append('
'); - else - $td.append(''); - $tr.append($td); - $td = $('' + parseInt((_this.currentPage - 1) * (_this.pageSize) + index + 1) + '.'); - $tr.append($td); - - var filter = ''; - var shortfilter = ''; - - $(_columns).each(function (i, cell) { - $td = $(''); - - if (_columns[i].aggregation) - $td.addClass('metricvalue'); - else { - //$td.html(row.FormattedValues[i]); - $td.html('' + row.FormattedValues[i] + ''); - - if (_this.mode != 'pie') - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i != _columns.length - 1) - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); - } - if (i == 0) { - $td.addClass('dimensionvalue'); - shortfilter = _columns[i].id + '=' + row.Values[i] + '[AND]'; - } - - filter += _columns[i].id + '=' + row.Values[i] + '[AND]' - } - - if (i == _this.sortColumnIndex) - $td.addClass('sortkey'); - - $tr.append($td); - }); + filter += _columns[i].id + '=' + row.Values[i] + '[AND]' + } - if (_this.mode == 'pie') { - if (index == 0) { - var $th = $('Contribution to total: '); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - - $($table.find('tr')[0]).append($th); - - //special cell - $td = $(''); - if (!_this.DateBox.comparePeriod) - $td.attr('rowspan', _this.pageSize); - else - $td.attr('rowspan', _this.pageSize * 3); - $tr.append($td); - - _this.drawPieChart(_this, $td, _columns, _datatoshow, _data, _totalsum_base, _totalsumcompare_base); - //_this.drawPieChart($td); - } - } - else if (_this.mode == 'perf') { - if (index == 0) { - //add the - var $th = $(''); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - $($table.find('tr')[0]).append($th); - var $header = $($table.find('tr')[0]); - $($header.find('th')[$header.find('th').length - 2]).remove(); - } - //special cell - - $($tr.find('td')[$tr.find('td').length - 1]).remove(); + if (i == _this.sortColumnIndex) + $td.addClass('sortkey'); - } - else if (_this.mode == 'compare') { - if (index == 0) { - //add the - var $th = $(''); - - $(_allcolumns).each(function (ai, ao) { - if (ao.aggregation) { - $th.find('.comparemetricpicker').append('') - } - }); - - $th.find('.comparemetricpicker').off('click'); - $th.find('.comparemetricpicker').on('click', function (e) { - e.stopPropagation(); - }); - $th.find('.comparemetricpicker').on('change', function (e) { - var selected = $(this).val(); - $(_allcolumns).each(function (ai, ao) { - if (ao.name == selected) { - _this.compareColumnIndex = ai; - } - - }); - _this.update(_this); - }); - $($table.find('tr')[0]).append($th); - var $header = $($table.find('tr')[0]); - $($header.find('th')[$header.find('th').length - 2]).remove(); - } - //special cell - - $($tr.find('td')[$tr.find('td').length - 1]).remove(); + $tr.append($td); + }); - } + if (_this.mode == 'pie') { + if (index == 0) { + var $th = $('Contribution to total: '); - var $checkbox = $tr.find('.checkfilter'); - - $checkbox.attr('data-filter', filter); - $checkbox.off('click'); - $checkbox.on('click', function (e) { - - - if ($checkbox.is(':checked')) { - - joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); - _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); - } - else { - joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); - if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { - _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); - //_this.fetch(_this); - } - } - - /* - - if ($checkbox.is(':checked')) { - joolaio.visualisation.report.addPartial(filter); - _this.Filters.push(filter); - } - else { - joolaio.visualisation.report.removePartial(filter); - if (_this.Filters.indexOf(filter) > -1) { - _this.Filters.splice(_this.Filters.indexOf(filter), 1); - //_this.fetch(_this); - } - } - */ - }); - if (_this.Filters.indexOf(filter) > -1) - $checkbox.attr('checked', true); - else - $checkbox.attr('checked', false); - - $tr.find('.drilldownlink').attr('data-filter', shortfilter); - $tr.find('.dimensionvalue .drilldownlink').off('click'); - $tr.find('.dimensionvalue .drilldownlink').on('click', function (e) { - $(this).off('click'); - if (_this.drilldownlevel < _this.levels.length - 1) - _this.drilldownlevel++; - - _this.dimensions.splice(0, _this.dimensions.length); - $(_this.levels[_this.drilldownlevel]).each(function (index, dimension) { - _this.dimensions.push(dimension); - }); - - $(_this.Filters).each(function (fi, f) { - joolaio.visualisation.report.removePartial(f); - }); - _this.Filters = []; - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Drilldown to level ' + _this.drilldownlevel + ': ' + shortfilter); - joolaio.visualisation.report.setFilter(joolaio.visualisation.report.globalfilter + shortfilter); - }); + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation) { + $th.find('.comparemetricpicker').append('') + } + }); - if (_this.drilldownlevel == _this.levels.length - 1 && joolaio.visualisation.report.globalfilter != '' && (_datatoshow.length == 1 || (_datatoshow.length > 1 && _datatoshow[0].FormattedValues[0] == _datatoshow[1].FormattedValues[0]))) { - var $td = $tr.find('.dimensionvalue'); - var $link = $tr.find('.dimensionvalue .drilldownlink') - $link.off('click'); - $link.removeClass('drilldownlink'); - $td.removeClass('dimensionvalue'); + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; } - $table.append($tr); - - $tr = $(''); - $td = $(''); - $tr.append($td); - $td = $(''); - $tr.append($td); - - $(_columns).each(function (i, cell) { - $td = $(''); - - if (_columns[i].aggregation) { - $td.addClass('metricvalue'); - //$td.html(row.FormattedValues[i]); - - if (_this.mode != 'pie') - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i != _columns.length - 1) - $td.html('' + row.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); - } - - } - else { - $td.addClass('compare-daterange'); - $td.attr('colspan', _this.dimensions.length); - if (i == 0) - $td.html(joolaio.date.formatDate(_this.DateBox.getDate().base_fromdate) + ' - ' + joolaio.date.formatDate(_this.DateBox.getDate().base_todate)); - else - $td = null; - } - - if (i == _this.sortColumnIndex && _columns[i].aggregation) - $td.addClass('sortkey'); - - $tr.append($td); - }); - - if (_this.mode == 'perf') { - $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row.FormattedValues[valIndex] + ''); - - var value = +row.Values[valIndex]; + }); + _this.update(_this); + }); - var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; - var $_bar = $('
' + - '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); + $($table.find('tr')[0]).append($th); - $td.html($_bar); + //special cell + $td = $(''); + if (!_this.DateBox.comparePeriod) + $td.attr('rowspan', _this.pageSize); + else + $td.attr('rowspan', _this.pageSize * 3); + $tr.append($td); - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); + _this.drawPieChart(_this, $td, _columns, _datatoshow, _data, _totalsum_base, _totalsumcompare_base); + //_this.drawPieChart($td); + } + } + else if (_this.mode == 'perf') { + if (index == 0) { + //add the + var $th = $(''); + + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation) { + $th.find('.comparemetricpicker').append('') + } + }); + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; } - else if (_this.mode == 'compare') { - $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row.FormattedValues[valIndex] + ''); - - var value = +row.Values[valIndex]; - var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; - var $_bar = $('
' + - '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); + }); + _this.update(_this); + }); + $($table.find('tr')[0]).append($th); + var $header = $($table.find('tr')[0]); + $($header.find('th')[$header.find('th').length - 2]).remove(); + } + //special cell - $td.html($_bar); + $($tr.find('td')[$tr.find('td').length - 1]).remove(); - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); + } + else if (_this.mode == 'compare') { + if (index == 0) { + //add the + var $th = $(''); + + $(_allcolumns).each(function (ai, ao) { + if (ao.aggregation) { + $th.find('.comparemetricpicker').append('') + } + }); + $th.find('.comparemetricpicker').off('click'); + $th.find('.comparemetricpicker').on('click', function (e) { + e.stopPropagation(); + }); + $th.find('.comparemetricpicker').on('change', function (e) { + var selected = $(this).val(); + $(_allcolumns).each(function (ai, ao) { + if (ao.name == selected) { + _this.compareColumnIndex = ai; } - $table.append($tr); - - //Compared row - $tr = $(''); - $td = $(''); - $tr.append($td); - $td = $(''); - $tr.append($td); + }); + _this.update(_this); + }); + $($table.find('tr')[0]).append($th); + var $header = $($table.find('tr')[0]); + $($header.find('th')[$header.find('th').length - 2]).remove(); + } + //special cell - var key = ''; - $(_columns).each(function (i, cell) { - if (_columns[i].aggregation == null) { - key += row.Values[i]; - } - }); + $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var row_compare; - $(_data_compare_toshow).each(function (icompare, checkrow) { - var key_compare = ''; + } - $(_columns).each(function (i, cell) { - if (_columns[i].aggregation == null) { - key_compare += checkrow.Values[i]; - } - }); + var $checkbox = $tr.find('.checkfilter'); + $checkbox.attr('data-filter', filter); + $checkbox.off('click'); + $checkbox.on('click', function (e) { - if (key == key_compare) - row_compare = checkrow; - }); - $(_columns).each(function (i, cell) { - $td = $(''); - - if (_columns[i].aggregation) { - $td.addClass('metricvalue'); - try { - //$td.html(row_compare.FormattedValues[i]); - if (_this.mode != 'pie') - $td.html('' + row_compare.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i != _columns.length - 1) - $td.html('' + row_compare.FormattedValues[i] + ''); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - $td.html('' + joolaio.string.formatNumber(row_compare.FormattedValues[i], 2) + '%'); - } - } - catch (ex) { - if (_this.mode != 'pie') - $td.html('N/A'); - else if (_this.mode == 'pie' && i != _columns.length - 1) - $td.html('N/A'); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - $td.html('N/A'); - } - } - } - else { - $td.addClass('compare-daterange'); - $td.attr('colspan', _this.dimensions.length); - if (i == 0) - $td.html(joolaio.date.formatDate(_this.DateBox.getDate().compare_fromdate) + ' - ' + joolaio.date.formatDate(_this.DateBox.getDate().compare_todate)); - else - $td = null; - } - - if (i == _this.sortColumnIndex && _columns[i].aggregation) - $td.addClass('sortkey'); - - $tr.append($td); - }); - if (_this.mode == 'perf') { - var $_bar; - try { - $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row_compare.FormattedValues[valIndex] + ''); - - var value = +row_compare.Values[valIndex]; - - var width = (Math.floor(row_compare.Values[valIndex]) - 5) + 'px'; - $_bar = $('
' + - '' + joolaio.string.formatNumber(row_compare.Values[valIndex], 2) + '%
'); - } - catch (ex) { - $td = $('0'); - $_bar = $('
' + - '' + joolaio.string.formatNumber(0, 2) + '%
'); - } - $td.html($_bar); - - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); - } - else if (_this.mode == 'compare') { - var $_bar; - try { - $($tr.find('td')[$tr.find('td').length - 1]).remove(); - var valIndex = row.FormattedValues.length - 1; - $td = $('' + row_compare.FormattedValues[valIndex] + ''); - - var value = +row_compare.Values[valIndex]; - - var width = (Math.floor(row_compare.Values[valIndex]) - 5) + 'px'; - $_bar = $('
' + - '' + joolaio.string.formatNumber(row_compare.Values[valIndex], 2) + '%
'); - } - catch (ex) { - $td = $('0'); - $_bar = $('
' + - '' + joolaio.string.formatNumber(0, 2) + '%
'); - } - $td.html($_bar); - - //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); - $tr.append($td); + if ($checkbox.is(':checked')) { - } - $table.append($tr); - - if (_this.mode == 'table') { - //Summary row - $tr = $(''); - $td = $(''); - $tr.append($td); - $td = $(''); - $tr.append($td); - - $(_columns).each(function (i, cell) { - $td = $(''); - - if (_columns[i].aggregation) { - var useNA = false; - $td.addClass('metricvalue comparison'); - - try { - var value = percentageChange(row_compare.Values[i], row.Values [i]); - } - catch (ex) { - value = 0; - useNA = true; - } - - var _class = ''; - var metric = cell; - if (metric.ratiodirection == -1 && value < 0) - _class = 'positive'; - if (metric.ratiodirection == -1 && value > 0) - _class = 'negative'; - if (metric.ratiodirection == 1 && value > 0) - _class = 'positive'; - if (metric.ratiodirection == 1 && value < 0) - _class = 'negative'; - if (_class == '') - _class = 'neutral'; - - if (_this.mode != 'pie') - //$td.html(joolaio.string.formatNumber(value, 2) + '%'); - if (useNA) - $td.html('N/A'); - else - $td.html(joolaio.string.formatNumber(value, 2) + '%'); - else if (_this.mode == 'pie' && i != _columns.length - 1) - //$td.html(joolaio.string.formatNumber(value, 2) + '%'); - if (useNA) - $td.html('N/A'); - else - $td.html(joolaio.string.formatNumber(value, 2) + '%'); - else if (_this.mode == 'pie' && i == _columns.length - 1) { - //$td.html('N/A'); - - if (useNA) - $td.html('N/A'); - else - $td.html(joolaio.string.formatNumber(value, 2) + '%'); - } - - $td.addClass(_class); - } - else { - $td.addClass('comparison'); - $td.attr('colspan', _this.dimensions.length); - if (i == 0) - $td.html('% Change'); - else - $td = null; - } - - if (i == _this.sortColumnIndex && _columns[i].aggregation) - $td.addClass('sortkey'); - - $tr.append($td); - }); - $table.append($tr); - } + joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); + _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); + } + else { + joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); + if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { + _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); + //_this.fetch(_this); } - ); - } - + } + + /* + + if ($checkbox.is(':checked')) { + joolaio.visualisation.report.addPartial(filter); + _this.Filters.push(filter); + } + else { + joolaio.visualisation.report.removePartial(filter); + if (_this.Filters.indexOf(filter) > -1) { + _this.Filters.splice(_this.Filters.indexOf(filter), 1); + //_this.fetch(_this); + } + } + */ + }); + if (_this.Filters.indexOf(filter) > -1) + $checkbox.attr('checked', true); + else + $checkbox.attr('checked', false); - var first = (_this.currentPage - 1) * (_this.pageSize) + 1; - var last = _this.currentPage * _this.pageSize; + $tr.find('.drilldownlink').attr('data-filter', shortfilter); + $tr.find('.dimensionvalue .drilldownlink').off('click'); + $tr.find('.dimensionvalue .drilldownlink').on('click', function (e) { + $(this).off('click'); + if (_this.drilldownlevel < _this.levels.length - 1) + _this.drilldownlevel++; - if (last > _data.length) - last = _data.length; + _this.dimensions.splice(0, _this.dimensions.length); + $(_this.levels[_this.drilldownlevel]).each(function (index, dimension) { + _this.dimensions.push(dimension); + }); - if (_this.mode == 'pie' && _datatoshow.length < _this.pageSize) { - for (i = _datatoshow.length; i < _this.pageSize; i++) { - var $tr = $(''); - var $td = $(' '); - $tr.append($td); - $table.append($tr); + $(_this.Filters).each(function (fi, f) { + joolaio.visualisation.report.removePartial(f); + }); + _this.Filters = []; + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Drilldown to level ' + _this.drilldownlevel + ': ' + shortfilter); + joolaio.visualisation.report.setFilter(joolaio.visualisation.report.globalfilter + shortfilter); + }); - if ($table.find('tr').length > 10) - break; + if (_this.drilldownlevel == _this.levels.length - 1 && joolaio.visualisation.report.globalfilter != '' && (_datatoshow.length == 1 || (_datatoshow.length > 1 && _datatoshow[0].FormattedValues[0] == _datatoshow[1].FormattedValues[0]))) { + var $td = $tr.find('.dimensionvalue'); + var $link = $tr.find('.dimensionvalue .drilldownlink') + $link.off('click'); + $link.removeClass('drilldownlink'); + $td.removeClass('dimensionvalue'); } - } - var $footer = $($(_this.Container).find('.bottomfooter')); - var $pager = $footer.find('.pager .pageinfoselect'); + $table.append($tr); - $pager.val(_this.pageSize); + $tr = $(''); + $td = $(''); + $tr.append($td); + $td = $(''); + $tr.append($td); + $(_columns).each(function (i, cell) { + $td = $(''); - var $pageinfo = $footer.find('.pageinfo'); - $pageinfo.html(first + ' - ' + last + ' of ' + _data.length); + if (_columns[i].aggregation) { + $td.addClass('metricvalue'); + //$td.html(row.FormattedValues[i]); - var $pagecontrol = $footer.find('.pagecontrol'); + if (_this.mode != 'pie') + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i != _columns.length - 1) + $td.html('' + row.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + $td.html('' + joolaio.string.formatNumber(row.FormattedValues[i], 2) + '%'); + } - if (_this.currentPage > 1) { - $($pagecontrol).find('.prev').removeClass('disabled'); - } - else { - $($pagecontrol).find('.prev').addClass('disabled'); - } + } + else { + $td.addClass('compare-daterange'); + $td.attr('colspan', _this.dimensions.length); + if (i == 0) + $td.html(joolaio.date.formatDate(_this.DateBox.getDate().base_fromdate) + ' - ' + joolaio.date.formatDate(_this.DateBox.getDate().base_todate)); + else + $td = null; + } - if (last < _data.length) { - $($pagecontrol).find('.next').removeClass('disabled'); - } - else { - $($pagecontrol).find('.next').addClass('disabled'); - } + if (i == _this.sortColumnIndex && _columns[i].aggregation) + $td.addClass('sortkey'); - var $charttype = $(_this.Container).find('.tabletype'); - $charttype.find('button').each(function (i, o) { - $(this).removeClass('active'); - }); - $charttype.find('.btn_' + this.mode).addClass('active'); - - var $tablecontrol = $(_this.Container).find('.tablecontrol'); - if (_this.dimensions.length > 1) { - var _html = 'Secondary dimension' + (_this.dimensions.length > 2 ? 's' : '') + ': '; - $(_this.dimensions).each(function (i, d) { - if (i > 0) - _html += d.name + ', '; - }); - _html = _html.substring(0, _html.length - 2); - $($tablecontrol).find('.secondarybutton').html(_html); - - var o = new joolaio.visualisation.picker.Dimensions({ - container: $item, - prefix: 'Secondary dimension: ', - placeholdertext: 'Add secondary dimension...', - exclude: _this.options.excludeDimensions, - selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) + $tr.append($td); }); - } - else { - //$($tablecontrol).find('.secondarybutton').html('Secondary dimension...'); - var $item = $('
'); - $($tablecontrol).find('.secondary').empty(); - $($tablecontrol).find('.secondary').append($item); - var o = new joolaio.visualisation.picker.Dimensions({ - container: $item, - prefix: 'Secondary dimension: ', - placeholdertext: 'Add secondary dimension...', - exclude: _this.options.excludeDimensions, - selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) - }); + if (_this.mode == 'perf') { + $($tr.find('td')[$tr.find('td').length - 1]).remove(); + var valIndex = row.FormattedValues.length - 1; + $td = $('' + row.FormattedValues[valIndex] + ''); - _this.dimensionPicker.disableDimension(o, _this.dimensions[0]); - $(o).bind('select', function (data, dimension) { - joolaio.visualisation.report.table.Filters = []; - dimension = _.find(joolaio.objects.Dimensions, function (item) { - return item.name == dimension - }); - if (_this.dimensions.indexOf(dimension) == -1) { - /*$dimlist.find('li').each(function (i, o) { - $(this).removeClass('active'); - });*/ - //$(this).addClass('active'); - if (_this.dimensions.length == 1) { - _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; - _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; - _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; - } - else { - _this.dimensions.splice(1, 1); - } - _this.dimensions.push(dimension); - _this.fetch(_this); + var value = +row.Values[valIndex]; - } - }) - } + var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; + var $_bar = $('
' + + '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); + $td.html($_bar); - if (!_this.isother) { - $('.japi.primarydimension').html(_this.levels[_this.drilldownlevel][0].name); - $('.japi.primarydimension').addClass('on'); - $('.japi.other.picker').removeClass('on'); - $('.japi.other.picker .jbtn').html('Other '); - } + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); - else { - $('.japi.primarydimension').removeClass('on'); - $('.drilldownlink').off('click'); - $('.drilldownlink').addClass('disabled'); - $('.drilldownlink').parent().addClass('disabled'); + } + else if (_this.mode == 'compare') { + $($tr.find('td')[$tr.find('td').length - 1]).remove(); + var valIndex = row.FormattedValues.length - 1; + $td = $('' + row.FormattedValues[valIndex] + ''); - } + var value = +row.Values[valIndex]; + + var width = (Math.floor(row.Values[valIndex]) - 5) + 'px'; + var $_bar = $('
' + + '' + joolaio.string.formatNumber(row.Values[valIndex], 2) + '%
'); + + $td.html($_bar); + + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); - if (_this.drilldownlevel > 0 || (_this.drilldownlevel == 0 && _this.levels.length == 1)) - $('.japi.other.picker').css('visibility', 'visible'); - else - $('.japi.other.picker').css('visibility', 'hidden'); - _this.setState(_this); - - //$(joolaio).unbind('joolaio-reportTable-update'); - //$(joolaio).bind('joolaio-reportTable-update', function () { - - if (_this.options.defaultSelected > 0 && _this.Filters == '') { - for (var i = 0; i < _this.options.defaultSelected; i++) { - $($('.checkfilter')[i]).attr('checked', 'true'); - var _filter = $($('.checkfilter')[i]).attr('data-filter'); - if (typeof _filter != 'undefined'){ - $(joolaio.visualisation.report).trigger('addpartialfilter', _filter); - _this.Filters.push(_filter); - } } - //console.log('filters',_this.Filters); - } + $table.append($tr); - //}); - //$(joolaio).trigger('joolaio-reportTable-update'); - $(joolaio).trigger('tableresize'); -}; + //Compared row + $tr = $(''); + $td = $(''); + $tr.append($td); + $td = $(''); + $tr.append($td); -joolaio.visualisation.report.Table.prototype.updateCompare = function (sender, metric, series) { - var _this = sender; -}; + var key = ''; + $(_columns).each(function (i, cell) { + if (_columns[i].aggregation == null) { + key += row.Values[i]; + } + }); -joolaio.visualisation.report.Table.prototype.drawPieChart = function (sender, Container, columns, data, alldata, _totalsum, _totalsumcompare) { - var _this = sender; - var chart = new Highcharts.Chart({ - chart: { - renderTo: $(Container).get(0), - backgroundColor: null, - plotBackgroundColor: null, - plotBorderWidth: null, - plotShadow: false, - width: 300, - height: 300, - type: 'pie', - marginTop: 0, - marginLeft: 0, - marginRight: 0, - marginBottom: 0, - spacingLeft: 0, - spacingTop: 0, - spacingRight: 0, - spacingBottom: 0 - }, - title: { - text: null - }, - tooltip: { - formatter: function () { - return '' + this.point.name + '
' + this.series.name + ': ' + joolaio.string.formatNumber(this.percentage, 2) + ' %'; + var row_compare; + $(_data_compare_toshow).each(function (icompare, checkrow) { + var key_compare = ''; + + $(_columns).each(function (i, cell) { + if (_columns[i].aggregation == null) { + key_compare += checkrow.Values[i]; } - }, - legend: { - enabled: false - }, - credits: { - enabled: false - }, - exporting: { - enabled: false - }, - plotOptions: { - pie: { - showInLegend: true, - size: '90%' + }); + + + if (key == key_compare) + row_compare = checkrow; + }); + $(_columns).each(function (i, cell) { + $td = $(''); + + if (_columns[i].aggregation) { + $td.addClass('metricvalue'); + try { + //$td.html(row_compare.FormattedValues[i]); + if (_this.mode != 'pie') + $td.html('' + row_compare.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i != _columns.length - 1) + $td.html('' + row_compare.FormattedValues[i] + ''); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + $td.html('' + joolaio.string.formatNumber(row_compare.FormattedValues[i], 2) + '%'); + } } - }, - series: [ - { - name: function () { - //var name = 'test'; - //$(columns).each(function (ci, co) { - // if (co.aggregation) { - var name = columns[columns.length - 2].name; - // } - //}); - return name; - }(), - type: 'pie', - data: function () { - var result = []; - var sum = 0; - - $(data).each(function (index, item) { - if (index < 10) { - var name = ''; - $(columns).each(function (ci, co) { - if (co.aggregation) { - - } - else - name += columns[ci].name + ': ' + item.FormattedValues[ci] + '
'; - }); - name = name.substring(0, name.length - 5); - var y = item.Values[item.Values.length - 2] / _totalsum * 100; - sum += y; - result.push({name: name, y: y, color: joolaio.colors[index]}); - } - }); - - if (100 - Math.floor(sum) > 0) { - var name = 'Other'; - var y = 100 - sum; - result.push({name: name, y: y, color: joolaio.colors[11]}); - } - - return result; - }(), - dataLabels: { - formatter: function () { - return this.y > 5 ? this.point.name : null; - }, - color: 'white', - distance: -30, - enabled: false - } - }, - { - name: function () { - //var name = 'test'; - //$(columns).each(function (ci, co) { - // if (co.aggregation) { - var name = columns[columns.length - 1].name; - // } - //}); - return name; - }(), - type: 'pie', - innerSize: '70%', - data: function () { - var result = []; - if (_this.ColumnIndex != _this.compareColumnIndex) { - var sum = 0; - - $(data).each(function (index, item) { - - if (index < 10) { - var name = ''; - $(columns).each(function (ci, co) { - if (co.aggregation) { - - } - else - name += columns[ci].name + ': ' + item.FormattedValues[ci] + '
'; - }); - name = name.substring(0, name.length - 5); - y = item.Values[item.Values.length - 1]; - sum += y; - result.push({name: name, y: y, color: joolaio.colors[index]}); - } - }); - - if (100 - Math.floor(sum) > 0) { - var name = 'Other'; - var y = 100 - sum; - result.push({name: name, y: y, color: joolaio.colors[11]}); - } - } - - return result; - }(), - - dataLabels: { - formatter: function () { - // display only if larger than 1 - return this.y > 1 ? '' + this.point.name + ': ' + this.y + '%' : null; - }, - enabled: false - } + catch (ex) { + if (_this.mode != 'pie') + $td.html('N/A'); + else if (_this.mode == 'pie' && i != _columns.length - 1) + $td.html('N/A'); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + $td.html('N/A'); + } } - ] - }); -}; + } + else { + $td.addClass('compare-daterange'); + $td.attr('colspan', _this.dimensions.length); + if (i == 0) + $td.html(joolaio.date.formatDate(_this.DateBox.getDate().compare_fromdate) + ' - ' + joolaio.date.formatDate(_this.DateBox.getDate().compare_todate)); + else + $td = null; + } -joolaio.visualisation.report.Table.prototype.draw = function (Container) { - var _this = this; + if (i == _this.sortColumnIndex && _columns[i].aggregation) + $td.addClass('sortkey'); - var _html = '
'; - var $table = $(_html); - $(Container).append($table); + $tr.append($td); + }); + if (_this.mode == 'perf') { + var $_bar; + try { + $($tr.find('td')[$tr.find('td').length - 1]).remove(); + var valIndex = row.FormattedValues.length - 1; + $td = $('' + row_compare.FormattedValues[valIndex] + ''); + + var value = +row_compare.Values[valIndex]; + + var width = (Math.floor(row_compare.Values[valIndex]) - 5) + 'px'; + $_bar = $('
' + + '' + joolaio.string.formatNumber(row_compare.Values[valIndex], 2) + '%
'); + } + catch (ex) { + $td = $('0'); + $_bar = $('
' + + '' + joolaio.string.formatNumber(0, 2) + '%
'); + } + $td.html($_bar); + + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); - //paging - //_html = '' + row_compare.FormattedValues[valIndex] + ''); + + var value = +row_compare.Values[valIndex]; + + var width = (Math.floor(row_compare.Values[valIndex]) - 5) + 'px'; + $_bar = $('
' + + '' + joolaio.string.formatNumber(row_compare.Values[valIndex], 2) + '%
'); + } + catch (ex) { + $td = $('0'); + $_bar = $('
' + + '' + joolaio.string.formatNumber(0, 2) + '%
'); + } + $td.html($_bar); + + //_this.drawBar(_this, $td, value, _data, _totalsum_base, _totalsumcompare_base); + $tr.append($td); + } + $table.append($tr); + + if (_this.mode == 'table') { + //Summary row + $tr = $(''); + $td = $(''); + $tr.append($td); + $td = $(''); + $tr.append($td); + + $(_columns).each(function (i, cell) { + $td = $(''); + + if (_columns[i].aggregation) { + var useNA = false; + $td.addClass('metricvalue comparison'); + + try { + var value = percentageChange(row_compare.Values[i], row.Values [i]); + } + catch (ex) { + value = 0; + useNA = true; + } + + var _class = ''; + var metric = cell; + if (metric.ratiodirection == -1 && value < 0) + _class = 'positive'; + if (metric.ratiodirection == -1 && value > 0) + _class = 'negative'; + if (metric.ratiodirection == 1 && value > 0) + _class = 'positive'; + if (metric.ratiodirection == 1 && value < 0) + _class = 'negative'; + if (_class == '') + _class = 'neutral'; + + if (_this.mode != 'pie') + //$td.html(joolaio.string.formatNumber(value, 2) + '%'); + if (useNA) + $td.html('N/A'); + else + $td.html(joolaio.string.formatNumber(value, 2) + '%'); + else if (_this.mode == 'pie' && i != _columns.length - 1) + //$td.html(joolaio.string.formatNumber(value, 2) + '%'); + if (useNA) + $td.html('N/A'); + else + $td.html(joolaio.string.formatNumber(value, 2) + '%'); + else if (_this.mode == 'pie' && i == _columns.length - 1) { + //$td.html('N/A'); - var $header = $('
'); - var $headercontent = $('
'); - $header.append($headercontent); - $(Container).prepend($header); + if (useNA) + $td.html('N/A'); + else + $td.html(joolaio.string.formatNumber(value, 2) + '%'); + } - var $footer = $('
'); - var $footer_content = $('
'); + $td.addClass(_class); + } + else { + $td.addClass('comparison'); + $td.attr('colspan', _this.dimensions.length); + if (i == 0) + $td.html('% Change'); + else + $td = null; + } - $footer_content.append('
') + if (i == _this.sortColumnIndex && _columns[i].aggregation) + $td.addClass('sortkey'); - _html = 'Show rows: '; + $tr.append($td); + }); + $table.append($tr); + } + } + ); + } - $footer_content.find('.pager').html(_html); - $footer_content.find('.pager .pageinfoselect').off('change'); - $footer_content.find('.pager .pageinfoselect').on('change', function (e) { - _this.pageSize = $(this).val(); - _this.update(_this); - }); - _html = '';//'x - y of ' + 'z'; - $footer_content.find('.pageinfo').html(_html); - $footer.append($footer_content); + var first = (_this.currentPage - 1) * (_this.pageSize) + 1; + var last = _this.currentPage * _this.pageSize; - _html = '
'; - $footer_content.find('.pagecontrol').html(_html); - $footer_content.find('.pagecontrol .prev').off('click'); - $footer_content.find('.pagecontrol .prev').on('click', function (e) { - if (!$(this).hasClass('disabled')) { - _this.currentPage -= 1; - _this.update(_this); - } - }); - $footer_content.find('.pagecontrol .next').off('click'); - $footer_content.find('.pagecontrol .next').on('click', function (e) { - if (!$(this).hasClass('disabled')) { - _this.currentPage += 1; - _this.update(_this); - } - }); + if (last > _data.length) + last = _data.length; - $footer.append($footer_content); + if (_this.mode == 'pie' && _datatoshow.length < _this.pageSize) { + for (i = _datatoshow.length; i < _this.pageSize; i++) { + var $tr = $(''); + var $td = $(' '); + $tr.append($td); + $table.append($tr); - $(Container).append($footer); + if ($table.find('tr').length > 10) + break; + } + } - _html = '
Primary Dimension: '; - _html += '
  • '; - _html += 'Name' + '
  • '; - _html += '
    '; - _html += '' + - '
    ' + - '
    '; + var $footer = $($(_this.Container).find('.bottomfooter')); + var $pager = $footer.find('.pager .pageinfoselect'); - $header.append(_html); + $pager.val(_this.pageSize); - var $tablecontrol = $('
    '); - $tablecontrol.append('
    '); - $tablecontrol.append('
    Advanced
    '); - var $charttype = $('
    '); - $charttype.append(''); - $charttype.append(''); - $charttype.append(''); - /* $charttype.append('');*/ + var $pageinfo = $footer.find('.pageinfo'); + $pageinfo.html(first + ' - ' + last + ' of ' + _data.length); + var $pagecontrol = $footer.find('.pagecontrol'); - $tablecontrol.find('.add-on').off('click'); - $tablecontrol.find('.add-on').on('click', function (e) { + if (_this.currentPage > 1) { + $($pagecontrol).find('.prev').removeClass('disabled'); + } + else { + $($pagecontrol).find('.prev').addClass('disabled'); + } - var $search = $($tablecontrol.find('.quicksearch')[$tablecontrol.find('.quicksearch').length - 1]); + if (last < _data.length) { + $($pagecontrol).find('.next').removeClass('disabled'); + } + else { + $($pagecontrol).find('.next').addClass('disabled'); + } - $(_this.Filters).each(function (fi, f) { - joolaio.visualisation.report.removePartial(f); - }); - _this.Filters = []; + var $charttype = $(_this.Container).find('.tabletype'); + $charttype.find('button').each(function (i, o) { + $(this).removeClass('active'); + }); + $charttype.find('.btn_' + this.mode).addClass('active'); - if ($search.val() == '') { - joolaio.visualisation.report.setFilter(''); - } - else { - var shortfilter = _this.dimensions[0].id + '*=' + $search.val() + '[AND]'; - joolaio.visualisation.report.setFilter(shortfilter); - } + var $tablecontrol = $(_this.Container).find('.tablecontrol'); + if (_this.dimensions.length > 1) { + var _html = 'Secondary dimension' + (_this.dimensions.length > 2 ? 's' : '') + ': '; + $(_this.dimensions).each(function (i, d) { + if (i > 0) + _html += d.name + ', '; }); + _html = _html.substring(0, _html.length - 2); + $($tablecontrol).find('.secondarybutton').html(_html); - $tablecontrol.find('.quicksearch').keypress(function (e) { - if (e.which == 13) { - $tablecontrol.find('.add-on').click(); - } + var o = new joolaio.visualisation.picker.Dimensions({ + container: $item, + prefix: 'Secondary dimension: ', + placeholdertext: 'Add secondary dimension...', + exclude: _this.options.excludeDimensions, + selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) }); - $charttype.find('.btn_table').off('click'); - $charttype.find('.btn_table').on('click', function (e) { - _this.mode = 'table'; - _this.update(_this); + } + else { + //$($tablecontrol).find('.secondarybutton').html('Secondary dimension...'); + var $item = $('
    '); + $($tablecontrol).find('.secondary').empty(); + $($tablecontrol).find('.secondary').append($item); + var o = new joolaio.visualisation.picker.Dimensions({ + container: $item, + prefix: 'Secondary dimension: ', + placeholdertext: 'Add secondary dimension...', + exclude: _this.options.excludeDimensions, + selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) }); - $charttype.find('.btn_pie').off('click'); - $charttype.find('.btn_pie').on('click', function (e) { - _this.mode = 'pie'; - _this.sortColumnIndex = -1; - _this.update(_this); - }); + _this.dimensionPicker.disableDimension(o, _this.dimensions[0]); + $(o).bind('select', function (data, dimension) { + if (joolaio.visualisation.report.table); + joolaio.visualisation.report.table.Filters = []; + dimension = _.find(joolaio.objects.Dimensions, function (item) { + return item.name == dimension + }); + if (_this.dimensions.indexOf(dimension) == -1) { + /*$dimlist.find('li').each(function (i, o) { + $(this).removeClass('active'); + });*/ + //$(this).addClass('active'); + if (_this.dimensions.length == 1) { + _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; + _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; + _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; + } + else { + _this.dimensions.splice(1, 1); + } + _this.dimensions.push(dimension); + _this.fetch(_this); - $charttype.find('.btn_perf').off('click'); - $charttype.find('.btn_perf').on('click', function (e) { - _this.mode = 'perf'; - _this.sortColumnIndex = -1; - _this.update(_this); - }); + } + }) + } - $charttype.find('.btn_compare').off('click'); - $charttype.find('.btn_compare').on('click', function (e) { - _this.mode = 'compare'; - _this.sortColumnIndex = -1; - _this.update(_this); - }); + if (!_this.isother) { + $('.japi.primarydimension').html(_this.levels[_this.drilldownlevel][0].name); + $('.japi.primarydimension').addClass('on'); + $('.japi.other.picker').removeClass('on'); + $('.japi.other.picker .jbtn').html('Other '); + } + + else { + $('.japi.primarydimension').removeClass('on'); + $('.drilldownlink').off('click'); + $('.drilldownlink').addClass('disabled'); + $('.drilldownlink').parent().addClass('disabled'); + + } + + if (_this.drilldownlevel > 0 || (_this.drilldownlevel == 0 && _this.levels.length == 1)) + $('.japi.other.picker').css('visibility', 'visible'); + else + $('.japi.other.picker').css('visibility', 'hidden'); + _this.setState(_this); + + //$(joolaio).unbind('joolaio-reportTable-update'); + //$(joolaio).bind('joolaio-reportTable-update', function () { + + if (_this.options.defaultSelected > 0 && _this.Filters == '') { + for (var i = 0; i < _this.options.defaultSelected; i++) { + $($('.checkfilter')[i]).attr('checked', 'true'); + var _filter = $($('.checkfilter')[i]).attr('data-filter'); + if (typeof _filter != 'undefined') { + $(joolaio.visualisation.report).trigger('addpartialfilter', _filter); + _this.Filters.push(_filter); + } + } - $tablecontrol.find('.tabletype').html($charttype); + //console.log('filters',_this.Filters); + } + //}); + //$(joolaio).trigger('joolaio-reportTable-update'); + $(joolaio).trigger('tableresize'); +}; - var $dimlist = $($tablecontrol.find('.joolaio.secondarylistcontainer')); - $dimlist.append($('')); +joolaio.visualisation.report.Table.prototype.updateCompare = function (sender, metric, series) { + var _this = sender; +}; +joolaio.visualisation.report.Table.prototype.drawPieChart = function (sender, Container, columns, data, alldata, _totalsum, _totalsumcompare) { + var _this = sender; + var chart = new Highcharts.Chart({ + chart: { + renderTo: $(Container).get(0), + backgroundColor: null, + plotBackgroundColor: null, + plotBorderWidth: null, + plotShadow: false, + width: 300, + height: 300, + type: 'pie', + marginTop: 0, + marginLeft: 0, + marginRight: 0, + marginBottom: 0, + spacingLeft: 0, + spacingTop: 0, + spacingRight: 0, + spacingBottom: 0 + }, + title: { + text: null + }, + tooltip: { + formatter: function () { + return '' + this.point.name + '
    ' + this.series.name + ': ' + joolaio.string.formatNumber(this.percentage, 2) + ' %'; + } + }, + legend: { + enabled: false + }, + credits: { + enabled: false + }, + exporting: { + enabled: false + }, + plotOptions: { + pie: { + showInLegend: true, + size: '90%' + } + }, + series: [ + { + name: function () { + //var name = 'test'; + //$(columns).each(function (ci, co) { + // if (co.aggregation) { + var name = columns[columns.length - 2].name; + // } + //}); + return name; + }(), + type: 'pie', + data: function () { + var result = []; + var sum = 0; + + $(data).each(function (index, item) { + if (index < 10) { + var name = ''; + $(columns).each(function (ci, co) { + if (co.aggregation) { - var $item = $('
    '); - $($tablecontrol).find('.secondary').empty(); - $($tablecontrol).find('.secondary').append($item); - var o = new joolaio.visualisation.picker.Dimensions({ - container: $item, - prefix: 'Secondary dimension: ', - placeholdertext: 'Add secondary dimension...', - selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) - }); - _this.dimensionPicker = o; - $(o).bind('select', function (data, dimension) { - dimension = _.find(joolaio.objects.Dimensions, function (item) { - return item.name == dimension - }); - if (_this.dimensions.indexOf(dimension) == -1) { - /*$dimlist.find('li').each(function (i, o) { - $(this).removeClass('active'); - });*/ - //$(this).addClass('active'); - if (_this.dimensions.length == 1) { - _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; - _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; - _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; + } + else + name += columns[ci].name + ': ' + item.FormattedValues[ci] + '
    '; + }); + name = name.substring(0, name.length - 5); + var y = item.Values[item.Values.length - 2] / _totalsum * 100; + sum += y; + result.push({name: name, y: y, color: joolaio.colors[index]}); } - else { - _this.dimensions.splice(1, 1); + }); + + if (100 - Math.floor(sum) > 0) { + var name = 'Other'; + var y = 100 - sum; + result.push({name: name, y: y, color: joolaio.colors[11]}); + } + + return result; + }(), + dataLabels: { + formatter: function () { + return this.y > 5 ? this.point.name : null; + }, + color: 'white', + distance: -30, + enabled: false + } + }, + { + name: function () { + //var name = 'test'; + //$(columns).each(function (ci, co) { + // if (co.aggregation) { + var name = columns[columns.length - 1].name; + // } + //}); + return name; + }(), + type: 'pie', + innerSize: '70%', + data: function () { + var result = []; + if (_this.ColumnIndex != _this.compareColumnIndex) { + var sum = 0; + + $(data).each(function (index, item) { + + if (index < 10) { + var name = ''; + $(columns).each(function (ci, co) { + if (co.aggregation) { + + } + else + name += columns[ci].name + ': ' + item.FormattedValues[ci] + '
    '; + }); + name = name.substring(0, name.length - 5); + y = item.Values[item.Values.length - 1]; + sum += y; + result.push({name: name, y: y, color: joolaio.colors[index]}); + } + }); + + if (100 - Math.floor(sum) > 0) { + var name = 'Other'; + var y = 100 - sum; + result.push({name: name, y: y, color: joolaio.colors[11]}); } - _this.dimensions.push(dimension); - _this.fetch(_this); + } + + return result; + }(), + dataLabels: { + formatter: function () { + // display only if larger than 1 + return this.y > 1 ? '' + this.point.name + ': ' + this.y + '%' : null; + }, + enabled: false } - }); + } + ] + }); +}; - $item = $($header.find('.japi.other.picker.dropdown')); - o = new joolaio.visualisation.picker.Dimensions({ - container: $item, - prefix: '', - placeholdertext: 'Other', - type: 'none', - exclude: _this.options.excludeDimensions, - selected: (_this.isother ? _this.dimensions[0].name : '') +joolaio.visualisation.report.Table.prototype.draw = function (Container) { + var _this = this; + + var _html = '
    '; + var $table = $(_html); + $(Container).append($table); + + //paging + //_html = ''); + var $headercontent = $('
    '); + $header.append($headercontent); + $(Container).prepend($header); + + var $footer = $('
    '); + var $footer_content = $('
    '); + + $footer_content.append('
    ') + + _html = 'Show rows: '; + + $footer_content.find('.pager').html(_html); + $footer_content.find('.pager .pageinfoselect').off('change'); + $footer_content.find('.pager .pageinfoselect').on('change', function (e) { + _this.pageSize = $(this).val(); + _this.update(_this); + }); + + _html = '';//'x - y of ' + 'z'; + $footer_content.find('.pageinfo').html(_html); + $footer.append($footer_content); + + _html = '
    '; + $footer_content.find('.pagecontrol').html(_html); + $footer_content.find('.pagecontrol .prev').off('click'); + $footer_content.find('.pagecontrol .prev').on('click', function (e) { + if (!$(this).hasClass('disabled')) { + _this.currentPage -= 1; + _this.update(_this); + } + }); + $footer_content.find('.pagecontrol .next').off('click'); + $footer_content.find('.pagecontrol .next').on('click', function (e) { + if (!$(this).hasClass('disabled')) { + _this.currentPage += 1; + _this.update(_this); + } + }); + + $footer.append($footer_content); + + $(Container).append($footer); + + _html = '
    Primary Dimension: '; + _html += '
  • '; + _html += 'Name' + '
  • '; + _html += '
    '; + _html += '' + + '
    ' + + '
    '; + + $header.append(_html); + + var $tablecontrol = $('
    '); + $tablecontrol.append('
    '); + $tablecontrol.append('
    Advanced
    '); + + var $charttype = $('
    '); + $charttype.append(''); + $charttype.append(''); + $charttype.append(''); + /* $charttype.append('');*/ + + + $tablecontrol.find('.add-on').off('click'); + $tablecontrol.find('.add-on').on('click', function (e) { + + var $search = $($tablecontrol.find('.quicksearch')[$tablecontrol.find('.quicksearch').length - 1]); + + $(_this.Filters).each(function (fi, f) { + joolaio.visualisation.report.removePartial(f); }); + _this.Filters = []; - $(o).bind('select', function (data, dimension) { - dimension = _.find(joolaio.objects.Dimensions, function (item) { - return item.name == dimension - }); - if (_this.dimensions.indexOf(dimension) == -1) { - /*$dimlist.find('li').each(function (i, o) { - $(this).removeClass('active'); - });*/ - //$(this).addClass('active'); - /* - if (_this.dimensions.length == 1) { - _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; - _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; - _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; - } - else { - _this.dimensions.splice(1, 1); - }*/ - _this.dimensions[0] = dimension; - _this.isother = true; - _this.fetch(_this); + if ($search.val() == '') { + joolaio.visualisation.report.setFilter(''); + } + else { + var shortfilter = _this.dimensions[0].id + '*=' + $search.val() + '[AND]'; + joolaio.visualisation.report.setFilter(shortfilter); + } + }); - } + $tablecontrol.find('.quicksearch').keypress(function (e) { + if (e.which == 13) { + $tablecontrol.find('.add-on').click(); + } + }); + + $charttype.find('.btn_table').off('click'); + $charttype.find('.btn_table').on('click', function (e) { + _this.mode = 'table'; + _this.update(_this); + }); + + $charttype.find('.btn_pie').off('click'); + $charttype.find('.btn_pie').on('click', function (e) { + _this.mode = 'pie'; + _this.sortColumnIndex = -1; + _this.update(_this); + }); + + $charttype.find('.btn_perf').off('click'); + $charttype.find('.btn_perf').on('click', function (e) { + _this.mode = 'perf'; + _this.sortColumnIndex = -1; + _this.update(_this); + }); + + $charttype.find('.btn_compare').off('click'); + $charttype.find('.btn_compare').on('click', function (e) { + _this.mode = 'compare'; + _this.sortColumnIndex = -1; + _this.update(_this); + }); + + $tablecontrol.find('.tabletype').html($charttype); + + + var $dimlist = $($tablecontrol.find('.joolaio.secondarylistcontainer')); + $dimlist.append($('')); + + + var $item = $('
    '); + $($tablecontrol).find('.secondary').empty(); + $($tablecontrol).find('.secondary').append($item); + var o = new joolaio.visualisation.picker.Dimensions({ + container: $item, + prefix: 'Secondary dimension: ', + placeholdertext: 'Add secondary dimension...', + selected: (_this.dimensions.length == 1 ? '' : _this.dimensions[1].name) + }); + _this.dimensionPicker = o; + $(o).bind('select', function (data, dimension) { + dimension = _.find(joolaio.objects.Dimensions, function (item) { + return item.name == dimension }); + if (_this.dimensions.indexOf(dimension) == -1) { + /*$dimlist.find('li').each(function (i, o) { + $(this).removeClass('active'); + });*/ + //$(this).addClass('active'); + if (_this.dimensions.length == 1) { + _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; + _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; + _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; + } + else { + _this.dimensions.splice(1, 1); + } + _this.dimensions.push(dimension); + _this.fetch(_this); - $('.japi.primarydimension').off('click'); - $('.japi.primarydimension').on('click', function (e) { + } + }); + + $item = $($header.find('.japi.other.picker.dropdown')); + o = new joolaio.visualisation.picker.Dimensions({ + container: $item, + prefix: '', + placeholdertext: 'Other', + type: 'none', + exclude: _this.options.excludeDimensions, + selected: (_this.isother ? _this.dimensions[0].name : '') + }); + + $(o).bind('select', function (data, dimension) { + dimension = _.find(joolaio.objects.Dimensions, function (item) { + return item.name == dimension + }); + if (_this.dimensions.indexOf(dimension) == -1) { + /*$dimlist.find('li').each(function (i, o) { + $(this).removeClass('active'); + });*/ + //$(this).addClass('active'); + /* + if (_this.dimensions.length == 1) { + _this.sortColumnIndex = parseInt(_this.sortColumnIndex) + 1; + _this.ColumnIndex = parseInt(_this.ColumnIndex) + 1; + _this.compareColumnIndex = parseInt(_this.compareColumnIndex) + 1; + } + else { + _this.dimensions.splice(1, 1); + }*/ + _this.dimensions[0] = dimension; + _this.isother = true; + _this.fetch(_this); - var dimension = $('.japi.primarydimension').text(); - dimension = _.find(joolaio.objects.Dimensions, function (item) { + } + }); - return item.name == dimension - }); - _this.dimensions[0] = dimension; - _this.isother = false; - _this.fetch(_this); + $('.japi.primarydimension').off('click'); + $('.japi.primarydimension').on('click', function (e) { + + var dimension = $('.japi.primarydimension').text(); + dimension = _.find(joolaio.objects.Dimensions, function (item) { + + return item.name == dimension }); + _this.dimensions[0] = dimension; + _this.isother = false; + _this.fetch(_this); + }); - $header.append($tablecontrol); + $header.append($tablecontrol); - var $advancedsearch = $('
    '); + var $advancedsearch = $('
    '); - var o = new joolaio.visualisation.container.Filter({ - container: $advancedsearch - }); + var o = new joolaio.visualisation.container.Filter({ + container: $advancedsearch + }); - $header.append($advancedsearch); + $header.append($advancedsearch); - $('.advancedcaption').off('click'); - $('.advancedcaption').on('click', function () { + $('.advancedcaption').off('click'); + $('.advancedcaption').on('click', function () { - $('#modal-notimplemented').modal('show'); - return; - if ($advancedsearch.is(':visible')) { - $advancedsearch.hide(); - } - else { - $advancedsearch.show(); - } - }); + $('#modal-notimplemented').modal('show'); + return; + if ($advancedsearch.is(':visible')) { + $advancedsearch.hide(); + } + else { + $advancedsearch.show(); + } + }); - $('.japi.primarydimension').html(_this.levels[_this.drilldownlevel][0].name); + $('.japi.primarydimension').html(_this.levels[_this.drilldownlevel][0].name); - if (!_this.isother) { + if (!_this.isother) { - $('.japi.primarydimension').addClass('on'); - $('.japi.other.picker').removeClass('on'); - $('.japi.other.picker .jbtn').html('Other '); + $('.japi.primarydimension').addClass('on'); + $('.japi.other.picker').removeClass('on'); + $('.japi.other.picker .jbtn').html('Other '); - } + } - else { - $('.japi.primarydimension').removeClass('on'); - $('.drilldownlink').off('click'); - $('.drilldownlink').addClass('disabled'); - $('.drilldownlink').parent().addClass('disabled'); + else { + $('.japi.primarydimension').removeClass('on'); + $('.drilldownlink').off('click'); + $('.drilldownlink').addClass('disabled'); + $('.drilldownlink').parent().addClass('disabled'); - } + } - if (_this.drilldownlevel > 0 || (_this.drilldownlevel == 0 && _this.levels.length == 1)) - $('.japi.other.picker').css('visibility', 'visible'); - else - $('.japi.other.picker').css('visibility', 'hidden'); + if (_this.drilldownlevel > 0 || (_this.drilldownlevel == 0 && _this.levels.length == 1)) + $('.japi.other.picker').css('visibility', 'visible'); + else + $('.japi.other.picker').css('visibility', 'hidden'); }; joolaio.visualisation.report.Table.prototype.uid = function (sender) { - return 'table-1234'; + return 'table-1234'; } joolaio.visualisation.report.Table.prototype.setState = function (sender) { - var _this = sender; - - if (!joolaio.state[_this.uid()]) - joolaio.state[_this.uid()] = {}; - - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Table "' + _this.uid() + '" saving state.'); - joolaio.state[_this.uid()].ChartType = _this.ChartType; - joolaio.state[_this.uid()].Resolution = _this.Resolution; - joolaio.state[_this.uid()].primaryMetric = _this.primaryMetric; - joolaio.state[_this.uid()].secondaryMetric = _this.secondaryMetric; - - joolaio.state[_this.uid()].sortColumnIndex = _this.sortColumnIndex; - joolaio.state[_this.uid()].ColumnIndex = _this.ColumnIndex; - joolaio.state[_this.uid()].compareColumnIndex = _this.compareColumnIndex; - joolaio.state[_this.uid()].sortDir = _this.sortDir; - joolaio.state[_this.uid()].currentPage = _this.currentPage; - joolaio.state[_this.uid()].pageSize = _this.pageSize; - - joolaio.state[_this.uid()].mode = _this.mode; - - //joolaio.state[_this.uid()].dimensions = _this.dimensions; - //joolaio.state[_this.uid()].levels = _this.levels; - joolaio.state[_this.uid()].drilldownlevel = _this.drilldownlevel; - joolaio.state[_this.uid()].isother = _this.isother; - //joolaio.state[_this.uid()].globalfilter = joolaio.visualisation.report.globalfilter; - - //joolaio.state[_this.uid()].metrics = _this.metrics; - joolaio.state[_this.uid()].Filters = _this.Filters; - //onsole.log(_this.mode); - //joolaio.saveState('Table "' + _this.uid() + '" change'); + var _this = sender; + + if (!joolaio.state[_this.uid()]) + joolaio.state[_this.uid()] = {}; + + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Table "' + _this.uid() + '" saving state.'); + joolaio.state[_this.uid()].ChartType = _this.ChartType; + joolaio.state[_this.uid()].Resolution = _this.Resolution; + joolaio.state[_this.uid()].primaryMetric = _this.primaryMetric; + joolaio.state[_this.uid()].secondaryMetric = _this.secondaryMetric; + + joolaio.state[_this.uid()].sortColumnIndex = _this.sortColumnIndex; + joolaio.state[_this.uid()].ColumnIndex = _this.ColumnIndex; + joolaio.state[_this.uid()].compareColumnIndex = _this.compareColumnIndex; + joolaio.state[_this.uid()].sortDir = _this.sortDir; + joolaio.state[_this.uid()].currentPage = _this.currentPage; + joolaio.state[_this.uid()].pageSize = _this.pageSize; + + joolaio.state[_this.uid()].mode = _this.mode; + + //joolaio.state[_this.uid()].dimensions = _this.dimensions; + //joolaio.state[_this.uid()].levels = _this.levels; + joolaio.state[_this.uid()].drilldownlevel = _this.drilldownlevel; + joolaio.state[_this.uid()].isother = _this.isother; + //joolaio.state[_this.uid()].globalfilter = joolaio.visualisation.report.globalfilter; + + //joolaio.state[_this.uid()].metrics = _this.metrics; + joolaio.state[_this.uid()].Filters = _this.Filters; + //onsole.log(_this.mode); + //joolaio.saveState('Table "' + _this.uid() + '" change'); }; joolaio.visualisation.report.Table.prototype.getState = function (sender) { - var _this = sender; - - joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Table "' + _this.uid() + '" loading state.'); - if (joolaio.state[_this.uid()] != null) { - _this.ChartType = joolaio.state[_this.uid()].ChartType; - _this.Resolution = joolaio.state[_this.uid()].Resolution; - _this.primaryMetric = joolaio.state[_this.uid()].primaryMetric; - _this.secondaryMetric = joolaio.state[_this.uid()].secondaryMetric; - - _this.sortColumnIndex = joolaio.state[_this.uid()].sortColumnIndex; - _this.ColumnIndex = joolaio.state[_this.uid()].ColumnIndex; - _this.compareColumnIndex = joolaio.state[_this.uid()].compareColumnIndex; - _this.sortDir = joolaio.state[_this.uid()].sortDir; - _this.currentPage = joolaio.state[_this.uid()].currentPage; - _this.pageSize = joolaio.state[_this.uid()].pageSize; - - _this.mode = joolaio.state[_this.uid()].mode; - - //_this.dimensions = joolaio.state[_this.uid()].dimensions; - //_this.levels = joolaio.state[_this.uid()].levels; - _this.drilldownlevel = joolaio.state[_this.uid()].drilldownlevel; - _this.isother = joolaio.state[_this.uid()].isother; - //_this.metrics = joolaio.state[_this.uid()].metrics; - //_this.Container = joolaio.state[_this.uid()].Container; - - //joolaio.visualisation.report.globalfilter = joolaio.state[_this.uid()].globalfilter; - - _this.Filters = joolaio.state[_this.uid()].Filters; - } + var _this = sender; + + joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'Table "' + _this.uid() + '" loading state.'); + if (joolaio.state[_this.uid()] != null) { + _this.ChartType = joolaio.state[_this.uid()].ChartType; + _this.Resolution = joolaio.state[_this.uid()].Resolution; + _this.primaryMetric = joolaio.state[_this.uid()].primaryMetric; + _this.secondaryMetric = joolaio.state[_this.uid()].secondaryMetric; + + _this.sortColumnIndex = joolaio.state[_this.uid()].sortColumnIndex; + _this.ColumnIndex = joolaio.state[_this.uid()].ColumnIndex; + _this.compareColumnIndex = joolaio.state[_this.uid()].compareColumnIndex; + _this.sortDir = joolaio.state[_this.uid()].sortDir; + _this.currentPage = joolaio.state[_this.uid()].currentPage; + _this.pageSize = joolaio.state[_this.uid()].pageSize; + + _this.mode = joolaio.state[_this.uid()].mode; + + //_this.dimensions = joolaio.state[_this.uid()].dimensions; + //_this.levels = joolaio.state[_this.uid()].levels; + _this.drilldownlevel = joolaio.state[_this.uid()].drilldownlevel; + _this.isother = joolaio.state[_this.uid()].isother; + //_this.metrics = joolaio.state[_this.uid()].metrics; + //_this.Container = joolaio.state[_this.uid()].Container; + + //joolaio.visualisation.report.globalfilter = joolaio.state[_this.uid()].globalfilter; + + _this.Filters = joolaio.state[_this.uid()].Filters; + } }; joolaio.debug.log('INFO', 'joolaio.visualisation.report.Table', 6, 'JS source loaded'); From 112abc211a16a18f649b97d718a6518dcb0854a8 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 3 Oct 2013 14:51:48 +0300 Subject: [PATCH 04/14] JARVIS-372 Fixed issue with null ref timeline and table. --- lib/joolaio.dataaccess.js | 2 +- lib/joolaio.visualisation.report.Table.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/joolaio.dataaccess.js b/lib/joolaio.dataaccess.js index 61e06c9..753b33d 100644 --- a/lib/joolaio.dataaccess.js +++ b/lib/joolaio.dataaccess.js @@ -110,7 +110,7 @@ joolaio.dataaccess.fetch = function (sender, endPoint, queryOptions, callback, t else if (result.resultcode == 500) throw { message: result.resulttext}; else if (typeof(callback) === "function") - callback(sender, result.data, this /*error*/); + callback(sender, result, this /*error*/); else { oResult = result; } diff --git a/lib/joolaio.visualisation.report.Table.js b/lib/joolaio.visualisation.report.Table.js index 8e98f3a..9d39433 100644 --- a/lib/joolaio.visualisation.report.Table.js +++ b/lib/joolaio.visualisation.report.Table.js @@ -1689,7 +1689,7 @@ joolaio.visualisation.report.Table.prototype.update = function (sender) { _this.dimensionPicker.disableDimension(o, _this.dimensions[0]); $(o).bind('select', function (data, dimension) { - if (joolaio.visualisation.report.table); + if (joolaio.visualisation.report.table) joolaio.visualisation.report.table.Filters = []; dimension = _.find(joolaio.objects.Dimensions, function (item) { return item.name == dimension diff --git a/package.json b/package.json index 01ef0df..b56f92f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "joola.io.sdk", "preferGlobal": false, - "version": "3.1.0", + "version": "3.1.2", "author": "Joola ", "description": "joola.io's software development kit (SDK)", "engine": "node >= 0.10.x", From 356e6a389709edd62b5570f135ec120f0b5115a2 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 3 Oct 2013 15:32:20 +0300 Subject: [PATCH 05/14] JARVIS-375 Added support for data parameter pageSize --- lib/joolaio.visualisation.report.Table.js | 3 +++ package.json | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/joolaio.visualisation.report.Table.js b/lib/joolaio.visualisation.report.Table.js index 9d39433..50a655b 100644 --- a/lib/joolaio.visualisation.report.Table.js +++ b/lib/joolaio.visualisation.report.Table.js @@ -173,6 +173,9 @@ joolaio.visualisation.report.Table.prototype.init = function (options, container _this.metrics[_metrics.indexOf(item.id)] = item; }); + var _pageSize = $(item).attr('data-pagesize'); + if (_pageSize) + _this.pageSize = _pageSize; $(item).empty(); _this.draw(item); diff --git a/package.json b/package.json index b56f92f..026a819 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "joola.io.sdk", "preferGlobal": false, - "version": "3.1.2", + "version": "3.1.4", "author": "Joola ", "description": "joola.io's software development kit (SDK)", "engine": "node >= 0.10.x", @@ -34,7 +34,8 @@ "data-cover-never": "node_modules" }, "coveralls": "mocha --require blanket --reporter mocha-lcov-reporter | node ./node_modules/coveralls/bin/coveralls.js", - "citest": "mocha --reporter xunit > test-reports.xml" + "citest": "mocha --reporter xunit > test-reports.xml", + "prepublish":"node ./build/dev-deploy.js" }, "dependencies": { "joola.io.config": "3.x", From e1677ebcf1f0f094afaaf8e7a049caf1d0b7f0b0 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Mon, 14 Oct 2013 11:53:34 +0300 Subject: [PATCH 06/14] JARVIS-375 Added data params to timline --- lib/joolaio.visualisation.report.Timeline.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/joolaio.visualisation.report.Timeline.js b/lib/joolaio.visualisation.report.Timeline.js index 771d9a3..e42db37 100644 --- a/lib/joolaio.visualisation.report.Timeline.js +++ b/lib/joolaio.visualisation.report.Timeline.js @@ -145,7 +145,9 @@ joolaio.visualisation.report.Timeline.prototype.init = function (options, contai this.options = $.extend({ height: 235, excludeMetrics: [], - showPrimary: true + showPrimary: true, + hide_xaxis:false, + bgcolor:'#fff' }, options); @@ -193,6 +195,17 @@ joolaio.visualisation.report.Timeline.prototype.init = function (options, contai _this.metrics.push(_this.primaryMetric); $(item).attr('data-metrics', _this.primaryMetric.name); } + + var _height = $(item).attr('data-height'); + if (_height) + _this.options.height = _height; + var _bgcolor = $(item).attr('data-bgcolor'); + if (_bgcolor) + _this.options.bgcolor = _bgcolor; + var _hidexaxis = $(item).attr('data-hidexaxis'); + if (_hidexaxis) + _this.options.hidexaxis = _hidexaxis; + _this.drawChart(item); _this.fetch(_this); @@ -983,6 +996,7 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) _this.Chart = new Highcharts.Chart({ chart: { height: _this.options.height, + backgroundColor:_this.options.bgcolor, marginTop: 0, marginLeft: -15, //0 marginRight: -20, //0 @@ -1106,7 +1120,7 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) return sDate; }, fontFamily: 'Signika', - enabled: true, + enabled: _this.options.hide_xaxis, style: { fontSize: '11px;', color: '#999'}, //10px, #333 y: 30 //removed From 46edbd01939a8b0615e8b935b7846fd35fe60fb1 Mon Sep 17 00:00:00 2001 From: orjoola Date: Mon, 14 Oct 2013 12:23:45 +0300 Subject: [PATCH 07/14] Added the option to choose between hide or disable when disabling metrics --- lib/joolaio.js | 6 + lib/joolaio.visualisation.picker.Metrics.js | 680 +++++++++++--------- 2 files changed, 383 insertions(+), 303 deletions(-) diff --git a/lib/joolaio.js b/lib/joolaio.js index a7efe8e..e4b05b5 100644 --- a/lib/joolaio.js +++ b/lib/joolaio.js @@ -1282,3 +1282,9 @@ function scrollTop(destino) { $('body').animate({scrollTop: '0px'}, delay); return true; } + +joolaio.options = {}; +joolaio.options.picker = {}; +joolaio.options.picker.metrics = {}; +joolaio.options.picker.metrics.hideDisabledMetrics = true; +joolaio.options.picker.dimensions = {}; \ No newline at end of file diff --git a/lib/joolaio.visualisation.picker.Metrics.js b/lib/joolaio.visualisation.picker.Metrics.js index 8dc0196..668caa5 100644 --- a/lib/joolaio.visualisation.picker.Metrics.js +++ b/lib/joolaio.visualisation.picker.Metrics.js @@ -17,123 +17,124 @@ joolaio.require('joolaio.string'); joolaio.require('joolaio.visualisation'); joolaio.visualisation.picker.Metrics = function (options) { - var start = new Date().getMilliseconds(); - - var _this = this; - this.type = 'metricpicker'; - this.selectedMetric = null; - this._this = this; - - var _options = { - container: null, - placeholdertext: 'Choose a metric...', - type: 'button', - selected: '', - showgrip: false, - allowremove: false, - metrics: null, - showlist: true, - exclude: [] - }; - - if (typeof options == 'undefined') - throw 'Container not specified'; - else - _options.container = $(options.container); - - if (typeof options.placeholdertext != 'undefined') - _options.placeholdertext = options.placeholdertext; - else if (typeof _options.container.attr('data-placeholdertext') != 'undefined') - _options.placeholdertext = _options.container.attr('data-placeholdertext'); - - if (typeof options.type != 'undefined') - _options.type = options.type; - else if (typeof _options.container.attr('data-type') != 'undefined') - _options.type = _options.container.attr('data-type'); - - if (typeof options.selected != 'undefined') - _options.selected = options.selected; - else if (typeof _options.container.attr('data-selected') != 'undefined') - _options.selected = _options.container.attr('data-selected'); - - if (typeof options.showgrip != 'undefined') - _options.showgrip = options.showgrip; - else if (typeof _options.container.attr('data-showgrip') != 'undefined') - _options.showgrip = _options.container.attr('data-showgrip'); - - if (typeof options.allowremove != 'undefined') - _options.allowremove = options.allowremove; - else if (typeof _options.container.attr('data-allowremove') != 'undefined') - _options.allowremove = _options.container.attr('data-allowremove'); - - if (typeof options.showlist != 'undefined') - _options.showlist = options.showlist; - else if (typeof _options.container.attr('data-showlist') != 'undefined') - _options.showlist = _options.container.attr('data-showlist'); - - if (typeof options.exclude != 'undefined') - _options.exclude = options.exclude; - else if (typeof _options.container.attr('data-exclude') != 'undefined') - _options.exclude = _options.container.attr('data-exclude'); - - if (typeof options.metrics != 'undefined') - _options.metrics = options.metrics; - - _this.container = _options.container; - _this.options = _options; - - if (!_options.metrics) { - joolaio.objects.Metrics.List(); - _options.metrics = joolaio.objects.Metrics - } - _this.init(_this); - - var executionTime = new Date().getMilliseconds() - start; - //joolaio.debug.log('INFO', 'joolaio.Visualisation.Picker.Metrics', 5, '...Constructor (' + executionTime + 'ms)'); + var start = new Date().getMilliseconds(); + + var _this = this; + this.type = 'metricpicker'; + this.selectedMetric = null; + this._this = this; + + var _options = { + container: null, + placeholdertext: 'Choose a metric...', + type: 'button', + selected: '', + showgrip: false, + allowremove: false, + metrics: null, + showlist: true, + exclude: [] + }; + + if (typeof options == 'undefined') + throw 'Container not specified'; + else + _options.container = $(options.container); + + if (typeof options.placeholdertext != 'undefined') + _options.placeholdertext = options.placeholdertext; + else if (typeof _options.container.attr('data-placeholdertext') != 'undefined') + _options.placeholdertext = _options.container.attr('data-placeholdertext'); + + if (typeof options.type != 'undefined') + _options.type = options.type; + else if (typeof _options.container.attr('data-type') != 'undefined') + _options.type = _options.container.attr('data-type'); + + if (typeof options.selected != 'undefined') + _options.selected = options.selected; + else if (typeof _options.container.attr('data-selected') != 'undefined') + _options.selected = _options.container.attr('data-selected'); + + if (typeof options.showgrip != 'undefined') + _options.showgrip = options.showgrip; + else if (typeof _options.container.attr('data-showgrip') != 'undefined') + _options.showgrip = _options.container.attr('data-showgrip'); + + if (typeof options.allowremove != 'undefined') + _options.allowremove = options.allowremove; + else if (typeof _options.container.attr('data-allowremove') != 'undefined') + _options.allowremove = _options.container.attr('data-allowremove'); + + if (typeof options.showlist != 'undefined') + _options.showlist = options.showlist; + else if (typeof _options.container.attr('data-showlist') != 'undefined') + _options.showlist = _options.container.attr('data-showlist'); + + if (typeof options.exclude != 'undefined') + _options.exclude = options.exclude; + else if (typeof _options.container.attr('data-exclude') != 'undefined') + _options.exclude = _options.container.attr('data-exclude'); + + if (typeof options.metrics != 'undefined') + _options.metrics = options.metrics; + + _this.container = _options.container; + _this.options = _options; + + if (!_options.metrics) { + joolaio.objects.Metrics.List(); + _options.metrics = joolaio.objects.Metrics + } + _this.init(_this); + + var executionTime = new Date().getMilliseconds() - start; + //joolaio.debug.log('INFO', 'joolaio.Visualisation.Picker.Metrics', 5, '...Constructor (' + executionTime + 'ms)'); }; /** * Inits the class and builds the base html for it. * @param {string=} container An optional container to apply the class to. */ joolaio.visualisation.picker.Metrics.prototype.init = function (sender) { - var _this = sender; - var start = new Date().getMilliseconds(); + var _this = sender; + var start = new Date().getMilliseconds(); - var $container = _this.container; - $container.empty(); - $container.html(_this.baseHTML(_this)); + var $container = _this.container; + $container.empty(); + $container.html(_this.baseHTML(_this)); - if (_this.options.selected != '') { - _this.setSelected(_this, _this.options.selected); - } + if (_this.options.selected != '') { + _this.setSelected(_this, _this.options.selected); + } - var executionTime = new Date().getMilliseconds() - start; - //joolaio.debug.log('INFO', 'joolaio.Visualisation.Picker.Metrics', 5, '...init (' + executionTime + 'ms)'); + var executionTime = new Date().getMilliseconds() - start; + //joolaio.debug.log('INFO', 'joolaio.Visualisation.Picker.Metrics', 5, '...init (' + executionTime + 'ms)'); }; joolaio.visualisation.picker.Metrics.prototype.collapseAll = function (sender) { - var _this = sender; - if (_this.options.showlist) - return; + var _this = sender; + if (_this.options.showlist) + return; - $(_this.container.find('.node.level_0')).removeClass('on'); - $(_this.container.find('.jcontainer ')).removeClass('on'); + $(_this.container.find('.node.level_0')).removeClass('on'); + $(_this.container.find('.jcontainer ')).removeClass('on'); }; joolaio.visualisation.picker.Metrics.prototype.expandAll = function (sender) { - var _this = sender; + var _this = sender; - $(_this.container.find('.node.level_0')).addClass('on'); - $(_this.container.find('.jcontainer ')).addClass('on'); + $(_this.container.find('.node.level_0')).addClass('on'); + $(_this.container.find('.jcontainer ')).addClass('on'); }; joolaio.visualisation.picker.Metrics.prototype.getSelected = function (sender) { - var _this = sender; - return _this.selectedMetric; + var _this = sender; + return _this.selectedMetric; } joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, metricname, multiple) { +<<<<<<< Updated upstream var _this = this; this.collapseAll(this); @@ -164,90 +165,119 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m s = _this.options.placeholdertext + ''; $(_this.container.find('.jbtn')[0]).html(s); +======= + var _this = this; + this.collapseAll(this); + + if (!multiple) + $(_this.container.find('li[data-metricname]')).removeClass('on'); + $(_this.container.find('li[data-metricname="' + metricname + '"]')).toggleClass('on'); + + _this.ensureVisible(_this, metricname); + + if (metricname != '') { + $(_this.container.find('.jbtn')[0]).html((metricname.length > 21 ? metricname.substring(0, 21) + '...' : metricname) + ''); + if (!$(_this.container).hasClass('on')) { + $(_this.container).addClass('on'); + if (_this.options.allowremove) + $(_this.container).append(''); + + $($(this.container).find('.jio-close')).off('click'); + $($(this.container).find('.jio-close')).on('click', function (e) { + _this.setSelected(_this, ''); + $(this).remove(); + }); } - - //to set the correct id for the container, used by report editor - $(this.container).closest('.pickerwrapper').attr('data-id', metricname); - - var $container = $(_this.container.find('.metricscontainer')); - if ($container.hasClass('on')) { - $container.hide(); - $container.removeClass('on'); - $(_this.container.find('.jbtn')[0]).removeClass('active'); + } + else { + $(_this.container).removeClass('on'); + var s = ' + add metric '; + if (_this.options.type == 'button') + s = _this.options.placeholdertext + ''; + + $(_this.container.find('.jbtn')[0]).html(s); + } + + //to set the correct id for the container, used by report editor + $(this.container).closest('.pickerwrapper').attr('data-id', metricname); + + var $container = $(_this.container.find('.metricscontainer')); + if ($container.hasClass('on')) { + $container.hide(); + $container.removeClass('on'); + $(_this.container.find('.jbtn')[0]).removeClass('active'); + } + + _this.options.selected = metricname; + + if (sender.type == _this.type) + $(_this).trigger('select', metricname) + + var metrics = joolaio.objects.Metrics; + $(metrics).each(function (i, m) { + if (m.name == metricname) { + _this.selectedMetric = m; +>>>>>>> Stashed changes } - - _this.options.selected = metricname; - - if (sender.type == _this.type) - $(_this).trigger('select', metricname) - - var metrics = joolaio.objects.Metrics; - $(metrics).each(function (i, m) { - if (m.name == metricname) { - _this.selectedMetric = m; - } - }); - //$('.metricswrapper') + }); + //$('.metricswrapper') }; joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, metricname) { - var container = sender.container[0]; - $(container).find('.key').each(function (i, m) { + var classname = 'disabled'; + if (joolaio.options.picker.metrics.hideDisabledMetrics) + classname += ' hidden'; + + var container = sender.container[0]; + $(container).find('.key').each(function (i, m) { + + if ($(m).closest('.node .' + classname.replace(' ','.'))[0]) { + $(m).closest('.node').off('click'); + $(m).closest('.node').on('click', function (e) { + //e.stopPropagation(); + sender.setSelected(sender, $(m).text()); + }); + } + $(m).closest('.node').removeClass(classname); - if ($(m).closest('.node .disabled')[0]) { - $(m).closest('.node').off('click'); - $(m).closest('.node').on('click', function (e) { - //e.stopPropagation(); - sender.setSelected(sender, $(m).text()); - }); - } - $(m).closest('.node').removeClass('disabled'); + }); - }); - - - - - - - - if (metricname && metricname != '') { - $(container).find('.key').each(function (i, m) { - - if ($(m).text() == metricname.name) { - $(m).closest('.node').unbind('click'); - $(m).closest('.node').bind('click', function (e) { - //e.stopPropagation(); - }); - var nodeParent = $(m).closest('.node'); - $(nodeParent).addClass('disabled'); - } + if (metricname && metricname != '') { + $(container).find('.key').each(function (i, m) { + + if ($(m).text() == metricname.name) { + $(m).closest('.node').unbind('click'); + $(m).closest('.node').bind('click', function (e) { + //e.stopPropagation(); }); - - - } + var nodeParent = $(m).closest('.node'); + $(nodeParent).addClass(classname); + } + }); + } } joolaio.visualisation.picker.Metrics.prototype.ensureVisible = function (sender, metricname) { - if (metricname != '') { + if (metricname != '') { + } + else { + if (sender.options.selected != null) { + metricname = sender.options.selected; } - else { - if (sender.options.selected != null) { - metricname = sender.options.selected; - } - } - - var _this = sender; - $(_this.container.find('li[data-metricname="' + metricname + '"]').each(function (index, item) { - var $li = $(item); - if (!$li.parent().hasClass('on')) - $li.parent().addClass('on'); - $li.closest('.node.level_0').addClass('on'); - })); + } + + var _this = sender; + $(_this.container.find('li[data-metricname="' + metricname + '"]').each(function (index, item) { + var $li = $(item); + if (!$li.parent().hasClass('on')) + $li.parent().addClass('on'); + $li.closest('.node.level_0').addClass('on'); + })); }; joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { +<<<<<<< Updated upstream var _this = sender; var $html = $('
    '); @@ -290,175 +320,219 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $this.closest('.level_1').show(); }); +======= + var _this = sender; + var $html = $('
    '); + + if (_this.options.type == 'button') { + $html.append('' + _this.options.placeholdertext + ''); + } + else { + if (_this.options.showgrip) + $html.append('
    '); + $html.append('
    + add metric
    '); + } + $html.append('
    '); + + var $container = $($html.find('.metricscontainer')); + + var search = function (e, term) { + if ((term == '' || term.length < 2 ) && e.which != 13) { + if (_this.options.showlist) { + _this.expandAll(_this); + $container.find('.category').hide(); + $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); + } + else { + _this.collapseAll(_this); + + $container.find('.category').show(); + $container.find('.node.level_0').removeClass('on'); + $container.find('.node.level_0').css('background-image', 'url(\'' + joolaio.hostname + '/assets/img/collapse.png\') no-repeat 0px 8px;'); + $container.find('.node.level_0').css('padding-left', '10px'); + + $container.find('.node.level_0').removeCss('background'); + $container.find('.node.level_0').removeCss('background-image'); + + } + + _this.ensureVisible(_this, _this.options.selected); + + $container.find('.node.leaf.level_1').find('.key').each(function (index, item) { + var $this = $(this); + + $this.closest('.level_1').show(); + }); + } + else { + _this.expandAll(_this); + $container.find('.category').hide(); + //$container.find('.node.level_0').addClass('on'); + + $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); + + $container.find('.node.leaf.level_1').hide(); + $container.find('.node.leaf.level_1').find('.key').each(function (index, item) { + + var $this = $(this); + if ($this.text().toLowerCase().indexOf(term.toLowerCase()) > -1) { + var shown = false; + $container.find('.node.leaf.level_1').find('.key').each(function (index, node) { + var $node = $(node); + if ($node != $this) + if ($node.text() == $this.text() && $node.is(':visible')) + shown = true; + }); + + if (shown) { + $this.closest('.level_1').hide(); + } + else + $this.closest('.level_1').show(); +>>>>>>> Stashed changes } - else { - _this.expandAll(_this); - $container.find('.category').hide(); - //$container.find('.node.level_0').addClass('on'); - - $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); - - $container.find('.node.leaf.level_1').hide(); - $container.find('.node.leaf.level_1').find('.key').each(function (index, item) { - - var $this = $(this); - if ($this.text().toLowerCase().indexOf(term.toLowerCase()) > -1) { - var shown = false; - $container.find('.node.leaf.level_1').find('.key').each(function (index, node) { - var $node = $(node); - if ($node != $this) - if ($node.text() == $this.text() && $node.is(':visible')) - shown = true; - }); - - if (shown) { - $this.closest('.level_1').hide(); - } - else - $this.closest('.level_1').show(); - } - else - $this.closest('.level_1').hide(); - }) - } - }; - - var $search = $(''); - $search.keyup(function (e) { - var term = $search.find('.quicksearch').val(); - search(e, term); - }); + else + $this.closest('.level_1').hide(); + }) + } + }; - $search.find('.icon-search').off('click'); - $search.find('.icon-search').on('click', function (e) { - var term = $search.find('.quicksearch').val(); - search(e, term); - }); + var $search = $(''); + $search.keyup(function (e) { + var term = $search.find('.quicksearch').val(); + search(e, term); + }); - $container.append($search); - //we first need to group the metrics together - var _metrics = _.groupBy(_this.options.metrics, function (obj) { - return obj.Category; - }); + $search.find('.icon-search').off('click'); + $search.find('.icon-search').on('click', function (e) { + var term = $search.find('.quicksearch').val(); + search(e, term); + }); - //let's iterate the metrics and add them to the drop down + $container.append($search); + //we first need to group the metrics together + var _metrics = _.groupBy(_this.options.metrics, function (obj) { + return obj.Category; + }); - $container.append('
      '); - var $categorylist = $($container.find('.categorylist')); + //let's iterate the metrics and add them to the drop down - _.each(_metrics, function (item, index) { - var $list = $('
    • '); - $list.append('
      ' + item[0].Category + '
      '); - $list.append('
        '); - $.each(item, function (index, metric) { - if (_this.options.exclude.indexOf(metric.name) == -1) { - var list = '
      • '; + $container.append('
          '); + var $categorylist = $($container.find('.categorylist')); - list += '
          '; - list += '
          '; + _.each(_metrics, function (item, index) { + var $list = $('
        • '); + $list.append('
          ' + item[0].Category + '
          '); + $list.append('
            '); + $.each(item, function (index, metric) { + if (_this.options.exclude.indexOf(metric.name) == -1) { + var list = '
          • '; - list += '
            ' + metric.name + '
            '; - list += '
            '; + list += '
            '; + list += '
            '; - list += '
            '; - list += '
            '; + list += '
            ' + metric.name + '
            '; + list += '
            '; - list += '
          • '; + list += '
            '; + list += '
            '; - var $li = $(list); - $($list.find('.jcontainer:last-of-type')).append($li); - } - }); + list += ''; - $categorylist.append($list); + var $li = $(list); + $($list.find('.jcontainer:last-of-type')).append($li); + } }); - $($container).find('.icon-question-sign').each(function (index, item) { - try { - $(item).popover({placement: 'right', trigger: 'hover', delay: 0, title: '' + $(item).attr('data-caption') + '', content: $(item).attr('data-text')}); - } - catch (e) { + $categorylist.append($list); + }); - } - }); - - $($html.find('.jbtn')[0]).off('click'); - $($html.find('.jbtn')[0]).on('click', function (e) { - if ($($container).is(':visible')) { - $($container).hide(); - } - else { - $(joolaio).trigger('joolaio-picker-metrics-popup', [_this]); - $($container).show(); - } - //$container.toggle(); - //$container.toggleClass('on'); - if (_this.options.showlist) { - _this.expandAll(_this); - - $container.find('.category').hide(); - $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); - } - $search.find('.quicksearch').val(''); - $search.keyup(); + $($container).find('.icon-question-sign').each(function (index, item) { + try { + $(item).popover({placement: 'right', trigger: 'hover', delay: 0, title: '' + $(item).attr('data-caption') + '', content: $(item).attr('data-text')}); + } + catch (e) { - $search.find('.quicksearch').focus(); + } + }); - _this.ensureVisible(_this, _this.options.selected); - $(this).toggleClass('active'); - }); + $($html.find('.jbtn')[0]).off('click'); + $($html.find('.jbtn')[0]).on('click', function (e) { + if ($($container).is(':visible')) { + $($container).hide(); + } + else { + $(joolaio).trigger('joolaio-picker-metrics-popup', [_this]); + $($container).show(); + } + //$container.toggle(); + //$container.toggleClass('on'); + if (_this.options.showlist) { + _this.expandAll(_this); - $('body').click(function () { - if ($($container).is(':visible')) { - $container.hide(); - $($html.find('.jbtn')[0]).removeClass('active'); - } - }); + $container.find('.category').hide(); + $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); + } + $search.find('.quicksearch').val(''); + $search.keyup(); - $html.click(function (e) { - e.stopPropagation(); - }); + $search.find('.quicksearch').focus(); - $($container).find('.node.level_0').each(function (index, item) { - var $li = $(this); - $li.off('click'); - $li.on('click', function (e) { - $('.metricscontainer').hide(); - $('.jbtn').removeClass('active'); - }); - }); + _this.ensureVisible(_this, _this.options.selected); + $(this).toggleClass('active'); + }); - $($container).find('.node.level_1').each(function (index, item) { - var $li = $(this); - $li.off('click'); - $li.on('click', function (e) { - $('.metricscontainer').hide(); - $('.jbtn').removeClass('active'); - _this.setSelected(_this, $(this).attr('data-metricname')); - }); + $('body').click(function () { + if ($($container).is(':visible')) { + $container.hide(); + $($html.find('.jbtn')[0]).removeClass('active'); + } + }); + + $html.click(function (e) { + e.stopPropagation(); + }); + + $($container).find('.node.level_0').each(function (index, item) { + var $li = $(this); + $li.off('click'); + $li.on('click', function (e) { + $('.metricscontainer').hide(); + $('.jbtn').removeClass('active'); }); - - $container.bind('mousewheel', function (e, d) { - if (d > 0 && $(this).scrollTop() == 0) - e.preventDefault(); - else if (d < 0 && $(this).scrollTop() == $(this).get(0).scrollHeight - $(this).innerHeight()) - e.preventDefault(); + }); + + $($container).find('.node.level_1').each(function (index, item) { + var $li = $(this); + $li.off('click'); + $li.on('click', function (e) { + $('.metricscontainer').hide(); + $('.jbtn').removeClass('active'); + _this.setSelected(_this, $(this).attr('data-metricname')); }); - return $html; + }); + + $container.bind('mousewheel', function (e, d) { + if (d > 0 && $(this).scrollTop() == 0) + e.preventDefault(); + else if (d < 0 && $(this).scrollTop() == $(this).get(0).scrollHeight - $(this).innerHeight()) + e.preventDefault(); + }); + return $html; }; $(joolaio).bind('joolaio-picker-metrics-popup', function (e, sender) { - $('.metricscontainer').hide(); - $('.metricscontainer').removeClass('on'); - $('.dimensionscontainer').hide(); - $('.dimensionscontainer').removeClass('on'); - $('.dimensionswrapper .jbtn').removeClass('active'); - $('.metricswrapper .jbtn').removeClass('active'); - $('.joolaio.picker.datebox .picker').hide(); - $('.joolaio.picker.datebox .container').removeClass('expanded') - $('.resolutionpicker-wrapper').hide(); - $('.resolutionwrapper .jbtn').removeClass('active'); + $('.metricscontainer').hide(); + $('.metricscontainer').removeClass('on'); + $('.dimensionscontainer').hide(); + $('.dimensionscontainer').removeClass('on'); + $('.dimensionswrapper .jbtn').removeClass('active'); + $('.metricswrapper .jbtn').removeClass('active'); + $('.joolaio.picker.datebox .picker').hide(); + $('.joolaio.picker.datebox .container').removeClass('expanded') + $('.resolutionpicker-wrapper').hide(); + $('.resolutionwrapper .jbtn').removeClass('active'); }); From 7119513a6bf6077a3333c053b22b7c2ef463d032 Mon Sep 17 00:00:00 2001 From: orjoola Date: Wed, 16 Oct 2013 10:48:14 +0300 Subject: [PATCH 08/14] Work in progress --- lib/joolaio.js | 7 +- lib/joolaio.visualisation.picker.Metrics.js | 176 ++-- lib/joolaio.visualisation.report.Panel.js | 834 ++++++++++--------- lib/joolaio.visualisation.report.Timeline.js | 38 +- 4 files changed, 527 insertions(+), 528 deletions(-) diff --git a/lib/joolaio.js b/lib/joolaio.js index e4b05b5..2b0d651 100644 --- a/lib/joolaio.js +++ b/lib/joolaio.js @@ -1276,7 +1276,6 @@ function getParameterByName(name) { return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); } - function scrollTop(destino) { var delay = 200; $('body').animate({scrollTop: '0px'}, delay); @@ -1286,5 +1285,7 @@ function scrollTop(destino) { joolaio.options = {}; joolaio.options.picker = {}; joolaio.options.picker.metrics = {}; -joolaio.options.picker.metrics.hideDisabledMetrics = true; -joolaio.options.picker.dimensions = {}; \ No newline at end of file +joolaio.options.picker.metrics.hideDisabledMetrics = false; +joolaio.options.picker.dimensions = {}; +joolaio.options.timeline = {}; +joolaio.options.timeline.plotDisabledWhenFiltered = true; \ No newline at end of file diff --git a/lib/joolaio.visualisation.picker.Metrics.js b/lib/joolaio.visualisation.picker.Metrics.js index 668caa5..9bf6f66 100644 --- a/lib/joolaio.visualisation.picker.Metrics.js +++ b/lib/joolaio.visualisation.picker.Metrics.js @@ -33,7 +33,8 @@ joolaio.visualisation.picker.Metrics = function (options) { allowremove: false, metrics: null, showlist: true, - exclude: [] + exclude: [], + disable: [] }; if (typeof options == 'undefined') @@ -76,6 +77,11 @@ joolaio.visualisation.picker.Metrics = function (options) { else if (typeof _options.container.attr('data-exclude') != 'undefined') _options.exclude = _options.container.attr('data-exclude'); + if (typeof options.disable != 'undefined') + _options.disable = options.disable; + else if (typeof _options.container.attr('data-disable') != 'undefined') + _options.disable = _options.container.attr('data-disable'); + if (typeof options.metrics != 'undefined') _options.metrics = options.metrics; @@ -134,38 +140,6 @@ joolaio.visualisation.picker.Metrics.prototype.getSelected = function (sender) { } joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, metricname, multiple) { -<<<<<<< Updated upstream - var _this = this; - this.collapseAll(this); - - if (!multiple) - $(_this.container.find('li[data-metricname]')).removeClass('on'); - $(_this.container.find('li[data-metricname="' + metricname + '"]')).toggleClass('on'); - - _this.ensureVisible(_this, metricname); - - if (metricname != '') { - $(_this.container.find('.jbtn')[0]).html((metricname.length > 21 ? metricname.substring(0, 21) + '...' : metricname) + ''); - if (!$(_this.container).hasClass('on')) { - $(_this.container).addClass('on'); - if (_this.options.allowremove) - $(_this.container).append(''); - - $($(this.container).find('.close')).off('click'); - $($(this.container).find('.close')).on('click', function (e) { - _this.setSelected(_this, ''); - $(this).remove(); - }); - } - } - else { - $(_this.container).removeClass('on'); - var s = ' + add metric '; - if (_this.options.type == 'button') - s = _this.options.placeholdertext + ''; - - $(_this.container.find('.jbtn')[0]).html(s); -======= var _this = this; this.collapseAll(this); @@ -176,14 +150,14 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m _this.ensureVisible(_this, metricname); if (metricname != '') { - $(_this.container.find('.jbtn')[0]).html((metricname.length > 21 ? metricname.substring(0, 21) + '...' : metricname) + ''); + $(_this.container.find('.jbtn')[0]).html((metricname.length > 21 ? metricname.substring(0, 21) + '...' : metricname) + ''); if (!$(_this.container).hasClass('on')) { $(_this.container).addClass('on'); if (_this.options.allowremove) - $(_this.container).append(''); + $(_this.container).append(''); - $($(this.container).find('.jio-close')).off('click'); - $($(this.container).find('.jio-close')).on('click', function (e) { + $($(this.container).find('.close')).off('click'); + $($(this.container).find('.close')).on('click', function (e) { _this.setSelected(_this, ''); $(this).remove(); }); @@ -191,11 +165,13 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m } else { $(_this.container).removeClass('on'); - var s = ' + add metric '; + var s = ' + add metric '; if (_this.options.type == 'button') - s = _this.options.placeholdertext + ''; + s = _this.options.placeholdertext + ''; $(_this.container.find('.jbtn')[0]).html(s); + $($(this.container).find('.close')).off('click'); + $($(this.container).find('.close')).remove(); } //to set the correct id for the container, used by report editor @@ -217,35 +193,40 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m $(metrics).each(function (i, m) { if (m.name == metricname) { _this.selectedMetric = m; ->>>>>>> Stashed changes } }); //$('.metricswrapper') }; -joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, metricname) { +joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, metricname, bind) { + bind = typeof bind !== 'undefined' ? bind : true; var classname = 'disabled'; if (joolaio.options.picker.metrics.hideDisabledMetrics) classname += ' hidden'; - + //var container = $('.joolaio.picker.metrics:first'); var container = sender.container[0]; - $(container).find('.key').each(function (i, m) { + if (bind) { + $(container).find('.key').each(function (i, m) { + if ($(m).closest('.node .hidden') || $(m).closest('.node .disabled')) { + console.log('binding ', metricname.name); + $(m).closest('.node').off('click'); + $(m).closest('.node').on('click', function (e) { + //e.stopPropagation(); + sender.setSelected(sender, $(m).text()); + }); + } - if ($(m).closest('.node .' + classname.replace(' ','.'))[0]) { - $(m).closest('.node').off('click'); - $(m).closest('.node').on('click', function (e) { - //e.stopPropagation(); - sender.setSelected(sender, $(m).text()); - }); - } - $(m).closest('.node').removeClass(classname); - }); + $(m).closest('.node').removeClass('hidden'); + $(m).closest('.node').removeClass('disabled'); - if (metricname && metricname != '') { + }); + } + if (metricname && metricname.name != '') { + $(container).find('.key').each(function (i, m) { - if ($(m).text() == metricname.name) { + console.log('unbinding ', metricname.name); $(m).closest('.node').unbind('click'); $(m).closest('.node').bind('click', function (e) { //e.stopPropagation(); @@ -257,6 +238,7 @@ joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, } } + joolaio.visualisation.picker.Metrics.prototype.ensureVisible = function (sender, metricname) { if (metricname != '') { } @@ -277,60 +259,16 @@ joolaio.visualisation.picker.Metrics.prototype.ensureVisible = function (sender, joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { -<<<<<<< Updated upstream - var _this = sender; - var $html = $('
            '); - - if (_this.options.type == 'button') { - $html.append('' + _this.options.placeholdertext + ''); - } - else { - if (_this.options.showgrip) - $html.append('
            '); - $html.append('
            + add metric
            '); - } - $html.append('
            '); - - var $container = $($html.find('.metricscontainer')); - - var search = function (e, term) { - if ((term == '' || term.length < 2 ) && e.which != 13) { - if (_this.options.showlist) { - _this.expandAll(_this); - $container.find('.category').hide(); - $container.find('.node.level_0').css({'background-image': 'none', 'padding-left': 0}); - } - else { - _this.collapseAll(_this); - - $container.find('.category').show(); - $container.find('.node.level_0').removeClass('on'); - $container.find('.node.level_0').css('background-image', 'url(\'' + joolaio.hostname + '/assets/img/collapse.png\') no-repeat 0px 8px;'); - $container.find('.node.level_0').css('padding-left', '10px'); - - $container.find('.node.level_0').removeCss('background'); - $container.find('.node.level_0').removeCss('background-image'); - - } - - _this.ensureVisible(_this, _this.options.selected); - - $container.find('.node.leaf.level_1').find('.key').each(function (index, item) { - var $this = $(this); - - $this.closest('.level_1').show(); - }); -======= var _this = sender; var $html = $('
            '); if (_this.options.type == 'button') { - $html.append('' + _this.options.placeholdertext + ''); + $html.append('' + _this.options.placeholdertext + ''); } else { if (_this.options.showgrip) $html.append('
            '); - $html.append('
            + add metric
            '); + $html.append('
            + add metric
            '); } $html.append('
            '); @@ -389,7 +327,6 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { } else $this.closest('.level_1').show(); ->>>>>>> Stashed changes } else $this.closest('.level_1').hide(); @@ -419,13 +356,12 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $container.append('
              '); var $categorylist = $($container.find('.categorylist')); - _.each(_metrics, function (item, index) { var $list = $('
            • '); $list.append('
              ' + item[0].Category + '
              '); $list.append('
                '); $.each(item, function (index, metric) { - if (_this.options.exclude.indexOf(metric.name) == -1) { + if (_this.options.exclude.indexOf(metric.name) == -1 && _this.options.disable.indexOf(metric.name) == -1) { var list = '
              • '; list += '
                '; @@ -442,8 +378,33 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { var $li = $(list); $($list.find('.jcontainer:last-of-type')).append($li); } - }); + else if (_this.options.exclude.indexOf(metric.name) == -1 && _this.options.disable.indexOf(metric.name) > -1) { + + var list = '
              • '; + + list += '
                '; + list += '
                '; + + list += '
                ' + metric.name + '
                '; + list += '
                '; + + list += '
                '; + list += '
                '; + + list += '
              • '; + + var $li = $(list); + $($list.find('.jcontainer:last-of-type')).append($li); + + } + + }); + $.each(item, function (index, metric) { + if (_this.options.exclude.indexOf(metric.name) == -1 && _this.options.disable.indexOf(metric.name) > -1) { + _this.disableMetric(_this, metric, false); + } + }); $categorylist.append($list); }); @@ -492,7 +453,7 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $html.click(function (e) { e.stopPropagation(); }); - + $($container).find('.node.level_0').each(function (index, item) { var $li = $(this); $li.off('click'); @@ -501,7 +462,7 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $('.jbtn').removeClass('active'); }); }); - + $($container).find('.node.level_1').each(function (index, item) { var $li = $(this); $li.off('click'); @@ -511,7 +472,7 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { _this.setSelected(_this, $(this).attr('data-metricname')); }); }); - + $container.bind('mousewheel', function (e, d) { if (d > 0 && $(this).scrollTop() == 0) e.preventDefault(); @@ -533,7 +494,6 @@ $(joolaio).bind('joolaio-picker-metrics-popup', function (e, sender) { $('.joolaio.picker.datebox .container').removeClass('expanded') $('.resolutionpicker-wrapper').hide(); $('.resolutionwrapper .jbtn').removeClass('active'); - }); joolaio.loaded.push('joolaio.visualisation.picker.metrics'); diff --git a/lib/joolaio.visualisation.report.Panel.js b/lib/joolaio.visualisation.report.Panel.js index ade386b..5431153 100644 --- a/lib/joolaio.visualisation.report.Panel.js +++ b/lib/joolaio.visualisation.report.Panel.js @@ -21,90 +21,91 @@ joolaio.require('joolaio.visualisation.report'); joolaio.visualisation.report.Panel = function (options) { - var start = new Date().getMilliseconds(); - - var _this = this; - //this._this = this; - - this.options = $.extend({ - widgets: { - timeline: { - height: 235, - excludeMetrics: [], - showPrimary: true - }, - table: { - pageSize: 10, - minSelected: 0, - maxSelected: 3, - excludeDimensions: [], - defaultSelected: 0 - } - } - }, options); - joolaio.objects.Reports.List(); - - try { - this.reportID = options.reportID; + var start = new Date().getMilliseconds(); + + var _this = this; + //this._this = this; + + this.options = $.extend({ + widgets: { + timeline: { + height: 235, + excludeMetrics: [], + disableMetrics: [], + showPrimary: true + }, + table: { + pageSize: 10, + minSelected: 0, + maxSelected: 3, + excludeDimensions: [], + defaultSelected: 0 + } } - catch (e) { - this.reportID = joolaio.objects.Reports[0].id; //this.getDefaultPanel(); - } - - this.containers = []; - - //lookup any containers relevant for the timeline - var matchedContainers = null; - matchedContainers = $('.joolaio.report.panel'); - if (matchedContainers.length > 0) { - joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Building Initial Panel (\'' + this.id + '\')'); - - var $editbutton = $('.joolaio.container').find('.panel-edit'); - $editbutton.off('click'); - $editbutton.on('click', function (e) { - var o = new joolaio.visualisation.report.Editor(); - o.init(o, {container: matchedContainers, reportID: _this.reportID}); - }); - } - - this.container = matchedContainers; - joolaio.visualisation.report.panel = this; - - joolaio.objects.Reports.List(); - joolaio.objects.Dimensions.List(); - joolaio.objects.Metrics.List(); - - if (joolaio.state != null) { - _this.reportID = joolaio.state.reportID; - _this.tabID = joolaio.state.tabID; - _this.metricgroupID = joolaio.state.metricgroupID; - - _this.tabType = joolaio.state.tabType; - } - else { - this.reportID = -1; - this.tabID = 0; - this.tabType = 'explorer'; - this.metricgroupID = 0; - } - - if (_this.reportID == null || _this.reportID == 'undefined') - _this.reportID = -1; - if (_this.tabID == null || _this.tabID == 'undefined') - _this.tabID = 0; - if (_this.tabType == null || _this.tabType == 'undefined') - _this.tabType = 'explorer'; - if (_this.metricgroupID == null || _this.metricgroupID == 'undefined') - _this.metricgroupID = 0; + }, options); + joolaio.objects.Reports.List(); + try { + this.reportID = options.reportID; + } + catch (e) { + this.reportID = joolaio.objects.Reports[0].id; //this.getDefaultPanel(); + } - var executionTime = new Date().getMilliseconds() - start; - //joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 5, '...Constructor (' + executionTime + 'ms)'); + this.containers = []; + //lookup any containers relevant for the timeline + var matchedContainers = null; + matchedContainers = $('.joolaio.report.panel'); + if (matchedContainers.length > 0) { + joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Building Initial Panel (\'' + this.id + '\')'); - if (!joolaio.visualisation.reportWrapper) - joolaio.visualisation.reportWrapper = _this; - return _this; + var $editbutton = $('.joolaio.container').find('.panel-edit'); + $editbutton.off('click'); + $editbutton.on('click', function (e) { + var o = new joolaio.visualisation.report.Editor(); + o.init(o, {container: matchedContainers, reportID: _this.reportID}); + }); + } + + this.container = matchedContainers; + joolaio.visualisation.report.panel = this; + + joolaio.objects.Reports.List(); + joolaio.objects.Dimensions.List(); + joolaio.objects.Metrics.List(); + + if (joolaio.state != null) { + _this.reportID = joolaio.state.reportID; + _this.tabID = joolaio.state.tabID; + _this.metricgroupID = joolaio.state.metricgroupID; + + _this.tabType = joolaio.state.tabType; + } + else { + this.reportID = -1; + this.tabID = 0; + this.tabType = 'explorer'; + this.metricgroupID = 0; + } + + if (_this.reportID == null || _this.reportID == 'undefined') + _this.reportID = -1; + if (_this.tabID == null || _this.tabID == 'undefined') + _this.tabID = 0; + if (_this.tabType == null || _this.tabType == 'undefined') + _this.tabType = 'explorer'; + if (_this.metricgroupID == null || _this.metricgroupID == 'undefined') + _this.metricgroupID = 0; + + + var executionTime = new Date().getMilliseconds() - start; + //joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 5, '...Constructor (' + executionTime + 'ms)'); + + + if (!joolaio.visualisation.reportWrapper) + joolaio.visualisation.reportWrapper = _this; + return _this; }; @@ -113,150 +114,153 @@ joolaio.visualisation.report.Panel = function (options) { * @param {string=} container An optional container to apply the class to. */ joolaio.visualisation.report.Panel.prototype.init = function (options, container, drawWidgets, breakBindLoop, saveState) { - var _this = this; - joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Building Panel for ID (\'' + _this.reportID + '\')'); - - /* - this.reportID = null; - this.tabID = 0; - this.tabType = 'explorer'; - this.metricgroupID = 0; - */ - if (options && options.showPrimary != null) - _this.options.widgets.timeline.showPrimary = options.showPrimary; - if (options && options.minSelected != null) - _this.options.widgets.table.minSelected = options.minSelected; - if (options && options.maxSelected != null) - _this.options.widgets.table.maxSelected = options.maxSelected; - if (options && options.defaultSelected != null) - _this.options.widgets.table.defaultSelected = options.defaultSelected; - - if (options && options.excludeMetrics != null) - _this.options.widgets.timeline.excludeMetrics = options.excludeMetrics; - - if (options && options.excludeDimensions != null) - _this.options.widgets.table.excludeDimensions = options.excludeDimensions; - - joolaio.visualisation.report.globalfilter = ''; - - try { - if ($('.joolaio.report.panel').attr('data-id') != null) - _this.reportID = $('.joolaio.report.panel').attr('data-id'); - if (options.reportID != null && options.reportID != 'undefined') - _this.reportID = options.reportID; - if (options.tabID != null && options.tabID != 'undefined') - _this.tabID = options.tabID; - if (options.tabType != null && options.tabType != 'undefined') - _this.tabType = options.tabType; - if (options.metricgroupID != null && options.metricgroupID != 'undefined') - _this.metricgroupID = options.metricgroupID; - } - catch (e) { - if (this.reportID == -1) - _this.reportID = joolaio.objects.Reports[0].id; //this.getDefaultPanel(); - } - - if (_this.reportID == null || _this.reportID == 'undefined') - _this.reportID = joolaio.objects.Reports[0].id//-1; - if (_this.tabID == null || _this.tabID == 'undefined') - _this.tabID = 0; - if (_this.tabType == null || _this.tabType == 'undefined') - _this.tabType = 'explorer'; - if (_this.metricgroupID == null || _this.metricgroupID == 'undefined') - _this.metricgroupID = 0; - if (_this.reportID == -1) - _this.reportID = joolaio.objects.Reports[0].id//-1; - - _this.panel = _this.get(_this, _this.reportID); - if (!this.panel) { - return; - } - - _this.tabType = _this.panel.tabs[_this.tabID].type; - - _this.setDisplay(); - - - if (typeof saveState == 'undefined' || saveState == true) { - joolaio.state.view = 'report'; - joolaio.state.dashboardID = _this.panelID; - joolaio.state.reportID = _this.reportID; - joolaio.state.tabID = _this.tabID; - joolaio.state.metricgroupID = _this.metricgroupID; - joolaio.state.tabType = _this.tabType; - //joolaio.saveState('Report Panel Init'); - } - - - var matchedContainers = null; - if (container) - matchedContainers = $(container); - else - matchedContainers = $('.joolaio.report.panel'); - if (matchedContainers.length == 0) - return; - - var $addwidgetbutton = $('body').find('.widget-add'); - - $addwidgetbutton.hide(); - - $(matchedContainers).each(function (index, item) { - if (options == null) - options = new Object(); + var _this = this; + joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Building Panel for ID (\'' + _this.reportID + '\')'); + + /* + this.reportID = null; + this.tabID = 0; + this.tabType = 'explorer'; + this.metricgroupID = 0; + */ + if (options && options.showPrimary != null) + _this.options.widgets.timeline.showPrimary = options.showPrimary; + if (options && options.minSelected != null) + _this.options.widgets.table.minSelected = options.minSelected; + if (options && options.maxSelected != null) + _this.options.widgets.table.maxSelected = options.maxSelected; + if (options && options.defaultSelected != null) + _this.options.widgets.table.defaultSelected = options.defaultSelected; + + if (options && options.excludeMetrics != null) + _this.options.widgets.timeline.excludeMetrics = options.excludeMetrics; + + if (options && options.disableMetrics != null) + _this.options.widgets.timeline.disableMetrics = options.disableMetrics; + + if (options && options.excludeDimensions != null) + _this.options.widgets.table.excludeDimensions = options.excludeDimensions; + + joolaio.visualisation.report.globalfilter = ''; + + try { + if ($('.joolaio.report.panel').attr('data-id') != null) + _this.reportID = $('.joolaio.report.panel').attr('data-id'); + if (options.reportID != null && options.reportID != 'undefined') + _this.reportID = options.reportID; + if (options.tabID != null && options.tabID != 'undefined') + _this.tabID = options.tabID; + if (options.tabType != null && options.tabType != 'undefined') + _this.tabType = options.tabType; + if (options.metricgroupID != null && options.metricgroupID != 'undefined') + _this.metricgroupID = options.metricgroupID; + } + catch (e) { + if (this.reportID == -1) + _this.reportID = joolaio.objects.Reports[0].id; //this.getDefaultPanel(); + } + + if (_this.reportID == null || _this.reportID == 'undefined') + _this.reportID = joolaio.objects.Reports[0].id//-1; + if (_this.tabID == null || _this.tabID == 'undefined') + _this.tabID = 0; + if (_this.tabType == null || _this.tabType == 'undefined') + _this.tabType = 'explorer'; + if (_this.metricgroupID == null || _this.metricgroupID == 'undefined') + _this.metricgroupID = 0; + if (_this.reportID == -1) + _this.reportID = joolaio.objects.Reports[0].id//-1; + + _this.panel = _this.get(_this, _this.reportID); + if (!this.panel) { + return; + } + + _this.tabType = _this.panel.tabs[_this.tabID].type; + + _this.setDisplay(); + + + if (typeof saveState == 'undefined' || saveState == true) { + joolaio.state.view = 'report'; + joolaio.state.dashboardID = _this.panelID; + joolaio.state.reportID = _this.reportID; + joolaio.state.tabID = _this.tabID; + joolaio.state.metricgroupID = _this.metricgroupID; + joolaio.state.tabType = _this.tabType; + //joolaio.saveState('Report Panel Init'); + } + + + var matchedContainers = null; + if (container) + matchedContainers = $(container); + else + matchedContainers = $('.joolaio.report.panel'); + if (matchedContainers.length == 0) + return; - options.reportID = _this.reportID; - options.container = item; - options._this = _this; - _this.updateDisplay(options); + var $addwidgetbutton = $('body').find('.widget-add'); - _this.baseHTML(_this, item); - _this.drawWidgets(_this, item, drawWidgets); + $addwidgetbutton.hide(); - $(joolaio).unbind('tabchange'); - $(joolaio).bind('tabchange', function (e, tabID) { + $(matchedContainers).each(function (index, item) { + if (options == null) + options = new Object(); - //_this.reportID = reportID; - _this.tabID = tabID; - _this.metricgroupID = 0; + options.reportID = _this.reportID; + options.container = item; + options._this = _this; + _this.updateDisplay(options); - joolaio.visualisation.report.globalfilter = ''; + _this.baseHTML(_this, item); + _this.drawWidgets(_this, item, drawWidgets); - //joolaio.visualisation.report.setFilter(''); - _this.init(_this, item, true, true); + $(joolaio).unbind('tabchange'); + $(joolaio).bind('tabchange', function (e, tabID) { - //joolaio.saveState("Tab change"); - // _this.drawWidgets(_this, $('.joolaio.container.report'), true, true); - }); + //_this.reportID = reportID; + _this.tabID = tabID; + _this.metricgroupID = 0; - $(joolaio).unbind('metricgroupchange'); - $(joolaio).bind('metricgroupchange', function (e, metricgroupID) { + joolaio.visualisation.report.globalfilter = ''; - //_this.reportID = reportID; - _this.metricgroupID = metricgroupID; - try { - joolaio.state['timeline-1234'].primaryMetric = null; - } - catch (ex) { - //ignore - } - //joolaio.state[_this.uid()].secondaryMetric = _this.secondaryMetric; - joolaio.state.metricgroupID = _this.metricgroupID; - _this.init(_this, item, true, true); - //joolaio.saveState("Metric Group change"); - // _this.drawWidgets(_this, $('.joolaio.container.report'), true, true); - }); + //joolaio.visualisation.report.setFilter(''); + _this.init(_this, item, true, true); - joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Applying to container (\'' + this.id + '\')'); + //joolaio.saveState("Tab change"); + // _this.drawWidgets(_this, $('.joolaio.container.report'), true, true); }); - var $editbutton = $('.joolaio.container').find('.panel-edit'); - $editbutton.off('click'); - $editbutton.on('click', function (e) { - var o = new joolaio.visualisation.report.Editor(); - o.init(o, {container: matchedContainers, reportID: _this.reportID}); + $(joolaio).unbind('metricgroupchange'); + $(joolaio).bind('metricgroupchange', function (e, metricgroupID) { + + //_this.reportID = reportID; + _this.metricgroupID = metricgroupID; + try { + joolaio.state['timeline-1234'].primaryMetric = null; + } + catch (ex) { + //ignore + } + //joolaio.state[_this.uid()].secondaryMetric = _this.secondaryMetric; + joolaio.state.metricgroupID = _this.metricgroupID; + _this.init(_this, item, true, true); + //joolaio.saveState("Metric Group change"); + // _this.drawWidgets(_this, $('.joolaio.container.report'), true, true); }); - return _this; + joolaio.debug.log('INFO', 'joolaio.Visualisation.Report.Panel', 6, 'Applying to container (\'' + this.id + '\')'); + }); + + var $editbutton = $('.joolaio.container').find('.panel-edit'); + $editbutton.off('click'); + $editbutton.on('click', function (e) { + var o = new joolaio.visualisation.report.Editor(); + o.init(o, {container: matchedContainers, reportID: _this.reportID}); + }); + + return _this; }; joolaio.visualisation.report.Panel.prototype.setDisplay = function () { @@ -264,236 +268,236 @@ joolaio.visualisation.report.Panel.prototype.setDisplay = function () { } joolaio.visualisation.report.Panel.prototype.show = function () { - $('.joolaio.report.panel').show(); + $('.joolaio.report.panel').show(); } joolaio.visualisation.report.Panel.prototype.hide = function () { - $('.joolaio.dashboard.panel').hide(); + $('.joolaio.dashboard.panel').hide(); } joolaio.visualisation.report.Panel.prototype.dispose = function () { - var container = $('.joolaio.report.panel'); - var $tabs = $(container).find('.tabs'); - var $mgs = $(container).find('.metricgroups'); - var $timeline = $(container).find('.timeline'); - var $metricbox = $(container).find('.metricbox'); - var $table = $(container).find('.jtable'); - - $tabs.empty(); - $mgs.empty(); - $timeline.empty(); - $metricbox.empty(); - $table.empty(); - - joolaio.visualisation.report.tabs = null; - joolaio.visualisation.report.metricgroup = null; - joolaio.visualisation.report.timeline = null; - joolaio.visualisation.report.metricbox = null; - if (joolaio.visualisation.report.table) - joolaio.visualisation.report.table.destroy(); - joolaio.visualisation.report.table = null; - if (joolaio.visualisation.report.tableex) - joolaio.visualisation.report.tableex.destroy(); - joolaio.visualisation.report.tableex = null; - if (joolaio.visualisation.report.histogram) - joolaio.visualisation.report.histogram.destroy(); - joolaio.visualisation.report.histogram = null; + var container = $('.joolaio.report.panel'); + var $tabs = $(container).find('.tabs'); + var $mgs = $(container).find('.metricgroups'); + var $timeline = $(container).find('.timeline'); + var $metricbox = $(container).find('.metricbox'); + var $table = $(container).find('.jtable'); + + $tabs.empty(); + $mgs.empty(); + $timeline.empty(); + $metricbox.empty(); + $table.empty(); + + joolaio.visualisation.report.tabs = null; + joolaio.visualisation.report.metricgroup = null; + joolaio.visualisation.report.timeline = null; + joolaio.visualisation.report.metricbox = null; + if (joolaio.visualisation.report.table) + joolaio.visualisation.report.table.destroy(); + joolaio.visualisation.report.table = null; + if (joolaio.visualisation.report.tableex) + joolaio.visualisation.report.tableex.destroy(); + joolaio.visualisation.report.tableex = null; + if (joolaio.visualisation.report.histogram) + joolaio.visualisation.report.histogram.destroy(); + joolaio.visualisation.report.histogram = null; } joolaio.visualisation.report.Panel.prototype.baseHTML = function (sender, container) { - var $container = $(container); - //$container.empty(); + var $container = $(container); + //$container.empty(); } joolaio.visualisation.report.Panel.prototype.drawWidgets = function (sender, container, redraw) { - var _this = sender; - var panel = _this.panel; - var widgets = panel.Widgets; - - var _html = ''; - - _this.dispose(); + var _this = sender; + var panel = _this.panel; + var widgets = panel.Widgets; - var dimensions = cloneextend(sender.panel.tabs[_this.tabID].dimensions); - var drilldowns = cloneextend(sender.panel.tabs[_this.tabID].drilldowns); - var metrics = sender.panel.tabs[_this.tabID].metricgroups[_this.metricgroupID].metrics.slice(0); + var _html = ''; - if (typeof(metrics[0] != 'object')) { - _.each(metrics, function (m, i) { - metrics[i] = joolaio.objects.Metrics.Get(null, {id: m}); - }); - } - if (typeof(dimensions[0] != 'object')) { - _.each(dimensions, function (d, i) { - dimensions[i] = joolaio.objects.Dimensions.Get(null, {id: d}); - }); - } + _this.dispose(); - if (typeof(drilldowns[0] != 'object')) { - _.each(drilldowns, function (d, i) { - drilldowns[i] = joolaio.objects.Dimensions.Get(null, {id: d.dimensions[0].id}); - }); - } + var dimensions = cloneextend(sender.panel.tabs[_this.tabID].dimensions); + var drilldowns = cloneextend(sender.panel.tabs[_this.tabID].drilldowns); + var metrics = sender.panel.tabs[_this.tabID].metricgroups[_this.metricgroupID].metrics.slice(0); - var dimensionslist = ''; - var metricslist = ''; - - $(dimensions).each(function (i, o) { - dimensionslist += o.id + ', '; + if (typeof(metrics[0] != 'object')) { + _.each(metrics, function (m, i) { + metrics[i] = joolaio.objects.Metrics.Get(null, {id: m}); }); - dimensionslist = dimensionslist.substring(0, dimensionslist.length - 2); - - $(metrics).each(function (i, o) { - metricslist += o.id + ', '; + } + if (typeof(dimensions[0] != 'object')) { + _.each(dimensions, function (d, i) { + dimensions[i] = joolaio.objects.Dimensions.Get(null, {id: d}); }); - metricslist = metricslist.substring(0, metricslist.length - 2); + } - var levels = []; - $(drilldowns).each(function (i, l) { - var dimensions = []; - $(l).each(function (i2, d) { - $(d.dimensions).each(function (i3, dimension) { - dimensions.push(dimension.id); - }) - }); - levels.push(dimensions); + if (typeof(drilldowns[0] != 'object')) { + _.each(drilldowns, function (d, i) { + drilldowns[i] = joolaio.objects.Dimensions.Get(null, {id: d.dimensions[0].id}); }); - - - var $tabs = $(container).find('.tabs'); - var $mgs = $(container).find('.metricgroups'); - var $timeline = $(container).find('.timeline'); - var $metricbox = $(container).find('.metricbox'); - var $table = $(container).find('.jtable'); - - $tabs.empty(); + } + + var dimensionslist = ''; + var metricslist = ''; + + $(dimensions).each(function (i, o) { + dimensionslist += o.id + ', '; + }); + dimensionslist = dimensionslist.substring(0, dimensionslist.length - 2); + + $(metrics).each(function (i, o) { + metricslist += o.id + ', '; + }); + metricslist = metricslist.substring(0, metricslist.length - 2); + + var levels = []; + $(drilldowns).each(function (i, l) { + var dimensions = []; + $(l).each(function (i2, d) { + $(d.dimensions).each(function (i3, dimension) { + dimensions.push(dimension.id); + }) + }); + levels.push(dimensions); + }); + + + var $tabs = $(container).find('.tabs'); + var $mgs = $(container).find('.metricgroups'); + var $timeline = $(container).find('.timeline'); + var $metricbox = $(container).find('.metricbox'); + var $table = $(container).find('.jtable'); + + $tabs.empty(); + $mgs.empty(); + $timeline.empty(); + $metricbox.empty(); + $table.empty(); + $table.removeClass('histogram'); + + $tabs.attr('data-reportid', _this.panel.id); + /* + joolaio.visualisation.report.tabs = null; + joolaio.visualisation.report.metricgroup = null; + joolaio.visualisation.report.timeline = null; + joolaio.visualisation.report.metricbox = null; + joolaio.visualisation.report.table = null; + joolaio.visualisation.report.tableex = null; + joolaio.visualisation.report.histogram = null;*/ + joolaio.visualisation.report.tabs = new joolaio.visualisation.report.Tabs().init({selected: this.tabID}); + + $mgs.attr('data-reportid', _this.panel.id); + $mgs.attr('data-tabid', _this.tabID); + $mgs.attr('data-mgid', _this.metricgroupID); + $timeline.attr('data-metrics', metrics[0].id); + $metricbox.attr('data-metrics', metricslist); + //$table.attr('data-dimensions', JSON.stringify(levels)); + $table.attr('data-dimensions', dimensions[0].id); + $table.attr('data-metrics', metricslist); + + if (this.tabType == 'explorer') { + $('.joolaio.report.metricgroups').show(); + $('.joolaio.report.row-top').show(); + $('.joolaio.report.row-middle').show(); + + joolaio.visualisation.report.metricgroup = new joolaio.visualisation.report.MetricGroup().init(); + + joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[0].id, height: _this.options.widgets.timeline.height, excludeMetrics: _this.options.widgets.timeline.excludeMetrics, disableMetrics: _this.options.widgets.timeline.disableMetrics, showPrimary: _this.options.widgets.timeline.showPrimary}); + joolaio.visualisation.report.metricbox = new joolaio.visualisation.report.MetricBox().init(); + + + if (!_this.options.widgets.table) + _this.options.widgets.table = {pageSize: 10}; + joolaio.visualisation.report.table = new joolaio.visualisation.report.Table().init({pageSize: _this.options.widgets.table.pageSize, + defaultSelected: _this.options.widgets.table.defaultSelected, + minSelected: _this.options.widgets.table.minSelected, + excludeDimensions: this.options.widgets.table.excludeDimensions, + maxSelected: _this.options.widgets.table.maxSelected}); + } + else if (this.tabType == 'table') { + //$tabs.empty(); $mgs.empty(); $timeline.empty(); $metricbox.empty(); $table.empty(); - $table.removeClass('histogram'); - - $tabs.attr('data-reportid', _this.panel.id); - /* - joolaio.visualisation.report.tabs = null; - joolaio.visualisation.report.metricgroup = null; - joolaio.visualisation.report.timeline = null; - joolaio.visualisation.report.metricbox = null; - joolaio.visualisation.report.table = null; - joolaio.visualisation.report.tableex = null; - joolaio.visualisation.report.histogram = null;*/ - joolaio.visualisation.report.tabs = new joolaio.visualisation.report.Tabs().init({selected: this.tabID}); - - $mgs.attr('data-reportid', _this.panel.id); - $mgs.attr('data-tabid', _this.tabID); - $mgs.attr('data-mgid', _this.metricgroupID); - $timeline.attr('data-metrics', metrics[0].id); - $metricbox.attr('data-metrics', metricslist); - //$table.attr('data-dimensions', JSON.stringify(levels)); - $table.attr('data-dimensions', dimensions[0].id); - $table.attr('data-metrics', metricslist); - - if (this.tabType == 'explorer') { - $('.joolaio.report.metricgroups').show(); - $('.joolaio.report.row-top').show(); - $('.joolaio.report.row-middle').show(); - - joolaio.visualisation.report.metricgroup = new joolaio.visualisation.report.MetricGroup().init(); - - joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[0].id, height: _this.options.widgets.timeline.height, excludeMetrics: _this.options.widgets.timeline.excludeMetrics, showPrimary: _this.options.widgets.timeline.showPrimary}); - joolaio.visualisation.report.metricbox = new joolaio.visualisation.report.MetricBox().init(); + $('.joolaio.report.metricgroups').hide(); + $('.joolaio.report.row-top').hide(); + $('.joolaio.report.row-middle').hide(); - if (!_this.options.widgets.table) - _this.options.widgets.table = {pageSize: 10}; - joolaio.visualisation.report.table = new joolaio.visualisation.report.Table().init({pageSize: _this.options.widgets.table.pageSize, - defaultSelected: _this.options.widgets.table.defaultSelected, - minSelected: _this.options.widgets.table.minSelected, - excludeDimensions: this.options.widgets.table.excludeDimensions, - maxSelected: _this.options.widgets.table.maxSelected}); - } - else if (this.tabType == 'table') { - //$tabs.empty(); - $mgs.empty(); - $timeline.empty(); - $metricbox.empty(); - $table.empty(); - - $('.joolaio.report.metricgroups').hide(); - $('.joolaio.report.row-top').hide(); - $('.joolaio.report.row-middle').hide(); - - joolaio.visualisation.report.tableex = new joolaio.visualisation.report.TableEx().init(); - } - else if (this.tabType == 'overview') { - $('.joolaio.report.metricgroups').show(); - $('.joolaio.report.row-top').show(); - $('.joolaio.report.row-middle').show(); + joolaio.visualisation.report.tableex = new joolaio.visualisation.report.TableEx().init(); + } + else if (this.tabType == 'overview') { + $('.joolaio.report.metricgroups').show(); + $('.joolaio.report.row-top').show(); + $('.joolaio.report.row-middle').show(); - joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[0].name, height: 180}); + joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[0].name, height: 180}); - var metrics = _this.panel.tabs[0].metricgroups[0].metrics; - var dimensions = _this.panel.tabs[0].dimensions; + var metrics = _this.panel.tabs[0].metricgroups[0].metrics; + var dimensions = _this.panel.tabs[0].dimensions; - $(dimensions).each(function (index, dimension) { - _html = '
                '; - $metricbox.append(_html); - }); + $(dimensions).each(function (index, dimension) { + _html = '
                '; + $metricbox.append(_html); + }); - $(metrics).each(function (index, metric) { - _html = '
                '; - $metricbox.append(_html); - }); + $(metrics).each(function (index, metric) { + _html = '
                '; + $metricbox.append(_html); + }); - _html = '
                '; - $table.append(_html); - var mb = new joolaio.visualisation.report.OverviewMetricBox().init(); - var pie = new joolaio.visualisation.report.OverviewPie().init(); - var table = new joolaio.visualisation.report.SummaryTable().init(); - } - else if (this.tabType == 'histogram') { - //_this.panel = joolaio.objects.Reports.Get(sender, {id:_this.reportID}, null, true); + _html = '
                '; + $table.append(_html); + var mb = new joolaio.visualisation.report.OverviewMetricBox().init(); + var pie = new joolaio.visualisation.report.OverviewPie().init(); + var table = new joolaio.visualisation.report.SummaryTable().init(); + } + else if (this.tabType == 'histogram') { + //_this.panel = joolaio.objects.Reports.Get(sender, {id:_this.reportID}, null, true); - metricslist = ''; - $(metrics).each(function (i, o) { - if (i > 0) - metricslist += o.name + ', '; - }); - metricslist = metricslist.substring(0, metricslist.length - 2); + metricslist = ''; + $(metrics).each(function (i, o) { + if (i > 0) + metricslist += o.name + ', '; + }); + metricslist = metricslist.substring(0, metricslist.length - 2); - // if (!_this.panel.Tabs[0].MetricGroups[0].histogramsorted){ - //_this.panel.Tabs[0].MetricGroups[0].Metrics.splice(0, 1); - // _this.panel.Tabs[0].MetricGroups[0].histogramsorted=true; - //} + // if (!_this.panel.Tabs[0].MetricGroups[0].histogramsorted){ + //_this.panel.Tabs[0].MetricGroups[0].Metrics.splice(0, 1); + // _this.panel.Tabs[0].MetricGroups[0].histogramsorted=true; + //} - $mgs.attr('data-reportid', _this.panel.id); - $mgs.attr('data-tabid', _this.tabID); - $mgs.attr('data-mgid', _this.metricgroupID); - $timeline.attr('data-metrics', metrics[1].name); - $metricbox.attr('data-metrics', metricslist); - $table.attr('data-dimensions', dimensions[0].name); - //$table.attr('data-metrics', metricslist); + $mgs.attr('data-reportid', _this.panel.id); + $mgs.attr('data-tabid', _this.tabID); + $mgs.attr('data-mgid', _this.metricgroupID); + $timeline.attr('data-metrics', metrics[1].name); + $metricbox.attr('data-metrics', metricslist); + $table.attr('data-dimensions', dimensions[0].name); + //$table.attr('data-metrics', metricslist); - $table.addClass('histogram'); + $table.addClass('histogram'); - $('.joolaio.report.metricgroups').show(); - $('.joolaio.report.row-top').show(); - $('.joolaio.report.row-middle').show(); + $('.joolaio.report.metricgroups').show(); + $('.joolaio.report.row-top').show(); + $('.joolaio.report.row-middle').show(); - joolaio.visualisation.report.metricgroup = new joolaio.visualisation.report.MetricGroup().init(); - joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[1].name}); - joolaio.visualisation.report.metricbox = new joolaio.visualisation.report.MetricBox().init(); - joolaio.visualisation.report.histogram = new joolaio.visualisation.report.Histogram().init(); + joolaio.visualisation.report.metricgroup = new joolaio.visualisation.report.MetricGroup().init(); + joolaio.visualisation.report.timeline = new joolaio.visualisation.report.Timeline().init({primaryMetric: metrics[1].name}); + joolaio.visualisation.report.metricbox = new joolaio.visualisation.report.MetricBox().init(); + joolaio.visualisation.report.histogram = new joolaio.visualisation.report.Histogram().init(); - } + } - $(joolaio).trigger('joolaio-report-draw'); + $(joolaio).trigger('joolaio-report-draw'); }; joolaio.visualisation.report.Panel.prototype.list = function (container) { @@ -501,36 +505,36 @@ joolaio.visualisation.report.Panel.prototype.list = function (container) { }; joolaio.visualisation.report.Panel.prototype.get = function (sender, id) { - if (id == -1) - return; + if (id == -1) + return; - var data = joolaio.objects.Reports.Get(sender, {id: id}); + var data = joolaio.objects.Reports.Get(sender, {id: id}); - sender.reportID = data.id; + sender.reportID = data.id; - //sender.tabID = 0; //data.Tabs[0].ID; + //sender.tabID = 0; //data.Tabs[0].ID; - return data; + return data; }; joolaio.visualisation.report.Panel.prototype.updateDisplay = function (options) { - //joolaio.dataaccess.fetch(this, '/engine/RealtimePanels.svc/get', {id:options.panelID}, function (sender, data, error) { - //data = $.parseJSON(data.data); - var $container = $(options.container); - var data = options._this.panel; - $('body').find('.joolaio.caption').text(data.name.replace('&', '&')).trigger('contentchange'); - $('body').find('.joolaio.description').text(data.description).trigger('contentchange'); - //}); - - - if ($('body').attr('class')) { - if (!$('body').attr('class').indexOf(data.name)) - $('body').addClass(data.name); - } - else - $('body').addClass(data.name); + //joolaio.dataaccess.fetch(this, '/engine/RealtimePanels.svc/get', {id:options.panelID}, function (sender, data, error) { + //data = $.parseJSON(data.data); + var $container = $(options.container); + var data = options._this.panel; + $('body').find('.joolaio.caption').text(data.name.replace('&', '&')).trigger('contentchange'); + $('body').find('.joolaio.description').text(data.description).trigger('contentchange'); + //}); + + + if ($('body').attr('class')) { + if (!$('body').attr('class').indexOf(data.name)) + $('body').addClass(data.name); + } + else + $('body').addClass(data.name); }; joolaio.debug.log('INFO', 'Report.Visualisation.Panel', 6, 'JS source loaded'); diff --git a/lib/joolaio.visualisation.report.Timeline.js b/lib/joolaio.visualisation.report.Timeline.js index 771d9a3..8dd339f 100644 --- a/lib/joolaio.visualisation.report.Timeline.js +++ b/lib/joolaio.visualisation.report.Timeline.js @@ -45,7 +45,7 @@ joolaio.visualisation.report.Timeline = function (options) { this.primaryMetric = null;// joolaio.dataaccess.metrics[0]; this.secondaryMetric = null; //joolaio.dataaccess.metrics[1]; this.Filters = []; - + this.pickers = {}; this.metrics = []; this.height = 235; //for (i = 0 ; i < 250 ; i++) @@ -145,12 +145,14 @@ joolaio.visualisation.report.Timeline.prototype.init = function (options, contai this.options = $.extend({ height: 235, excludeMetrics: [], + disableMetrics: [], showPrimary: true }, options); _this.height = this.options.height; _this.excludeMetrics = this.options.excludeMetrics; + _this.disableMetrics = this.options.disableMetrics; _this.showPrimary = this.options.showPrimary; @@ -218,10 +220,36 @@ joolaio.visualisation.report.Timeline.prototype.init = function (options, contai }; joolaio.visualisation.report.Timeline.prototype.fetch = function (sender) { + if (!sender) sender = joolaio.visualisation.report.Timeline; var _this = sender; + + if (_this.disableMetrics.indexOf(_this.primaryMetric.name) != -1 && joolaio.options.timeline.plotDisabledWhenFiltered && _this.Filters.length == 0) { + _this.pickers.primarymetric.setSelected(_this.pickers.primarymetric,joolaio.objects.Metrics[0].name); + _this.primaryMetric = joolaio.objects.Metrics[0]; + console.log('not fetching primaryMetric'); + //console.log(_this); + + } + + if (_this.secondaryMetric && _this.disableMetrics.indexOf(_this.secondaryMetric.name) != -1 && joolaio.options.timeline.plotDisabledWhenFiltered && _this.Filters.length == 0) { + console.log('not fetching secondaryMetric'); + _this.pickers.secondarymetric.setSelected(_this.pickers.secondarymetric,''); + _this.secondaryMetric = null; + } + /* + if (_this.disableMetrics.indexOf(_this.primaryMetric.name) != -1 && !joolaio.options.timeline.plotDisabledWhenFiltered) { + console.log('not fetching primaryMetric'); + return; + } + + if (_this.secondaryMetric && _this.disableMetrics.indexOf(_this.secondaryMetric.name) != -1 && !joolaio.options.timeline.plotDisabledWhenFiltered) { + console.log('not fetching secondaryMetric'); + return; + } + */ var startdate = joolaio.visualisation.picker.DateBox.getDate().base_fromdate; var enddate = joolaio.visualisation.picker.DateBox.getDate().base_todate; @@ -827,13 +855,14 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) var picker_metrics = new joolaio.visualisation.picker.Metrics({ container: $item, exclude: _this.options.excludeMetrics, + disable: _this.options.disableMetrics, selected: _this.primaryMetric.name//, //metrics: _metrics }); _this.selectedMetric = picker_metrics.selectedMetric; - + _this.pickers.primarymetric = picker_metrics; $(picker_metrics).bind('select', function (data, metric) { metric = _.find(joolaio.objects.Metrics, function (item) { @@ -870,10 +899,14 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) container: $item, allowremove: true, exclude: _this.options.excludeMetrics, + disable: _this.options.disableMetrics, selected: (_this.secondaryMetric ? _this.secondaryMetric.name : '')//, //metrics: _metrics }); + _this.pickers.secondarymetric = picker_secondary; + + picker_secondary.disableMetric(picker_secondary, _this.primaryMetric); $(picker_secondary).bind('select', function (data, metric) { @@ -1005,6 +1038,7 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) }, redraw: function () { + $(Container).find('.legend').empty(); var _series = _this.Chart.series; From 67f2cf58e0fa9bf74f0021e48e46ce13f1da3c55 Mon Sep 17 00:00:00 2001 From: orjoola Date: Wed, 16 Oct 2013 16:40:37 +0300 Subject: [PATCH 09/14] More progress --- lib/joolaio.visualisation.picker.Metrics.js | 53 +++++++++++++++----- lib/joolaio.visualisation.report.Table.js | 15 ++++-- lib/joolaio.visualisation.report.Timeline.js | 19 +++---- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/lib/joolaio.visualisation.picker.Metrics.js b/lib/joolaio.visualisation.picker.Metrics.js index 9bf6f66..9f62992 100644 --- a/lib/joolaio.visualisation.picker.Metrics.js +++ b/lib/joolaio.visualisation.picker.Metrics.js @@ -198,22 +198,25 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m //$('.metricswrapper') }; -joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, metricname, bind) { +joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, metricname, bind) { bind = typeof bind !== 'undefined' ? bind : true; var classname = 'disabled'; if (joolaio.options.picker.metrics.hideDisabledMetrics) classname += ' hidden'; - //var container = $('.joolaio.picker.metrics:first'); + //var container = $('.joolaio.picker.metrics'); var container = sender.container[0]; + console.log(container, sender); if (bind) { $(container).find('.key').each(function (i, m) { if ($(m).closest('.node .hidden') || $(m).closest('.node .disabled')) { - console.log('binding ', metricname.name); - $(m).closest('.node').off('click'); - $(m).closest('.node').on('click', function (e) { - //e.stopPropagation(); - sender.setSelected(sender, $(m).text()); - }); + if (sender.options.disable.indexOf($(m).text()) == -1) { + console.log('binding ', $(m).text()); + $(m).closest('.node').off('click'); + $(m).closest('.node').on('click', function (e) { + //e.stopPropagation(); + sender.setSelected(sender, $(m).text()); + }); + } } @@ -222,8 +225,7 @@ joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, }); } - if (metricname && metricname.name != '') { - + if (metricname && metricname.name != '') { $(container).find('.key').each(function (i, m) { if ($(m).text() == metricname.name) { console.log('unbinding ', metricname.name); @@ -377,6 +379,12 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { var $li = $(list); $($list.find('.jcontainer:last-of-type')).append($li); + $li.on('click', function (e) { + $('.metricscontainer').hide(); + $('.jbtn').removeClass('active'); + + _this.setSelected(_this, $(this).attr('data-metricname')); + }); } else if (_this.options.exclude.indexOf(metric.name) == -1 && _this.options.disable.indexOf(metric.name) > -1) { @@ -397,6 +405,25 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { var $li = $(list); $($list.find('.jcontainer:last-of-type')).append($li); + + $(joolaio).bind('joolaio-report-filter-applied', function() { + if (joolaio.options.timeline.plotDisabledWhenFiltered && joolaio.visualisation.report.timeline.disableMetrics.length > 0) { + $li.on('click', function (e) { + $('.metricscontainer').hide(); + $('.jbtn').removeClass('active'); + + _this.setSelected(_this, $(this).attr('data-metricname')); + }); + } + }); + + $(joolaio).bind('joolaio-report-filter-removed', function() { + if (joolaio.options.timeline.plotDisabledWhenFiltered && joolaio.visualisation.report.timeline.disableMetrics.length > 0) { + _this.disableMetric(_this, metric, false); + console.log('unhiding ', metric.name); + $($li).removeClass('hidden'); + } + }); } }); @@ -462,17 +489,19 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $('.jbtn').removeClass('active'); }); }); - + /* $($container).find('.node.level_1').each(function (index, item) { var $li = $(this); + console.log('binding all nodes'); $li.off('click'); $li.on('click', function (e) { $('.metricscontainer').hide(); $('.jbtn').removeClass('active'); + _this.setSelected(_this, $(this).attr('data-metricname')); }); }); - + */ $container.bind('mousewheel', function (e, d) { if (d > 0 && $(this).scrollTop() == 0) e.preventDefault(); diff --git a/lib/joolaio.visualisation.report.Table.js b/lib/joolaio.visualisation.report.Table.js index 50a655b..ddefd82 100644 --- a/lib/joolaio.visualisation.report.Table.js +++ b/lib/joolaio.visualisation.report.Table.js @@ -898,13 +898,18 @@ joolaio.visualisation.report.Table.prototype.update = function (sender) { $checkbox.attr('data-filter', filter); $checkbox.off('click'); $checkbox.on('click', function (e) { - + if ($checkbox.is(':checked')) { - + $(joolaio).trigger('joolaio-report-filter-applied'); + joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); } else { + if ($('.checkfilter:checked').length == 0) { + $(joolaio).trigger('joolaio-report-filter-removed'); + } + joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); @@ -1274,13 +1279,15 @@ joolaio.visualisation.report.Table.prototype.update = function (sender) { $checkbox.off('click'); $checkbox.on('click', function (e) { - if ($checkbox.is(':checked')) { - + $(joolaio).trigger('joolaio-report-filter-applied'); joolaio.visualisation.report.addPartial(joolaio.visualisation.report.globalfilter + filter); _this.Filters.push(joolaio.visualisation.report.globalfilter + filter); } else { + if ($('.checkfilter:checked').length == 0) { + $(joolaio).trigger('joolaio-report-filter-removed'); + } joolaio.visualisation.report.removePartial(joolaio.visualisation.report.globalfilter + filter); if (_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter) > -1) { _this.Filters.splice(_this.Filters.indexOf(joolaio.visualisation.report.globalfilter + filter), 1); diff --git a/lib/joolaio.visualisation.report.Timeline.js b/lib/joolaio.visualisation.report.Timeline.js index 8dd339f..0118dfd 100644 --- a/lib/joolaio.visualisation.report.Timeline.js +++ b/lib/joolaio.visualisation.report.Timeline.js @@ -239,17 +239,7 @@ joolaio.visualisation.report.Timeline.prototype.fetch = function (sender) { _this.pickers.secondarymetric.setSelected(_this.pickers.secondarymetric,''); _this.secondaryMetric = null; } - /* - if (_this.disableMetrics.indexOf(_this.primaryMetric.name) != -1 && !joolaio.options.timeline.plotDisabledWhenFiltered) { - console.log('not fetching primaryMetric'); - return; - } - if (_this.secondaryMetric && _this.disableMetrics.indexOf(_this.secondaryMetric.name) != -1 && !joolaio.options.timeline.plotDisabledWhenFiltered) { - console.log('not fetching secondaryMetric'); - return; - } - */ var startdate = joolaio.visualisation.picker.DateBox.getDate().base_fromdate; var enddate = joolaio.visualisation.picker.DateBox.getDate().base_todate; @@ -919,7 +909,7 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) _this.setState(_this); //$(joolaio.visualisation).trigger('secondarymetric', _this, metric); - picker_metrics.disableMetric(picker_metrics, _this.secondaryMetric); + picker_metrics.disableMetric(picker_secondary, _this.secondaryMetric); }); $(joolaio.visualisation).unbind('secondarymetric'); $(joolaio.visualisation).bind('secondarymetric', function (e, sender, metric) { @@ -983,7 +973,12 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) $($metlist).append(item); }); - //$('.joolaio.metricname').html(joolaio.dataaccess.metrics[0].Name); + + + + + + //$('.joolaio.metricname').html(joolaio.dataaccess.metrics[0].Name); $('.joolaio.metricname').html(_this.primaryMetric.name); $(Container).find('.joolaio.metriccontainer.current').append($metlist); From 526babd8381969d994fe541a8774e667af3b3f10 Mon Sep 17 00:00:00 2001 From: orjoola Date: Thu, 17 Oct 2013 14:03:46 +0300 Subject: [PATCH 10/14] Finished working on JARVIS-399 --- lib/joolaio.visualisation.picker.Metrics.js | 17 ++++++++------- lib/joolaio.visualisation.report.Timeline.js | 22 ++++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/joolaio.visualisation.picker.Metrics.js b/lib/joolaio.visualisation.picker.Metrics.js index 9f62992..8f74148 100644 --- a/lib/joolaio.visualisation.picker.Metrics.js +++ b/lib/joolaio.visualisation.picker.Metrics.js @@ -187,8 +187,9 @@ joolaio.visualisation.picker.Metrics.prototype.setSelected = function (sender, m _this.options.selected = metricname; if (sender.type == _this.type) + { $(_this).trigger('select', metricname) - + } var metrics = joolaio.objects.Metrics; $(metrics).each(function (i, m) { if (m.name == metricname) { @@ -203,14 +204,14 @@ joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, var classname = 'disabled'; if (joolaio.options.picker.metrics.hideDisabledMetrics) classname += ' hidden'; + //var container = $('.joolaio.picker.metrics'); var container = sender.container[0]; - console.log(container, sender); + if (bind) { $(container).find('.key').each(function (i, m) { if ($(m).closest('.node .hidden') || $(m).closest('.node .disabled')) { if (sender.options.disable.indexOf($(m).text()) == -1) { - console.log('binding ', $(m).text()); $(m).closest('.node').off('click'); $(m).closest('.node').on('click', function (e) { //e.stopPropagation(); @@ -228,13 +229,14 @@ joolaio.visualisation.picker.Metrics.prototype.disableMetric = function (sender, if (metricname && metricname.name != '') { $(container).find('.key').each(function (i, m) { if ($(m).text() == metricname.name) { - console.log('unbinding ', metricname.name); - $(m).closest('.node').unbind('click'); - $(m).closest('.node').bind('click', function (e) { + //$(m).closest('.node') + //$(m).closest('.node').bind('click', function (e) { //e.stopPropagation(); - }); + // }); var nodeParent = $(m).closest('.node'); + nodeParent.unbind('click'); $(nodeParent).addClass(classname); + } }); } @@ -420,7 +422,6 @@ joolaio.visualisation.picker.Metrics.prototype.baseHTML = function (sender) { $(joolaio).bind('joolaio-report-filter-removed', function() { if (joolaio.options.timeline.plotDisabledWhenFiltered && joolaio.visualisation.report.timeline.disableMetrics.length > 0) { _this.disableMetric(_this, metric, false); - console.log('unhiding ', metric.name); $($li).removeClass('hidden'); } }); diff --git a/lib/joolaio.visualisation.report.Timeline.js b/lib/joolaio.visualisation.report.Timeline.js index 0118dfd..429fc60 100644 --- a/lib/joolaio.visualisation.report.Timeline.js +++ b/lib/joolaio.visualisation.report.Timeline.js @@ -227,15 +227,20 @@ joolaio.visualisation.report.Timeline.prototype.fetch = function (sender) { var _this = sender; if (_this.disableMetrics.indexOf(_this.primaryMetric.name) != -1 && joolaio.options.timeline.plotDisabledWhenFiltered && _this.Filters.length == 0) { - _this.pickers.primarymetric.setSelected(_this.pickers.primarymetric,joolaio.objects.Metrics[0].name); - _this.primaryMetric = joolaio.objects.Metrics[0]; - console.log('not fetching primaryMetric'); - //console.log(_this); + var metricName = joolaio.visualisation.reportWrapper.panel.tabs[0].metricgroups[0].metrics[0]; + _this.primaryMetric = _.filter(joolaio.objects.Metrics, function(metric){ + return metric.id== metricName; + }); + if (Array.isArray(_this.primaryMetric )) + _this.primaryMetric=_this.primaryMetric[0]; + + _this.pickers.primarymetric.setSelected(_this.pickers.primarymetric,_this.primaryMetric.name); + + return; } if (_this.secondaryMetric && _this.disableMetrics.indexOf(_this.secondaryMetric.name) != -1 && joolaio.options.timeline.plotDisabledWhenFiltered && _this.Filters.length == 0) { - console.log('not fetching secondaryMetric'); _this.pickers.secondarymetric.setSelected(_this.pickers.secondarymetric,''); _this.secondaryMetric = null; } @@ -883,6 +888,7 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) var $item = $('
                '); + //$(Container).find('.btn-group').empty(); $(Container).find('.comparemetricwrapper').append($item); var picker_secondary = new joolaio.visualisation.picker.Metrics({ @@ -909,7 +915,8 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) _this.setState(_this); //$(joolaio.visualisation).trigger('secondarymetric', _this, metric); - picker_metrics.disableMetric(picker_secondary, _this.secondaryMetric); + + picker_metrics.disableMetric(picker_metrics, _this.secondaryMetric); }); $(joolaio.visualisation).unbind('secondarymetric'); $(joolaio.visualisation).bind('secondarymetric', function (e, sender, metric) { @@ -921,6 +928,9 @@ joolaio.visualisation.report.Timeline.prototype.drawChart = function (Container) _this.secondaryMetric = metric; _this.fetch(_this); _this.setState(_this); + + + //picker_metrics.disableMetric(picker_secondary, _this.secondaryMetric); } }); From 18b76aab74aa5f30b081b70715b2fd84ea841b67 Mon Sep 17 00:00:00 2001 From: orjoola Date: Sun, 20 Oct 2013 14:59:20 +0300 Subject: [PATCH 11/14] Fixed if condition for pie chart --- lib/joolaio.visualisation.dashboard.Pie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/joolaio.visualisation.dashboard.Pie.js b/lib/joolaio.visualisation.dashboard.Pie.js index 80aecb2..3021724 100644 --- a/lib/joolaio.visualisation.dashboard.Pie.js +++ b/lib/joolaio.visualisation.dashboard.Pie.js @@ -620,7 +620,7 @@ joolaio.visualisation.dashboard.Pie.prototype.draw = function (container) { var $html = $('
                '); - if ($($(container).parent()).attr('class').indexOf('span5') > -1) { + if ($($(container).parent()).attr('class') && $($(container).parent()).attr('class').indexOf('span5') > -1) { $html.append('
                ' + '
                ' + '
                ' + From b2cdb7545c57cfd5c1c42cac9e2de889dbbb4879 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 24 Oct 2013 08:17:06 +0300 Subject: [PATCH 12/14] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 026a819..fb47fb6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "joola.io.sdk", "preferGlobal": false, - "version": "3.1.4", + "version": "3.2.0", "author": "Joola ", "description": "joola.io's software development kit (SDK)", "engine": "node >= 0.10.x", From 5958d3d889cc72b27806f09d74a00296265ef32a Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Thu, 24 Oct 2013 10:09:05 +0300 Subject: [PATCH 13/14] Fixed missing , --- lib/joolaio.visualisation.report.Timeline.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/joolaio.visualisation.report.Timeline.js b/lib/joolaio.visualisation.report.Timeline.js index c3d58b1..0804c9b 100644 --- a/lib/joolaio.visualisation.report.Timeline.js +++ b/lib/joolaio.visualisation.report.Timeline.js @@ -146,8 +146,8 @@ joolaio.visualisation.report.Timeline.prototype.init = function (options, contai height: 235, excludeMetrics: [], disableMetrics: [], - showPrimary: true - hide_xaxis:false, + showPrimary: true, + hide_xaxis:false, bgcolor:'#fff' }, options); From cbeb0ce7373b9e8589edd11d501e1d8a2daa5cd2 Mon Sep 17 00:00:00 2001 From: Itay Weinberger Date: Mon, 28 Oct 2013 16:52:38 +0200 Subject: [PATCH 14/14] version bump 3.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb47fb6..9ff32c6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "joola.io.sdk", "preferGlobal": false, - "version": "3.2.0", + "version": "3.2.2", "author": "Joola ", "description": "joola.io's software development kit (SDK)", "engine": "node >= 0.10.x",