Skip to content
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

Custom asset field editor ux redesign #18577

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions ajax/asset/assetdefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
62 changes: 34 additions & 28 deletions js/src/vue/CustomObject/FieldPreview/Field.vue
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
<script setup>
import {computed} from 'vue';

const props = defineProps({
field_key: String,
customfields_id: {
type: Number,
default: -1,
},
label_classes: {
type: String,
default: 'col-form-label cursor-grab col-xxl-5 text-xxl-end',
},
field_classes: {
type: String,
default: 'col-xxl-7 field-container btn-group shadow-none',
field_options: {
type: Object,
default: () => ({}),
},
wrapper_classes: {
type: String,
default: 'form-field row flex-grow-1',
is_active: {
type: Boolean,
default: true,
},
});

const sortable_classes = computed(() => {
return props.wrapper_classes.split(' ').filter((cls) => cls.startsWith('col-')).join(' ');
});
</script>

<template>
<div :class="`sortable-field align-items-center p-1 ${(!!$slots.field_preview) ? sortable_classes : 'col-12 col-sm-6'}`"
:data-key="field_key" :data-customfield-id="customfields_id" :style="`display: ${(!!$slots.field_preview) ? 'flex' : 'none'};`">
<input type="hidden" name="fields_display[]" :value="field_key" />
<div :class="`sortable-field align-items-center ${parseInt(field_options.full_width ?? 0) === 1 ? 'col-12' : 'col-12 col-sm-6'} cursor-grab`"
:data-key="field_key" :data-customfield-id="customfields_id">
<input type="hidden" name="fields_display[]" :value="field_key" :disabled="!is_active" />
<slot name="field_options"></slot>
<div :class="wrapper_classes">
<label :class="label_classes">
<div :class="`form-field row flex-grow-1 m-1`">
<div class="col py-2">
<slot name="field_label"></slot>
<slot name="field_markers"></slot>
<i class="ti ti-grip-vertical sort-handle align-middle"></i>
</label>
<div :class="field_classes">
<slot name="field_preview"></slot>
</div>
<div v-if="is_active" class="col-auto btn-group shadow-none field-actions">
<button type="button" class="btn btn-ghost-secondary btn-sm edit-field" :title="__('Edit')">
<i class="ti ti-pencil"></i>
</button>
Expand All @@ -51,8 +39,26 @@
</template>

<style scoped>
.sortable-field .btn-group .select2-container {
flex-basis: auto;
width: 100% !important;
[data-glpi-theme-dark="1"] .form-field {
border: var(--tblr-border-width) solid var(--tblr-border-color);
}
.form-field {
border-radius: var(--tblr-border-radius);
border: var(--tblr-border-width) solid transparent;
background-color: var(--tblr-gray-200);

& > .col {
border-left: 1px solid var(--tblr-border-color);
}

@media (pointer: fine) {
& > .field-actions {
visibility: hidden;
}

&:hover > .field-actions {
visibility: visible;
}
}
}
</style>
Loading
Loading