Skip to content

Commit 3cd910c

Browse files
Configure helpdesk home page illustration
1 parent fc1204f commit 3cd910c

File tree

15 files changed

+768
-37
lines changed

15 files changed

+768
-37
lines changed

install/empty_data.php

+2
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,8 @@ public function getEmptyData(): array
25122512
'is_location_autoclean' => '0',
25132513
'state_autoclean_mode' => '0',
25142514
'show_tickets_properties_on_helpdesk' => 0,
2515+
'custom_helpdesk_home_scene_left' => '',
2516+
'custom_helpdesk_home_scene_right' => '',
25152517
],
25162518
];
25172519

install/migrations/update_10.0.x_to_11.0.0/form.php

+18
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@
292292
);
293293
}
294294

295+
$fields = ['custom_helpdesk_home_scene_left', 'custom_helpdesk_home_scene_right'];
296+
foreach ($fields as $field) {
297+
if (!$DB->fieldExists("glpi_entities", $field)) {
298+
$migration->addField(
299+
'glpi_entities',
300+
$field,
301+
"varchar(255) NOT NULL DEFAULT '-2'"
302+
);
303+
$migration->addPostQuery(
304+
$DB->buildUpdate(
305+
'glpi_entities',
306+
[$field => ''],
307+
['id' => 0]
308+
)
309+
);
310+
}
311+
}
312+
295313
// Add rights for the forms object
296314
$migration->addRight("form", ALLSTANDARDRIGHT, ['config' => UPDATE]);
297315

install/mysql/glpi-empty.sql

