Skip to content

Commit

Permalink
feat: provide search options on model characteristics for computer, m…
Browse files Browse the repository at this point in the history
…onitor and net devices
  • Loading branch information
btry committed Oct 3, 2024
1 parent f3af05c commit 86d9e8a
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 6 deletions.
72 changes: 72 additions & 0 deletions install/migrations/update_10.0.17_to_10.0.18.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* Update from 10.0.17 to 10.0.18
*
* @return bool for success (will die for most error)
**/
function update10017to10018()
{
/**
* @var \DBmysql $DB
* @var \Migration $migration
*/
global $DB, $migration;

$updateresult = true;
$ADDTODISPLAYPREF = [];
$DELFROMDISPLAYPREF = [];
$update_dir = __DIR__ . '/update_10.0.17_to_10.0.18/';

//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), '10.0.18'));
$migration->setVersion('10.0.18');

$update_scripts = scandir($update_dir);
foreach ($update_scripts as $update_script) {
if (preg_match('/\.php$/', $update_script) !== 1) {
continue;
}
require $update_dir . $update_script;
}

// ************ Keep it at the end **************
$migration->updateDisplayPrefs($ADDTODISPLAYPREF, $DELFROMDISPLAYPREF);

$migration->executeMigration();

return $updateresult;
}
58 changes: 58 additions & 0 deletions install/migrations/update_10.0.17_to_10.0.18/models.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/**
* @var \DBmysql $DB
* @var \Migration $migration
*/

// Change model search options
$itemtypes = [
'ComputerModel',
'EnclosureModel',
'MonitorModel',
'NetworkEquipmentModel',
'PassiveDEquipmentModel',
'PDUModel',
'PeripheralModel',
];
foreach ($itemtypes as $itemtype) {
$migration->changeSearchOption($itemtype, 131, 1500);
$migration->changeSearchOption($itemtype, 132, 1501);
$migration->changeSearchOption($itemtype, 133, 1502);
$migration->changeSearchOption($itemtype, 134, 1503);
$migration->changeSearchOption($itemtype, 135, 1504);
$migration->changeSearchOption($itemtype, 136, 1505);
}
82 changes: 76 additions & 6 deletions src/CommonDCModelDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'weight')) {
$options[] = [
'id' => '131',
'id' => '1500',
'table' => $table,
'field' => 'weight',
'name' => __('Weight'),
Expand All @@ -145,7 +145,7 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'required_units')) {
$options[] = [
'id' => '132',
'id' => '1501',
'table' => $table,
'field' => 'required_units',
'name' => __('Required units'),
Expand All @@ -155,7 +155,7 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'depth')) {
$options[] = [
'id' => '133',
'id' => '1502',
'table' => $table,
'field' => 'depth',
'name' => __('Depth'),
Expand All @@ -164,7 +164,7 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'power_connections')) {
$options[] = [
'id' => '134',
'id' => '1503',
'table' => $table,
'field' => 'power_connections',
'name' => __('Power connections'),
Expand All @@ -174,7 +174,7 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'power_consumption')) {
$options[] = [
'id' => '135',
'id' => '1504',
'table' => $table,
'field' => 'power_consumption',
'name' => __('Power consumption'),
Expand All @@ -184,7 +184,77 @@ public function rawSearchOptions()

if ($DB->fieldExists($table, 'is_half_rack')) {
$options[] = [
'id' => '136',
'id' => '1505',
'table' => $table,
'field' => 'is_half_rack',
'name' => __('Is half rack'),
'datatype' => 'bool'
];
}

return $options;
}

public static function rawSearchOptionsToAdd()
{
/** @var DBmysql $DB */
global $DB;

$options = [];
$table = self::getTable();

if ($DB->fieldExists($table, 'weight')) {
$options[] = [
'id' => '1500',
'table' => $table,
'field' => 'weight',
'name' => __('Weight'),
'datatype' => 'decimal'
];
}

if ($DB->fieldExists($table, 'required_units')) {
$options[] = [
'id' => '1501',
'table' => $table,
'field' => 'required_units',
'name' => __('Required units'),
'datatype' => 'number'
];
}

if ($DB->fieldExists($table, 'depth')) {
$options[] = [
'id' => '1502',
'table' => $table,
'field' => 'depth',
'name' => __('Depth'),
];
}

if ($DB->fieldExists($table, 'power_connections')) {
$options[] = [
'id' => '1503',
'table' => $table,
'field' => 'power_connections',
'name' => __('Power connections'),
'datatype' => 'number'
];
}

if ($DB->fieldExists($table, 'power_consumption')) {
$options[] = [
'id' => '1504',
'table' => $table,
'field' => 'power_consumption',
'name' => __('Power consumption'),
'datatype' => 'decimal'
];
}

if ($DB->fieldExists($table, 'is_half_rack')) {
$options[] = [
'id' => '1505',
'table' => $table,
'field' => 'is_half_rack',
'name' => __('Is half rack'),
Expand Down
2 changes: 2 additions & 0 deletions src/Computer.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ public function rawSearchOptions()
'datatype' => 'dropdown'
];

$tab = array_merge($tab, ComputerModel::rawSearchOptionsToAdd());

// add operating system search options
$tab = array_merge($tab, Item_OperatingSystem::rawSearchOptionsToAdd(get_class($this)));

Expand Down
2 changes: 2 additions & 0 deletions src/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ public function rawSearchOptions()
'massiveaction' => false
];

$tab = array_merge($tab, MonitorModel::rawSearchOptionsToAdd());

$tab = array_merge($tab, Notepad::rawSearchOptionsToAdd());

$tab = array_merge($tab, Datacenter::rawSearchOptionsToAdd(get_class($this)));
Expand Down
2 changes: 2 additions & 0 deletions src/NetworkEquipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ public function rawSearchOptions()
'massiveaction' => false
];

$tab = array_merge($tab, NetworkEquipmentModel::rawSearchOptionsToAdd());

// add operating system search options
$tab = array_merge($tab, Item_OperatingSystem::rawSearchOptionsToAdd(get_class($this)));

Expand Down

0 comments on commit 86d9e8a

Please sign in to comment.