Skip to content

Commit

Permalink
Refs matomo-org#4041, matomo-org#3317, allow visualization ID to be w…
Browse files Browse the repository at this point in the history
…hole class name, allow footer icons to be customized per report/visualization, made visitor log a new visualization and removed the datatable_template display property.
  • Loading branch information
Benaka Moorthi committed Sep 18, 2013
1 parent c22a40a commit c0768bf
Show file tree
Hide file tree
Showing 18 changed files with 409 additions and 299 deletions.
4 changes: 2 additions & 2 deletions core/DataTableVisualization.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class DataTableVisualization
* @param array $properties The view properties.
* @return string The visualization HTML.
*/
public abstract function render($dataTable, $properties);
//public abstract function render($dataTable, $properties); temporarily commented out

/**
* Default implementation of getDefaultPropertyValues static function.
Expand Down Expand Up @@ -106,7 +106,7 @@ public static function getViewDataTableId()
if (defined('static::ID')) {
return static::ID;
} else {
return Piwik::getUnnamespacedClassName($this);
return get_called_class();
}
}

Expand Down
26 changes: 11 additions & 15 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ public function __construct($currentControllerAction,
$viewProperties = array(),
$visualizationId = null)
{
$visualizationClass = $visualizationId ? DataTableVisualization::getClassFromId($visualizationId) : null;
if (class_exists($visualizationId)
&& is_subclass_of($visualizationId, "Piwik\\DataTableVisualization")
) {
$visualizationClass = $visualizationId;
} else {
$visualizationClass = $visualizationId ? DataTableVisualization::getClassFromId($visualizationId) : null;
}

$this->visualizationClass = $visualizationClass;

list($currentControllerName, $currentControllerAction) = explode('.', $currentControllerAction);
Expand Down Expand Up @@ -764,17 +771,6 @@ protected function getJavascriptVariablesToSet()
$javascriptVariablesToSet['totalRows'] = $this->dataTable->getRowsCountBeforeLimitFilter();
}

// we escape the values that will be displayed in the javascript footer of each datatable
// to make sure there is no malicious code injected (the value are already htmlspecialchar'ed as they
// are loaded with Common::getRequestVar()
foreach ($javascriptVariablesToSet as &$value) {
if (is_array($value)) {
$value = array_map('addslashes', $value);
} else {
$value = addslashes($value);
}
}

$deleteFromJavascriptVariables = array(
'filter_excludelowpop',
'filter_excludelowpop_value',
Expand Down Expand Up @@ -1044,8 +1040,7 @@ protected function buildView()
$loadingError = array('message' => $e->getMessage());
}

$template = $this->viewProperties['datatable_template'];
$view = new View($template);
$view = new View("@CoreHome/_dataTable");

if (!empty($loadingError)) {
$view->error = $loadingError;
Expand Down Expand Up @@ -1074,7 +1069,8 @@ protected function buildView()
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->clientSidePropertiesToSet = $this->getClientSidePropertiesToSet();
$view->properties = $this->viewProperties; // TODO: should be $this. need to move non-view properties from the class
$view->footerIcons = $this->getFooterIconsToShow();
$view->footerIcons = $this->viewProperties['footer_icons'] ?: $this->getFooterIconsToShow();
$view->isWidget = Common::getRequestVar('widget', 0, 'int');

$this->view = $view;
}
Expand Down
41 changes: 33 additions & 8 deletions core/ViewDataTable/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,34 @@ class Properties
const DEFAULT_VIEW_TYPE = 'default_view_type';

/**
* This property determines which Twig template to use when rendering a ViewDataTable.
*
* TODO: shouldn't have this property. should only use visualization classes.
*/
const DATATABLE_TEMPLATE = 'datatable_template';
* Controls what footer icons are displayed on the bottom left of the DataTable view.
* The value of this property must be an array of footer icon groups. Footer icon groups
* have set of properties, including an array of arrays describing footer icons. See
* this example to get a clear idea of what is required:
*
* array(
* array( // footer icon group 1
* 'class' => 'footerIconGroup1CssClass',
* 'buttons' => array(
* 'id' => 'myid',
* 'title' => 'My Tooltip',
* 'icon' => 'path/to/my/icon.png'
* )
* ),
* array( // footer icon group 2
* 'class' => 'footerIconGroup2CssClass',
* 'buttons' => array(...)
* )
* )
*
* By default, when a user clicks on a footer icon, Piwik will assume the 'id' is
* a viewDataTable ID and try to reload the DataTable w/ the new viewDataTable. You
* can provide your own footer icon behavior by adding an appropriate handler via
* DataTable.registerFooterIconHandler in your JavaScript.
*
* Default value: // TODO
*/
const FOOTER_ICONS = 'footer_icons';

