From 4d6efa605becdbfb836c8fe824780f37aa2b3a46 Mon Sep 17 00:00:00 2001 From: Curtis Conard Date: Wed, 18 Dec 2024 13:36:26 -0500 Subject: [PATCH] custom asset field editor ux redesign --- ajax/asset/assetdefinition.php | 34 ---- .../vue/CustomObject/FieldPreview/Field.vue | 56 +++--- .../FieldPreview/FieldDisplay.vue | 179 ++++++------------ .../vue/CustomObject/FieldPreview/Sidebar.vue | 60 ++++++ src/Glpi/Asset/AssetDefinition.php | 5 +- .../assetdefinition/fields_display.html.twig | 49 +---- 6 files changed, 158 insertions(+), 225 deletions(-) create mode 100644 js/src/vue/CustomObject/FieldPreview/Sidebar.vue diff --git a/ajax/asset/assetdefinition.php b/ajax/asset/assetdefinition.php index d24e59d0b49..183648b3cda 100644 --- a/ajax/asset/assetdefinition.php +++ b/ajax/asset/assetdefinition.php @@ -63,40 +63,6 @@ 'count' => count($all_fields) ], JSON_THROW_ON_ERROR); return; -} else if ($_REQUEST['action'] === 'get_field_placeholder' && isset($_POST['fields']) && is_array($_POST['fields'])) { - header("Content-Type: application/json; charset=UTF-8"); - $custom_field = new CustomFieldDefinition(); - $results = []; - foreach ($_POST['fields'] as $field) { - if ($field['customfields_id'] > 0) { - if (!$custom_field->getFromDB($field['customfields_id'])) { - throw new NotFoundHttpException(); - } - } else { - $custom_field->fields['system_name'] = ''; - $custom_field->fields['label'] = $field['label']; - $custom_field->fields['type'] = $field['type']; - $custom_field->fields['itemtype'] = 'Computer'; // Doesn't matter what it is as long as it's not empty - $custom_field->fields['default_value'] = ''; - - $asset_definition = new AssetDefinition(); - if (!$asset_definition->getFromDB($field['assetdefinitions_id'])) { - throw new NotFoundHttpException(); - } - $fields_display = $asset_definition->getDecodedFieldsField(); - foreach ($fields_display as $field_display) { - if ($field_display['key'] === $field['key']) { - $custom_field->fields['field_options'] = $field_display['field_options'] ?? []; - break; - } - } - } - $custom_field->fields['field_options'] = array_merge($custom_field->fields['field_options'] ?? [], $field['field_options'] ?? []); - $custom_field->fields['field_options']['disabled'] = true; - $results[$field['key']] = $custom_field->getFieldType()->getFormInput('', null); - } - echo json_encode($results, JSON_THROW_ON_ERROR); - return; } else if ($_REQUEST['action'] === 'get_core_field_editor') { header("Content-Type: text/html; charset=UTF-8"); $asset_definition = new AssetDefinition(); diff --git a/js/src/vue/CustomObject/FieldPreview/Field.vue b/js/src/vue/CustomObject/FieldPreview/Field.vue index 309815e1f18..218b2336fc9 100644 --- a/js/src/vue/CustomObject/FieldPreview/Field.vue +++ b/js/src/vue/CustomObject/FieldPreview/Field.vue @@ -7,38 +7,31 @@ type: Number, default: -1, }, - label_classes: { - type: String, - default: 'col-form-label cursor-grab col-xxl-5 text-xxl-end', + field_options: { + type: Object, + default: () => ({}), }, - field_classes: { - type: String, - default: 'col-xxl-7 field-container btn-group shadow-none', + is_active: { + type: Boolean, + default: true, }, - wrapper_classes: { - type: String, - default: 'form-field row flex-grow-1', - }, - }); - - const sortable_classes = computed(() => { - return props.wrapper_classes.split(' ').filter((cls) => cls.startsWith('col-')).join(' '); }); diff --git a/js/src/vue/CustomObject/FieldPreview/FieldDisplay.vue b/js/src/vue/CustomObject/FieldPreview/FieldDisplay.vue index 5061444d11d..fb5e1881137 100644 --- a/js/src/vue/CustomObject/FieldPreview/FieldDisplay.vue +++ b/js/src/vue/CustomObject/FieldPreview/FieldDisplay.vue @@ -1,6 +1,7 @@