Skip to content

Commit accb416

Browse files
committed
Timeline: Disable drag&drop for single rotations
1 parent 51ff1f9 commit accb416

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

library/Notifications/Widget/Timeline.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class Timeline extends BaseHtmlElement implements EntryProvider
6262
/** @var bool Whether to create the Timeline only with the Result using MinimalGrid */
6363
protected $minimalLayout = false;
6464

65+
/** @var int */
66+
protected int $noOfRotations = 0;
67+
6568
/**
6669
* Set the style object to register inline styles in
6770
*
@@ -289,6 +292,7 @@ protected function getGrid()
289292
if (! isset($occupiedPriorities[$rotation->getPriority()])) {
290293
$occupiedPriorities[$rotation->getPriority()] = true;
291294
$this->grid->addToSideBar($this->assembleSidebarEntry($rotation));
295+
$this->noOfRotations++;
292296
}
293297
}
294298
}
@@ -308,15 +312,16 @@ protected function assembleSidebarEntry(Rotation $rotation): BaseHtmlElement
308312
'priority' => $rotation->getPriority()
309313
]);
310314

315+
$dragInitiator = new Icon('bars', [
316+
'title' => $this->translate('Drag to change the priority of the rotation')
317+
]);
318+
$dragInitiator
319+
->getAttributes()
320+
->registerAttributeCallback('data-drag-initiator', fn () => $this->noOfRotations > 1);
321+
311322
$entry->addHtml(
312323
$form,
313-
new Icon(
314-
'bars',
315-
[
316-
'data-drag-initiator' => true,
317-
'title' => $this->translate('Drag to change the priority of the rotation')
318-
]
319-
),
324+
$dragInitiator,
320325
(new Link(
321326
[new HtmlElement('span', null, Text::create($rotation->getName())), new Icon('cog')],
322327
Links::rotationSettings($rotation->getId(), $rotation->getScheduleId())

public/css/timeline.less

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,17 @@
245245
font-size: 1.25em;
246246
font-weight: bold;
247247

248-
[data-drag-initiator] {
248+
> .icon[data-drag-initiator] {
249249
color: @gray-light;
250250

251251
&:hover {
252252
cursor: grab;
253253
color: @list-item-title-hover-color;
254254
}
255255
}
256+
> .icon:not([data-drag-initiator]) {
257+
display: none;
258+
}
256259

257260
// :not(:empty) is only necessary to increase specificity
258261
&:not(:empty).sortable-drag {

0 commit comments

Comments
 (0)