Skip to content

Commit

Permalink
In segmented visitor log, allow opening segment editor in new tab w/ …
Browse files Browse the repository at this point in the history
…segment used. (matomo-org#14092)

* In segmented visitor log, allow opening segment editor in new tab w/ segment used.

* Remove empty title.
  • Loading branch information
diosmosis committed Feb 24, 2019
1 parent c02e6ce commit 2b3bb2c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 19 deletions.
10 changes: 10 additions & 0 deletions core/ViewDataTable/Config.php
Expand Up @@ -505,6 +505,16 @@ class Config
public $no_data_message = '';

/**
* List of extra actions to display as icons in the datatable footer.
*
* Not API yet.
*
* @var array
* @ignore
*/
public $datatable_actions = [];

/*
* Can be used to add a segment condition to the segment used to launch the segmented visitor log.
* This can be useful if you'd like to have this segment condition applied ONLY to the segmented visitor
* log, and not to the report itself.
Expand Down
14 changes: 14 additions & 0 deletions plugins/CoreHome/templates/_dataTableActions.twig
Expand Up @@ -103,6 +103,20 @@
</a>
{% endif %}
{% if properties.datatable_actions|default is not empty %}
{% for action in properties.datatable_actions %}
<a class='dataTableAction {{ action.id|e('html_attr') }}'
href='javascript:;' title="{{ action.title|e('html_attr') }}"
>
{% if action.icon starts with 'icon-' %}
<span class="{{ action.icon }}"></span>
{% else %}
<img width="16" height="16" title="{{ action.title }}" src="{{ action.icon }}"/>
{% endif %}
</a>
{% endfor %}
{% endif %}
<ul id='dropdownConfigure{{ randomIdForDropdown }}' class='dropdown-content tableConfiguration'>
{% if properties.show_flatten_table %}
{% if clientSideParameters.flat is defined and clientSideParameters.flat == 1 %}
Expand Down
9 changes: 9 additions & 0 deletions plugins/Live/Visualizations/VisitorLog.php
Expand Up @@ -113,6 +113,15 @@ public function beforeRender()
)
)
);

$enableAddNewSegment = Common::getRequestVar('enableAddNewSegment', false);
if ($enableAddNewSegment) {
$this->config->datatable_actions[] = [
'id' => 'addSegmentToMatomo',
'title' => Piwik::translate('SegmentEditor_AddThisToMatomo'),
'icon' => 'icon-segment',
];
}
}

public static function canDisplayViewDataTable(ViewDataTable $view)
Expand Down
3 changes: 2 additions & 1 deletion plugins/Live/javascripts/SegmentedVisitorLog.js
Expand Up @@ -122,7 +122,8 @@ var SegmentedVisitorLog = function() {
action: 'indexVisitorLog',
segment: encodeURIComponent(segment),
disableLink: 1,
small: 1
small: 1,
enableAddNewSegment: 1,
};

$.extend(requestParams, extraParams);
Expand Down
13 changes: 13 additions & 0 deletions plugins/Live/javascripts/visitorLog.js
Expand Up @@ -38,6 +38,7 @@
init: function () {
dataTablePrototype.init.call(this);

var self = this;
initializeVisitorActions(this.$element);

// launch visitor profile on visitor profile link click
Expand All @@ -46,6 +47,18 @@
broadcast.propagateNewPopoverParameter('visitorProfile', $(this).attr('data-visitor-id'));
return false;
});

this.$element.on('click', '.addSegmentToMatomo.dataTableAction', function (e) {
e.preventDefault();
e.stopPropagation();

var url = window.location.href;
url = broadcast.updateParamValue('addSegmentAsNew=' + self.param.segment, url);
url = broadcast.updateParamValue('segment=', url);
url = broadcast.updateParamValue('popover=', url);

window.open(url, "_blank");
});
},

_destroy: function () {
Expand Down
46 changes: 29 additions & 17 deletions plugins/SegmentEditor/javascripts/Segmentation.js
Expand Up @@ -123,6 +123,13 @@ Segmentation = (function($) {
}
};

function handleAddNewSegment() {
var segmentToAdd = broadcast.getValueFromHash('addSegmentAsNew') || broadcast.getValueFromUrl('addSegmentAsNew');
if (segmentToAdd) {
showAddNewSegmentForm({ definition: decodeURIComponent(segmentToAdd) });
}
}

var getSegmentFromId = function (id) {
if(self.availableSegments.length > 0) {
for(var i = 0; i < self.availableSegments.length; i++)
Expand Down Expand Up @@ -298,11 +305,22 @@ Segmentation = (function($) {
});
};

var displayFormAddNewSegment = function (e) {
var displayFormAddNewSegment = function (segment) {
closeAllOpenLists();
addForm("new");
addForm("new", segment);
};

function showAddNewSegmentForm(segment) {
var parameters = {isAllowed: true};
var $rootScope = piwikHelper.getAngularDependency('$rootScope');
$rootScope.$emit('Segmentation.initAddSegment', parameters);
if (parameters && !parameters.isAllowed) {
return;
}

displayFormAddNewSegment(segment);
}

var filterSegmentList = function (keyword) {
var curTitle;
clearFilterSegmentList();
Expand All @@ -327,7 +345,7 @@ Segmentation = (function($) {
if ($(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser li:visible").length == 0) {
$(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser").hide();
}
}
};

var clearFilterSegmentList = function () {
$(self.target).find(" .filterNoResults").remove();
Expand All @@ -336,7 +354,7 @@ Segmentation = (function($) {
});
$(self.target).find(".segmentList .segmentsVisibleToSuperUser").show();
$(self.target).find(".segmentList .segmentsSharedWithMeBySuperUser").show();
}
};

var bindEvents = function () {
self.target.on('click', '.segmentationContainer', function (e) {
Expand Down Expand Up @@ -391,16 +409,9 @@ Segmentation = (function($) {
});

self.target.on('click', '.add_new_segment', function (e) {

var parameters = {isAllowed: true};
var $rootScope = piwikHelper.getAngularDependency('$rootScope');
$rootScope.$emit('Segmentation.initAddSegment', parameters);
if (parameters && !parameters.isAllowed) {
return;
}

e.stopPropagation();
displayFormAddNewSegment(e);

showAddNewSegmentForm();
});

// attach event that will clear segment list filtering input after clicking x
Expand Down Expand Up @@ -574,18 +585,18 @@ Segmentation = (function($) {
}

if(mode == "edit") {
var userSelector = $(self.form).find('.enable_all_users_select > option[value="' + segment.enable_all_users + '"]').prop("selected",true);
$(self.form).find('.enable_all_users_select > option[value="' + segment.enable_all_users + '"]').prop("selected",true);

// Replace "Visible to me" by "Visible to $login" when user is super user
if(hasSuperUserAccessAndSegmentCreatedByAnotherUser(segment)) {
$(self.form).find('.enable_all_users_select > option[value="' + 0 + '"]').text(segment.login);
}
$(self.form).find('.visible_to_website_select > option[value="'+segment.enable_only_idsite+'"]').prop("selected",true);
$(self.form).find('.auto_archive_select > option[value="'+segment.auto_archive+'"]').prop("selected",true);
}

if (segment.definition != ""){
self.form.find('[piwik-segment-generator]').attr('segment-definition', segment.definition);
}
if (segment.definition != ""){
self.form.find('[piwik-segment-generator]').attr('segment-definition', segment.definition);
}

makeDropList(".enable_all_users" , ".enable_all_users_select");
Expand Down Expand Up @@ -782,6 +793,7 @@ Segmentation = (function($) {

this.initHtml();
bindEvents();
handleAddNewSegment();
};

return segmentation;
Expand Down
3 changes: 2 additions & 1 deletion plugins/SegmentEditor/lang/en.json
Expand Up @@ -51,6 +51,7 @@
"CustomUnprocessedSegmentApiError4": "Once created the segment in the editor (or via API), this error message will disappear and within a few hours you will see your segmented report data, after the segment data has been pre-processed. (If it does not, there may be a problem.)",
"CustomUnprocessedSegmentApiError5": "Please note that you can test whether your segment will work without having to wait for it to be processed by using the Live.getLastVisitsDetails API.",
"CustomUnprocessedSegmentApiError6": "When using this API method, you will see which users and actions were matched by your &segment= parameter.",
"CustomUnprocessedSegmentNoData": "To see data for this segment, you must create this segment manually in the Segment Editor, then wait a couple hours for preprocessing to complete."
"CustomUnprocessedSegmentNoData": "To see data for this segment, you must create this segment manually in the Segment Editor, then wait a couple hours for preprocessing to complete.",
"AddThisToMatomo": "Add this segment to Matomo"
}
}

0 comments on commit 2b3bb2c

Please sign in to comment.