diff --git a/plugins/Dashboard/javascripts/widgetMenu.js b/plugins/Dashboard/javascripts/widgetMenu.js index 2a5af68e45969e17639acedf182ff31027fa0754..bb24b98d67e20f3a0afb2f41e8e8adb3d848e4f8 100644 --- a/plugins/Dashboard/javascripts/widgetMenu.js +++ b/plugins/Dashboard/javascripts/widgetMenu.js @@ -258,7 +258,7 @@ widgetsHelper.loadWidgetAjax = function (widgetUniqueId, widgetParameters, onWid } // delay widget preview a few millisconds - $('li:not(.' + settings.unavailableClass + ')', widgetList).on('mouseenter', function () { + $('li', widgetList).on('mouseenter', function () { var that = this, widgetUniqueId = $(this).attr('uniqueid'); clearTimeout(widgetPreview); diff --git a/plugins/Insights/API.php b/plugins/Insights/API.php index ad7f780f1f6ef2e5bd259a6d2dd78c1c17deae53..e69f494f0d426fb4bb49a312b1c204dc75edca14 100644 --- a/plugins/Insights/API.php +++ b/plugins/Insights/API.php @@ -22,8 +22,14 @@ use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI; */ class API extends \Piwik\Plugin\API { - - public function getOverallMoversAndShakers($idSite, $period, $date) + const FILTER_BY_NEW = 'new'; + const FILTER_BY_MOVERS = 'movers'; + const FILTER_BY_DISAPPEARED = 'disappeared'; + const ORDER_BY_RELATIVE = 'relative'; + const ORDER_BY_ABSOLUTE = 'absolute'; + const ORDER_BY_IMPORTANCE = 'importance'; + + public function getInsightsOverview($idSite, $period, $date) { /** @var DataTable[] $tables */ $tables = array( @@ -35,6 +41,7 @@ class API extends \Piwik\Plugin\API ); // post event to add other reports? + // display new and disappeared only if very high impact $map = new DataTable\Map(); @@ -48,8 +55,8 @@ class API extends \Piwik\Plugin\API // force $limitX and ignore minVisitsPercent, minGrowthPercent public function getInsights( $idSite, $period, $date, $reportUniqueId, $limitIncreaser = 5, $limitDecreaser = 5, - $basedOnTotalMetric = false, $minVisitsPercent = 2, $minGrowthPercent = 20, - $comparedToXPeriods = 1, $orderBy = 'absolute', $filterBy = '', $segment = false) + $filterBy = '', $basedOnTotalMetric = false, $minVisitsPercent = 2, $minGrowthPercent = 20, + $comparedToXPeriods = 1, $orderBy = 'absolute', $segment = false) { Piwik::checkUserHasViewAccess(array($idSite)); @@ -71,20 +78,19 @@ class API extends \Piwik\Plugin\API $considerDisappeared = false; switch ($filterBy) { - case '': + case self::FILTER_BY_MOVERS: $considerMovers = true; + break; + case self::FILTER_BY_NEW: $considerNew = true; + break; + case self::FILTER_BY_DISAPPEARED: $considerDisappeared = true; break; - case 'movers': + default: $considerMovers = true; - break; - case 'new': $considerNew = true; - break; - case 'disappeared': $considerDisappeared = true; - break; } $dataTable = new DataTable(); @@ -202,11 +208,11 @@ class API extends \Piwik\Plugin\API private function getOrderByColumn($orderBy) { - if ('relative' == $orderBy) { + if (self::ORDER_BY_RELATIVE == $orderBy) { $orderByColumn = 'growth_percent_numeric'; - } elseif ('absolute' == $orderBy) { + } elseif (self::ORDER_BY_ABSOLUTE == $orderBy) { $orderByColumn = 'difference'; - } elseif ('importance' == $orderBy) { + } elseif (self::ORDER_BY_IMPORTANCE == $orderBy) { $orderByColumn = 'importance'; } else { throw new \Exception('Unsupported orderBy'); diff --git a/plugins/Insights/Controller.php b/plugins/Insights/Controller.php index ed67b9fada093b6452cc267f35634161330c1d65..eede85ea356b1f56eab83716142f27089ef619ba 100644 --- a/plugins/Insights/Controller.php +++ b/plugins/Insights/Controller.php @@ -17,7 +17,7 @@ use Piwik\View; class Controller extends \Piwik\Plugin\Controller { - public function getOverviewMoversAndShakers() + public function getInsightOverview() { $idSite = Common::getRequestVar('idSite', null, 'int'); $period = Common::getRequestVar('period', null, 'string'); @@ -26,7 +26,7 @@ class Controller extends \Piwik\Plugin\Controller $view = new View('@Insights/index.twig'); $this->setBasicVariablesView($view); - $view->moversAndShakers = API::getInstance()->getOverallMoversAndShakers($idSite, $period, $date); + $view->moversAndShakers = API::getInstance()->getInsightsOverview($idSite, $period, $date); $view->showNoDataMessage = false; $view->showInsightsControls = false; $view->properties = array( diff --git a/plugins/Insights/Insights.php b/plugins/Insights/Insights.php index b8c7a549d273f54e0f34ec61bea21bfb84035fdf..dacd4d2cd34f64922b20627d92ba10eb3fb2f423 100644 --- a/plugins/Insights/Insights.php +++ b/plugins/Insights/Insights.php @@ -33,7 +33,7 @@ class Insights extends \Piwik\Plugin public function addWidgets() { - WidgetsList::add('Insights_Category', 'Insights_OverviewWidgetTitle', 'Insights', 'getOverviewMoversAndShakers'); + WidgetsList::add('Insights_Category', 'Insights_OverviewWidgetTitle', 'Insights', 'getInsightOverview'); } public function getJsFiles(&$jsFiles) diff --git a/plugins/Insights/Visualizations/Insight.php b/plugins/Insights/Visualizations/Insight.php index 6d112e0b2b7df8a2a808b1a1bc16f374588b8c59..eaa89954912ff19ceac4467d8d12d9a960faec67 100644 --- a/plugins/Insights/Visualizations/Insight.php +++ b/plugins/Insights/Visualizations/Insight.php @@ -33,6 +33,23 @@ class Insight extends Visualization $report = $this->requestConfig->apiMethodToRequestDataTable; $report = str_replace('.', '_', $report); + if (!$this->requestConfig->filter_limit) { + $this->requestConfig->filter_limit = 25; + } + + $limit = $this->requestConfig->filter_limit; + $limitDecrease = 0; + $limitIncrease = 0; + + if ($this->requestConfig->limit_increaser && !$this->requestConfig->limit_decreaser) { + $limitIncrease = $limit; + } elseif (!$this->requestConfig->limit_increaser && $this->requestConfig->limit_decreaser) { + $limitDecrease = $limit; + } elseif ($this->requestConfig->limit_increaser && $this->requestConfig->limit_decreaser) { + $limitIncrease = round($limit / 2); + $limitDecrease = $limit - $limitIncrease; + } + $this->requestConfig->apiMethodToRequestDataTable = 'Insights.getInsights'; $this->requestConfig->request_parameters_to_modify = array( 'reportUniqueId' => $report, @@ -42,8 +59,8 @@ class Insight extends Visualization 'comparedToXPeriods' => $this->requestConfig->compared_to_x_periods_ago, 'orderBy' => $this->requestConfig->order_by, 'filterBy' => $this->requestConfig->filter_by, - 'limitIncreaser' => $this->requestConfig->limit_increaser, - 'limitDecreaser' => $this->requestConfig->limit_decreaser, + 'limitIncreaser' => $limitIncrease, + 'limitDecreaser' => $limitDecrease, ); } @@ -72,7 +89,7 @@ class Insight extends Visualization public function beforeRender() { $this->config->datatable_js_type = 'InsightsDataTable'; - $this->config->show_limit_control = false; + $this->config->show_limit_control = true; $this->config->show_pagination_control = false; $this->config->show_offset_information = false; $this->config->show_search = false; diff --git a/plugins/Insights/Visualizations/Insight/RequestConfig.php b/plugins/Insights/Visualizations/Insight/RequestConfig.php index 0b9b6ac164af342dfa605de7ec085a690841960b..7cd4e21bf0eedbde22347689733a08cc31acad90 100644 --- a/plugins/Insights/Visualizations/Insight/RequestConfig.php +++ b/plugins/Insights/Visualizations/Insight/RequestConfig.php @@ -19,8 +19,8 @@ class RequestConfig extends VisualizationRequestConfig public $compared_to_x_periods_ago = 1; public $order_by = 'absolute'; public $filter_by = ''; - public $limit_increaser = 5; - public $limit_decreaser = 5; + public $limit_increaser = '13'; + public $limit_decreaser = '12'; public function __construct() { @@ -35,7 +35,8 @@ class RequestConfig extends VisualizationRequestConfig 'compared_to_x_periods_ago', 'filter_by', 'limit_increaser', - 'limit_decreaser' + 'limit_decreaser', + 'filter_limit' ); $this->addPropertiesThatShouldBeAvailableClientSide($properties); diff --git a/plugins/Insights/javascripts/insightsDataTable.js b/plugins/Insights/javascripts/insightsDataTable.js index 400e50022ea86f2de45a547805ae89b7a3d579b2..3e39b669ef4e9e8e1413018271768852a3f97988 100644 --- a/plugins/Insights/javascripts/insightsDataTable.js +++ b/plugins/Insights/javascripts/insightsDataTable.js @@ -11,6 +11,11 @@ DataTable = exports.DataTable, dataTablePrototype = DataTable.prototype; + function getValueFromEvent(event) + { + return event.target.value ? event.target.value : $(event.target).attr('value'); + } + /** * UI control that handles extra functionality for Actions datatables. * @@ -38,62 +43,79 @@ this.initFilterBy(domElem); }, + _changeParameter: function (params) { + + var widgetParams = {}; + + for (var index in params) { + if (params.hasOwnProperty(index)) { + this.param[index] = params[index]; + widgetParams[index] = params[index]; + } + } + + this.notifyWidgetParametersChange(this.$element, widgetParams); + }, + + _changeParameterAndReload: function (params) { + this._changeParameter(params); + this.reloadAjaxDataTable(true); + }, + initShowIncreaseOrDecrease: function (domElem) { var self = this; $('[name=showIncreaseOrDecrease]', domElem).bind('change', function (event) { - var value = event.target.value; + var value = getValueFromEvent(event); - self.param.limit_increaser = (value == 'both' || value == 'increase') ? '5' : '0'; - self.param.limit_decreaser = (value == 'both' || value == 'decrease') ? '5' : '0'; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({ + limit_increaser: (value == 'both' || value == 'increase') ? '5' : '0', + limit_decreaser: (value == 'both' || value == 'decrease') ? '5' : '0' + }); }); }, initMinGrowthPercentage: function (domElem) { var self = this; $('[name=minGrowthPercent]', domElem).bind('change', function (event) { - self.param.min_growth_percent = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({min_growth_percent: getValueFromEvent(event)}); }); }, initOrderBy: function (domElem) { var self = this; $('[name=orderBy]', domElem).bind('change', function (event) { - self.param.order_by = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({order_by: getValueFromEvent(event)}); + }); + $('th[name=orderBy]', domElem).bind('click', function (event) { + self._changeParameterAndReload({order_by: getValueFromEvent(event)}); }); }, initMinVisitsPercent: function (domElem) { var self = this; $('[name=minVisitsPercent]', domElem).bind('change', function (event) { - self.param.min_visits_percent = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({min_visits_percent: getValueFromEvent(event)}); }); }, initBasedOnTotalMetric: function (domElem) { var self = this; $('[name=basedOnTotalMetric]', domElem).bind('change', function (event) { - self.param.based_on_total_metric = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({based_on_total_metric: getValueFromEvent(event)}); }); }, initComparedToXPeriodsAgo: function (domElem) { var self = this; $('[name=comparedToXPeriodsAgo]', domElem).bind('change', function (event) { - self.param.compared_to_x_periods_ago = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({compared_to_x_periods_ago: getValueFromEvent(event)}); }); }, initFilterBy: function (domElem) { var self = this; $('[name=filterBy]', domElem).bind('change', function (event) { - self.param.filter_by = event.target.value; - self.reloadAjaxDataTable(true); + self._changeParameterAndReload({filter_by: getValueFromEvent(event)}); }); } }); diff --git a/plugins/Insights/lang/en.json b/plugins/Insights/lang/en.json index cde88325336daa32cd2965c60ea9d63f0bb17cdf..e56aa7a470b7cc1981cbfca5d40b5c96bda43d2e 100644 --- a/plugins/Insights/lang/en.json +++ b/plugins/Insights/lang/en.json @@ -1,6 +1,6 @@ { "Insights": { - "OverviewWidgetTitle": "Overview of movers and shakers", + "OverviewWidgetTitle": "Insights Overview", "Category": "Insights" } } \ No newline at end of file diff --git a/plugins/Insights/templates/insightControls.twig b/plugins/Insights/templates/insightControls.twig index c0314bf0a4dabee5efe016c768bd0d3198ebbdae..d976ecccf8cca065ec7301e533d8fe016e748de0 100644 --- a/plugins/Insights/templates/insightControls.twig +++ b/plugins/Insights/templates/insightControls.twig @@ -1,24 +1,18 @@ <div style="padding: 10px;padding-bottom: 0px;"> - Show only rows with a - - minimum impact of - <select name="minVisitsPercent"> - {% for i in range(0, 20) %} + Minimum impact of + <select name="minVisitsPercent" title="Based on a total of {{ dataTable.getMetadata('totalValue') }} visitors or metricname"> + {% for i in range(0, 10) %} + <option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option> + {% endfor %} + {% for i in range(12, 30, 2) %} <option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option> {% endfor %} - {% for i in range(22, 100, 2) %} + {% for i in range(35, 100, 5) %} <option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option> {% endfor %} </select> - {% if properties.show_based_on_total_metric %} - <select size="1" name="basedOnTotalMetric"> - <option value="1" {% if 1 == properties.based_on_total_metric %}selected{% endif %}>compared to metric</option> - <option value="0" {% if 0 == properties.based_on_total_metric %}selected{% endif %}>compared to total visits</option> - </select> - {% endif %} - - and min growth of + and growth of at least <select size="1" name="minGrowthPercent"> {% for i in range(0, 1, 1) %} <option {% if i == properties.min_growth_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option> @@ -31,63 +25,52 @@ {% endfor %} </select> + compared to {% if period == 'day' %} <select size="1" name="comparedToXPeriodsAgo"> <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}> - compare to previous day + previous day </option> <option value="7" {% if properties.compared_to_x_periods_ago == 7 %}selected{% endif %}> - compare to same day in previous week + same day in previous week </option> <option value="365" {% if properties.compared_to_x_periods_ago == 365 %}selected{% endif %}> - compare to same day in previous year + same day in previous year </option> </select> {% elseif period == 'month' %} <select size="1" name="comparedToXPeriodsAgo"> <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}> - compare to previous month + previous month </option> <option value="12" {% if properties.compared_to_x_periods_ago == 12 %}selected{% endif %}> - compare to same month in previous year + same month in previous year </option> </select> {% endif %} - Order them by - <select name="orderBy"> - <option {% if 'absolute' == properties.order_by %}selected{% endif %} value="absolute"> - absolute - </option> - <option {% if 'relative' == properties.order_by %}selected{% endif %} value="relative"> - relative - </option> - <option {% if 'importance' == properties.order_by %}selected{% endif %} value="importance"> - importance - </option> - </select> value + <hr style="height: 1px;border: 0px;background-color: #cccccc;" /> - and show + Filter {% if properties.show_filter_by %} - <select size="1" name="filterBy"> - <option {% if not properties.filter_by %}selected{% endif %} value="">all</option> - <option {% if properties.filter_by == 'movers' %}selected{% endif %} value="movers">only movers</option> - <option {% if properties.filter_by == 'new' %}selected{% endif %} value="new">only new entries</option> - <option {% if properties.filter_by == 'disappeared' %}selected{% endif %} value="disappeared">only disappeared entries</option> + <select size="1" name="filterBy" title="Show all, only movers, only new, only disappeared"> + <option {% if not properties.filter_by %}selected{% endif %} value="">All</option> + <option {% if properties.filter_by == 'movers' %}selected{% endif %} value="movers">Only movers</option> + <option {% if properties.filter_by == 'new' %}selected{% endif %} value="new">Only new</option> + <option {% if properties.filter_by == 'disappeared' %}selected{% endif %} value="disappeared">Only disappeared</option> </select> {% endif %} - if they - <select size="1" name="showIncreaseOrDecrease"> + <select size="1" name="showIncreaseOrDecrease" title="Show increaser and/or decreaser"> <option value="both" {% if properties.limit_increaser and properties.limit_decreaser %}selected{%endif%}> - increase or decrease + All </option> <option value="increase" {% if properties.limit_increaser and not properties.limit_decreaser %}selected{%endif%}> - increase + Only increaser </option> <option value="decrease" {% if not properties.limit_increaser and properties.limit_decreaser %}selected{%endif%}> - decrease + Only decreaser </option> </select> </div> \ No newline at end of file diff --git a/plugins/Insights/templates/insightVisualization.twig b/plugins/Insights/templates/insightVisualization.twig index 8ef6f7184fb2c53b869c10835d72b9c5d0a9ae79..3ff3466a220bf4daa2e0ecf77a05f9fb3cd85ce3 100644 --- a/plugins/Insights/templates/insightVisualization.twig +++ b/plugins/Insights/templates/insightVisualization.twig @@ -6,11 +6,14 @@ <th class="label" style="width:60%;"> {{ dataTable.getMetadata('reportName') }} </th> - <th class="label" style="width:20%;"> + <th class="label" name="orderBy" value="absolute" + style="width:20%;cursor:pointer;{% if 'absolute' == properties.order_by %}font-weight:bold;{% endif %}" + > {{ dataTable.getMetadata('metricName') }} </th> - <th class="label" style="width:20%;"> - Evolution + <th class="label" name="orderBy" value="relative" + style="width:20%;cursor:pointer;{% if 'relative' == properties.order_by %}font-weight:bold;{% endif %}"> + {{ 'MultiSites_Evolution'|translate }} </th> </tr> </thead>