A free open source IT asset/license management system
format the edit page
Godfrey Mb2ee1b5717fa
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.phpindex 553671fb30..fa8151b27b 100755--- a/app/Http/Controllers/LabelsController.php+++ b/app/Http/Controllers/LabelsController.php@@ -103,8 +103,15 @@ class LabelsController extends Controllerpublic function edit(CustomUserLabel $label){+ $config = $label->config_snapshot;++ $selectedType = $label->type+ ?? data_get($config, 'type')+ ?? 'sheet';+return view('settings.label-edit', [- 'config' => $label->config_snapshot,+ 'config' => $config,+ 'sections' => ($selectedType === 'tape' ? new PreviewTapeLabel() : new PreviewSheetLabel())->applyEditorConfig($config)->getEditorSections(),'selectedLabel' => $label->base_label,'importedConfig' => null,'customLabel' => $label,@@ -322,96 +329,32 @@ class LabelsController extends Controller$validated = $request->validate(['type' => ['required', 'in:sheet,tape'],- 'page_size' => ['required_if:type,sheet', 'nullable',- Rule::in(array_keys(RectangleSheet::supportedPageSizes())),- ],+ 'page_size' => ['required_if:type,sheet', 'nullable', Rule::in(array_keys(RectangleSheet::supportedPageSizes())),],'rows' => ['required', 'numeric', 'min:1'],'columns' => ['required', 'numeric', 'min:1'],'label_width' => ['required', 'numeric', 'gt:0'],'label_height' => ['required', 'numeric', 'gt:0'],]);-+ //A new label will seed the DefaultLabel valuesif ($validated['type'] === 'sheet') {$page = RectangleSheet::supportedPageSize($validated['page_size']);+ $label = (new PreviewSheetLabel())->seedFromTemplate(new DefaultLabel());+ $config = $label->toEditorConfig();- if ($page === null) {- throw ValidationException::withMessages([- 'page_size' => trans('validation.in', [- 'attribute' => 'page size',- ]),- ]);- }+ $config['page']['width'] = $page['width'];+ $config['page']['height'] = $page['height'];+ $config['label']['width'] = (float)$validated['label_width'];+ $config['label']['height'] = (float)$validated['label_height'];+ $config['grid']['rows'] = (int)$validated['rows'];+ $config['grid']['columns'] = (int)$validated['columns'];- $label = new PreviewSheetLabel(- pageWidth: $page['width'],- pageHeight: $page['height'],- labelWidth: (float)$validated['label_width'],- labelHeight: (float)$validated['label_height'],- rows: $validated['rows'],- columns: $validated['columns'],- );+ $label->applyEditorConfig($config);} else {$label = new PreviewTapeLabel(width: (float)$validated['label_width'],height: (float)$validated['label_height'],);}-// $customLabelId = $request->get('custom_label_id');-//-// if ($customLabelId) {-// // creating a custom label from another custom label-// $customLabel = CustomUserLabel::findOrFail($customLabelId);-//-// $config = $customLabel->config_snapshot;-// $config['name'] = 'Copy of ' . $customLabel->name;-//-// return view('settings.label-edit', [-// 'config' => $config,-// 'selectedLabel' => $customLabel->base_label,-// 'selectedType' => $customLabel->type,-// 'importedConfig' => null,-// 'customLabel' => null,-// 'formMethod' => 'POST',-// 'formAction' => route('settings.labels.store'),-// ]);-// }-// $selectedLabel = $request->get('label');-//-// if ($selectedLabel) {-// $selectedLabel = str_replace('/', '\\', $selectedLabel);-// }-// $importedConfig = session('imported_label_config');-//-// if ($importedConfig) {-// $selectedLabel = data_get($importedConfig, 'template', $selectedLabel);-// }-// try {-// $template = $selectedLabel-// ? Label::find(str_replace('/', '\\', $selectedLabel))-// : new DefaultLabel;-// } catch (\Throwable $e) {-// $template = new DefaultLabel;-// $selectedLabel = 'DefaultLabel';-// }-//-// $label = $this->previewLabelForTemplate($template);-// $config = $importedConfig ?: $label->toEditorConfig();-// $type = data_get($importedConfig, 'type');-//-// if ($type === null) {-// $type = str_starts_with($selectedLabel ?? '', 'Tapes\\')-// ? 'tape'-// : 'sheet';-// }-// $page = RectangleSheet::supportedPageSize($validated['page_size']);-//-// if ($page === null) {-// throw ValidationException::withMessages([-// 'page_size' => trans('validation.in', [-// 'attribute' => 'page size',-// ]),-// ]);-// }return view('settings.label-edit', ['config' => $label->toEditorConfig(),diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.phpindex 2d12e6e795..67424771a3 100644--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php@@ -17,10 +17,10 @@ trait HasCustomLabelEditorSections'column_span' => 2,'display' => 'inline','fields' => [+ 'fields' => ['type' => 'number'],'asset_tag' => ['type' => 'checkbox'],'barcode_1d' => ['type' => 'checkbox'],'barcode_2d' => ['type' => 'checkbox'],- 'fields' => ['type' => 'number'],'logo' => ['type' => 'checkbox'],'title' => ['type' => 'checkbox'],],@@ -138,38 +138,47 @@ trait HasCustomLabelEditorSections],],],- 'page' => [- 'label' => 'admin/labels/general.sections.page',- 'fields' => [- 'width' => ['type' => 'number'],- 'height' => ['type' => 'number'],- 'margin_top' => ['type' => 'number'],- 'margin_right' => ['type' => 'number'],- 'margin_bottom' => ['type' => 'number'],- 'margin_left' => ['type' => 'number'],- ],- ],+ 'layout' => [+ 'label' => 'admin/labels/general.sections.layout',+ 'column_span' => 2,+ 'groups' => [+ 'page' => [+ 'label' => 'admin/labels/general.sections.page',+ 'section_key' => 'page',+ 'fields' => [+ 'width' => ['type' => 'number'],+ 'height' => ['type' => 'number'],+ 'margin_top' => ['type' => 'number'],+ 'margin_right' => ['type' => 'number'],+ 'margin_bottom' => ['type' => 'number'],+ 'margin_left' => ['type' => 'number'],+ ],+ ],- 'grid' => [- 'label' => 'admin/labels/general.sections.grid',- 'fields' => [- 'columns' => ['type' => 'number'],- 'rows' => ['type' => 'number'],- 'column_spacing' => ['type' => 'number'],- 'row_spacing' => ['type' => 'number'],- ],- ],+ 'grid' => [+ 'label' => 'admin/labels/general.sections.grid',+ 'section_key' => 'grid',+ 'fields' => [+ 'columns' => ['type' => 'number'],+ 'rows' => ['type' => 'number'],+ 'column_spacing' => ['type' => 'number'],+ 'row_spacing' => ['type' => 'number'],+ ],+ ],- 'label' => [- 'label' => 'admin/labels/general.sections.label',- 'fields' => [- 'width' => ['type' => 'number'],- 'height' => ['type' => 'number'],- 'border' => ['type' => 'number'],- 'padding_top' => ['type' => 'number'],- 'padding_right' => ['type' => 'number'],- 'padding_bottom' => ['type' => 'number'],- 'padding_left' => ['type' => 'number'],+ 'label' => [+ 'label' => 'admin/labels/general.sections.label',+ 'section_key' => 'label',+ 'fields' => [+ 'width' => ['type' => 'number'],+ 'height' => ['type' => 'number'],+ 'border' => ['type' => 'number'],+ 'padding_top' => ['type' => 'number'],+ 'padding_right' => ['type' => 'number'],+ 'padding_bottom' => ['type' => 'number'],+ 'padding_left' => ['type' => 'number'],+ ],+ ],],],];diff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.phpindex 6793474f04..ac786d5a03 100644--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php@@ -68,36 +68,7 @@ abstract class CustomSheetLabel extends RectangleSheet*/protected string $tagHAlign = 'R';protected string $tagVAlign = 'B';-- public function getSupportAssetTag(): bool- {- return true;- }-- public function getSupport1DBarcode(): bool- {- return true;- }-- public function getSupport2DBarcode(): bool- {- return true;- }-- public function getSupportLogo(): bool- {- return true;- }-- public function getSupportTitle(): bool- {- return true;- }-- public function getSupportFields(): int- {- return 5;- }+public function getUnit(){return $this->unit;diff --git a/app/Models/Labels/CustomLabels/PreviewSheetLabel.php b/app/Models/Labels/CustomLabels/PreviewSheetLabel.phpindex aaea5d9275..586675ff72 100644--- a/app/Models/Labels/CustomLabels/PreviewSheetLabel.php+++ b/app/Models/Labels/CustomLabels/PreviewSheetLabel.php@@ -4,21 +4,25 @@ namespace App\Models\Labels\CustomLabels;class PreviewSheetLabel extends CustomSheetLabel{+ protected bool $supportAssetTag = true;+ protected bool $support1DBarcode = true;+ protected bool $support2DBarcode = true;+ protected int $supportFields = 5;+ protected bool $supportLogo = true;+ protected bool $supportTitle = true;public function __construct(float $pageWidth = 210.0,float $pageHeight = 297.0,float $labelWidth = 50.0,float $labelHeight = 25.0,- int $rows = 9,- int $columns = 3,+ int $rows = 9,+ int $columns = 3,){$this->pageWidth = $pageWidth;$this->pageHeight = $pageHeight;-$this->labelWidth = $labelWidth;$this->labelHeight = $labelHeight;-$this->rows = $rows;$this->columns = $columns;}diff --git a/resources/lang/en-US/admin/labels/general.php b/resources/lang/en-US/admin/labels/general.phpindex 122f069e8e..543c9df698 100644--- a/resources/lang/en-US/admin/labels/general.php+++ b/resources/lang/en-US/admin/labels/general.php@@ -7,6 +7,7 @@ return ['label' => 'Label','content' => 'Content','supports' => 'Supports',+ 'layout' => 'Layout',],'groups' => [diff --git a/resources/views/partials/label-editor-field.blade.php b/resources/views/partials/label-editor-field.blade.phpnew file mode 100644index 0000000000..2162790403--- /dev/null+++ b/resources/views/partials/label-editor-field.blade.php@@ -0,0 +1,41 @@+@php+ $name = "{$sectionKey}[{$fieldKey}]";+ $value = data_get($config, "{$sectionKey}.{$fieldKey}");+@endphp++<div class="form-group">+ <label class="col-md-4 control-label">+ {{ trans("admin/labels/general.fields.{$fieldKey}") }}+ </label>++ <div class="col-md-4">+ @if ($field['type'] === 'checkbox')+ <input type="hidden" name="{{ $name }}" value="0">++ <input+ type="checkbox"+ name="{{ $name }}"+ value="1"+ @checked((bool) $value)+ >+ @elseif ($field['type'] === 'select')+ <select name="{{ $name }}" class="form-control">+ @foreach ($field['options'] as $optionValue => $optionLabel)+ <option+ value="{{ $optionValue }}"+ @selected($value == $optionValue)+ >+ {{ trans($optionLabel) }}+ </option>+ @endforeach+ </select>+ @else+ <input+ type="{{ $field['type'] }}"+ name="{{ $name }}"+ value="{{ $value }}"+ class="form-control"+ >+ @endif+ </div>+</div>\ No newline at end of filediff --git a/resources/views/partials/label-editor-section.blade.php b/resources/views/partials/label-editor-section.blade.phpnew file mode 100644index 0000000000..37bd704eba--- /dev/null+++ b/resources/views/partials/label-editor-section.blade.php@@ -0,0 +1,95 @@+<div class="box box-default label-config-panel">+ <div class="box-header with-border">+ <x-form.legend>+ {{ trans($section['label']) }}+ </x-form.legend>+ </div>++ <div class="box-body">+ @if ($inlineFields)+ <div class="row">+ @foreach ($section['fields'] as $fieldKey => $field)+ @php+ $name = "{$sectionKey}[{$fieldKey}]";+ $value = data_get($config, "{$sectionKey}.{$fieldKey}");+ @endphp++ <div class="col-md-2">+ <label>+ @if ($field['type'] === 'checkbox')+ <input type="hidden" name="{{ $name }}" value="0">++ <input+ type="checkbox"+ name="{{ $name }}"+ value="1"+ @checked((bool) $value)+ >++ {{ trans("admin/labels/general.fields.{$fieldKey}") }}++ @elseif ($field['type'] === 'number')++ <div class="supports-number-field">+ <input+ id="{{ $name }}"+ type="number"+ name="{{ $name }}"+ value="{{ $value }}"+ class="form-control"+ >++ <label for="{{ $name }}">+ {{ trans("admin/labels/general.fields.{$fieldKey}") }}+ </label>+ </div>++ @else++ {{ trans("admin/labels/general.fields.{$fieldKey}") }}++ <input+ type="{{ $field['type'] }}"+ name="{{ $name }}"+ value="{{ $value }}"+ class="form-control"+ >++ @endif+ </label>+ </div>+ @endforeach+ </div>+ @elseif (isset($section['groups']))+ <div class="label-content-groups">+ @foreach ($section['groups'] as $groupKey => $group)+ <div class="panel panel-default">+ <div class="panel-heading">+ <strong>{{ trans($group['label']) }}</strong>+ </div>++ <div class="panel-body">+ @foreach ($group['fields'] as $fieldKey => $field)+ @include('partials.label-editor-field', [+ 'sectionKey' => $group['section_key'] ?? $groupKey,+ 'fieldKey' => $fieldKey,+ 'field' => $field,+ 'config' => $config,+ ])+ @endforeach+ </div>+ </div>+ @endforeach+ </div>+ @else+ @foreach ($section['fields'] as $fieldKey => $field)+ @include('partials.label-editor-field', [+ 'sectionKey' => $sectionKey,+ 'fieldKey' => $fieldKey,+ 'field' => $field,+ 'config' => $config,+ ])+ @endforeach+ @endif+ </div>+</div>\ No newline at end of filediff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.phpindex 836bfb4b43..15506bea3e 100644--- a/resources/views/settings/label-edit.blade.php+++ b/resources/views/settings/label-edit.blade.php@@ -45,38 +45,64 @@}.label-config-grid {+ display: block;+ }++ .label-form-header,+ .label-supports-row,+ .label-content-row,+ .label-dimensions-row {+ max-width: 100%;+ margin-bottom: 16px;+ }++ .label-content-row {+ width: 100%;+ margin-bottom: 16px;+ }++ .label-content-groups {display: grid;- grid-template-columns: repeat(1, minmax(320px, 1fr));+ grid-template-columns: repeat(3, minmax(260px, 1fr));gap: 16px;align-items: start;}- @media (min-width: 992px) {- .label-config-grid {- grid-template-columns: repeat(2, minmax(320px, 1fr));- }+ .label-dimensions-row {+ display: grid;+ grid-template-columns: repeat(3, minmax(260px, 1fr));+ gap: 16px;+ }++ .label-layout-row {+ width: 100%;+ margin-bottom: 16px;}.label-config-panel {margin-bottom: 0;+ box-shadow: none;}- .label-config-panel .box-body {- padding-right: 15px;+ .label-config-panel .form-control {+ width: 160px;+ max-width: 160px;}- .label-config-panel .form-group:last-child {- margin-bottom: 0;+ .label-supports-row .col-md-2 {+ text-align: center;}- .label-config-panel .form-control {- width: 120px;- max-width: 120px;+ .label-supports-row .number-field label {+ flex-direction: row;+ gap: 8px;}- .label-form-header,- .label-form-footer {- grid-column: 1 / -1;+ .label-supports-row .col-md-2 label {+ display: inline-flex;+ flex-direction: column;+ align-items: center;+ margin-bottom: 0;}</style>@@ -130,177 +156,46 @@style="max-width: 320px;"></div>+<p class="text-muted">Unit: {{ $config['unit'] }} (applies to all dimensions)</p></div>- <div class="row">- @foreach ($sections as $sectionKey => $section)- @continue(empty($section))- @php- $isFullWidth = ($section['column_span'] ?? 1) === 2;-- $sectionClass = ($section['column_span'] ?? 1) === 2- ? 'col-md-12'- : 'col-md-6';-- $inlineFields = ($section['display'] ?? null) === 'inline';- @endphp- @if ($isFullWidth)- </div>- <div class="row">- @endif-- <div class="{{ $sectionClass }}">- <div class="box box-default">- <div class="box-header with-border">- <h3 class="box-title">{{ trans($section['label']) }}</h3>- </div>-- <div class="box-body">- @if ($inlineFields)- <div class="row">- @foreach ($section['fields'] as $fieldKey => $field)- @php- $name = "{$sectionKey}[{$fieldKey}]";- $value = data_get($config, "{$sectionKey}.{$fieldKey}");- @endphp-- <div class="col-md-2">- @if ($field['type'] === 'checkbox')- <input type="hidden" name="{{ $name }}" value="0">-- <label>- <input- type="checkbox"- name="{{ $name }}"- value="1"- @checked((bool) $value)- >- {{ trans("admin/labels/general.fields.{$fieldKey}") }}- </label>- @else- <label>- {{ trans("admin/labels/general.fields.{$fieldKey}") }}- </label>-- <input- type="{{ $field['type'] }}"- name="{{ $name }}"- value="{{ $value }}"- class="form-control"- >- @endif- </div>- @endforeach- </div>- @elseif (isset($section['groups']))- @foreach ($section['groups'] as $groupKey => $group)- <div class="panel panel-default">- <div class="panel-heading">- <strong>{{ trans($group['label']) }}</strong>- </div>-- <div class="panel-body">- @foreach ($group['fields'] as $fieldKey => $field)- @php- $name = "{$sectionKey}[{$fieldKey}]";- $value = data_get($config, "{$sectionKey}.{$fieldKey}");- @endphp-- <div class="form-group">- <label class="col-md-4 control-label">- {{ trans("admin/labels/general.fields.{$fieldKey}") }}- </label>-- <div class="col-md-4">- @if ($field['type'] === 'checkbox')- <input type="hidden" name="{{ $name }}"- value="0">-- <input- type="checkbox"- name="{{ $name }}"- value="1"- @checked((bool) $value)- >- @elseif ($field['type'] === 'select')- <select name="{{ $name }}"- class="form-control">- @foreach ($field['options'] as $optionValue => $optionLabel)- <option- value="{{ $optionValue }}"- @selected($value == $optionValue)- >- {{ trans($optionLabel) }}- </option>- @endforeach- </select>- @else- <input- type="{{ $field['type'] }}"- name="{{ $name }}"- value="{{ $value }}"- class="form-control"- >- @endif- </div>- </div>- @endforeach- </div>- </div>- @endforeach- @else- @foreach ($section['fields'] as $fieldKey => $field)- @php- $name = "{$sectionKey}[{$fieldKey}]";- $value = data_get($config, "{$sectionKey}.{$fieldKey}");- @endphp-- <div class="form-group">- <label class="col-md-4 control-label">- {{ trans("admin/labels/general.fields.{$fieldKey}") }}- </label>-- <div class="col-md-4">- @if ($field['type'] === 'checkbox')- <input type="hidden" name="{{ $name }}" value="0">-- <input- type="checkbox"- name="{{ $name }}"- value="1"- @checked((bool) $value)- >- @elseif ($field['type'] === 'select')- <select name="{{ $name }}" class="form-control">- @foreach ($field['options'] as $optionValue => $optionLabel)- <option- value="{{ $optionValue }}"- @selected($value == $optionValue)- >- {{ trans($optionLabel) }}- </option>- @endforeach- </select>- @else- <input- type="{{ $field['type'] }}"- name="{{ $name }}"- value="{{ $value }}"- class="form-control"- >- @endif- </div>- </div>- @endforeach- @endif- </div>- </div>+ @if(isset($sections['supports']))+ <div class="label-supports-row">+ @include('partials.label-editor-section', [+ 'sectionKey' => 'supports',+ 'section' => $sections['supports'],+ 'config' => $config,+ 'inlineFields' => true,+ 'showLegend' => true,+ ])</div>- @endforeach- </div>+ @endif++ @if(isset($sections['content']))+ <div class="label-content-row">+ @include('partials.label-editor-section', [+ 'sectionKey' => 'content',+ 'section' => $sections['content'],+ 'config' => $config,+ 'inlineFields' => false,+ 'showLegend' => true,+ ])+ </div>+ @endif++ @if(isset($sections['layout']))+ <div class="label-layout-row">+ @include('partials.label-editor-section', [+ 'sectionKey' => 'layout',+ 'section' => $sections['layout'],+ 'config' => $config,+ 'inlineFields' => false,+ ])+ </div>+ @endif</div></form>