/**
* Controls whether the buttons and UI controls around the visualization or shown or
Expand Down Expand Up @@ -412,7 +435,9 @@ class Properties
*
* @see Piwik\DataTableVisualization::getClientSideProperties
*/
public static $clientSideProperties = array();
public static $clientSideProperties = array(
'show_limit_control'
);

/**
* The list of ViewDataTable properties that can be overriden by query parameters.
Expand Down Expand Up @@ -561,7 +586,7 @@ public static function checkValidVisualizationProperty($visualizationClass, $nam
public static function getDefaultPropertyValues()
{
$result = array(
'datatable_template' => '@CoreHome/_dataTable',
'footer_icons' => false,
'show_visualization_only' => false,
'datatable_js_type' => 'DataTable',
'show_goals' => false,
Expand All @@ -580,7 +605,7 @@ public static function getDefaultPropertyValues()
'show_flatten_table' => true,
'show_offset_information' => true,
'show_pagination_control' => true,
'show_limit_control' => false,
'show_limit_control' => true,
'show_footer' => true,
'show_footer_icons' => true,
'show_related_reports' => true,
Expand Down
1 change: 1 addition & 0 deletions core/Visualization/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function __construct($view)
public static function getDefaultPropertyValues()
{
return array(
'show_limit_control' => false,
'visualization_properties' => array(
'graph' => array(
'add_total_row' => 0,
Expand Down
14 changes: 7 additions & 7 deletions plugins/CoreHome/javascripts/dataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,7 @@ $.extend(DataTable.prototype, UIControl.prototype, {
// setup limit control
$('.limitSelection', domElem).append('<div><span>' + self.param[limitParamName] + '</span></div><ul></ul>');

if (self.param.viewDataTable == 'table'
|| self.param.viewDataTable == 'tableAllColumns'
|| self.param.viewDataTable == 'tableGoals'
|| self.param.viewDataTable == 'ecommerceOrder'
|| self.param.viewDataTable == 'ecommerceAbandonedCart'
|| self.param.viewDataTable == 'graphEvolution') {
if (self.props.show_limit_control) {
$('.limitSelection ul', domElem).hide();
for (var i = 0; i < numbers.length; i++) {
$('.limitSelection ul', domElem).append('<li value="' + numbers[i] + '"><span>' + numbers[i] + '</span></li>');
Expand Down Expand Up @@ -734,7 +729,12 @@ $.extend(DataTable.prototype, UIControl.prototype, {
return;
}

DataTable._footerIconHandlers[id](self, id);
var handler = DataTable._footerIconHandlers[id];
if (!handler) {
handler = DataTable._footerIconHandlers['table'];
}

handler(self, id);
})

//Graph icon Collapsed functionality
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/templates/_dataTable.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% endif %}
</div>
{% else %}
{{ visualization.render(dataTable, properties)|raw }}
{{ visualization.render(dataTable, properties, javascriptVariablesToSet)|raw }}
{% endif %}

{% if properties.show_footer %}
Expand Down
1 change: 1 addition & 0 deletions plugins/CoreVisualizations/Visualizations/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function getDefaultPropertyValues()
return array(
'show_offset_information' => false,
'show_exclude_low_population' => false,
'show_limit_control' => false,
'visualization_properties' => array(
'cloud' => array(
'display_logo_instead_of_label' => false,
Expand Down
28 changes: 21 additions & 7 deletions plugins/Live/Live.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/Live/javascripts/live.js";
$jsFiles[] = "plugins/Live/javascripts/visitorProfile.js";
$jsFiles[] = "plugins/Live/javascripts/visitorLog.js";
}

public function addMenu()
Expand All @@ -82,6 +83,7 @@ public function getClientSideTranslationKeys(&$translationKeys)
$translationKeys[] = "Live_NoMoreVisits";
$translationKeys[] = "Live_ShowMap";
$translationKeys[] = "Live_HideMap";
$translationKeys[] = "Live_PageRefreshed";
}

public function getReportDisplayProperties(&$properties)
Expand All @@ -92,7 +94,7 @@ public function getReportDisplayProperties(&$properties)
private function getDisplayPropertiesForGetLastVisitsDetails()
{
return array(
'datatable_template' => "@Live/getVisitorLog.twig",
'default_view_type' => 'Piwik\\Plugins\\Live\\VisitorLog',
'disable_generic_filters' => true,
'enable_sort' => false,
'filter_sort_column' => 'idVisit',
Expand All @@ -101,18 +103,30 @@ private function getDisplayPropertiesForGetLastVisitsDetails()
'filter_limit' => 20,
'show_offset_information' => false,
'show_exclude_low_population' => false,
'show_all_views_icons' => false,
'show_table_all_columns' => false,
'show_export_as_rss_feed' => false,
'documentation' => Piwik_Translate('Live_VisitorLogDocumentation', array('<br />', '<br />')),
'custom_parameters' => array(
'show_all_views_icons' => false,
'show_table_all_columns' => false,
'show_export_as_rss_feed' => false,
'documentation' => Piwik_Translate('Live_VisitorLogDocumentation', array('<br />', '<br />')),
'custom_parameters' => array(
// set a very high row count so that the next link in the footer of the data table is always shown
'totalRows' => 10000000,

'filterEcommerce' => Common::getRequestVar('filterEcommerce', 0, 'int'),
'pageUrlNotDefined' => Piwik_Translate('General_NotDefined', Piwik_Translate('Actions_ColumnPageURL'))
),
'visualization_properties' => array(
'footer_icons' => array(
array(
'class' => 'tableAllColumnsSwitch',
'buttons' => array(
array(
'id' => 'Piwik\\Plugins\\Live\\VisitorLog',
'title' => Piwik_Translate('Live_LinkVisitorLog'),
'icon' => 'plugins/Zeitgeist/images/table.png'
)
)
)
),
'visualization_properties' => array(
'table' => array(
'disable_row_actions' => true,
)
Expand Down
51 changes: 51 additions & 0 deletions plugins/Live/VisitorLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
* @category Piwik_Plugins
* @package Live
*/
namespace Piwik\Plugins\Live;

