Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.0.0 #65

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c34f6c7
Refactor Views and ViewConfig
martialblog Jul 16, 2024
bec858a
Merge pull request #61 from Icinga/refactor-views
martialblog Jul 22, 2024
9351314
Add view and edit restrictions
martialblog Jul 16, 2024
b1f7c2d
Merge pull request #63 from Icinga/add-restrictions
martialblog Jul 22, 2024
aa91abd
Some minor CSS fixes
martialblog Jul 22, 2024
5f013cd
Merge pull request #64 from Icinga/css-fixes
martialblog Jul 22, 2024
829997c
Update docs
martialblog Jul 23, 2024
0d7e80b
Update TLV Overtile CSS
martialblog Jul 23, 2024
d9323fd
Optimize CSS
martialblog Jul 23, 2024
6186be1
Merge pull request #66 from Icinga/css
martialblog Jul 23, 2024
8fcaf63
Bump version in module.info
martialblog Jul 24, 2024
7e448dd
Fix examples in docs
martialblog Jul 24, 2024
4998af1
Fix restriction issue in loadAll
martialblog Jul 24, 2024
e704cd0
Optimize error display in config editor
martialblog Jul 24, 2024
ed043b8
Add small color update @tlv-color-downtime-bg
martialblog Jul 25, 2024
61fd5a6
Update PHPDoc
martialblog Jul 25, 2024
95a30f4
Update PHPDoc return types
martialblog Jul 25, 2024
4831249
Update docs
martialblog Jul 25, 2024
e9a7300
Add more validation for YAML configuration
martialblog Jul 26, 2024
a077e12
Merge pull request #70 from Icinga/fix/yaml-error
martialblog Jul 29, 2024
19e72cf
Add option to toggle notification_enabled behavior
martialblog Jul 26, 2024
18f42ed
Merge pull request #68 from Icinga/feature/notification-option
martialblog Jul 29, 2024
2ecf4f4
Update docs
martialblog Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ children:
- host: anotherhost
service: ssh
- name: Tile 2
- hostgroup: linux-servers
hostgroup: linux-servers
- name: Tile 3
- name: Section 2
- name: Tile 1
- name: Tile 2
```

With a caching layer, this view can aggregate thousands of status objects and make
them easily available for overview and drill down.

This view extends the status logic and behavior of Icinga Web 2 a bit,
please see the documentation on details.

## Requirements

* Icinga Web 2 >= 2.5.0
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Specify the release version.

```
VERSION=0.x.x
VERSION=1.x.x
```

## Issues
Expand Down
30 changes: 23 additions & 7 deletions application/controllers/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

namespace Icinga\Module\Toplevelview\Controllers;

use Icinga\Module\Toplevelview\Model\View;
use Icinga\Module\Toplevelview\Forms\EditForm;
use Icinga\Module\Toplevelview\ViewConfig;
use Icinga\Module\Toplevelview\Web\Controller;

use Icinga\Web\Url;

class EditController extends Controller
Expand Down Expand Up @@ -39,26 +41,40 @@ public function indexAction()
{
$action = $this->getRequest()->getActionName();

$c = new ViewConfig();
$view = null;

if ($action === 'add') {
$this->view->title = sprintf('%s Top Level View', $this->translate('Add'));
$view = new ViewConfig();
$view->setConfigDir();
$view = new View('', $c::FORMAT_YAML);
} elseif ($action === 'clone') {
// Clone the view and give it to the View
$name = $this->params->getRequired('name');
$this->view->title = sprintf('%s Top Level View', $this->translate('Clone'));
$view = clone ViewConfig::loadByName($name);

// Check if the user has permissions/restrictions for this View
$restrictions = $c->getRestrictions('toplevelview/filter/edit');
$c->assertAccessToView($restrictions, $name);

$view = clone $c->loadByName($name);
} else {
$this->view->name = $name = $this->params->getRequired('name');
$this->view->title = sprintf('%s Top Level View: %s', $this->translate('Edit'), $this->params->getRequired('name'));
$view = ViewConfig::loadByName($name);

// Check if the user has permissions/restrictions for this View
$restrictions = $c->getRestrictions('toplevelview/filter/edit');
$c->assertAccessToView($restrictions, $name);

$view = $c->loadByName($name);
}

$view->setFormat($c::FORMAT_YAML);

$this->view->form = $form = new EditForm();
$form->setViewConfig($c);
$form->setViews($view);

$view->setFormat(ViewConfig::FORMAT_YAML);
$form->setViewConfig($view);
$form->handleRequest();

$this->setViewScript('edit/index');
}

Expand Down
5 changes: 4 additions & 1 deletion application/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function indexAction()
])->activate('index');

// Load add views from the existing YAML files
$this->view->views = ViewConfig::loadAll();
$c = new ViewConfig();
$views = $c->loadAll();

$this->view->views = $views;

$this->setAutorefreshInterval(30);
}
Expand Down
34 changes: 29 additions & 5 deletions application/controllers/ShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

use Icinga\Module\Toplevelview\ViewConfig;
use Icinga\Module\Toplevelview\Web\Controller;

use Icinga\Web\Url;

class ShowController extends Controller
{
public function init()
{
$tabs = $this->getTabs();

$url = Url::fromRequest()->setParams(clone $this->params);

$tiles = Url::fromPath('toplevelview/show', ['name' => $this->params->getRequired('name')]);

$tabs->add('index', [
Expand Down Expand Up @@ -43,7 +42,16 @@ public function init()
public function indexAction()
{
$this->view->name = $name = $this->params->getRequired('name');
$this->view->view = $view = ViewConfig::loadByName($name);

$c = new ViewConfig();

// Check if the user has permissions/restrictions for this View
$restrictions = $c->getRestrictions('toplevelview/filter/views');
$c->assertAccessToView($restrictions, $name);

$view = $c->loadByName($name);
$this->view->view = $view;

$tree = $view->getTree();

if (($lifetime = $this->getParam('cache')) !== null) {
Expand All @@ -56,7 +64,15 @@ public function indexAction()
public function treeAction()
{
$this->view->name = $name = $this->params->getRequired('name');
$this->view->view = $view = ViewConfig::loadByName($name);

$c = new ViewConfig();

// Check if the user has permissions/restrictions for this View
$restrictions = $c->getRestrictions('toplevelview/filter/views');
$c->assertAccessToView($restrictions, $name);

$view = $c->loadByName($name);
$this->view->view = $view;

$tree = $view->getTree();

Expand All @@ -72,7 +88,15 @@ public function treeAction()
public function sourceAction()
{
$this->view->name = $name = $this->params->getRequired('name');
$this->view->view = $view = ViewConfig::loadByName($name);

$c = new ViewConfig();

// Check if the user has permissions/restrictions for this View
$restrictions = $c->getRestrictions('toplevelview/filter/views');
$c->assertAccessToView($restrictions, $name);

$view = $c->loadByName($name);
$this->view->view = $view;

$this->view->text = $view->getText();
$this->setViewScript('index', 'text');
Expand Down
55 changes: 34 additions & 21 deletions application/forms/EditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace Icinga\Module\Toplevelview\Forms;

use Exception;
use Icinga\Module\Toplevelview\ViewConfig;
use Icinga\Module\Toplevelview\Model\View;

use Exception;
use Icinga\Web\Form;
use Icinga\Web\Notification;
use Icinga\Web\Url;
Expand All @@ -14,7 +16,12 @@ class EditForm extends Form
/**
* @var ViewConfig
*/
protected $viewConfig;
protected $viewconfig;

/**
* @var View
*/
protected $view;

/**
* {@inheritdoc}
Expand All @@ -24,9 +31,15 @@ public function init()
$this->setName('form_toplevelview_edit');
}

public function setViewConfig(ViewConfig $viewConfig)
public function setViews(View $view)
{
$this->view = $view;
return $this;
}

public function setViewConfig(ViewConfig $config)
{
$this->viewConfig = $viewConfig;
$this->viewconfig = $config;
return $this;
}

Expand All @@ -36,42 +49,43 @@ public function setViewConfig(ViewConfig $viewConfig)
public function onSuccess()
{
try {
$this->viewConfig->setName($this->getValue('name'));
$this->viewConfig->setText($this->getValue('config'));
$this->view->setName($this->getValue('name'));
$this->view->setText($this->getValue('config'));

// ensure config can be parsed...
$this->viewConfig->getMetaData();
$this->viewConfig->getTree();
$this->view->getMetaData();
$this->view->getTree();

$this->viewConfig->storeToSession();
// Store the view to the session
$this->viewconfig->storeToSession($this->view);

$cancel = $this->getElement('btn_submit_cancel');
$delete = $this->getElement('btn_submit_delete');

if ($this->getElement('btn_submit_save_file')->getValue() !== null) {
$this->viewConfig->store();
$this->viewconfig->storeToFile($this->view);
Notification::success($this->translate('Top Level View successfully saved'));
} elseif ($cancel !== null && $cancel->getValue() !== null) {
$this->viewConfig->clearSession();
$this->viewconfig->clearSession($this->view);
Notification::success($this->translate('Top Level View restored from disk'));
} elseif ($delete != null && $delete->getValue() !== null) {
$this->viewConfig->delete();
$this->viewconfig->delete($this->view);
$this->setRedirectUrl('toplevelview');
Notification::success($this->translate('Top Level View successfully deleted'));
} else {
Notification::success($this->translate('Top Level View successfully saved for the current session'));
}
return true;
} catch (Exception $e) {
$this->addError(sprintf('Could not save config: %s', $e->getMessage()));
$this->error(sprintf('Could not save config: %s', $e->getMessage()));
return false;
}
}

public function getRedirectUrl()
{
if ($this->redirectUrl === null && ($name = $this->viewConfig->getName()) !== null) {
$this->redirectUrl = Url::fromPath('toplevelview/show', array('name' => $name));
if ($this->redirectUrl === null && ($name = $this->view->getName()) !== null) {
$this->redirectUrl = Url::fromPath('toplevelview/show', ['name' => $name]);
}
return parent::getRedirectUrl();
}
Expand All @@ -84,8 +98,8 @@ public function getRedirectUrl()
public function onRequest()
{
$values = array();
$values['name'] = $this->viewConfig->getName();
$values['config'] = $this->viewConfig->getText();
$values['name'] = $this->view->getName();
$values['config'] = $this->view->getText();

$this->populate($values);
}
Expand All @@ -95,7 +109,7 @@ public function onRequest()
*/
public function createElements(array $formData)
{
if ($this->viewConfig->hasBeenLoadedFromSession()) {
if ($this->view->hasBeenLoadedFromSession()) {
$this->warning(
$this->translate(
'This config is only stored in your session!'
Expand All @@ -117,7 +131,6 @@ public function createElements(array $formData)
'textarea',
'config',
array(
//'required' => true,
'label' => $this->translate('YAML Config'),
'class' => 'code-editor codemirror',
'decorators' => array(
Expand Down Expand Up @@ -149,7 +162,7 @@ public function createElements(array $formData)
)
);

if ($this->viewConfig->hasBeenLoadedFromSession()) {
if ($this->view->hasBeenLoadedFromSession()) {
$this->addElement(
'submit',
'btn_submit_cancel',
Expand All @@ -162,7 +175,7 @@ public function createElements(array $formData)
);
}

if ($this->viewConfig->hasBeenLoaded()) {
if ($this->view->hasBeenLoaded()) {
$this->addElement(
'submit',
'btn_submit_delete',
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/Tiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
$title . $badges,
'toplevelview/show/tree',
array(
'name' => $node->getRoot()->getConfig()->getName(),
'name' => $node->getRoot()->getView()->getName(),
'id' => $node->getFullId()
),
array(
Expand Down
2 changes: 1 addition & 1 deletion application/views/helpers/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
$url = Url::fromPath(
'toplevelview/show/tree',
array(
'name' => $node->getRoot()->getConfig()->getName(),
'name' => $node->getRoot()->getView()->getName(),
'id' => $node->getFullId()
)
);
Expand Down
29 changes: 6 additions & 23 deletions application/views/scripts/index/index.phtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php
use Icinga\Module\Toplevelview\Util\Str;

/** @var array $views */

if (! $this->compact): ?>
<div class="controls separated">
<?= $this->tabs ?>
<div class="action-links">
<?php if ($this->hasPermission('toplevelview/edit')): ?>
<?= $this->qlink(
$this->translate('Add'),
'toplevelview/edit/add',
Expand All @@ -16,37 +13,23 @@ if (! $this->compact): ?>
'icon' => 'plus',
)
) ?>
<?php endif; ?>
</div>
</div>
<?php endif ?>
<div class="content separated">
<div class="tlv-overview-tiles">
<?php
foreach ($views as $name => $view):
/** @var \Icinga\Module\Toplevelview\ViewConfig $view */
$url = $this->url('toplevelview/show', array('name' => $name));
?>
<div class="tlv-overview-tile">
<div class="tlv-title"><?= $this->qlink($view->getMeta('name'), $url) ?></div>
<a href="<?= $url ?>" class="tlv-overview-tile">
<div class="tlv-title"><?= $view->getMeta('name') ?></div>
<div class="tlv-name"><?= $name ?></div>
<?php if ($view->hasBeenLoadedFromSession()): ?>
<div class="unsaved"><?= $this->translate('Unsaved changes!') ?></div>
<p class="warning-note"><?= $this->translate('Unsaved changes!') ?></p>
<?php endif; ?>

<?php if (! $this->compact && $this->hasPermission('toplevelview/edit')): ?>
<div class="action-links">
<?= $this->qlink(
$this->translate('Edit'),
'toplevelview/edit',
array('name' => $view->getName()),
array(
'class' => 'action-link',
'icon' => 'edit',
)
) ?>
</div>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
</div>
</div>
Loading
Loading