Skip to content

Commit 88b40ee

Browse files
committed
Consolidate and add more tests
1 parent 475ffa6 commit 88b40ee

9 files changed

Lines changed: 936 additions & 211 deletions

File tree

plugins/SegmentEditor/Menu.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
<?php
22

33
/**
4-
* Copyright (C) InnoCraft Ltd - All rights reserved.
4+
* Matomo - free/libre analytics platform
55
*
6-
* NOTICE: All information contained herein is, and remains the property of InnoCraft Ltd.
7-
* The intellectual and technical concepts contained herein are protected by trade secret or copyright law.
8-
* Redistribution of this information or reproduction of this material is strictly forbidden
9-
* unless prior written permission is obtained from InnoCraft Ltd.
10-
*
11-
* You shall use this code only in accordance with the license agreement obtained from InnoCraft Ltd.
12-
*
13-
* @link https://www.innocraft.com/
14-
* @license For license details see https://www.innocraft.com/license
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
158
*/
169

1710
namespace Piwik\Plugins\SegmentEditor;

plugins/SegmentEditor/SegmentEditor.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,33 @@ public function getClientSideTranslationKeys(&$translationKeys): void
375375
$translationKeys[] = 'SegmentEditor_AddANDorORCondition';
376376
$translationKeys[] = 'SegmentEditor_DefaultAllVisits';
377377
$translationKeys[] = 'SegmentEditor_AreYouSureDeleteSegment';
378+
$translationKeys[] = 'SegmentEditor_AddNewSegment';
379+
$translationKeys[] = 'SegmentEditor_ManageSegments';
380+
$translationKeys[] = 'SegmentEditor_SegmentPageTitle';
381+
$translationKeys[] = 'SegmentEditor_SegmentPageDescription';
382+
$translationKeys[] = 'SegmentEditor_SeeDashboardForThisSegment';
383+
$translationKeys[] = 'SegmentEditor_SparklineTooltipDays';
384+
$translationKeys[] = 'SegmentEditor_SparklineTooltipWeeks';
385+
$translationKeys[] = 'SegmentEditor_SparklineTooltipMonths';
386+
$translationKeys[] = 'SegmentEditor_SparklineTooltipYears';
387+
$translationKeys[] = 'SegmentEditor_ManageSegmentsRealtimeNotice';
388+
$translationKeys[] = 'SegmentEditor_ManageSegmentsRealtimeNoDataTooltip';
389+
$translationKeys[] = 'General_CanNotEditGlobalSegment';
390+
$translationKeys[] = 'General_CanNotDeleteGlobalSegment';
391+
$translationKeys[] = 'General_CanNotStarGlobalSegment';
392+
$translationKeys[] = 'General_CanNotUnstarGlobalSegment';
393+
$translationKeys[] = 'General_CanEditGlobalSegment';
394+
$translationKeys[] = 'General_CanDeleteGlobalSegment';
395+
$translationKeys[] = 'General_CanStarGlobalSegment';
396+
$translationKeys[] = 'General_CanUnstarGlobalSegment';
397+
$translationKeys[] = 'General_CanNotEditSiteSegment';
398+
$translationKeys[] = 'General_CanNotDeleteSiteSegment';
399+
$translationKeys[] = 'General_CanNotStarSiteSegment';
400+
$translationKeys[] = 'General_CanNotUnstarSiteSegment';
401+
$translationKeys[] = 'General_CanEditSiteSegment';
402+
$translationKeys[] = 'General_CanDeleteSiteSegment';
403+
$translationKeys[] = 'General_CanStarSiteSegment';
404+
$translationKeys[] = 'General_CanUnstarSiteSegment';
378405
$translationKeys[] = 'General_OperationEquals';
379406
$translationKeys[] = 'General_OperationNotEquals';
380407
$translationKeys[] = 'General_OperationAtMost';

plugins/SegmentEditor/javascripts/Segmentation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ Segmentation = (function($) {
427427
$(event.target).parents().hasClass("segmentFilterContainer") === true ||
428428
$(event.target).hasClass("filterNoResults")
429429
) {
430-
e.stopPropagation();
430+
event.stopPropagation();
431431
}
432432
}
433433
self.target.closest('.segmentEditorPanel').removeClass('expanded');
@@ -1103,7 +1103,8 @@ Segmentation = (function($) {
11031103
});
11041104
}
11051105

