Skip to content

Commit f6b7b23

Browse files
committed
Update the tooltip to precise who star a segment
1 parent 412fd8c commit f6b7b23

File tree

7 files changed

+98
-33
lines changed

7 files changed

+98
-33
lines changed

core/Updates/5.6.0-b3.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* Matomo - free/libre analytics platform
5+
*
6+
* @link https://matomo.org
7+
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8+
*/
9+
10+
namespace Piwik\Updates;
11+
12+
use Piwik\Updater;
13+
use Piwik\Updater\Migration\Factory as MigrationFactory;
14+
use Piwik\Updates;
15+
16+
class Updates_5_6_0_b3 extends Updates
17+
{
18+
/**
19+
* @var MigrationFactory
20+
*/
21+
private $migration;
22+
23+
public function __construct(MigrationFactory $factory)
24+
{
25+
$this->migration = $factory;
26+
}
27+
28+
public function getMigrations(Updater $updater)
29+
{
30+
return [
31+
$this->migration->db->addColumn('segment', 'starred_by', 'VARCHAR(100)'),
32+
];
33+
}
34+
35+
public function doUpdate(Updater $updater)
36+
{
37+
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
38+
}
39+
}

core/Version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class Version
2222
* The current Matomo version.
2323
* @var string
2424
*/
25-
public const VERSION = '5.6.0-b2';
25+
public const VERSION = '5.6.0-b3';
2626

2727
public const MAJOR_VERSION = 5;
2828

lang/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"Action": "Action",
99
"Actions": "Actions",
1010
"Add": "Add",
11-
"AddToFavorites": "Add to favorites",
1211
"AfterEntry": "after entering here",
1312
"All": "All",
1413
"AllWebsitesDashboard": "All Websites dashboard",
@@ -419,7 +418,6 @@
419418
"RelatedReport": "Related report",
420419
"RelatedReports": "Related reports",
421420
"Remove": "Remove",
422-
"RemoveFromFavorites": "Remove from favorites",
423421
"Report": "Report",
424422
"ReportGeneratedFrom": "This report was generated using data from %s.",
425423
"ReportRatioTooltip": "'%1$s' represents %2$s of %3$s %4$s in segment %5$s with %6$s.",
@@ -465,6 +463,8 @@
465463
"SmtpServerAddress": "SMTP server address",
466464
"SmtpUsername": "SMTP username",
467465
"Source": "Source",
466+
"Star": "Star",
467+
"StarredBy": "Starred by",
468468
"StatisticsAreNotRecorded": "Matomo Visitor Tracking is currently disabled! Re-enable tracking by setting record_statistics = 1 in your config/config.ini.php file.",
469469
"Subtotal": "Subtotal",
470470
"Summary": "Summary",