use Piwik\View;
use Piwik\DataTableVisualization;

/**
* A special DataTable visualization for the Live.getLastVisitsDetails API method.
*/
class VisitorLog extends DataTableVisualization
{
static public $clientSideParameters = array(
'filter_limit',
'filter_offset',
'filter_sort_column',
'filter_sort_order',
);

/**
* Constructor.
*/
public function __construct($view)
{
$view->datatable_js_type = 'VisitorLog';
}

/**
* Renders this visualization.
*
* @param DataTable $dataTable
* @param array $properties View Properties.
* @return string
*/
public function render($dataTable, $properties, $javascriptVariablesToSet)
{
$view = new View("@Live/_dataTableViz_visitorLog.twig");
$view->properties = $properties;
$view->dataTable = $dataTable;
$view->javascriptVariablesToSet = $javascriptVariablesToSet;
return $view->render();
}
}
77 changes: 77 additions & 0 deletions plugins/Live/javascripts/visitorLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Piwik - Web Analytics
*
* Visitor profile popup control.
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

(function ($, require) {

var exports = require('piwik/UI'),
DataTable = exports.DataTable,
dataTablePrototype = DataTable.prototype;

/**
* DataTable UI class for jqPlot graph datatable visualizations.
*
* @constructor
*/
exports.VisitorLog = function (element) {
DataTable.call(this, element);
};

$.extend(exports.VisitorLog.prototype, dataTablePrototype, {

/**
* Initializes this class.
*/
init: function () {
dataTablePrototype.init.call(this);

// Replace duplicated page views by a NX count instead of using too much vertical space
$("ol.visitorLog").each(function () {
var prevelement;
var prevhtml;
var counter = 0;
$(this).find("li").each(function () {
counter++;
$(this).val(counter);
var current = $(this).html();
if (current == prevhtml) {
var repeat = prevelement.find(".repeat");
if (repeat.length) {
repeat.html((parseInt(repeat.html()) + 1) + "x");
} else {
prevelement.append($("<em>2x</em>").attr({'class': 'repeat', 'title': _pk_translate('Live_PageRefreshed')}));
}
$(this).hide();
} else {
prevhtml = current;
prevelement = $(this);
}

$(this).tooltip({
track: true,
show: false,
hide: false,
content: function() {
var title = $(this).attr('title');
return $('<a>').text( title ).html().replace(/\n/g, '<br />');
},
tooltipClass: 'small'
});
});
});

// launch visitor profile on visitor profile link click
this.$element.on('click', '.visitor-log-visitor-profile-link', function (e) {
e.preventDefault();
broadcast.propagateNewPopoverParameter('visitorProfile', $(this).attr('data-visitor-id'));
return false;
});
},
});

})(jQuery, require);
Loading

0 comments on commit c0768bf

Please sign in to comment.