Skip to content

Commit

Permalink
fix(DataCenter): add missing search option
Browse files Browse the repository at this point in the history
  • Loading branch information
adhil0 authored Feb 5, 2024
1 parent 3cbc0e3 commit 8026e4e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
72 changes: 53 additions & 19 deletions src/Datacenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,63 @@ public function rawSearchOptions()
return $tab;
}


public static function rawSearchOptionsToAdd($itemtype)
{
return [
[
'id' => 'datacenter',
'name' => _n('Data center', 'Data centers', Session::getPluralNumber())
],
[
'id' => '178',
'table' => $itemtype::getTable(),
'field' => '_virtual_datacenter_position', // virtual field
'additionalfields' => [
'id',
'name'
],
'name' => __('Data center position'),
'datatype' => 'specific',
'nosearch' => true,
'nosort' => true,
'massiveaction' => false
$tab = [];

$tab[] = [
'id' => 'datacenter',
'name' => _n('Data center', 'Data centers', Session::getPluralNumber())
];

$tab[] = [
'id' => '178',
'table' => $itemtype::getTable(),
'field' => '_virtual_datacenter_position', // virtual field
'additionalfields' => [
'id',
'name'
],
'name' => __('Data center position'),
'datatype' => 'specific',
'nosearch' => true,
'nosort' => true,
'massiveaction' => false
];

if (($itemtype != Rack::getType()) && ($itemtype != DCRoom::getType())) {
$tab[] = [
'id' => '1451',
'table' => Datacenter::getTable(),
'field' => 'name',
'datatype' => 'dropdown',
'linkfield' => 'datacenters_id',
'name' => Datacenter::getTypeName(1),
'massiveaction' => false,
'joinparams' => [
'beforejoin' => [
'table' => DCRoom::getTable(),
'linkfield' => 'dcrooms_id',
'joinparams' => [
'beforejoin' => [
'table' => Rack::getTable(),
'linkfield' => 'racks_id',
'joinparams' => [
'beforejoin' => [
'table' => Item_Rack::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item'
]
]
]
]
]
]
]
];
}

return $tab;
}

public static function getAdditionalMenuLinks()
Expand Down
13 changes: 13 additions & 0 deletions src/Rack.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ public function rawSearchOptions()
'datatype' => 'dropdown'
];

$tab[] = [
'id' => '81',
'table' => Datacenter::getTable(),
'field' => 'name',
'name' => Datacenter::getTypeName(1),
'datatype' => 'dropdown',
'joinparams' => [
'beforejoin' => [
'table' => DCRoom::getTable(),
]
]
];

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

$tab = array_merge($tab, Datacenter::rawSearchOptionsToAdd(get_class($this)));
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -4444,6 +4444,17 @@ public function testDCRoomSearchOption()
$this->variable(array_search('dcroom', array_column($so, 'id')))->isNotEqualTo(false, $item->getTypeName() . ' should use \'$tab = array_merge($tab, DCRoom::rawSearchOptionsToAdd());');
}
}

public function testDataCenterSearchOption()
{
global $CFG_GLPI;
foreach ($CFG_GLPI['rackable_types'] as $rackable_type) {
$item = new $rackable_type();
$so = $item->rawSearchOptions();
//check if search option separator 'datacenter' exist
$this->variable(array_search('datacenter', array_column($so, 'id')))->isNotEqualTo(false, $item->getTypeName() . ' should use \'$tab = array_merge($tab, DataCenter::rawSearchOptionsToAdd());');
}
}
}

// @codingStandardsIgnoreStart
Expand Down

0 comments on commit 8026e4e

Please sign in to comment.