-
Notifications
You must be signed in to change notification settings - Fork 3
Change config UI #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
bdcf523
cd2851c
717346c
7b7c868
1fc84cf
b64c765
f652e8f
7f59755
6e761b9
a14bb8a
09f4322
3ab0e34
fca8018
02af14b
4a9dd6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| { | ||
| public $dohistory = true; | ||
| public static $rightname = 'config'; | ||
| public const CONFIG_PARENT = \Entity::CONFIG_PARENT; | ||
| public static function getMenuName(): string | ||
| { | ||
| return __('More options', 'moreoptions'); | ||
|
|
@@ -105,10 +106,8 @@ | |
| } | ||
|
|
||
| foreach (self::getItilConfigFields() as $field) { | ||
| if (!isset($item->input[$field])) { | ||
| $item->input[$field] = 0; | ||
| } elseif ($item->input[$field] == 'on') { | ||
| $item->input[$field] = 1; | ||
| if (isset($item->input[$field])) { | ||
| $item->input[$field] = (int) $item->input[$field]; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -121,7 +120,6 @@ | |
| public static function getItilConfigFields(): array | ||
| { | ||
| return [ | ||
| 'use_parent_entity', | ||
| 'take_item_group_ticket', | ||
| 'take_item_group_change', | ||
| 'take_item_group_problem', | ||
|
|
@@ -156,6 +154,21 @@ | |
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string> | ||
| */ | ||
| private static function getActorGroupConfigFields(): array | ||
| { | ||
| return [ | ||
| 'take_requester_group_ticket', | ||
| 'take_requester_group_change', | ||
| 'take_requester_group_problem', | ||
| 'take_technician_group_ticket', | ||
| 'take_technician_group_change', | ||
| 'take_technician_group_problem', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<int, string> | ||
| */ | ||
|
|
@@ -175,24 +188,31 @@ | |
| 'entities_id' => $item->getID(), | ||
| ]); | ||
|
|
||
| // Get effective configuration to show which entity's config is actually used | ||
| $effectiveConfig = self::getConfig($item->getID(), true); | ||
| $parentEntityInfo = null; | ||
|
|
||
| if (($moconfig->fields['use_parent_entity'] ?? false) && ($effectiveConfig->fields['entities_id'] != $item->getID())) { | ||
| $parentEntity = new Entity(); | ||
| if ($parentEntity->getFromDB($effectiveConfig->fields['entities_id'])) { | ||
| $parentEntityInfo = $parentEntity->getName(); | ||
| $inheritance_labels = []; | ||
| if ($item->getID() > 0) { | ||
| $parentConfig = self::getConfig($item->fields['entities_id'], true); | ||
| foreach (self::getItilConfigFields() as $field) { | ||
| $inheritance_labels[$field] = self::getInheritedValueBadge($parentConfig->fields[$field] ?? 0); | ||
| } | ||
| foreach ([ | ||
| 'take_requester_group_ticket', | ||
| 'take_requester_group_change', | ||
| 'take_requester_group_problem', | ||
| 'take_technician_group_ticket', | ||
| 'take_technician_group_change', | ||
| 'take_technician_group_problem', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be replaced by getActorGroupConfigFields There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. up
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not done |
||
| ] as $field) { | ||
| $inheritance_labels[$field] = self::getInheritedValueBadgeForActorGroup($parentConfig->fields[$field] ?? 0); | ||
|
Lainow marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| TemplateRenderer::getInstance()->display( | ||
| '@moreoptions/config.html.twig', | ||
| [ | ||
| 'item' => $moconfig, | ||
| 'dropdown_options' => self::getSelectableActorGroup(), | ||
| 'parent_entity_info' => $parentEntityInfo, | ||
| 'params' => [ | ||
| 'item' => $moconfig, | ||
| 'dropdown_options' => self::getSelectableActorGroup(), | ||
| 'inheritance_labels' => $inheritance_labels, | ||
| 'params' => [ | ||
| 'canedit' => true, | ||
| ], | ||
| ], | ||
|
|
@@ -204,13 +224,33 @@ | |
| return "ti ti-send"; | ||
| } | ||
|
|
||
| private static function getInheritedValueBadge(mixed $value): string | ||
| { | ||
| $text = match ((int) $value) { | ||
| 1 => __('Yes'), | ||
| default => __('No'), | ||
| }; | ||
| return Entity::inheritedValue(htmlescape($text), false, false); | ||
| } | ||
|
|
||
| private static function getInheritedValueBadgeForActorGroup(mixed $value): string | ||
| { | ||
| $options = self::getSelectableActorGroup(); | ||
| $text = $options[(int) $value] ?? __('No'); | ||
| return Entity::inheritedValue(htmlescape($text), false, false); | ||
| } | ||
|
|
||
| public static function addConfig(CommonDBTM $item): void | ||
| { | ||
| $moconfig = new self(); | ||
| $moconfig->add([ | ||
| 'is_active' => 0, | ||
| 'entities_id' => $item->getID(), | ||
| ]); | ||
| $entity_id = $item->getID(); | ||
| $data = ['entities_id' => $entity_id]; | ||
| if ($entity_id > 0) { | ||
| foreach (array_merge(self::getItilConfigFields(), self::getActorGroupConfigFields()) as $field) { | ||
| $data[$field] = self::CONFIG_PARENT; | ||
| } | ||
| } | ||
| $moconfig->add($data); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -222,7 +262,6 @@ | |
| */ | ||
| public static function getConfig(?int $entityId = null, bool $useInheritance = true): self | ||
| { | ||
| // Use current entity if not specified | ||
| if ($entityId === null) { | ||
| $entityId = Session::getActiveEntity(); | ||
| } | ||
|
|
@@ -232,12 +271,19 @@ | |
| 'entities_id' => $entityId, | ||
| ]); | ||
|
|
||
| // If inheritance is enabled, use_parent_entity is set, and we're not at root entity | ||
| if ($useInheritance && ($moconfig->fields['use_parent_entity'] ?? false) && $entityId > 0) { | ||
| if ($useInheritance && $entityId > 0) { | ||
| $entity = new Entity(); | ||
| if ($entity->getFromDB($entityId)) { | ||
| $parentId = $entity->fields['entities_id']; | ||
| return self::getConfig($parentId, true); | ||
| $parentConfig = self::getConfig((int) $entity->fields['entities_id'], true); | ||
| $allFields = array_merge( | ||
| self::getItilConfigFields(), | ||
|
Lainow marked this conversation as resolved.
Outdated
|
||
| self::getActorGroupConfigFields(), | ||
| ); | ||
| foreach ($allFields as $field) { | ||
| if (($moconfig->fields[$field] ?? 0) == self::CONFIG_PARENT) { | ||
| $moconfig->fields[$field] = $parentConfig->fields[$field] ?? 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -253,18 +299,16 @@ | |
| $migration->displayMessage("Installing $table"); | ||
| $query = "CREATE TABLE IF NOT EXISTS `$table` ( | ||
| `id` int unsigned NOT NULL AUTO_INCREMENT, | ||
| `is_active` tinyint NOT NULL DEFAULT '1', | ||
|
Rom1-B marked this conversation as resolved.
|
||
| `entities_id` int unsigned NOT NULL DEFAULT '0', | ||
| `use_parent_entity` tinyint NOT NULL DEFAULT '0', | ||
| `take_item_group_ticket` tinyint NOT NULL DEFAULT '-2', | ||
| `take_item_group_ticket` tinyint NOT NULL DEFAULT '0', | ||
| `take_item_group_change` tinyint NOT NULL DEFAULT '0', | ||
| `take_item_group_problem` tinyint NOT NULL DEFAULT '0', | ||
| `take_requester_group_ticket` int unsigned NOT NULL DEFAULT '0', | ||
| `take_requester_group_change` int unsigned NOT NULL DEFAULT '0', | ||
| `take_requester_group_problem` int unsigned NOT NULL DEFAULT '0', | ||
| `take_technician_group_ticket` int unsigned NOT NULL DEFAULT '0', | ||
| `take_technician_group_change` int unsigned NOT NULL DEFAULT '0', | ||
| `take_technician_group_problem` int unsigned NOT NULL DEFAULT '0', | ||
| `take_requester_group_ticket` tinyint NOT NULL DEFAULT '0', | ||
| `take_requester_group_change` tinyint NOT NULL DEFAULT '0', | ||
| `take_requester_group_problem` tinyint NOT NULL DEFAULT '0', | ||
| `take_technician_group_ticket` tinyint NOT NULL DEFAULT '0', | ||
| `take_technician_group_change` tinyint NOT NULL DEFAULT '0', | ||
| `take_technician_group_problem` tinyint NOT NULL DEFAULT '0', | ||
| `prevent_closure_ticket` tinyint NOT NULL DEFAULT '0', | ||
| `prevent_closure_change` tinyint NOT NULL DEFAULT '0', | ||
| `prevent_closure_problem` tinyint NOT NULL DEFAULT '0', | ||
|
|
@@ -294,29 +338,35 @@ | |
| `mandatory_task_user` tinyint NOT NULL DEFAULT '0', | ||
| `mandatory_task_group` tinyint NOT NULL DEFAULT '0', | ||
| PRIMARY KEY (`id`), | ||
| KEY `entities_id` (`entities_id`), | ||
| KEY `is_active` (`is_active`) | ||
|
Rom1-B marked this conversation as resolved.
|
||
| KEY `entities_id` (`entities_id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; | ||
| "; | ||
| $DB->doQuery($query); | ||
| } | ||
|
|
||
| // Migration: Add use_parent_entity column if it doesn't exist | ||
| if (!$DB->fieldExists($table, 'use_parent_entity')) { | ||
| $migration->displayMessage("Adding use_parent_entity field to $table"); | ||
| $migration->addField($table, 'use_parent_entity', 'tinyint', [ | ||
| 'after' => 'entities_id', | ||
| 'value' => 0, | ||
| 'nodefault' => false, | ||
| ]); | ||
| foreach ([ | ||
| self::getActorGroupConfigFields() | ||
| ] as $field) { | ||
| if ($DB->fieldExists($table, $field)) { | ||
|
Check failure on line 350 in src/Config.php
|
||
| $migration->changeField($table, $field, $field, 'bool', ['value' => '0']); | ||
|
Check failure on line 351 in src/Config.php
|
||
| } | ||
| } | ||
|
|
||
| $migration->executeMigration(); | ||
|
|
||
| $entities = new Entity(); | ||
| foreach ($entities->find() as $entity) { | ||
| if (is_array($entity) && isset($entity['id'])) { | ||
| $data = [ | ||
| 'entities_id' => $entity['id'], | ||
| ]; | ||
| $entity_id = (int) $entity['id']; | ||
| if (countElementsInTable(self::getTable(), ['entities_id' => $entity_id]) > 0) { | ||
| continue; | ||
| } | ||
| $data = ['entities_id' => $entity_id]; | ||
| if ($entity_id > 0) { | ||
| foreach (array_merge(self::getItilConfigFields(), self::getActorGroupConfigFields()) as $field) { | ||
| $data[$field] = self::CONFIG_PARENT; | ||
| } | ||
| } | ||
| $DB->insert( | ||
| self::getTable(), | ||
| $data, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.