A free open source IT asset/license management system
add label actions, remove preview label from list, add destroy method and route, reconfigure seedTemplate"
Godfrey M36b91398e334
diff --git a/app/Http/Controllers/Api/LabelsController.php b/app/Http/Controllers/Api/LabelsController.phpindex 360df040dc..eb45ecee5a 100644--- a/app/Http/Controllers/Api/LabelsController.php+++ b/app/Http/Controllers/Api/LabelsController.php@@ -10,6 +10,7 @@ use App\Models\Labels\Label;use Illuminate\Http\JsonResponse;use Illuminate\Http\Request;use Illuminate\Support\ItemNotFoundException;+use App\Models\Labels\CustomLabels\PreviewLabel;class LabelsController extends Controller{@@ -23,6 +24,7 @@ class LabelsController extends Controller$this->authorize('view', Label::class);$baseLabels = Label::find()+ ->reject(fn(Label $label) => $label instanceof PreviewLabel)->map(function (Label $label) {return ['source' => 'base',@@ -38,7 +40,7 @@ class LabelsController extends Controller'label' => $label,];});-+$labels = $baseLabels->merge($customLabels);if ($request->filled('search')) {diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.phpindex c7cebc3c23..97c7286063 100755--- a/app/Http/Controllers/LabelsController.php+++ b/app/Http/Controllers/LabelsController.php@@ -216,6 +216,23 @@ class LabelsController extends Controller]);}+ public function destroy(CustomUserLabel $label)+ {+ $labelName = $label->name;+ if ($label->is_default) {+ return response()->json([+ 'status' => 'error',+ 'message' => trans('admin/labels/labels.default_label_cannot_be_deleted'),+ ], 403);+ }++ $label->delete();++ return redirect()+ ->route('settings.labels.index')+ ->with('success', $labelName . ' ' . trans('admin/labels/labels.label_deleted_successfully'));+ }+public function customLabelPreview(Request $request, string $labelName){$labelName = str_replace('/', '\\', $labelName);diff --git a/app/Http/Transformers/LabelsTransformer.php b/app/Http/Transformers/LabelsTransformer.phpindex f4ee49aae6..df939d70db 100644--- a/app/Http/Transformers/LabelsTransformer.php+++ b/app/Http/Transformers/LabelsTransformer.php@@ -82,11 +82,13 @@ class LabelsTransformer$snapshot = $label->config_snapshot ?? [];return [+ 'custom_label_id' => $label->id,'name' => $label->name,'source' => 'custom','source_label' => 'Custom','base_label' => $label->base_label,'type' => $label->type,+ 'config_snapshot' => $label->config_snapshot,'is_default' => $label->is_default,'unit' => 'mm',diff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.phpindex a0e2e3b6cb..89bc5e15f8 100644--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php@@ -17,8 +17,8 @@ abstract class CustomSheetLabel extends CustomLabelprotected ?float $pageMarginBottom = 0.0;protected ?float $pageMarginLeft = 0.0;- protected int $rows = 1;- protected int $columns = 1;+ protected int $rows = 9;+ protected int $columns = 3;protected ?float $labelWidth = 50.0;protected ?float $labelHeight = 25.0;@@ -40,7 +40,7 @@ abstract class CustomSheetLabel extends CustomLabelprotected float $barcodeSize = 3;protected float $barcode2DSize = 20;- protected float $barcodeMargin = 2.0;+ protected float $barcodeMargin = .025;protected float $barcode2Margin = 0.075;protected float $logoMaxWidth = 12.0;protected float $logoMargin = 2.0;@@ -53,6 +53,7 @@ abstract class CustomSheetLabel extends CustomLabelprotected float $titleMargin = 2.0;+ protected float $titleOffsetX = 0.0;protected float $labelMargin = 1.5;protected float $fieldMargin = 2.0;@@ -241,6 +242,11 @@ abstract class CustomSheetLabel extends CustomLabelreturn $this->titleSize;}+ public function getTitleOffsetX(): float+ {+ return $this->titleOffsetX;+ }+public function getLabelSize(): float{return $this->labelSize;@@ -329,6 +335,7 @@ abstract class CustomSheetLabel extends CustomLabel'tag_offset_y' => $this->getTagOffsetY(),'title_font_size' => $this->getTitleSize(),'title_margin' => $this->getTitleMargin(),+ 'title_offset_x' => $this->getTitleOffsetX(),'field_label_font_size' => $this->getLabelSize(),'field_label_margin' => $this->getLabelMargin(),'field_value_font_size' => $this->getFieldSize(),@@ -343,111 +350,203 @@ abstract class CustomSheetLabel extends CustomLabel$sourceUnit = $template->getUnit();$convert = function ($value) use ($sourceUnit) {- if ($value === null) {- return null;+ if ($value === null || $value === '') {+ return $value;}- return $sourceUnit === 'in' ? $value * 25.4 : $value;+ return $sourceUnit === 'in' && is_numeric($value)+ ? (float)$value * 25.4+ : $value;};$this->unit = 'mm';- $this->pageWidth = $convert($template->getPageWidth());- $this->pageHeight = $convert($template->getPageHeight());-- $this->pageMarginTop = $convert($template->getPageMarginTop());- $this->pageMarginRight = $convert($template->getPageMarginRight());- $this->pageMarginBottom = $convert($template->getPageMarginBottom());- $this->pageMarginLeft = $convert($template->getPageMarginLeft());-- $this->labelWidth = $convert($template->getLabelWidth());- $this->labelHeight = $convert($template->getLabelHeight());+ /*+ |--------------------------------------------------------------------------+ | Page / label measurements+ |--------------------------------------------------------------------------+ */+ $measurementMap = [+ 'pageWidth' => 'getPageWidth',+ 'pageHeight' => 'getPageHeight',+ 'pageMarginTop' => 'getPageMarginTop',+ 'pageMarginRight' => 'getPageMarginRight',+ 'pageMarginBottom' => 'getPageMarginBottom',+ 'pageMarginLeft' => 'getPageMarginLeft',++ 'labelWidth' => 'getLabelWidth',+ 'labelHeight' => 'getLabelHeight',+ 'labelRowSpacing' => 'getLabelRowSpacing',+ 'labelColumnSpacing' => 'getLabelColumnSpacing',+ 'labelMarginTop' => 'getLabelMarginTop',+ 'labelMarginRight' => 'getLabelMarginRight',+ 'labelMarginBottom' => 'getLabelMarginBottom',+ 'labelMarginLeft' => 'getLabelMarginLeft',+ ];- $this->labelRowSpacing = $convert($template->getLabelRowSpacing());- $this->labelColumnSpacing = $convert($template->getLabelColumnSpacing());+ foreach ($measurementMap as $property => $method) {+ if (method_exists($template, $method)) {+ $this->{$property} = $convert($template->{$method}());+ }+ }- $this->labelMarginTop = $convert($template->getLabelMarginTop());- $this->labelMarginRight = $convert($template->getLabelMarginRight());- $this->labelMarginBottom = $convert($template->getLabelMarginBottom());- $this->labelMarginLeft = $convert($template->getLabelMarginLeft());+ /*+ |--------------------------------------------------------------------------+ | Grid+ |--------------------------------------------------------------------------+ */+ if (method_exists($template, 'getRows')) {+ $this->rows = (int)$template->getRows();+ }- $this->rows = $template->getRows();- $this->columns = $template->getColumns();+ if (method_exists($template, 'getColumns')) {+ $this->columns = (int)$template->getColumns();+ }- $this->supportAssetTag = $template->getSupportAssetTag();- $this->support1DBarcode = $template->getSupport1DBarcode();- $this->support2DBarcode = $template->getSupport2DBarcode();- $this->supportFields = $template->getSupportFields();- $this->supportLogo = $template->getSupportLogo();- $this->supportTitle = $template->getSupportTitle();+ /*+ |--------------------------------------------------------------------------+ | Supports+ |--------------------------------------------------------------------------+ */+ $supportMap = [+ 'supportAssetTag' => 'getSupportAssetTag',+ 'support1DBarcode' => 'getSupport1DBarcode',+ 'support2DBarcode' => 'getSupport2DBarcode',+ 'supportFields' => 'getSupportFields',+ 'supportLogo' => 'getSupportLogo',+ 'supportTitle' => 'getSupportTitle',+ ];- if (method_exists($template, 'getBarcodeSize')) {- $this->barcodeSize = $convert($template->getBarcodeSize());- } elseif (method_exists($template, 'getBarcode1DSize')) {- $this->barcodeSize = $convert($template->getBarcode1DSize());+ foreach ($supportMap as $property => $method) {+ if (method_exists($template, $method)) {+ $this->{$property} = $template->{$method}();+ }}- if (method_exists($template, 'get2DBarcodeSize')) {- $this->barcode2DSize = $convert($template->get2DBarcodeSize());- } elseif (method_exists($template, 'getBarcode2DSize')) {- $this->barcode2DSize = $convert($template->getBarcode2DSize());- }+ /*+ |--------------------------------------------------------------------------+ | Legacy getter fallbacks+ |--------------------------------------------------------------------------+ */+ $legacyContentMap = [+ 'barcodeSize' => ['getBarcodeSize', 'getBarcode1DSize'],+ 'barcode2DSize' => ['get2DBarcodeSize', 'getBarcode2DSize'],+ 'barcodeMargin' => ['getBarcodeMargin'],+ 'barcode2Margin' => ['getBarcode2DMargin'],+ 'logoMaxWidth' => ['getLogoMaxWidth'],+ 'logoMargin' => ['getLogoMargin'],+ 'tagSize' => ['getTagSize'],+ 'titleSize' => ['getTitleSize'],+ 'labelSize' => ['getLabelSize'],+ 'fieldSize' => ['getFieldSize'],+ 'titleMargin' => ['getTitleMargin'],+ 'labelMargin' => ['getLabelMargin'],+ 'fieldMargin' => ['getFieldMargin'],+ ];- if (method_exists($template, 'getBarcodeMargin')) {- $this->barcodeMargin = $convert($template->getBarcodeMargin());- } elseif (method_exists($template, 'getBarcode2DMargin')) {- $this->barcodeMargin = $convert($template->getBarcode2DMargin());- $this->barcode2Margin = $convert($template->getBarcode2DMargin());+ foreach ($legacyContentMap as $property => $methods) {+ foreach ($methods as $method) {+ if (method_exists($template, $method)) {+ $this->{$property} = $convert($template->{$method}());+ break;+ }+ }}- if (method_exists($template, 'getLogoMaxWidth')) {- $this->logoMaxWidth = $convert($template->getLogoMaxWidth());- } elseif (method_exists($template, 'getLogoSize')) {+ /*+ |--------------------------------------------------------------------------+ | Special legacy fallbacks+ |--------------------------------------------------------------------------+ */+ if (method_exists($template, 'getLogoSize') && !method_exists($template, 'getLogoMaxWidth')) {$logoSize = $template->getLogoSize();- $this->logoMaxWidth = isset($logoSize[0]) ? $convert($logoSize[0]) : $this->logoMaxWidth;+ $this->logoMaxWidth = isset($logoSize[0])+ ? $convert($logoSize[0])+ : $this->logoMaxWidth;}- if (method_exists($template, 'getLogoMargin')) {- $this->logoMargin = $convert($template->getLogoMargin());- }-- if (method_exists($template, 'getTagSize')) {- $this->tagSize = $convert($template->getTagSize());- } elseif (method_exists($template, 'getTextSize')) {+ if (method_exists($template, 'getTextSize')) {$textSize = $convert($template->getTextSize());- $this->tagSize = $textSize;- $this->titleSize = $textSize;- $this->labelSize = $textSize;- $this->fieldSize = $textSize;- }- if (method_exists($template, 'getTitleSize')) {- $this->titleSize = $convert($template->getTitleSize());- }+ if (!method_exists($template, 'getTagSize')) {+ $this->tagSize = $textSize;+ }- if (method_exists($template, 'getLabelSize')) {- $this->labelSize = $convert($template->getLabelSize());- }+ if (!method_exists($template, 'getTitleSize')) {+ $this->titleSize = $textSize;+ }- if (method_exists($template, 'getFieldSize')) {- $this->fieldSize = $convert($template->getFieldSize());+ if (!method_exists($template, 'getLabelSize')) {+ $this->labelSize = $textSize;+ }++ if (!method_exists($template, 'getFieldSize')) {+ $this->fieldSize = $textSize;+ }}- if (method_exists($template, 'getTitleMargin')) {- $this->titleMargin = $convert($template->getTitleMargin());- } elseif (method_exists($template, 'getTextMargin')) {+ if (method_exists($template, 'getTextMargin')) {$textMargin = $convert($template->getTextMargin());- $this->titleMargin = $textMargin;- $this->labelMargin = $textMargin;- $this->fieldMargin = $textMargin;++ if (!method_exists($template, 'getTitleMargin')) {+ $this->titleMargin = $textMargin;+ }++ if (!method_exists($template, 'getLabelMargin')) {+ $this->labelMargin = $textMargin;+ }++ if (!method_exists($template, 'getFieldMargin')) {+ $this->fieldMargin = $textMargin;+ }}- if (method_exists($template, 'getLabelMargin')) {- $this->labelMargin = $convert($template->getLabelMargin());+ /*+ |--------------------------------------------------------------------------+ | Editor config overrides+ |--------------------------------------------------------------------------+ |+ | These are applied last so editor-specific values win over legacy getters.+ */+ $content = method_exists($template, 'getEditorConfigSections')+ ? ($template->getEditorConfigSections()['content'] ?? [])+ : [];++ $contentMap = [+ 'barcode_size' => 'barcodeSize',+ 'barcode_margin' => 'barcodeMargin',+ 'barcode_2d_size' => 'barcode2DSize',+ 'logo_max_width' => 'logoMaxWidth',+ 'logo_margin' => 'logoMargin',+ 'tag_font_size' => 'tagSize',+ 'title_font_size' => 'titleSize',+ 'title_margin' => 'titleMargin',+ 'field_label_font_size' => 'labelSize',+ 'field_label_margin' => 'labelMargin',+ 'field_value_font_size' => 'fieldSize',+ 'field_value_margin' => 'fieldMargin',+ 'text_area_width' => 'textAreaWidth',+ 'text_area_height' => 'textAreaHeight',+ ];++ foreach ($contentMap as $key => $property) {+ if (array_key_exists($key, $content)) {+ $this->{$property} = $convert($content[$key]);+ }}- if (method_exists($template, 'getFieldMargin')) {- $this->fieldMargin = $convert($template->getFieldMargin());+ $stringContentMap = [+ 'barcode2D_h_align' => 'barcode2DHAlign',+ 'barcode2D_v_align' => 'barcode2DVAlign',+ 'logo_h_align' => 'logoHAlign',+ 'logo_v_align' => 'logoVAlign',+ 'tag_alignment' => 'tagAlignment',+ ];++ foreach ($stringContentMap as $key => $property) {+ if (array_key_exists($key, $content)) {+ $this->{$property} = (string)$content[$key];+ }}return $this;@@ -516,6 +615,7 @@ abstract class CustomSheetLabel extends CustomLabel$this->textAreaHeight = isset($content['text_area_height']) && $content['text_area_height'] !== '' ? (float)$content['text_area_height'] : $this->textAreaHeight;$this->titleMargin = isset($content['title_margin']) ? (float)$content['title_margin'] : $this->titleMargin;+ $this->titleOffsetX = isset($content['title_offset_x']) ? (float)$content['title_offset_x'] : $this->titleOffsetX;$this->labelMargin = isset($content['field_label_margin']) ? (float)$content['field_label_margin'] : $this->labelMargin;$this->fieldMargin = isset($content['field_value_margin']) ? (float)$content['field_value_margin'] : $this->fieldMargin;}@@ -662,10 +762,11 @@ abstract class CustomSheetLabel extends CustomLabel);if ($fieldLayout['hasTitle']) {+ $x = $layout['text']['x1'] + $this->getTitleOffsetX();$layout['title'] = [- 'x' => $layout['text']['x1'],+ 'x' => $x,'y' => $textY,- 'w' => $layout['text']['w'],+ 'w' => max(0, $layout['text']['x2'] - $x),'h' => $fieldLayout['titleSize'],'font_size' => $fieldLayout['titleSize'],'advance' => $fieldLayout['titleAdvance'],diff --git a/app/Models/Labels/CustomUserLabel.php b/app/Models/Labels/CustomUserLabel.phpindex 9bd3b77f50..e9a9f7f207 100644--- a/app/Models/Labels/CustomUserLabel.php+++ b/app/Models/Labels/CustomUserLabel.php@@ -6,9 +6,11 @@ use Illuminate\Database\Eloquent\Model;use Illuminate\Support\Str;use RecursiveDirectoryIterator;use RecursiveIteratorIterator;-+use Illuminate\Database\Eloquent\SoftDeletes;class CustomUserLabel extends Model{+ use SoftDeletes;+protected $table = 'custom_user_labels';protected $fillable = [@@ -19,11 +21,9 @@ class CustomUserLabel extends Model'config_snapshot','is_default',];-protected $casts = ['overrides' => 'array','config_snapshot' => 'array',- 'is_default' => 'boolean',];/**diff --git a/app/Models/Labels/Sheets/Avery/_5520_B.php b/app/Models/Labels/Sheets/Avery/_5520_B.phpindex 1762e5f864..e4a4c73891 100644--- a/app/Models/Labels/Sheets/Avery/_5520_B.php+++ b/app/Models/Labels/Sheets/Avery/_5520_B.php@@ -125,7 +125,7 @@ class _5520_B extends _5520{return ['barcode_size' => $this->getBarcodeSize(),- 'barcode_margin' => $this->getBarcodeMargin(),+ 'barcode_margin' => .025,'tag_font_size' => $this->getTagSize(),'title_font_size' => $this->getTitleSize(),'title_margin' => $this->getTitleMargin(),diff --git a/database/migrations/2026_03_23_184904_create_custom_labels_table.php b/database/migrations/2026_03_23_184904_create_custom_labels_table.phpindex 028a98f0b9..def10a6986 100644--- a/database/migrations/2026_03_23_184904_create_custom_labels_table.php+++ b/database/migrations/2026_03_23_184904_create_custom_labels_table.php@@ -16,10 +16,11 @@ return new class extends Migration$table->string('name');$table->string('base_label')->nullable();$table->string('type')->default('sheet');- $table->json('overrides')->nullable();- $table->json('config_snapshot')->nullable(); //change to text+ $table->text('overrides')->nullable();+ $table->text('config_snapshot')->nullable(); //change to text$table->boolean('is_default')->default(false);$table->timestamps();+ $table->softDeletes();});}diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.phpindex eda4e5a755..666a9aecb7 100644--- a/resources/views/partials/bootstrap-table.blade.php+++ b/resources/views/partials/bootstrap-table.blade.php@@ -1893,20 +1893,51 @@return linkToUserSectionBasedOnCount(value, row.id, 'managed-locations');}- function labelActionsFormatter(value, row) {+ function labelActionsFormatter(value, row, index) {if (!row.name) return '';- const baseUrl = '{{ route('settings.labels.edit') }}';-- return `- <a href="${baseUrl}?label=${encodeURIComponent(row.name)}"- class="actions btn btn-sm btn-primary hidden-print"- data-tooltip="true"- title="{{ trans('general.clone') }}">- <i class="fa-regular fa-clone"></i>- <span class="sr-only">{{ trans('general.clone') }}</span>- </a>- `;+ const editUrl = '{{ route('settings.labels.edit') }}';+ const deleteUrl = '{{ route('settings.labels.destroy', '__id__') }}';++ let actions = `+ <a href="${editUrl}?label=${encodeURIComponent(row.name)}"+ class="actions btn btn-sm btn-primary hidden-print"+ data-tooltip="true"+ title="{{ trans('general.clone') }}">+ <i class="fa-regular fa-clone"></i>+ <span class="sr-only">{{ trans('general.clone') }}</span>+ </a>+ `;+ // Only allow delete/share for custom labels+ if (row.source === 'custom') {++ // Share button+ actions += `+ <button+ type="button"+ class="btn btn-sm btn-primary copy-label-json"+ title="Share Label"+ data-tooltip="true"+ >+ <i class="fa-solid fa-up-right-from-square"></i>+ <span class="sr-only">Share Label</span>+ </button>+ `;+ // Delete button++ var safeName = $('<div>').text(row.name || 'this label').html();++ actions += '<button type="button" '+ + 'class="btn btn-danger btn-sm delete-custom-label hidden-print" '+ + 'data-id="' + row.custom_label_id + '" '+ + 'data-name="' + safeName + '">'+ + '<x-icon type="delete" class="fa-fw" />'+ + '<span class="sr-only">{{ trans('general.delete') }}</span>'+ + '</button> ';+ }+++ return actions;}function labelNameFormatter(value) {diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.phpindex 802f37e9ba..49e3a6e121 100644--- a/resources/views/settings/labels.blade.php+++ b/resources/views/settings/labels.blade.php@@ -584,6 +584,10 @@</div> <!-- /.row--></form>+ <form id="delete-custom-label-form" method="POST" style="display:none;">+ @csrf+ @method('DELETE')+ </form>@stop@@ -639,14 +643,43 @@});});- document.addEventListener('DOMContentLoaded', () => {- const display = document.getElementById('selected-template-display');+ const deleteLabelUrlTemplate = "{{ route('settings.labels.destroy', ['label' => '__LABEL_ID__']) }}";- $('#label2TemplateTable').on('change', 'input[name="label2_template"]', function () {- if (display) {- display.textContent = this.value || '';- }- });+ $(document).on('click', '.delete-custom-label', function (e) {+ e.preventDefault();+ e.stopPropagation();++ const id = $(this).data('id');+ const name = $(this).data('name') || 'this label';++ if (!confirm('{{ trans('general.sure_to_delete') }}: ' + name + '?')) {+ return;+ }++ const url = deleteLabelUrlTemplate.replace('__LABEL_ID__', id);++ $('#delete-custom-label-form')+ .attr('action', url)+ .trigger('submit');+ });+ $(document).on('click', '.label-config-snapshot', async function () {+ const index = $(this).data('index');+ const row = $('#label2TemplateTable').bootstrapTable('getData')[index];++ if (!row || !row.config_snapshot) {+ alert('No config snapshot found.');+ return;+ }++ const json = JSON.stringify(row.config_snapshot, null, 2);++ try {+ await navigator.clipboard.writeText(json);+ alert('Label JSON copied!');+ } catch (e) {+ console.error(e);+ alert('Could not copy label JSON.');+ }});</script>{{-- Can't use @script here because we're not in a livewire component so let's manually load --}}diff --git a/routes/web.php b/routes/web.phpindex da46727d30..b4758d0d45 100644--- a/routes/web.php+++ b/routes/web.php@@ -212,6 +212,8 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser->name('settings.labels.edit');Route::post('/settings/labels', [LabelsController::class, 'store'])->name('settings.labels.store');+ Route::delete('settings/labels/{label}', [LabelsController::class, 'destroy'])+ ->name('settings.labels.destroy');Route::get('ldap', [SettingsController::class, 'getLdapSettings'])->name('settings.ldap.index')