Skip to content

A free open source IT asset/license management system

formats label names, getting custom label heirarchy in order

Godfrey M5217001e26df
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php
index 209148d43e..537e664c28 100755
--- a/app/Http/Controllers/LabelsController.php
+++ b/app/Http/Controllers/LabelsController.php
@@ -111,11 +111,13 @@ class LabelsController extends Controller
: new \App\Models\Labels\DefaultLabel();
} catch (\Throwable $e) {
$label = new \App\Models\Labels\DefaultLabel();
+ $selectedLabel = null;
}
return view('settings.label-edit', [
'config' => $label->toEditorConfig(),
- 'selectedLabel' => Label::find(),
+ 'selectedLabel' => $label->getName(),
+ 'labels' => Label::find(),
]);
}
diff --git a/app/Models/Labels/CustomLabels/CustomLabel.php b/app/Models/Labels/CustomLabels/CustomLabel.php
new file mode 100644
index 0000000000..3cf954f7a7
--- /dev/null
+++ b/app/Models/Labels/CustomLabels/CustomLabel.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Models\Labels\CustomLabels;
+
+use App\Models\Labels\Label;
+use App\Models\Labels\RectangleSheet;
+
+abstract class CustomLabel extends RectangleSheet
+{
+ protected array $editorConfig = [];
+ protected ?float $pageWidth = null;
+ protected ?float $pageHeight = null;
+
+ protected ?float $pageMarginTop = null;
+ protected ?float $pageMarginRight = null;
+ protected ?float $pageMarginBottom = null;
+ protected ?float $pageMarginLeft = null;
+
+ protected ?float $labelWidth = null;
+ protected ?float $labelHeight = null;
+
+ protected ?float $columnSpacing = null;
+ protected ?float $rowSpacing = null;
+
+ protected ?int $gridColumns = null;
+ protected ?int $gridRows = null;
+
+ public function applyEditorConfig(array $config): static
+ {
+ $this->editorConfig = $config;
+ $this->hydrateFromEditorConfig($config);
+
+ return $this;
+ }
+
+ protected function hydrateFromEditorConfig(array $config): void
+ {
+ $page = $config['page'] ?? [];
+ $label = $config['label'] ?? [];
+ $grid = $config['grid'] ?? [];
+
+ $this->pageWidth = $page['width'] ?? $this->pageWidth;
+ $this->pageHeight = $page['height'] ?? $this->pageHeight;
+
+ $this->pageMarginTop = $page['margin_top'] ?? $this->pageMarginTop;
+ $this->pageMarginRight = $page['margin_right'] ?? $this->pageMarginRight;
+ $this->pageMarginBottom = $page['margin_bottom'] ?? $this->pageMarginBottom;
+ $this->pageMarginLeft = $page['margin_left'] ?? $this->pageMarginLeft;
+
+ $this->labelWidth = $label['width'] ?? $this->labelWidth;
+ $this->labelHeight = $label['height'] ?? $this->labelHeight;
+
+ $this->gridColumns = $grid['columns'] ?? $this->gridColumns;
+ $this->gridRows = $grid['rows'] ?? $this->gridRows;
+ $this->columnSpacing = $grid['column_spacing'] ?? $this->columnSpacing;
+ $this->rowSpacing = $grid['row_spacing'] ?? $this->rowSpacing;
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.php
new file mode 100644
index 0000000000..b2e0575e33
--- /dev/null
+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Models\Labels\CustomLabels;
+
+use App\Models\Labels\RectangleSheet;
+
+abstract class CustomSheetLabel extends CustomLabel
+{
+
+}
\ No newline at end of file
diff --git a/app/Models/Labels/Label.php b/app/Models/Labels/Label.php
index 74a6ced3dc..c6d0c663a8 100644
--- a/app/Models/Labels/Label.php
+++ b/app/Models/Labels/Label.php
@@ -731,7 +731,6 @@ abstract class Label
return [
'name' => $this->getName(),
'unit' => $this->getUnit(),
- 'dimensions' => $this->getDimensionsEditorConfig(),
'printable_area' => $this->getPrintableAreaEditorConfig(),
'supports' => $this->getSupportsEditorConfig(),
'content' => $this->getContentEditorConfig(),
@@ -739,6 +738,7 @@ abstract class Label
];
}
+
protected function getDimensionsEditorConfig(): array
{
return [
diff --git a/app/Presenters/LabelPresenter.php b/app/Presenters/LabelPresenter.php
index e8601472ef..4d1a5b7272 100644
--- a/app/Presenters/LabelPresenter.php
+++ b/app/Presenters/LabelPresenter.php
@@ -26,6 +26,7 @@ class LabelPresenter extends Presenter
'switchable' => true,
'title' => trans('general.name'),
'visible' => true,
+ 'formatter' => 'labelNameFormatter',
], [
'field' => 'size',
'searchable' => false,
diff --git a/resources/views/blade/table/labels.blade.php b/resources/views/blade/table/labels.blade.php
index d7385aa7c7..3a0a4cf3dc 100644
--- a/resources/views/blade/table/labels.blade.php
+++ b/resources/views/blade/table/labels.blade.php
@@ -21,6 +21,9 @@
data-sort-order="{{ $sortOrder }}"
data-url="{{ $route }}"
id="{{ $tableId }}"
+ data-pagination="true"
+ data-page-size="50"
+ data-height="600"
buttons="labelButtons"
class="table table-striped snipe-table"
></table>
\ No newline at end of file
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index 4e1d4eaaa6..4f9ea3bdbb 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -1840,14 +1840,24 @@
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>&nbsp;
- `;
+ <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>
+ `;
+ }
+
+ function labelNameFormatter(value) {
+ if (!value) return '';
+
+ // Normalize slashes just in case
+ value = value.replace(/\//g, '\\');
+
+ // Remove "Sheets\" or "Tapes\" from the beginning
+ return value.replace(/^(Sheets|Tapes)\\/, '');
}
function labelPerPageFormatter(value, row, index, field) {
if (row) {