From 708b4dbe8ff910c458397b7fc7d83bfc73ab6e61 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 11 Jan 2024 13:09:04 +0100 Subject: [PATCH 1/5] Remove unnecessary inline style --- application/controllers/BasketController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/controllers/BasketController.php b/application/controllers/BasketController.php index 0e7f36a8..7e2cfa76 100644 --- a/application/controllers/BasketController.php +++ b/application/controllers/BasketController.php @@ -333,7 +333,6 @@ class BasketController extends ActionController $this->content()->add(Html::tag('h2', $type)); $this->content()->add($table); } - $this->content()->add(Html::tag('div', ['style' => 'height: 5em'])); } /** From 72f44c326fad945f590a6c07c58db8688a03af41 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 12 Jan 2024 12:01:32 +0100 Subject: [PATCH 2/5] Remove unnecessary and unused code --- application/forms/AddToBasketForm.php | 54 +++++++++++---------------- application/forms/IcingaHostForm.php | 9 ----- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/application/forms/AddToBasketForm.php b/application/forms/AddToBasketForm.php index 44b53576..36091feb 100644 --- a/application/forms/AddToBasketForm.php +++ b/application/forms/AddToBasketForm.php @@ -11,9 +11,6 @@ use Icinga\Module\Director\Web\Form\DirectorForm; class AddToBasketForm extends DirectorForm { - /** @var Basket */ - private $basket; - private $type = '(has not been set)'; private $names = []; @@ -30,7 +27,6 @@ class AddToBasketForm extends DirectorForm 'b' => 'basket_name', ])->order('basket_name')); - $names = []; $basket = null; if ($this->hasBeenSent()) { $basketName = $this->getSentValue('basket'); @@ -38,25 +34,17 @@ class AddToBasketForm extends DirectorForm $basket = Basket::load($basketName, $this->getDb()); } } - $count = 0; - $type = $this->type; + + $names = []; foreach ($this->names as $name) { - if (! empty($names)) { - $names[] = ', '; - } - if ($basket && $basket->hasObject($type, $name)) { - $names[] = Html::tag('span', [ - 'style' => 'text-decoration: line-through' - ], $name); - } else { - $count++; + if (! $basket || ! $basket->hasObject($this->type, $name)) { $names[] = $name; } } - $this->addHtmlHint((new HtmlDocument())->add([ - 'The following objects will be added: ', - $names - ])); + $this->addHtmlHint( + (new HtmlDocument()) + ->add(sprintf('The following objects will be added: %s', implode(", ", $names))) + ); $this->addElement('select', 'basket', [ 'label' => $this->translate('Basket'), 'multiOptions' => $this->optionalEnum($enum), @@ -64,10 +52,10 @@ class AddToBasketForm extends DirectorForm 'class' => 'autosubmit', ]); - if ($count > 0) { + if (! empty($names)) { $this->setSubmitLabel(sprintf( $this->translate('Add %s objects'), - $count + count($names) )); } else { $this->setSubmitLabel($this->translate('Add')); @@ -112,18 +100,18 @@ class AddToBasketForm extends DirectorForm 'Configuration objects have been added to the chosen basket "%s"' ), $basketName)); return parent::onSuccess(); - } else { - $this->addHtmlHint(Hint::error(Html::sprintf($this->translate( - 'Please check your Basket configuration, %s does not support' - . ' single "%s" configuration objects' - ), Link::create( - $basketName, - 'director/basket', - ['name' => $basketName], - ['data-base-target' => '_next'] - ), $type))); - - return false; } + + $this->addHtmlHint(Hint::error(Html::sprintf($this->translate( + 'Please check your Basket configuration, %s does not support' + . ' single "%s" configuration objects' + ), Link::create( + $basketName, + 'director/basket', + ['name' => $basketName], + ['data-base-target' => '_next'] + ), $type))); + + return false; } } diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index c2cdf556..c7e14c48 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -264,15 +264,6 @@ class IcingaHostForm extends DirectorObjectForm return $this; } - protected function strikeGroupLinks(BaseHtmlElement $links) - { - /** @var BaseHtmlElement $link */ - foreach ($links->getContent() as $link) { - $link->getAttributes()->add('style', 'text-decoration: strike'); - } - $links->add('aha'); - } - protected function getInheritedGroups() { if ($this->hasObject()) { From c25a66b484f5486afde322178a05a4912381f50e Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 11 Jan 2024 13:10:17 +0100 Subject: [PATCH 3/5] Avoid inline css style --- application/controllers/BasketController.php | 10 ++- application/controllers/ConfigController.php | 40 ++++++----- application/controllers/DataController.php | 4 +- .../controllers/SyncruleController.php | 5 +- application/forms/IcingaHostForm.php | 4 +- application/forms/RemoveLinkForm.php | 7 +- .../Web/Controller/ActionController.php | 2 +- .../Table/IcingaServiceSetServiceTable.php | 6 +- library/Director/Web/Table/TemplatesTable.php | 2 +- .../Director/Web/Widget/ActivityLogInfo.php | 3 +- .../Director/Web/Widget/DeploymentInfo.php | 24 ++++--- public/css/module.less | 72 +++++++++++++++++++ 12 files changed, 126 insertions(+), 53 deletions(-) diff --git a/application/controllers/BasketController.php b/application/controllers/BasketController.php index 7e2cfa76..8d4db034 100644 --- a/application/controllers/BasketController.php +++ b/application/controllers/BasketController.php @@ -304,17 +304,21 @@ class BasketController extends ActionController $this->translate('modified'), 'director/basket/snapshotobject', $linkParams, - ['style' => 'color: orange; font-weight: bold'] + ['class' => 'basket-modified'] ); } else { - $link = Html::tag('span', ['style' => 'color: green'], $this->translate('unchanged')); + $link = Html::tag( + 'span', + ['class' => 'basket-unchanged'], + $this->translate('unchanged') + ); } } else { $link = Link::create( $this->translate('new'), 'director/basket/snapshotobject', $linkParams, - ['style' => 'color: green; font-weight: bold'] + ['class' => 'basket-new'] ); } $table->addNameValueRow($key, $link); diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index ed3a01df..8e6febef 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -376,25 +376,27 @@ class ConfigController extends ActionController } $baseUrl = $this->url()->without(['left', 'right']); - $this->content()->add(Html::tag('form', ['action' => (string) $baseUrl, 'method' => 'GET'], [ - new HtmlString($this->view->formSelect( - 'left', - $leftSum, - ['class' => 'autosubmit', 'style' => 'width: 37%'], - [null => $this->translate('- please choose -')] + $configs - )), - Link::create( - Icon::create('flapping'), - $baseUrl, - ['left' => $rightSum, 'right' => $leftSum] - ), - new HtmlString($this->view->formSelect( - 'right', - $rightSum, - ['class' => 'autosubmit', 'style' => 'width: 37%'], - [null => $this->translate('- please choose -')] + $configs - )), - ])); + $this->content()->add( + Html::tag('form', ['action' => (string) $baseUrl, 'method' => 'GET', 'class' => 'director-form'], [ + new HtmlString($this->view->formSelect( + 'left', + $leftSum, + ['class' => ['autosubmit', 'config-diff']], + [null => $this->translate('- please choose -')] + $configs + )), + Link::create( + Icon::create('flapping'), + $baseUrl, + ['left' => $rightSum, 'right' => $leftSum] + ), + new HtmlString($this->view->formSelect( + 'right', + $rightSum, + ['class' => ['autosubmit', 'config-diff']], + [null => $this->translate('- please choose -')] + $configs + )), + ]) + ); if ($rightSum === null || $leftSum === null || ! strlen($rightSum) || ! strlen($leftSum)) { return; diff --git a/application/controllers/DataController.php b/application/controllers/DataController.php index ae4bbcf3..7480db24 100644 --- a/application/controllers/DataController.php +++ b/application/controllers/DataController.php @@ -216,7 +216,7 @@ class DataController extends ActionController $subTitle = $this->translate('Add a new instance'); } - $this->content()->add(Html::tag('h2', ['style' => 'margin-top: 2em'], $subTitle)); + $this->content()->add(Html::tag('h2', ['class' => 'dictionary-header'], $subTitle)); $form->handleRequest($this->getRequest()); $this->content()->add($form); if ($form->succeeded()) { @@ -326,7 +326,7 @@ class DataController extends ActionController Table::row([ $this->translate('Key / Instance'), $this->translate('Properties') - ], ['style' => 'text-align: left'], 'th') + ], ['class' => 'text-align-left'], 'th') ); foreach ($currentValue as $key => $item) { $table->add(Table::row([ diff --git a/application/controllers/SyncruleController.php b/application/controllers/SyncruleController.php index 60c14f9d..a19da036 100644 --- a/application/controllers/SyncruleController.php +++ b/application/controllers/SyncruleController.php @@ -380,10 +380,7 @@ class SyncruleController extends ActionController protected function firstNames($objects, $max = 50) { $names = []; - $list = new UnorderedList(); - $list->addAttributes([ - 'style' => 'list-style-type: none; marign: 0; padding: 0', - ]); + $list = new UnorderedList([], ['class' => 'unordred-list']); $total = count($objects); $i = 0; PrefetchCache::forget(); diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index c7e14c48..ed572515 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -288,9 +288,7 @@ class IcingaHostForm extends DirectorObjectForm ); } - return Html::tag('span', [ - 'style' => 'line-height: 2.5em; padding-left: 0.5em' - ], $links); + return Html::tag('span', ['class' => 'host-group-links'], $links); } protected function getAppliedGroups() diff --git a/application/forms/RemoveLinkForm.php b/application/forms/RemoveLinkForm.php index 6f0c7cc9..fb43db09 100644 --- a/application/forms/RemoveLinkForm.php +++ b/application/forms/RemoveLinkForm.php @@ -17,10 +17,7 @@ class RemoveLinkForm extends DirectorForm { // Required to detect the right instance $this->formName = 'RemoveSet' . sha1(json_encode($params)); - parent::__construct([ - 'style' => 'float: right', - 'data-base-target' => '_self' - ]); + parent::__construct(['data-base-target' => '_self']); $this->label = $label; $this->title = $title; foreach ($params as $name => $value) { @@ -38,7 +35,7 @@ class RemoveLinkForm extends DirectorForm public function setup() { - $this->setAttrib('class', 'inline'); + $this->addAttribs(['class' => ['inline', 'remove-link-form']]); $this->addHtml(Icon::create('cancel')); $this->addSubmitButton($this->label, [ 'class' => 'link-button', diff --git a/library/Director/Web/Controller/ActionController.php b/library/Director/Web/Controller/ActionController.php index 2e01bdaa..e851d82d 100644 --- a/library/Director/Web/Controller/ActionController.php +++ b/library/Director/Web/Controller/ActionController.php @@ -223,7 +223,7 @@ abstract class ActionController extends Controller implements ControlsAndContent // Hint -> $this->view->compact is the only way since v2.8.0 if ($this->view->compact || $this->getOriginalUrl()->getParam('view') === 'compact') { if ($this->view->controls) { - $this->controls()->getAttributes()->add('style', 'display: none;'); + $this->controls()->getAttributes()->add('class', 'compact'); } } } else { diff --git a/library/Director/Web/Table/IcingaServiceSetServiceTable.php b/library/Director/Web/Table/IcingaServiceSetServiceTable.php index 0f0c4d54..2c3dbc40 100644 --- a/library/Director/Web/Table/IcingaServiceSetServiceTable.php +++ b/library/Director/Web/Table/IcingaServiceSetServiceTable.php @@ -219,8 +219,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable protected function createFakeRemoveLinkForReadonlyView() { return Html::tag('span', [ - 'class' => 'icon-paste', - 'style' => 'float: right; font-weight: normal', + 'class' => ['icon-paste', 'seviceset-obj-link'], ], $this->host->getObjectName()); } @@ -228,8 +227,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable { $hostname = $host->getObjectName(); return Link::create($hostname, 'director/host/services', ['name' => $hostname], [ - 'class' => 'icon-paste', - 'style' => 'float: right; font-weight: normal', + 'class' => ['icon-paste', 'seviceset-obj-link'], 'data-base-target' => '_next', 'title' => sprintf( $this->translate('This set has been inherited from %s'), diff --git a/library/Director/Web/Table/TemplatesTable.php b/library/Director/Web/Table/TemplatesTable.php index 9b75cd4c..d6582fd9 100644 --- a/library/Director/Web/Table/TemplatesTable.php +++ b/library/Director/Web/Table/TemplatesTable.php @@ -60,7 +60,7 @@ class TemplatesTable extends ZfQueryBasedTable implements FilterableByUsage $name, Html::tag( 'span', - ['style' => 'font-style: italic'], + ['class' => 'font-italic'], $this->translate(' - not in use -') ) ]; diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index 8454b263..8034c5a4 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -83,8 +83,7 @@ class ActivityLogInfo extends HtmlDocument /** @var Url $url */ $url = $url->without('checksum')->without('show'); $div = Html::tag('div', [ - 'class' => 'pagination-control', - 'style' => 'float: right; width: 5em' + 'class' => ['pagination-control', 'activity-log-control'], ]); $ul = Html::tag('ul', ['class' => 'nav tab-nav']); diff --git a/library/Director/Web/Widget/DeploymentInfo.php b/library/Director/Web/Widget/DeploymentInfo.php index c0a52b92..1f87abcd 100644 --- a/library/Director/Web/Widget/DeploymentInfo.php +++ b/library/Director/Web/Widget/DeploymentInfo.php @@ -73,7 +73,8 @@ class DeploymentInfo extends HtmlDocument protected function createInfoTable() { $dep = $this->deployment; - $table = new NameValueTable(); + $table = (new NameValueTable()) + ->addAttributes(['class' => 'deployment-details']); $table->addNameValuePairs([ $this->translate('Deployment time') => $dep->start_time, $this->translate('Sent to') => $dep->peer_identity, @@ -136,16 +137,21 @@ class DeploymentInfo extends HtmlDocument } else { return [$this->translate('Unknown, failed to collect related information'), new Icon('help')]; } - } elseif ($dep->startup_succeeded === 'y') { - return $this->colored('green', [$this->translate('Succeeded'), new Icon('ok')]); } else { - return $this->colored('red', [$this->translate('Failed'), new Icon('cancel')]); - } - } + $div = Html::tag('div')->setSeparator(' '); - protected function colored($color, array $content) - { - return Html::tag('div', ['style' => "color: $color;"], $content)->setSeparator(' '); + if ($dep->startup_succeeded === 'y') { + $div + ->addAttributes(['class' => 'succeeded']) + ->add([$this->translate('Succeeded'), new Icon('ok')]); + } else { + $div + ->addAttributes(['class' => 'failed']) + ->add([$this->translate('Failed'), new Icon('cancel')]); + } + + return $div; + } } public function render() diff --git a/public/css/module.less b/public/css/module.less index cb94f206..51c4ec25 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -49,6 +49,15 @@ div.action-bar > a { margin-right: 1em; } +.controls.compact { + display: none; +} + +.controls > .pagination-control.activity-log-control { + float: right; + width: 5em; +} + .controls > .pagination-control li > a { padding: 0.5em 0 0.5em 0; } @@ -337,6 +346,10 @@ table.avp th { left: -100%; } +form.remove-link-form { + float: right; +} + form.director-form input[type=file] { padding-right: 1em; } @@ -462,6 +475,11 @@ form.director-form dl { padding: 0; } +form.director-form .host-group-links { + line-height: 2.5em; + padding-left: 0.5em; +} + .strike-links a, table.common-table .strike-links a { text-decoration: line-through; &:hover { @@ -502,6 +520,12 @@ form.director-form.editor { } } +ul.unordred-list { + list-style-type: none; + margin: 0; + padding: 0; +} + ul.extensible-set { margin: 0; padding: 0; @@ -917,6 +941,10 @@ form.director-form dd.active li.active input.related-action[type='submit'] { } form.director-form { + select.config-diff { + width: auto; + } + p.description { color: @gray; font-style: italic; @@ -1223,6 +1251,17 @@ div.content.compact table.icinga-objects thead { display: none; } +table.deployment-details { + .succeeded { + color: @state-ok; + } + + .failed { + color: @color-critical; + } +} + + table.deployment-log { tr td:nth-child(2), tr th:nth-child(2) { @@ -1833,3 +1872,36 @@ table.table-basket-changes { min-width: 10em; } } + +.font-italic { + font-style: italic; +} + +.table-basket-changes { + .basket-new { + color: green; + font-weight: bold + } + + .basket-modified { + color: orange; + font-weight: bold + } + + .basket-unchanged { + color: green; + } +} + +.seviceset-obj-link { + float: right; + font-weight: normal +} + +.dictionary-header { + margin-top: 2em; +} + +.text-align-left { + text-align: left +} From be6447874c1798cb4eb86c21c799b9d7e88d7620 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 12 Jan 2024 16:00:26 +0100 Subject: [PATCH 4/5] Remove not in use class `ReadOnlyFormAvpTable` --- .../Web/Table/ReadOnlyFormAvpTable.php | 113 ------------------ 1 file changed, 113 deletions(-) delete mode 100644 library/Director/Web/Table/ReadOnlyFormAvpTable.php diff --git a/library/Director/Web/Table/ReadOnlyFormAvpTable.php b/library/Director/Web/Table/ReadOnlyFormAvpTable.php deleted file mode 100644 index c3b44f36..00000000 --- a/library/Director/Web/Table/ReadOnlyFormAvpTable.php +++ /dev/null @@ -1,113 +0,0 @@ -form = $form; - } - - protected function renderDisplayGroups(QuickForm $form) - { - $html = ''; - - foreach ($form->getDisplayGroups() as $group) { - $elements = $this->filterGroupElements($group); - - if (empty($elements)) { - continue; - } - - $html .= '' . $group->getLegend() . ''; - $html .= $this->renderElements($elements); - } - - return $html; - } - - /** - * @param ZfDisplayGroup $group - * @return ZfElement[] - */ - protected function filterGroupElements(ZfDisplayGroup $group) - { - $blacklist = array('disabled', 'assign_filter'); - $elements = array(); - /** @var ZfElement $element */ - foreach ($group->getElements() as $element) { - if ($element->getValue() === null) { - continue; - } - - if ($element->getType() === 'Zend_Form_Element_Hidden') { - continue; - } - - if (in_array($element->getName(), $blacklist)) { - continue; - } - - - $elements[] = $element; - } - - return $elements; - } - - protected function renderElements($elements) - { - $html = ''; - foreach ($elements as $element) { - $html .= $this->renderElement($element); - } - - return $html; - } - - /** - * @param ZfElement $element - * - * @return string - */ - protected function renderElement(ZfElement $element) - { - $value = $element->getValue(); - return '' - . $this->escape($element->getLabel()) - . '' - . $this->renderValue($value) - . ''; - } - - protected function renderValue($value) - { - if (is_string($value)) { - return $this->escape($value); - } elseif (is_array($value)) { - return $this->escape(implode(', ', $value)); - } - return $this->escape(PlainObjectRenderer::render($value)); - } - - protected function escape($string) - { - return htmlspecialchars($string); - } - - public function render() - { - $this->form->initializeForObject(); - return '' . "\n" - . $this->renderDisplayGroups($this->form) - . '
'; - } -} From 28d8f0e7d1cb5c2eb297c98bb1eb42aca7968810 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 19 Jan 2024 13:56:43 +0100 Subject: [PATCH 5/5] ImportsourceController: Remove unnecessary inline js for `collapse` --- application/controllers/ImportsourceController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/application/controllers/ImportsourceController.php b/application/controllers/ImportsourceController.php index cbddb9e9..f417bf76 100644 --- a/application/controllers/ImportsourceController.php +++ b/application/controllers/ImportsourceController.php @@ -180,9 +180,7 @@ class ImportsourceController extends ActionController 'target' => '_blank', 'class' => 'icon-download', ] - ))->add(Link::create('[..]', '#', null, [ - 'onclick' => 'javascript:$("table.raw-data-table").toggleClass("collapsed");' - ])); + )); try { (new ImportsourceHookTable())->setImportSource($source)->renderTo($this); } catch (Exception $e) {