mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-25 18:59:04 +02:00
Disable drag&drop events for the default home
This commit is contained in:
parent
4fc410c6e9
commit
f9aba0c7ff
@ -170,7 +170,7 @@ trait DashboardManager
|
||||
'user_id' => self::getUser()->getAdditional('id'),
|
||||
'name' => $home->getName(),
|
||||
'label' => $home->getTitle(),
|
||||
'priority' => $home->getName() === DashboardHome::DEFAULT_HOME ? 0 : $priority++,
|
||||
'priority' => $home->isDefaultHome() ? 0 : $priority++,
|
||||
'type' => $home->getType() !== Dashboard::SYSTEM ? $home->getType() : Dashboard::PRIVATE_DS
|
||||
]);
|
||||
|
||||
|
@ -44,6 +44,16 @@ abstract class ItemListControl extends BaseHtmlElement
|
||||
*/
|
||||
abstract protected function createItemList(): BaseHtmlElement;
|
||||
|
||||
/**
|
||||
* Get whether to render the drag initiator icon bars
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldRenderDragInitiator(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a drag initiator for this widget item
|
||||
*
|
||||
@ -76,7 +86,10 @@ abstract class ItemListControl extends BaseHtmlElement
|
||||
]));
|
||||
|
||||
$header->addHtml(HtmlElement::create('div', ['class' => 'spacer']));
|
||||
$header->addHtml(self::createDragInitiator());
|
||||
if ($this->shouldRenderDragInitiator()) {
|
||||
$header->addHtml(self::createDragInitiator());
|
||||
}
|
||||
|
||||
$this->addHtml($header);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ class Dashboard extends BaseHtmlElement implements DashboardEntry
|
||||
protected function assemble()
|
||||
{
|
||||
$activeHome = $this->getActiveHome();
|
||||
if (! $activeHome || (! $activeHome->hasEntries() && $activeHome->getName() === DashboardHome::DEFAULT_HOME)) {
|
||||
if (! $activeHome || (! $activeHome->hasEntries() && $activeHome->isDefaultHome())) {
|
||||
$this->setAttribute('class', 'dashboard-introduction');
|
||||
|
||||
$this->addHtml(HtmlElement::create('h2', null, t('Welcome to Icinga Web 2!')));
|
||||
|
@ -63,6 +63,16 @@ class DashboardHome extends BaseDashboard implements Sortable
|
||||
return $self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this home is the default one
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefaultHome(): bool
|
||||
{
|
||||
return $this->getName() === self::DEFAULT_HOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of this dashboard home
|
||||
*
|
||||
|
@ -26,6 +26,12 @@ class DashboardHomeList extends ItemListControl
|
||||
public function __construct(DashboardHome $home)
|
||||
{
|
||||
$this->home = $home;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
if (! $this->home->hasEntries()) {
|
||||
// Just retry to load dashboards
|
||||
$this->home->loadDashboardEntries();
|
||||
@ -34,6 +40,9 @@ class DashboardHomeList extends ItemListControl
|
||||
$this->getAttributes()
|
||||
->registerAttributeCallback('data-icinga-home', function () {
|
||||
return $this->home->getName();
|
||||
})
|
||||
->registerAttributeCallback('data-disable-widget-sorting', function () {
|
||||
return $this->home->isDefaultHome();
|
||||
});
|
||||
}
|
||||
|
||||
@ -61,6 +70,11 @@ class DashboardHomeList extends ItemListControl
|
||||
return $this->home->isActive();
|
||||
}
|
||||
|
||||
protected function shouldRenderDragInitiator(): bool
|
||||
{
|
||||
return ! $this->home->isDefaultHome();
|
||||
}
|
||||
|
||||
protected function createItemList(): BaseHtmlElement
|
||||
{
|
||||
if (! $this->headerDisabled) {
|
||||
|
@ -24,7 +24,7 @@ class Settings extends BaseHtmlElement
|
||||
protected function assemble()
|
||||
{
|
||||
$activeHome = $this->dashboard->getActiveHome();
|
||||
if (count($this->dashboard->getEntries()) === 1 && $activeHome->getName() === DashboardHome::DEFAULT_HOME) {
|
||||
if (count($this->dashboard->getEntries()) === 1 && $activeHome->isDefaultHome()) {
|
||||
$this->setAttribute('data-icinga-home', DashboardHome::DEFAULT_HOME);
|
||||
$this->addFrom((new DashboardHomeList($activeHome))->setHeaderDisabled());
|
||||
} else {
|
||||
|
@ -166,7 +166,10 @@
|
||||
draggable : draggable,
|
||||
handle : '.widget-drag-initiator',
|
||||
group : { name : groupName },
|
||||
chosenClass : 'draggable-widget-chosen'
|
||||
chosenClass : 'draggable-widget-chosen',
|
||||
onMove : function (evt, orgEvt) {
|
||||
return ! evt.related.matches('[data-disable-widget-sorting]');
|
||||
}
|
||||
};
|
||||
|
||||
_this.Sortable.create(sortable, options);
|
||||
|
Loading…
x
Reference in New Issue
Block a user