Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

feat(widgets): add buttons to install and upgrade all #6401

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 51 additions & 3 deletions src/CentreonLegacy/Core/Widget/Information.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,29 @@
class Information
{
/**
*
* @var \Pimple\Container
*/
protected $dependencyInjector;

/**
*
* @var \CentreonLegacy\Core\Utils\Utils
*/
protected $utils;

/**
* @var array
*/
protected $cachedWidgetsList = [];

/**
* @var bool
*/
protected $hasWidgetsForUpgrade = false;

/**
* @var bool
*/
protected $hasWidgetsForInstallation = false;

/**
*
Expand Down Expand Up @@ -251,15 +264,19 @@ public function getList()
$widgets[$name]['upgradeable'] = false;
$widgets[$name]['installed_version'] = _('N/A');
$widgets[$name]['available_version'] = $widgets[$name]['version'];

unset($widgets[$name]['version']);

if (isset($installedWidgets[$name])) {
$widgets[$name]['id'] = $installedWidgets[$name]['widget_model_id'];
$widgets[$name]['is_installed'] = true;
$widgets[$name]['installed_version'] = $installedWidgets[$name]['version'];
$widgets[$name]['upgradeable'] = $this->isUpgradeable(
$widgetIsUpgradable = $this->isUpgradeable(
$widgets[$name]['available_version'],
$widgets[$name]['installed_version']
);
$widgets[$name]['upgradeable'] = $widgetIsUpgradable;
$this->hasWidgetsForUpgrade = $widgetIsUpgradable ?: $this->hasWidgetsForUpgrade;
}
}

Expand All @@ -270,6 +287,9 @@ public function getList()
}
}

$this->hasWidgetsForInstallation = count($availableWidgets) > count($installedWidgets);
$this->cachedWidgetsList = $widgets;

return $widgets;
}

Expand Down Expand Up @@ -316,4 +336,32 @@ public function getWidgetPath($widgetName = '')
{
return $this->utils->buildPath('/widgets/' . $widgetName) . '/';
}

public function hasWidgetsForUpgrade()
{
return $this->hasWidgetsForUpgrade;
}

public function getUpgradeableList()
{
$list = empty($this->cachedWidgetsList) ? $this->getList() : $this->cachedWidgetsList;

return array_filter($list, function ($widget) {
return $widget['upgradeable'];
});
}

public function hasWidgetsForInstallation()
{
return $this->hasWidgetsForInstallation;
}

public function getInstallableList()
{
$list = empty($this->cachedWidgetsList) ? $this->getList() : $this->cachedWidgetsList;

return array_filter($list, function ($widget) {
return !$widget['is_installed'];
});
}
}
16 changes: 16 additions & 0 deletions www/include/options/oreon/widgets/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
$widgetInstaller = $factory->newInstaller($directory);
$widgetInstaller->install();
break;
case 'install-all':
$widgetsToInstall = $widgetInfoObj->getInstallableList();

foreach ($widgetsToInstall as $widgetName => $widgetData) {
$widgetInstaller = $factory->newInstaller($widgetName);
$widgetInstaller->install();
}
break;
case 'uninstall':
$widgetRemover = $factory->newRemover($directory);
$widgetRemover->remove();
Expand All @@ -77,6 +85,14 @@
$widgetUpgrader = $factory->newUpgrader($directory);
$widgetUpgrader->upgrade();
break;
case 'upgrade-all':
$widgetsToUpgrade = $widgetInfoObj->getUpgradeableList();

foreach ($widgetsToUpgrade as $widgetName => $widgetData) {
$widgetUpgrader = $factory->newUpgrader($widgetName);
$widgetUpgrader->upgrade();
}
break;
default:
throw new Exception('Unknown action');
}
Expand Down
8 changes: 8 additions & 0 deletions www/include/options/oreon/widgets/list.ihtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{if $hasWidgetsForInstallation}
<img class="installAllBtn ico-16 margin_right" src="./img/icons/generate_conf.png" style="cursor: pointer;" title="Install all widgets">
{/if}

{if $hasWidgetsForUpgrade}
<img class="upgradeAllBtn ico-16" src="./img/icons/upgrade.png" style="cursor: pointer;" title="Upgrade all widgets">
{/if}

<table class="ListTable">
<tr class="ListHeader">
<td class="ListColHeaderLeft">{$labels.title}</td>
Expand Down
24 changes: 18 additions & 6 deletions www/include/options/oreon/widgets/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,43 @@
$tpl = initSmartyTpl($path, $tpl);

$labels = array();
$labels['title'] = _("Title");
$labels['description'] = _("Description");
$labels['version'] = _("Version");
$labels['author'] = _("Author");
$labels['actions'] = _("Actions");
$labels['title'] = _('Title');
$labels['description'] = _('Description');
$labels['version'] = _('Version');
$labels['author'] = _('Author');
$labels['actions'] = _('Actions');

$tpl->assign('hasWidgetsForInstallation', $widgetInfoObj->hasWidgetsForInstallation());
$tpl->assign('hasWidgetsForUpgrade', $widgetInfoObj->hasWidgetsForUpgrade());
$tpl->assign('widgets', $widgets);
$tpl->assign('labels', $labels);
$tpl->display("list.ihtml");
$tpl->display('list.ihtml');
?>
<script type='text/javascript'>
var installConfirmMsg = '<?php echo _('Would you like to install this widget?');?>';
var installAllConfirmMsg = '<?php echo _('Would you like to install all widgets?');?>';
var uninstallConfirmMsg = '<?php echo _('Are you sure you want to uninstall this widget?');?>';
var upgradeConfirmMsg = '<?php echo _('Would you like to upgrade this widget?');?>';
var upgradeAllConfirmMsg = '<?php echo _('Would you like to upgrade all widgets?');?>';
var p = '<?php echo $p;?>';

jQuery(function() {
jQuery('.installBtn').click(function() {
forwardAction(installConfirmMsg, 'install', jQuery(this).parent('td').attr('id'));
});

jQuery('.installAllBtn').click(function() {
forwardAction(installAllConfirmMsg, 'install-all', 'widget_all');
});

jQuery('.upgradeBtn').click(function() {
forwardAction(upgradeConfirmMsg, 'upgrade', jQuery(this).parent('td').attr('id'));
});

jQuery('.upgradeAllBtn').click(function() {
forwardAction(upgradeAllConfirmMsg, 'upgrade-all', 'widget_all');
});

jQuery('.uninstallBtn').click(function() {
forwardAction(uninstallConfirmMsg, 'uninstall', jQuery(this).parent('td').attr('id'));
});
Expand Down