+2
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,8 @@ CREATE TABLE `glpi_entities` (
28452845
`is_location_autoclean` tinyint NOT NULL DEFAULT '-2',
28462846
`state_autoclean_mode` int NOT NULL DEFAULT '-2',
28472847
`show_tickets_properties_on_helpdesk` int NOT NULL DEFAULT '-2',
2848+
`custom_helpdesk_home_scene_left` varchar(255) NOT NULL DEFAULT '-2',
2849+
`custom_helpdesk_home_scene_right` varchar(255) NOT NULL DEFAULT '-2',
28482850
PRIMARY KEY (`id`),
28492851
UNIQUE KEY `unicity` (`entities_id`,`name`),
28502852
KEY `name` (`name`),

js/modules/DynamicDropdownController.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
*/
3333

3434
/**
35-
* Helper class to easily manage sub dropdowns (i.e. you have a main dropdown
36-
* and a few secondary dropdown that will only be displayed depending on the
37-
* values of the main dropdown).
35+
* Helper class to easily manage items that should be hidden / shown depending
36+
* on a dropdown value.
3837
*
39-
* The children dropdown must define two data attributes:
38+
* The item must define two data attributes:
4039
* - data-glpi-parent-dropdown: the name of the parent dropdown
4140
* - data-glpi-parent-dropdown-condition: the value that the parent dropdown
42-
* must have for this dropdown to be displayed
41+
* must have for this item to be displayed
4342
*/
4443
export class DynamicDropdownController
4544
{
@@ -51,16 +50,16 @@ export class DynamicDropdownController
5150
const dropdowns = $('select[data-select2-id]');
5251

5352
$(dropdowns).on('change', (e) => {
54-
this.#updateChildrenDropdownsVisiblity($(e.target));
53+
this.#updateItemsVisiblity($(e.target));
5554
});
5655
}
5756

58-
#updateChildrenDropdownsVisiblity(select) {
57+
#updateItemsVisiblity(select) {
5958
const name = $.escapeSelector(select.prop("name"));
60-
const child_dropdowns = $(`[data-glpi-parent-dropdown='${name}']`);
59+
const items = $(`[data-glpi-parent-dropdown='${name}']`);
6160
const value = select.val();
6261

63-
child_dropdowns.each((i, dropdown) => {
62+
items.each((i, dropdown) => {
6463
const expected_value = $(dropdown).data(
6564
'glpi-parent-dropdown-condition'
6665
);

phpunit/functional/EntityTest.php

+131
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use CommonITILActor;
3838
use Contract;
3939
use DbTestCase;
40+
use Entity;
4041
use ITILFollowup;
4142
use ITILSolution;
4243
use NotificationTarget;
@@ -1459,4 +1460,134 @@ public function testGetEntitySelectorTree(): void
14591460
$fn_find_entities_in_selector(\Entity::getEntitySelectorTree(), $entities, null, $found);
14601461
$this->assertCount(count($entities), $found);
14611462
}
1463+
1464+
public function testGetHelpdeskSceneIdIsInheritedByDefault(): void
1465+
{
1466+
$this->login();
1467+
$root_entity = $this->getTestRootEntity();
1468+
1469+
// Act: create a child entity without values for the scene fields
1470+
$entity = $this->createItem(Entity::class, [
1471+
'name' => "Test entity",
1472+
'entities_id' => $root_entity->getID(),
1473+
]);
1474+
1475+
// Assert: scenes should be inherited
1476+
$this->assertEquals(
1477+
Entity::CONFIG_PARENT,
1478+
$entity->fields['custom_helpdesk_home_scene_left'],
1479+
);
1480+
$this->assertEquals(
1481+
Entity::CONFIG_PARENT,
1482+
$entity->fields['custom_helpdesk_home_scene_right'],
1483+
);
1484+
}
1485+
1486+
public function testGetHelpdeskSceneIdInheritedDefaultValue(): void
1487+
{
1488+
$this->login();
1489+
$root_entity = $this->getTestRootEntity();
1490+
1491+
// Arrange: create a child entity that inherit its parent values
1492+
$entity = $this->createItem(Entity::class, [
1493+
'name' => "Test entity",
1494+
'entities_id' => $root_entity->getID(),
1495+
'custom_helpdesk_home_scene_left' => Entity::CONFIG_PARENT,
1496+
'custom_helpdesk_home_scene_right' => Entity::CONFIG_PARENT,
1497+
]);
1498+
1499+
// Act: get the scenes id
1500+
$left_scene_id = $entity->getHelpdeskSceneId(
1501+
'custom_helpdesk_home_scene_left'
1502+
);
1503+
$right_scene_id = $entity->getHelpdeskSceneId(
1504+
'custom_helpdesk_home_scene_right'
1505+
);
1506+
1507+
// Assert: the default illustration must be found
1508+
$this->assertEquals($left_scene_id, Entity::DEFAULT_LEFT_SCENE);
1509+
$this->assertEquals($right_scene_id, Entity::DEFAULT_RIGHT_SCENE);
1510+
}
1511+
1512+
public function testGetHelpdeskSceneIdInheritedCustomValue(): void
1513+
{
1514+
$this->login();
1515+
$root_entity = $this->getTestRootEntity();
1516+
1517+
// Arrange: create a child entity that inherit its parent values
1518+
$entity = $this->createItem(Entity::class, [
1519+
'name' => "Test entity",
1520+
'entities_id' => $root_entity->getID(),
1521+
'custom_helpdesk_home_scene_left' => Entity::CONFIG_PARENT,
1522+
'custom_helpdesk_home_scene_right' => Entity::CONFIG_PARENT,
1523+
]);
1524+
1525+
// Act: set custom values for the parent and get the scenes ids
1526+
$this->updateItem(Entity::class, $root_entity->getID(), [
1527+
'custom_helpdesk_home_scene_left' => 'test-left.png',
1528+
'custom_helpdesk_home_scene_right' => 'test-right.png',
1529+
]);
1530+
$left_scene_id = $entity->getHelpdeskSceneId(
1531+
'custom_helpdesk_home_scene_left'
1532+
);
1533+
$right_scene_id = $entity->getHelpdeskSceneId(
1534+
'custom_helpdesk_home_scene_right'
1535+
);
1536+
1537+
// Assert: the specific file names should be found.
1538+
$this->assertEquals($left_scene_id, 'custom:test-left.png');
1539+
$this->assertEquals($right_scene_id, 'custom:test-right.png');
1540+
}
1541+
1542+
public function testGetHelpdeskSceneIdDefaultValue(): void
1543+
{
1544+
$this->login();
1545+
$root_entity = $this->getTestRootEntity();
1546+
1547+
// Arrange: create a child entity with default illustrations
1548+
$entity = $this->createItem(Entity::class, [
1549+
'name' => "Test entity",
1550+
'entities_id' => $root_entity->getID(),
1551+
'custom_helpdesk_home_scene_left' => '',
1552+
'custom_helpdesk_home_scene_right' => '',
1553+
]);
1554+
1555+
// Act: get the scenes id
1556+
$left_scene_id = $entity->getHelpdeskSceneId(
1557+
'custom_helpdesk_home_scene_left'
1558+
);
1559+
$right_scene_id = $entity->getHelpdeskSceneId(
1560+
'custom_helpdesk_home_scene_right'
1561+
);
1562+
1563+
// Assert: the default illustration must be found
1564+
$this->assertEquals($left_scene_id, Entity::DEFAULT_LEFT_SCENE);
1565+
$this->assertEquals($right_scene_id, Entity::DEFAULT_RIGHT_SCENE);
1566+
}
1567+
1568+
public function testGetHelpdeskSceneIdCustomValue(): void
1569+
{
1570+
$this->login();
1571+
$root_entity = $this->getTestRootEntity();
1572+
1573+
// Arrange: create a child entity with custom illustrations
1574+
$entity = $this->createItem(Entity::class, [
1575+
'name' => "Test entity",
1576+
'entities_id' => $root_entity->getID(),
1577+
'custom_helpdesk_home_scene_left' => 'test-left.png',
1578+
'custom_helpdesk_home_scene_right' => 'test-right.png',
1579+
]);
1580+
1581+
// Act: Get the scenes ids
1582+
$left_scene_id = $entity->getHelpdeskSceneId(
1583+
'custom_helpdesk_home_scene_left'
1584+
);
1585+
$right_scene_id = $entity->getHelpdeskSceneId(
1586+
'custom_helpdesk_home_scene_right'
1587+
);
1588+
1589+
// Assert: the specific file names should be found.
1590+
$this->assertEquals($left_scene_id, 'custom:test-left.png');
1591+
$this->assertEquals($right_scene_id, 'custom:test-right.png');
1592+
}
14621593
}

0 commit comments

Comments
 (0)