mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
IcingaServiceSetServiceTable: refactor link logic
This commit is contained in:
parent
d433631174
commit
28c149efed
@ -154,73 +154,21 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
|||||||
return $this->title ?: $this->translate('Servicename');
|
return $this->title ?: $this->translate('Servicename');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param HtmlElement $parent
|
|
||||||
*/
|
|
||||||
protected function renderTitleColumns()
|
protected function renderTitleColumns()
|
||||||
{
|
{
|
||||||
if (! $this->host || ! $this->affectedHost) {
|
if (! $this->host || ! $this->affectedHost) {
|
||||||
return Html::tag('th', $this->getTitle());
|
return Html::tag('th', $this->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->host) {
|
if ($this->readonly) {
|
||||||
$deleteLink = '';
|
$link = $this->createFakeRemoveLinkForReadonlyView();
|
||||||
} elseif ($this->readonly) {
|
|
||||||
$deleteLink = Html::tag('span', [
|
|
||||||
'class' => 'icon-paste',
|
|
||||||
'style' => 'float: right; font-weight: normal',
|
|
||||||
], $this->host->getObjectName());
|
|
||||||
} elseif ($this->affectedHost->get('id') !== $this->host->get('id')) {
|
} elseif ($this->affectedHost->get('id') !== $this->host->get('id')) {
|
||||||
$host = $this->host;
|
$link = $this->linkToHost($this->host);
|
||||||
$deleteLink = Link::create(
|
|
||||||
$host->getObjectName(),
|
|
||||||
'director/host/services',
|
|
||||||
['name' => $host->getObjectName()],
|
|
||||||
[
|
|
||||||
'class' => 'icon-paste',
|
|
||||||
'style' => 'float: right; font-weight: normal',
|
|
||||||
'data-base-target' => '_next',
|
|
||||||
'title' => sprintf(
|
|
||||||
$this->translate('This set has been inherited from %s'),
|
|
||||||
$host->getObjectName()
|
|
||||||
)
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$deleteLink = new RemoveLinkForm(
|
$link = $this->createRemoveLinkForm();
|
||||||
$this->translate('Remove'),
|
|
||||||
sprintf(
|
|
||||||
$this->translate('Remove "%s" from this host'),
|
|
||||||
$this->getTitle()
|
|
||||||
),
|
|
||||||
Url::fromPath('director/host/services', [
|
|
||||||
'name' => $this->host->getObjectName()
|
|
||||||
]),
|
|
||||||
['title' => $this->getTitle()]
|
|
||||||
);
|
|
||||||
$deleteLink->runOnSuccess(function () {
|
|
||||||
$conn = $this->set->getConnection();
|
|
||||||
$db = $conn->getDbAdapter();
|
|
||||||
$query = $db->select()->from(
|
|
||||||
['ss' => 'icinga_service_set'],
|
|
||||||
'ss.id'
|
|
||||||
)->join(
|
|
||||||
['ssih' => 'icinga_service_set_inheritance'],
|
|
||||||
'ssih.service_set_id = ss.id',
|
|
||||||
[]
|
|
||||||
)->where(
|
|
||||||
'ssih.parent_service_set_id = ?',
|
|
||||||
$this->set->get('id')
|
|
||||||
)->where('ss.host_id = ?', $this->host->get('id'));
|
|
||||||
IcingaServiceSet::loadWithAutoIncId(
|
|
||||||
$db->fetchOne($query),
|
|
||||||
$conn
|
|
||||||
)->delete();
|
|
||||||
});
|
|
||||||
$deleteLink->handleRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this::th([$this->getTitle(), $deleteLink]);
|
return $this::th([$this->getTitle(), $link]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,4 +216,55 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
|
|||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function createFakeRemoveLinkForReadonlyView()
|
||||||
|
{
|
||||||
|
return Html::tag('span', [
|
||||||
|
'class' => 'icon-paste',
|
||||||
|
'style' => 'float: right; font-weight: normal',
|
||||||
|
], $this->host->getObjectName());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function linkToHost(IcingaHost $host)
|
||||||
|
{
|
||||||
|
$hostname = $host->getObjectName();
|
||||||
|
return Link::create($hostname, 'director/host/services', ['name' => $hostname], [
|
||||||
|
'class' => 'icon-paste',
|
||||||
|
'style' => 'float: right; font-weight: normal',
|
||||||
|
'data-base-target' => '_next',
|
||||||
|
'title' => sprintf(
|
||||||
|
$this->translate('This set has been inherited from %s'),
|
||||||
|
$hostname
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createRemoveLinkForm()
|
||||||
|
{
|
||||||
|
$deleteLink = new RemoveLinkForm(
|
||||||
|
$this->translate('Remove'),
|
||||||
|
sprintf(
|
||||||
|
$this->translate('Remove "%s" from this host'),
|
||||||
|
$this->getTitle()
|
||||||
|
),
|
||||||
|
Url::fromPath('director/host/services', [
|
||||||
|
'name' => $this->host->getObjectName()
|
||||||
|
]),
|
||||||
|
['title' => $this->getTitle()]
|
||||||
|
);
|
||||||
|
$deleteLink->runOnSuccess(function () {
|
||||||
|
$conn = $this->set->getConnection();
|
||||||
|
$db = $conn->getDbAdapter();
|
||||||
|
$query = $db->select()->from(['ss' => 'icinga_service_set'], 'ss.id')
|
||||||
|
->join(['ssih' => 'icinga_service_set_inheritance'], 'ssih.service_set_id = ss.id', [])
|
||||||
|
->where('ssih.parent_service_set_id = ?', $this->set->get('id'))
|
||||||
|
->where('ss.host_id = ?', $this->host->get('id'));
|
||||||
|
IcingaServiceSet::loadWithAutoIncId(
|
||||||
|
$db->fetchOne($query),
|
||||||
|
$conn
|
||||||
|
)->delete();
|
||||||
|
});
|
||||||
|
$deleteLink->handleRequest();
|
||||||
|
return $deleteLink;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user