plugins/SegmentEditor/API.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,22 @@ public function add(
355355
* @param int $idSegment
356356
* @throws Exception if the user is not logged in or does not have the required permissions.
357357
*/
358-
public function star(int $idSegment): bool
358+
public function star(int $idSegment): ?array
359359
{
360360
$segment = $this->getSegmentOrFail($idSegment);
361361
$this->checkUserCanEditOrDeleteSegment($segment);
362-
$bind = ['starred' => 1];
362+
$login = Piwik::getCurrentUserLogin();
363+
$bind = [
364+
'starred' => 1,
365+
'starred_by' => $login,
366+
];
363367

364-
return $this->getModel()->updateSegment($idSegment, $bind);
368+
$result = $this->getModel()->updateSegment($idSegment, $bind);
369+
370+
return [
371+
'result' => $result,
372+
'starred_by' => $login,
373+
];
365374
}
366375

367376
/**
@@ -370,13 +379,20 @@ public function star(int $idSegment): bool
370379
* @param int $idSegment
371380
* @throws Exception if the user is not logged in or does not have the required permissions.
372381
*/
373-
public function unstar(int $idSegment): bool
382+
public function unstar(int $idSegment): ?array
374383
{
375384
$segment = $this->getSegmentOrFail($idSegment);
376385
$this->checkUserCanEditOrDeleteSegment($segment);
377-
$bind = ['starred' => 0];
386+
$bind = [
387+
'starred' => 0,
388+
'starred_by' => null,
389+
];
378390

379-
return $this->getModel()->updateSegment($idSegment, $bind);
391+
$result = $this->getModel()->updateSegment($idSegment, $bind);
392+
393+
return [
394+
'result' => $result,
395+
];
380396
}
381397

382398
/**

plugins/SegmentEditor/SegmentSelectorControl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ private function getTranslations()
127127
'General_DefaultAppended',
128128
'SegmentEditor_AddNewSegment',
129129
'General_Edit',
130-
'General_AddToFavorites',
131-
'General_RemoveFromFavorites',
130+
'General_Star',
131+
'General_StarredBy',
132132
'General_Edit',
133133
'General_Search',
134134
'General_SearchNoResults',

plugins/SegmentEditor/javascripts/Segmentation.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Segmentation = (function($) {
222222
'<span class="segname" tabindex="4" title="' + getSegmentTooltipEnrichedWithUsername(segment) + '" >' + getSegmentName(segment) + '</span>';
223223
if (self.segmentAccess === "write") {
224224
listHtml += '' +
225-
'<button data-star class="starSegment" title="' + self.translations[segment.starred ? 'General_RemoveFromFavorites' : 'General_AddToFavorites'].toLocaleLowerCase() + '">️' +
225+
'<button data-star class="starSegment" title="' + getStarSegmentTitle(segment) + '">️' +
226226
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24">' +
227227
'<path stroke="black" stroke-width="3" fill="none" d="M9.153 5.408C10.42 3.136 11.053 2 12 2c.947 0 1.58 1.136 2.847 3.408l.328.588c.36.646.54.969.82 1.182.28.213.63.292 1.33.45l.636.144c2.46.557 3.689.835 3.982 1.776.292.94-.546 1.921-2.223 3.882l-.434.507c-.476.557-.715.836-.822 1.18-.107.345-.071.717.001 1.46l.066.677c.253 2.617.38 3.925-.386 4.506-.766.582-1.918.051-4.22-1.009l-.597-.274c-.654-.302-.981-.452-1.328-.452-.347 0-.674.15-1.329.452l-.595.274c-2.303 1.06-3.455 1.59-4.22 1.01-.767-.582-.64-1.89-.387-4.507l.066-.676c.072-.744.108-1.116 0-1.46-.106-.345-.345-.624-.821-1.18l-.434-.508c-1.677-1.96-2.515-2.941-2.223-3.882.293-.941 1.523-1.22 3.983-1.776l.636-.144c.699-.158 1.048-.237 1.329-.45.28-.213.46-.536.82-1.182l.328-.588Z"/>' +
228228
'</svg>' +
@@ -411,19 +411,6 @@ Segmentation = (function($) {
411411
e.preventDefault();
412412
});
413413

414-
function updateStarredSegment($segment, isStarred, isError = false) {
415-
const $starButton = $segment.find('.starSegment');
416-
const title = self.translations[isStarred ? 'General_RemoveFromFavorites' : 'General_AddToFavorites'].toLocaleLowerCase();
417-
addTooltip($starButton, title);
418-
$segment.toggleClass('segmentStarred', isStarred);
419-
$segment.one('animationend', function avoidAnimationRepetion() {
420-
$segment.removeClass('segmentStarAnimation');
421-
$segment.removeClass('segmentStarErrorAnimation');
422-
});
423-
$segment.toggleClass('segmentStarAnimation', !isError);
424-
$segment.toggleClass('segmentStarErrorAnimation', isError);
425-
}
426-
427414
self.target.on('click', '[data-star]', function (e) {
428415
e.stopPropagation();
429416
e.preventDefault();
@@ -432,7 +419,7 @@ Segmentation = (function($) {
432419
const segment = getSegmentFromId(idSegment);
433420
segment.starred = !segment.starred;
434421
const method = segment.starred ? 'star' : 'unstar';
435-
updateStarredSegment($root, segment.starred);
422+
updateStarredSegment($root, segment);
436423

437424
var ajaxHandler = new ajaxHelper();
438425
ajaxHandler.addParams({
@@ -442,9 +429,13 @@ Segmentation = (function($) {
442429
"userLogin": piwik.userLogin,
443430
"idSegment": idSegment,
444431
}, 'POST');
445-
ajaxHandler.setErrorCallback(function (response) {
432+
ajaxHandler.setErrorCallback(function () {
446433
segment.starred = !segment.starred;
447-
updateStarredSegment($root, segment.starred, true);
434+
updateStarredSegment($root, segment, true);
435+
});
436+
ajaxHandler.setCallback(function (response) {
437+
segment.starred_by = response.starred_by;
438+
updateStarSegmentTooltip($root, segment);
448439
});
449440
ajaxHandler.send();
450441
});
@@ -598,12 +589,31 @@ Segmentation = (function($) {
598589
}
599590
});
600591

601-
//
602-
// segment manipulation events
603-
//
604-
605592
};
606593

594+
function getStarSegmentTitle(segment) {
595+
if (segment.starred) {
596+
return self.translations['General_StarredBy'] + ' ' + (segment.starred_by || '');
597+
}
598+
return self.translations['General_Star'];
599+
}
600+
601+
function updateStarSegmentTooltip($segment, segment) {
602+
const $starButton = $segment.find('.starSegment');
603+
addTooltip($starButton, getStarSegmentTitle(segment));
604+
}
605+
606+
function updateStarredSegment($segment, segment, isError = false) {
607+
updateStarSegmentTooltip($segment, segment);
608+
$segment.toggleClass('segmentStarred', segment.starred);
609+
$segment.one('animationend', function avoidAnimationRepetition() {
610+
$segment.removeClass('segmentStarAnimation');
611+
$segment.removeClass('segmentStarErrorAnimation');
612+
});
613+
$segment.toggleClass('segmentStarAnimation', !isError);
614+
$segment.toggleClass('segmentStarErrorAnimation', isError);
615+
}
616+
607617
function addTooltip(element, title) {
608618
$(element).attr('title', title).tooltip({
609619
track: true,

plugins/SegmentEditor/stylesheets/segmentation.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ div.scrollable {
306306
5%, 15%, 25%, 35%, 45% { transform: translate(-2px)}
307307
10%, 20%, 30%, 40% { transform: translate(2px)}
308308
50% { opacity: 1; }
309-
100% { transform: translate(0px); opacity: 0.5; }
309+
100% { transform: translate(0); opacity: 0.5; }
310310
}
311311

312312
@keyframes starErrorAnimationPath {

0 commit comments

Comments
 (0)