Commit 47b0812f authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #5056 Allowing plugins to easily add argonaut actions to the menu

Conflicts:
	systems/admin/systems/class_systemManagement.inc
parent 20ef1e77
......@@ -220,52 +220,5 @@ class argonautAction extends simplePlugin
return $ret;
}
/*! \brief Returns event information, like menu strings, images ...
@return Array Event informations.
*/
static public function get_event_info($action)
{
$events = self::get_event_types();
if (isset($events[$action])) {
$infos = $events[$action];
$infos['menuimg'] = '<img src="'.$infos['img'].'" alt="'.$infos['name'].'" class="center"/>';
$infos['listimg'] = '<img src="'.$infos['img'].'" title="'.$infos['name'].
'"alt="'.$infos['name'].'" class="center"/>';
return $infos;
} else {
return FALSE;
}
}
/*! \brief Returns a complete list of all available events.
@return Array Containing info for all available events.
*/
static public function get_event_types()
{
return array(
'System.halt' => array(
'name' => _('Switch off'),
'img' => 'geticon.php?context=actions&icon=system-shutdown&size=16'
),
'Deployment.reboot' => array(
'name' => _('Reboot'),
'img' => 'geticon.php?context=actions&icon=system-reboot&size=16'
),
'Deployment.wake' => array(
'name' => _('Wake up'),
'img' => 'geticon.php?context=status&icon=task-running&size=16'
),
'Deployment.update' => array(
'name' => _('Software update'),
'img' => 'geticon.php?context=actions&icon=system-update&size=16'
),
'Deployment.reinstall' => array(
'name' => _('(Re)Install'),
'img' => 'geticon.php?context=actions&icon=system-reinstall&size=16'
),
);
}
}
?>
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2015-2016 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class argonautEventTypes
{
static protected function get_event_types_list()
{
die('get_event_types_list needs to be implemented in all subclass of argonautEventTypes');
}
/*! \brief Returns a complete list of all available events.
@return Array Containing info for all available events.
*/
static public function get_event_types()
{
global $class_mapping;
if (session::is_set('argonautEventTypes::get_event_types')) {
return session::get('argonautEventTypes::get_event_types');
} else {
$ret = array();
foreach (array_keys($class_mapping) as $class) {
if (is_subclass_of($class, 'argonautEventTypes')) {
$ret = array_merge($ret, $class::get_event_types_list());
}
}
session::set('argonautEventTypes::get_event_types', $ret);
return $ret;
}
}
/*! \brief Returns event information, like menu strings, images ...
@return Array Event informations.
*/
static public function get_event_info($action)
{
$events = self::get_event_types();
if (isset($events[$action])) {
$infos = $events[$action];
$infos['listimg'] = '<img src="'.$infos['img'].'" title="'.$infos['name'].
'"alt="'.$infos['name'].'" class="center"/>';
return $infos;
} else {
return FALSE;
}
}
}
class argonautEventSystem extends argonautEventTypes
{
static protected function get_event_types_list()
{
return array(
'System.halt' => array(
'name' => _('Switch off'),
'img' => 'geticon.php?context=actions&icon=system-shutdown&size=16'
)
);
}
}
class argonautEventDeployment extends argonautEventTypes
{
static protected function get_event_types_list()
{
return array(
'Deployment.reboot' => array(
'name' => _('Reboot'),
'img' => 'geticon.php?context=actions&icon=system-reboot&size=16'
),
'Deployment.wake' => array(
'name' => _('Wake up'),
'img' => 'geticon.php?context=status&icon=task-running&size=16'
),
'Deployment.update' => array(
'name' => _('Software update'),
'img' => 'geticon.php?context=actions&icon=system-update&size=16'
),
'Deployment.reinstall' => array(
'name' => _('(Re)Install'),
'img' => 'geticon.php?context=actions&icon=system-reinstall&size=16'
),
);
}
}
......@@ -84,7 +84,7 @@ class argonautImportFile extends simplePlugin
$this->attributesAccess['import']->setLinearRendering(TRUE);
$this->events = array();
$this->daemon_events = argonautAction::get_event_types();
$this->daemon_events = argonautEventTypes::get_event_types();
}
function execute()
......
......@@ -103,7 +103,7 @@ class argonautQueue extends simpleManagement
$task = $tmp['EVENT'];
/* Create a printable job name/description */
$infos = argonautAction::get_event_info($task['HEADERTAG']);
$infos = argonautEventTypes::get_event_info($task['HEADERTAG']);
if ($infos) {
$j_name = $task['ID']." - ".$infos['name']."&nbsp;".$task['MACADDRESS'];
} else {
......@@ -130,7 +130,7 @@ class argonautQueue extends simpleManagement
foreach ($this->dns as $dn) {
$tmp = $this->headpage->getEntry($dn);
$task = $tmp['EVENT'];
$infos = argonautAction::get_event_info($task['HEADERTAG']);
$infos = argonautEventTypes::get_event_info($task['HEADERTAG']);
if ($infos) {
$objects[] = array(
'name' => $infos['name'],
......@@ -290,7 +290,7 @@ class argonautQueue extends simpleManagement
/* Check if this event exists as Daemon class
* In this case, display a more accurate entry.
*/
$infos = argonautAction::get_event_info($tag);
$infos = argonautEventTypes::get_event_info($tag);
if ($infos) {
$str = $infos['name'];
......
......@@ -26,7 +26,7 @@ class filterArgonautEvents extends filterLDAP
global $config;
$o_queue = new supportDaemon();
$events = argonautAction::get_event_types();
$events = argonautEventTypes::get_event_types();
/* Get tags that will be used in queue searches */
$event_tags = array("none");
......
......@@ -174,7 +174,7 @@ class termgroup extends plugin
$action = $this->mapActions[$_POST['saction']];
if (class_available('argonautAction')) {
$events = argonautAction::get_event_types();
$events = argonautEventTypes::get_event_types();
$macaddresses = array();
foreach ($this->members as $cn => $macAddress){
$macaddresses[]= $macAddress;
......
......@@ -62,7 +62,7 @@ class systemManagement extends management
if (class_available('argonautAction') && class_available('supportDaemon')) {
$this->headpage->xmlData['actionmenu']['action'][2]['action'] = array();
$this->headpage->xmlData['actionmenu']['action'][3]['action'] = array();
$events = argonautAction::get_event_types();
$events = argonautEventTypes::get_event_types();
foreach ($events as $name => $data) {
$this->registerAction("T_".$name, "handleEvent");
$headpage->xmlData['actionmenu']['action'][2]['action'][] = array(
......@@ -142,7 +142,7 @@ class systemManagement extends management
$mac = array();
// Collect target mac addresses
$events = argonautAction::get_event_types();
$events = argonautEventTypes::get_event_types();
$o_queue = new supportDaemon();
foreach ($target as $dn) {
$obj = $headpage->getEntry($dn);
......
......@@ -267,7 +267,7 @@ class workstationGeneric extends systemSimplePluginGlue
if ($activate && class_available('supportDaemon')) {
/* Send installation activation */
$events = argonautAction::get_event_types();
$events = argonautEventTypes::get_event_types();
if (isset($events['installation_activation'])) {
$o_queue = new supportDaemon();
$o_queue->append_call('installation_activation', array($this->netConfigDNS->macAddress), array());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment