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

Commit

Permalink
enh(config): add display locked checkbox for objects listing (#7444)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgagnaire authored and kduret committed Oct 3, 2019
1 parent ea9d0ce commit dbc1dae
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 65 deletions.
7 changes: 5 additions & 2 deletions doc/en/configuration_guide/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ All the commands can be configured in the menu: **Configuration > Commands**.
.. image :: /images/user/configuration/04commandlist.png
:align: center
.. note::
By default, locked commands are hidden. Check the "Locked elements" box to list all commands.

****************
****************
Adding a command
****************

Expand All @@ -48,11 +50,12 @@ Configuration fields
* The **Command Type** field allows us to choose the type of command.
* The **Command Line** field indicates the application or the script use with the command.
* The **Enable shell** box allows us to enable functions that are specific to a shell such as the pipe, etc.
* The **Argument Example** and **$HOSTADDRESS$** fields define examples of arguments (each argument starts with a ”!”) and a test IP address respectively.
* The **Argument Example** and **$HOSTADDRESS$** fields define examples of arguments (each argument starts with a ”!”) and a test IP address respectively.
These fields serve to execute the command line defined above via the web interface by clicking on the blue arrow : |bluearrow|.
* The **Describe arguments** button serves to add a description to arguments of the “$ARGn$” type. This description will be visible when using the command in a host or service form.
* The **Clear arguments** button deletes the description of arguments defined
* The **Describe macros** button serves to add a description to all macros. This description will be visible when using the command in a host or service form.

* The **Connectors** field serves to link a Connector to the command. For more information on Connectors refer to the chapter entitled: `Perl Connector's documentation <http://documentation.centreon.com/docs/centreon-perl-connector/en/latest/>`_ and `SSH Connector's documentation <http://documentation.centreon.com/docs/centreon-ssh-connector/en/latest/>`_.
* The **Graph template** field serves to link the command to a graphic model.
* The **Comment** field can be used to make a comment on the command.
Expand Down
6 changes: 6 additions & 0 deletions doc/en/configuration_guide/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ To add a host template:
.. note::
Refer to the chapter covering configuration of :ref:`hosts<hostconfiguration>` to configure a template because the form is identical.

.. note::
By default, locked host templates are hidden. Check the "Locked elements" box to list all templates.

******************
Services Templates
******************
Expand All @@ -93,6 +96,9 @@ To add a Service Template:
.. note::
Refer to the chapter covering configuration of :ref:`services<serviceconfiguration>` to configure a template because the form is identical.

.. note::
By default, locked service templates are hidden. Check the "Locked elements" box to list all templates.

*************
Best practice
*************
Expand Down
Binary file modified doc/en/images/user/configuration/04commandlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 15 additions & 9 deletions doc/fr/configuration_guide/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ Il est possible d'exécuter cette commande en précisant des arguments.

Il existe trois types de commandes :

* Les commandes de **vérification** sont utilisées par les ordonnanceurs afin de vérifier le statut d'un hôte ou d'un service.
* Les commandes de **vérification** sont utilisées par les ordonnanceurs afin de vérifier le statut d'un hôte ou d'un
service.
* Les commandes de **notification** sont utilisées par les ordonnanceurs pour alerter les contacts (via mail, SMS...).
* Des commandes **diverses** sont utilisées par les modules complémentaires (pour effectuer certaines actions), par l'ordonnanceur pour le traitement des données...
* Les commandes de **découverte** sont utilisées par les règles de découverte de services.
* Des commandes **diverses** sont utilisées par les modules complémentaires (pour effectuer certaines actions), par
l'ordonnanceur pour le traitement des données...

Toutes les commandes peuvent être configurées au sein du menu **Configuration > Commandes**.

.. image :: /images/guide_utilisateur/configuration/04commandlist.png
:align: center
:align: center
.. note::
Par défaut, les commandes verrouillées sont masquées. Cocher la case "Eléments verrouillés" pour les afficher toutes.

********************
Ajouter une commande
Expand All @@ -27,14 +33,14 @@ Ajouter une commande
Avant d'ajouter une commande :

1. Sélectionnez dans le menu de gauche le type de commande que vous souhaitez ajouter (Contrôles, Notifications, Divers).

.. image :: /images/guide_utilisateur/configuration/04leftmenu.png
:align: center
:align: center
2. Cliquez sur **Ajouter**

.. image :: /images/guide_utilisateur/configuration/04command.png
:align: center
:align: center
.. note::
Les champs de configuration d'une commande sont les mêmes qu'importe le type de commande choisi.
Expand Down
6 changes: 6 additions & 0 deletions doc/fr/configuration_guide/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Pour ajouter un modèle d'hôtes :
.. note::
Se rapporter au chapitre de configuration des :ref:`hôtes<hostconfiguration>` pour configurer un modèle car le formulaire est identique.

.. note::
Par défaut, les modèles d'hôte verrouillés sont masqués. Cocher la case "Eléments verrouillés" pour les afficher tous.

***********************
Les modèles de services
***********************
Expand Down Expand Up @@ -128,6 +131,9 @@ Configuration

La liaison des modèles de services avec les modèles d'hôtes a lieu dans l'onglet **Relations** des modèles de services ou des modèles d'hôtes.

.. note::
Par défaut, les modèles de service verrouillés sont masqués. Cocher la case "Eléments verrouillés" pour les afficher tous.

***********************
Les modèles de contacts
***********************
Expand Down
Binary file modified doc/fr/images/guide_utilisateur/configuration/04commandlist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lang/fr_FR.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -14836,3 +14836,6 @@ msgstr "Un Remote Server principal doit être sélectionné, avant d'utiliser de

msgid "Attach additional Remote Servers"
msgstr "Ajouter des Remote Server additonnels"

msgid "Locked elements"
msgstr "Eléments verrouillés"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
</tr>
<tr>
<td><input type="text" name="searchC" value="{$searchC}"></td>
<td>{$form.Search.html}</td>
<td>
<div class="md-checkbox md-checkbox-inline">
<input type="checkbox" id="displayLocked" name="displayLocked" {if $displayLocked}checked{/if} />
<label for="displayLocked">{t}Locked elements{/t}</label>
</div>
</td>
<td><input type="submit" value="{t}Search{/t}" class="btc bt_success"></td>
</tr>
</tbody>
</table>
Expand Down
61 changes: 30 additions & 31 deletions www/include/configuration/configObject/command/listCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,27 @@
include_once "./class/centreonUtils.class.php";
include_once "./include/common/autoNumLimit.php";

$type = filter_var(
$_POST['type'] ?? $_GET['type'] ?? $centreon->historySearch[$url]['type'] ?? null,
FILTER_VALIDATE_INT
);

$search = filter_var(
$_POST['searchC'] ?? $_GET['searchC'] ?? null,
$_POST['searchC'] ?? $_GET['searchC'] ?? $centreon->historySearch[$url]['search' . $type] ?? '',
FILTER_SANITIZE_STRING
);

$type = filter_var(
$_POST['type'] ?? $_GET['type'] ?? null,
FILTER_VALIDATE_INT
$displayLocked = filter_var(
$_POST['displayLocked'] ?? $_GET['displayLocked'] ?? 'off',
FILTER_VALIDATE_BOOLEAN
);

// keep checkbox state if navigating in pagination
// this trick is mandatory cause unchecked checkboxes do not post any data
if (($centreon->historyPage[$url] > 0 || $num !== 0) && isset($centreon->historySearch[$url]['displayLocked'])) {
$displayLocked = $centreon->historySearch[$url]['displayLocked'];
}

// As the four pages of this menu are generated dynamically from the same ihtml and php files,
// we need to save $type and to overload the $num value set in the pagination.php file to restore each user's filter.
$savedType = $centreon->historySearch[$url]['type'] ?? null;
Expand All @@ -59,40 +70,28 @@
if (isset($type) && $type !== $savedType) {
//if so, we reset the pagination and save the current $type
$num = $centreon->historyPage[$url] = 0;
$centreon->historySearch[$url]['type'] = $type;
} else {
//saving again the pagination filter
$centreon->historyPage[$url] = $num;
}

if (isset($_POST['searchC']) || isset($_GET['searchC'])) {
//saving user's search field value
$centreon->historySearch[$url] = array();
// the four pages have the same $url, so we need to distinguish each page using its $type,
// and to save the four search filters.
$centreon->historySearch[$url]['search' . $type] = $search;
} else {
//restoring user's search field value
$search = $centreon->historySearch[$url]['search' . $type] ?? null;
}
// store filters in session
$centreon->historySearch[$url] = [
'search' . $type => $search,
'type' => $type,
'displayLocked' => $displayLocked
];

// Locked filter
$lockedFilter = $displayLocked ? "" : "AND command_locked = 0 ";

$type_str = $type ? " AND `command_type` = " . $type : "";
// Type filter
$typeFilter = $type ? "AND `command_type` = " . $type . " " : "";
$search = tidySearchKey($search, $advanced_search);

//List of elements - Depends on different criteria
if (isset($search) && $search) {
$rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " .
"`command_activate` FROM `command` WHERE `command_name` LIKE '%" . $search . "%' " .
$type_str . " ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit;
} elseif ($type) {
$rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " .
"`command_activate` FROM `command` WHERE `command_type` = '" . $type .
"' ORDER BY command_name LIMIT " . $num * $limit . ", " . $limit;
} else {
$rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " .
"`command_activate` FROM `command` ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit;
}
$rq = "SELECT SQL_CALC_FOUND_ROWS `command_id`, `command_name`, `command_line`, `command_type`, " .
"`command_activate` FROM `command` WHERE `command_name` LIKE '%" . $search . "%' " .
$typeFilter . $lockedFilter . " ORDER BY `command_name` LIMIT " . $num * $limit . ", " . $limit;

$dbResult = $pearDB->query($rq);
$rows = $pearDB->query("SELECT FOUND_ROWS()")->fetchColumn();
Expand All @@ -117,7 +116,7 @@
$tpl->assign("headerMenu_suse", _("Services Uses"));
$tpl->assign("headerMenu_options", _("Options"));

$form = new HTML_QuickForm('form', 'POST', "?p=" . $p);
$form = new HTML_QuickFormCustom('form', 'POST', "?p=" . $p);

// Different style between each lines
$style = "one";
Expand Down Expand Up @@ -253,5 +252,5 @@ function setO(_i) {
$tpl->assign('limit', $limit);
$tpl->assign('type', $type);
$tpl->assign('searchC', $search);

$tpl->assign("displayLocked", $displayLocked);
$tpl->display("listCommand.ihtml");
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
</tr>
<tr>
<td><input type="text" name="searchHT" value="{$searchHT}"></td>
<td>{$form.Search.html}</td>
<td>
<div class="md-checkbox md-checkbox-inline">
<input type="checkbox" id="displayLocked" name="displayLocked" {if $displayLocked}checked{/if} />
<label for="displayLocked">{t}Locked elements{/t}</label>
</div>
</td>
<td><input type='submit' value='{t}Search{/t}' class="btc bt_success"/></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,35 @@
$DBRESULT->closeCursor();

$search = filter_var(
$_POST['searchHT'] ?? $_GET['searchHT'] ?? null,
$_POST['searchHT'] ?? $_GET['searchHT'] ?? $centreon->historySearch[$url]['search'] ?? '',
FILTER_SANITIZE_STRING
);

if (isset($_POST['searchHT']) || isset($_GET['searchHT'])) {
//saving filters values
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]['search'] = $search;
} else {
//restoring saved values
$search = $centreon->historySearch[$url]['search'] ?? null;
$displayLocked = filter_var(
$_POST['displayLocked'] ?? $_GET['displayLocked'] ?? 'off',
FILTER_VALIDATE_BOOLEAN
);

// keep checkbox state if navigating in pagination
// this trick is mandatory cause unchecked checkboxes do not post any data
if (($centreon->historyPage[$url] > 0 || $num !== 0) && isset($centreon->historySearch[$url]['displayLocked'])) {
$displayLocked = $centreon->historySearch[$url]['displayLocked'];
}

// Host Template list
// store filters in session
$centreon->historySearch[$url] = [
'search' => $search,
'displayLocked' => $displayLocked
];

// Locked filter
$lockedFilter = $displayLocked ? "" : "AND host_locked = 0 ";

// Host Template list
$rq = "SELECT SQL_CALC_FOUND_ROWS host_id, host_name, host_alias, host_activate, host_template_model_htm_id " .
"FROM host" .
" WHERE host_register = '0' ";
"FROM host " .
"WHERE host_register = '0' " .
$lockedFilter;
if ($search) {
$rq .= "AND (host_name LIKE '%" . CentreonDB::escape($search) . "%' OR host_alias LIKE '%" .
CentreonDB::escape($search) . "%')";
Expand Down Expand Up @@ -252,4 +263,5 @@ function setO(_i) {
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->assign('searchHT', $search);
$tpl->assign("displayLocked", $displayLocked);
$tpl->display("listHostTemplateModel.ihtml");
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
</tr>
<tr>
<td><input type="text" name="searchST" value="{$searchST}"></td>
<td>{$form.Search.html}</td>
<td>
<div class="md-checkbox md-checkbox-inline">
<input type="checkbox" id="displayLocked" name="displayLocked" {if $displayLocked}checked{/if} />
<label for="displayLocked">{t}Locked elements{/t}</label>
</div>
</td>
<td><input type="submit" value="{t}Search{/t}" class="btc bt_success"></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,45 @@
$o = "";

$search = filter_var(
$_POST['searchST'] ?? $_GET['searchST'] ?? null,
$_POST['searchST'] ?? $_GET['searchST'] ?? $centreon->historySearch[$url]['search'] ?? '',
FILTER_SANITIZE_STRING
);

if (isset($_POST['searchST']) || isset($_GET['searchST'])) {
//saving filters values
$centreon->historySearch[$url] = array();
$centreon->historySearch[$url]["search"] = $search;
} else {
//restoring saved values
$search = $centreon->historySearch[$url]["search"] ?? null;
$displayLocked = filter_var(
$_POST['displayLocked'] ?? $_GET['displayLocked'] ?? 'off',
FILTER_VALIDATE_BOOLEAN
);

// keep checkbox state if navigating in pagination
// this trick is mandatory cause unchecked checkboxes do not post any data
if (($centreon->historyPage[$url] > 0 || $num !== 0) && isset($centreon->historySearch[$url]['displayLocked'])) {
$displayLocked = $centreon->historySearch[$url]['displayLocked'];
}

// store filters in session
$centreon->historySearch[$url] = [
'search' => $search,
'displayLocked' => $displayLocked
];

// Locked filter
$lockedFilter = $displayLocked ? "" : "AND sv.service_locked = 0 ";

//Service Template Model list
if ($search) {
$query = "SELECT SQL_CALC_FOUND_ROWS sv.service_id, sv.service_description, sv.service_alias, " .
"sv.service_activate, sv.service_template_model_stm_id " .
"FROM service sv " .
"WHERE (sv.service_description LIKE '%" . $search . "%' OR sv.service_alias LIKE '%" . $search . "%') " .
"AND sv.service_register = '0' " .
$lockedFilter .
"ORDER BY service_description LIMIT " . $num * $limit . ", " . $limit;
} else {
$query = "SELECT SQL_CALC_FOUND_ROWS sv.service_id, sv.service_description, sv.service_alias, " .
"sv.service_activate, sv.service_template_model_stm_id " .
"FROM service sv " .
"WHERE sv.service_register = '0' " .
$lockedFilter .
"ORDER BY service_description LIMIT " . $num * $limit . ", " . $limit;
}
$dbResult = $pearDB->query($query);
Expand Down Expand Up @@ -319,10 +332,10 @@ function setO(_i) {

$tpl->assign('limit', $limit);
$tpl->assign('searchST', $search);
$tpl->assign("displayLocked", $displayLocked);

// Apply a template definition
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display("listServiceTemplateModel.ihtml");
?>

0 comments on commit dbc1dae

Please sign in to comment.