1106-
window.SegmentEditorPanel = {
1106+
window.matomoPluginSegmentEditor = window.matomoPluginSegmentEditor || {};
1107+
window.matomoPluginSegmentEditor.panelAPI = {
11071108
askToDeleteSegment,
11081109
closePanel,
11091110
getDeleteSegmentTitle,

plugins/SegmentEditor/javascripts/manageSegmentsPage.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ function initManageSegmentsPage() {
33
if (!root) {
44
return;
55
}
6+
const panelApi = window.matomoPluginSegmentEditor
7+
&& window.matomoPluginSegmentEditor.panelAPI;
8+
if (!panelApi) {
9+
return;
10+
}
611
const tbody = root.querySelector('tbody');
712
const rowList = Array.from(tbody.children).reverse();
813
const noResultElement = root.querySelector('.tableFooterLabel');
@@ -14,7 +19,7 @@ function initManageSegmentsPage() {
1419
initListener();
1520
initHref();
1621
initTitles();
17-
window.SegmentEditorPanel.onSegmentsStarChange(onSegmentsStarChange);
22+
panelApi.onSegmentsStarChange(onSegmentsStarChange);
1823
}
1924

2025
function reorderSegments() {
@@ -49,7 +54,8 @@ function initManageSegmentsPage() {
4954
rowList.forEach(function (row) {
5055
const definition = row.getAttribute('data-segment-definition');
5156
const $dashboardLink = $('.icon-show', row);
52-
$dashboardLink.attr('href', window.broadcast.buildReportingUrl('category=Dashboard_Dashboard&segment='+definition));
57+
const encodedDefinition = encodeURIComponent(definition || '');
58+
$dashboardLink.attr('href', window.broadcast.buildReportingUrl(`category=Dashboard_Dashboard&segment=${encodedDefinition}`));
5359
});
5460
}
5561

@@ -59,19 +65,19 @@ function initManageSegmentsPage() {
5965
const $editButton = $('[data-edit-segment]', row);
6066
const $deleteButton = $('[data-delete-segment]', row);
6167
const idSegment = $starButton.attr('data-star');
62-
const segment = window.SegmentEditorPanel.getSegmentFromId(idSegment);
68+
const segment = panelApi.getSegmentFromId(idSegment);
6369
if (segment && typeof segment.enable_only_idsite === 'string') {
6470
segment.enable_only_idsite = parseInt(segment.enable_only_idsite, 10) || 0;
6571
}
66-
const canEdit = window.SegmentEditorPanel.getCanUserEditSegment(segment);
72+
const canEdit = panelApi.getCanUserEditSegment(segment);
6773
if (!canEdit) {
6874
$starButton.attr('data-state', 'disabled');
6975
$editButton.attr('data-state', 'disabled');
7076
$deleteButton.attr('data-state', 'disabled');
7177
}
72-
window.SegmentEditorPanel.updateStarSegmentTitle($starButton, segment);
73-
$editButton.attr('title', window.SegmentEditorPanel.getEditSegmentTitle(segment, canEdit));
74-
$deleteButton.attr('title', window.SegmentEditorPanel.getDeleteSegmentTitle(segment, canEdit));
78+
panelApi.updateStarSegmentTitle($starButton, segment);
79+
$editButton.attr('title', panelApi.getEditSegmentTitle(segment, canEdit));
80+
$deleteButton.attr('title', panelApi.getDeleteSegmentTitle(segment, canEdit));
7581
});
7682
}
7783

@@ -84,7 +90,7 @@ function initManageSegmentsPage() {
8490
return false;
8591
}
8692
const idSegment = $button.attr('data-edit-segment');
87-
SegmentEditorPanel.openEditFormGivenIdSegment(idSegment);
93+
panelApi.openEditFormGivenIdSegment(idSegment);
8894
});
8995
$(root).on('click', '[data-delete-segment]', function (e) {
9096
e.stopPropagation();
@@ -94,8 +100,8 @@ function initManageSegmentsPage() {
94100
return false;
95101
}
96102
const idSegment = $button.attr('data-delete-segment');
97-
SegmentEditorPanel.openEditFormGivenIdSegment(idSegment);
98-
SegmentEditorPanel.askToDeleteSegment(idSegment);
103+
panelApi.openEditFormGivenIdSegment(idSegment);
104+
panelApi.askToDeleteSegment(idSegment);
99105
});
100106
$(root).on('click', '[data-star]', function (e) {
101107
e.stopPropagation();
@@ -106,7 +112,7 @@ function initManageSegmentsPage() {
106112
}
107113
const $segment = $button.closest('tr');
108114
const idSegment = $button.attr('data-star');
109-
window.SegmentEditorPanel.toggleStarredSegment($segment, idSegment);
115+
panelApi.toggleStarredSegment($segment, idSegment);
110116
});
111117
$(root).on('input', '#manageSegmentSearch', function (e) {
112118
e.stopPropagation();
@@ -128,7 +134,7 @@ function initManageSegmentsPage() {
128134
$(root).on('click', '.createNewSegment', function (e) {
129135
e.stopPropagation();
130136
e.preventDefault();
131-
window.SegmentEditorPanel.openEditFormGivenIdSegment();
137+
panelApi.openEditFormGivenIdSegment();
132138
});
133139
}
134140

@@ -144,20 +150,20 @@ function initManageSegmentsPage() {
144150
if (tooltip) {
145151
tooltip.disable();
146152
}
147-
window.SegmentEditorPanel.updateStarSegmentTitle($starButton, segment);
153+
panelApi.updateStarSegmentTitle($starButton, segment);
148154
if (tooltip) {
149155
tooltip.enable();
150156
}
151157
$segment.attr('data-segment-order', $previousOrder === '2' ? 2 : segment.starred ? 1 : 0);
152158
reorderSegments();
153-
window.SegmentEditorPanel.triggerStarAnimation($segment, segment, isError);
159+
panelApi.triggerStarAnimation($segment, segment, isError);
154160
}
155161

156162
function filterSegmentList(keyword) {
157163
clearFilterSegmentList();
158-
const search = window.SegmentEditorPanel.normalizeSearchString(keyword);
164+
const search = panelApi.normalizeSearchString(keyword);
159165
rowList.forEach(function (row) {
160-
const segmentSeed = window.SegmentEditorPanel.normalizeSearchString($(row).attr('data-segment-name'));
166+
const segmentSeed = panelApi.normalizeSearchString($(row).attr('data-segment-name'));
161167
if (segmentSeed.indexOf(search) === -1) {
162168
$(row).hide();
163169
}

plugins/SegmentEditor/stylesheets/segmentation.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ div.scrollable {
420420
border-bottom-right-radius: 0;
421421

422422
.dropdown-body {
423-
min-width: 240px;
423+
min-width: 280px;
424424
}
425425

426426
@media screen and (max-width: 600px) {

0 commit comments

Comments
 (0)