Skip to content

A free open source IT asset/license management system

add defaults for standard tape label, fix textbox positioning, fix preview

Godfrey Mebd6c9334e98
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php
index fee6d1e65e..5ffa6d3c92 100755
--- a/app/Http/Controllers/LabelsController.php
+++ b/app/Http/Controllers/LabelsController.php
@@ -111,9 +111,21 @@ class LabelsController extends Controller
?? data_get($config, 'type')
?? 'sheet';
+ if ($selectedType === 'tape') {
+ $previewLabel = (new PreviewTapeLabel())->applyEditorConfig($config);
+
+ $config['dimensions'] = [
+ 'width' => $previewLabel->getWidth(),
+ 'height' => $previewLabel->getHeight(),
+ 'label_gap' => $previewLabel->getLabelGap(),
+ ];
+ } else {
+ $previewLabel = (new PreviewSheetLabel())->applyEditorConfig($config);
+ }
+
return view('settings.label-edit', [
'config' => $config,
- 'sections' => ($selectedType === 'tape' ? new PreviewTapeLabel() : new PreviewSheetLabel())->applyEditorConfig($config)->getEditorSections(),
+ 'sections' => $previewLabel->getEditorSections(),
'selectedLabel' => $label->base_label,
'selectedType' => $selectedType,
'importedConfig' => null,
@@ -240,6 +252,9 @@ class LabelsController extends Controller
$rules['grid'] = ['required', 'array'];
$rules['label'] = ['required', 'array'];
}
+ if ($type === 'tape') {
+ $rules['dimensions'] = ['required', 'array'];
+ }
$validated = $request->validate($rules);
@@ -263,7 +278,13 @@ class LabelsController extends Controller
$content = $castNumeric($validated['content']);
- $baseLabel = CustomUserLabel::makeBaseLabel($validated['template'] ?? null);
+ $template = $validated['template'] ?? null;
+
+ if ($type === 'tape' && $template === 'StandardTape') {
+ $baseLabel = new PreviewTapeLabel;
+ } else {
+ $baseLabel = CustomUserLabel::makeBaseLabel($template);
+ }
if (!$baseLabel) {
return redirect()->back()
@@ -275,6 +296,7 @@ class LabelsController extends Controller
$workingLabel = new PreviewTapeLabel;
$submittedConfig = [
+ 'dimensions' => $castNumeric($validated['dimensions']),
'content' => $content,
'supports' => $supports,
];
@@ -303,7 +325,7 @@ class LabelsController extends Controller
$configSnapshot = [
'unit' => 'mm',
- 'template' => $validated['template'] ?? null,
+ 'template' => $template,
'type' => $type,
'name' => $validated['name'],
...$finalConfig,
@@ -313,7 +335,7 @@ class LabelsController extends Controller
$customLabel = CustomUserLabel::create([
'name' => $validated['name'],
- 'base_label' => $validated['template'] ?? null,
+ 'base_label' => $template,
'type' => $type,
'overrides' => $overrides,
'config_snapshot' => $configSnapshot,
@@ -358,7 +380,7 @@ class LabelsController extends Controller
$label = new PreviewTapeLabel(
width: (float)$validated['label_width'],
height: (float)$validated['label_height'],
- gap: (float)$validated['label_gap'] ?? 0,
+ labelGap: (float)$validated['label_gap'] ?? 0,
);
}
@@ -395,11 +417,13 @@ class LabelsController extends Controller
{
$labelName = str_replace('/', '\\', $labelName);
- $baseTemplate = $labelName === 'DefaultLabel'
- ? new DefaultLabel
- : Label::find($labelName);
+ $baseTemplate = match (true) {
+ $labelName === 'DefaultLabel' => new DefaultLabel,
+ $labelName === 'StandardTape' => null,
+ default => Label::find($labelName),
+ };
- $isTape = str_starts_with($labelName, 'Tapes\\');
+ $isTape = str_starts_with($labelName, 'Tapes\\') || $labelName === 'StandardTape';
$editorConfig = [
'content' => $request->input('content', []),
@@ -407,7 +431,7 @@ class LabelsController extends Controller
];
if ($isTape) {
- $editorConfig['tape'] = $request->input('tape', []);
+ $editorConfig['dimensions'] = $request->input('dimensions', []);
$template = new PreviewTapeLabel;
} else {
$editorConfig['page'] = $request->input('page', []);
@@ -416,16 +440,11 @@ class LabelsController extends Controller
$template = new PreviewSheetLabel;
}
- $template->seedFromTemplate($baseTemplate);
- $template->applyEditorConfig($editorConfig);
-
- if (method_exists($template, 'seedFromTemplate')) {
+ if ($baseTemplate) {
$template->seedFromTemplate($baseTemplate);
}
- if (method_exists($template, 'applyEditorConfig')) {
- $template->applyEditorConfig($editorConfig);
- }
+ $template->applyEditorConfig($editorConfig);
$exampleAsset = Asset::factory()->labelPreview()->make();
diff --git a/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php b/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php
index 220c12721b..3fb2a586d0 100644
--- a/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php
+++ b/app/Models/Labels/CustomLabels/Concerns/RenderCustomLabelContent.php
@@ -285,7 +285,9 @@ trait RenderCustomLabelContent
$rightEdge = $body['x2'];
$topEdge = $body['y1'];
$bottomEdge = $body['y2'];
-
+ $barcode2DMargin = method_exists($this, 'getBarcode2DMargin')
+ ? $this->getBarcode2DMargin()
+ : 0;
foreach ($boxes as $box) {
if (!$box) {
continue;
@@ -296,12 +298,19 @@ trait RenderCustomLabelContent
$isTopAnchored = abs($box['y'] - $body['y1']) < 0.01;
$isBottomAnchored = abs(($box['y'] + $box['h']) - $body['y2']) < 0.01;
+ // Reserve enough spacing for either a logo or a QR code.
+ $sideMargin = max(
+ $this->getLogoMargin(),
+ $barcode2DMargin
+ );
+
+
if ($isLeftAnchored) {
- $leftEdge = max($leftEdge, $box['x'] + $box['w'] + $this->getLogoMargin());
+ $leftEdge = max($leftEdge, $box['x'] + $box['w'] + $sideMargin);
}
if ($isRightAnchored) {
- $rightEdge = min($rightEdge, $box['x'] - $this->getLogoMargin());
+ $rightEdge = min($rightEdge, $box['x'] - $sideMargin);
}
if ($isTopAnchored && $box['w'] > ($body['w'] * 0.6)) {
@@ -313,13 +322,8 @@ trait RenderCustomLabelContent
}
}
- if ($rightEdge < $leftEdge) {
- $rightEdge = $leftEdge;
- }
-
- if ($bottomEdge < $topEdge) {
- $bottomEdge = $topEdge;
- }
+ $rightEdge = max($rightEdge, $leftEdge);
+ $bottomEdge = max($bottomEdge, $topEdge);
return [
'x1' => $leftEdge,
diff --git a/app/Models/Labels/CustomLabels/CustomTapeLabel.php b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
index c9bd008307..b771686da6 100644
--- a/app/Models/Labels/CustomLabels/CustomTapeLabel.php
+++ b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
@@ -214,6 +214,8 @@ abstract class CustomTapeLabel extends Label
$this->hydrateContent($config['content'] ?? []);
$dimensions = $config['dimensions'] ?? [];
+ $this->width = isset($dimensions['width']) ? (float)$dimensions['width'] : $this->width;
+ $this->height = isset($dimensions['height']) ? (float)$dimensions['height'] : $this->height;
$this->labelGap = isset($dimensions['label_gap']) ? (float)$dimensions['label_gap'] : $this->labelGap;
$meta = $config['meta'] ?? [];
@@ -404,10 +406,8 @@ abstract class CustomTapeLabel extends Label
max(0, $this->getFieldMargin()),
$this->getLabelSize(),
$this->getFieldSize(),
- $this->getLabelSize()
- + $this->getLabelMargin()
- + $this->getFieldSize()
- + $this->getFieldMargin(),
+ max($this->getLabelSize(), $this->getFieldSize())
+ + max($this->getFieldMargin(), $this->getLabelMargin(), 0)
);
return $layout;
diff --git a/app/Models/Labels/CustomLabels/PreviewTapeLabel.php b/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
index 40d6fac92b..93ac576a3f 100644
--- a/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
+++ b/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
@@ -6,23 +6,59 @@ class PreviewTapeLabel extends CustomTapeLabel
{
protected float $width = 50.0;
protected float $height = 24.0;
- protected ?float $gap = 0;
+ protected float $labelGap = 0.0;
protected bool $supportAssetTag = true;
protected bool $support1DBarcode = true;
protected bool $support2DBarcode = true;
protected int $supportFields = 5;
protected bool $supportLogo = true;
protected bool $supportTitle = true;
+ protected float $barcodeSize = 6.0;
+ protected float $barcodeMargin = 1.0;
+
+ protected float $barcode2DSize = 10.0;
+ protected string $barcode2DHAlign = 'L';
+ protected string $barcode2DVAlign = 'T';
+
+ protected float $tagSize = 5.5;
+ protected string $tagFont = 'freemono';
+ protected string $tagAlignment = 'L';
+
+ protected float $titleSize = 8.0;
+ protected float $titleMargin = 1.0;
+ protected string $titleFont = 'freesans';
+
+ protected float $labelSize = 5.0;
+ protected float $labelMargin = 1.0;
+ protected string $fieldLabelFont = 'freesans';
+
+ protected float $fieldSize = 5.0;
+ protected float $fieldMargin = 1.0;
+ protected string $fieldValueFont = 'freemono';
+
+ protected float $logoMaxWidth = 12.0;
+ protected float $logoMargin = 2.0;
+ protected string $logoHAlign = 'R';
+ protected string $logoVAlign = 'T';
+
+ protected string $barcode1DVAlign = 'M';
+ protected string $barcode1DPlacement = 'inline';
+ protected string $barcode2DPlacement = 'inline';
+ protected string $logoPlacement = 'inline';
+
+ protected float $textSizeMod = 1.0;
+ protected float $textAreaOffsetY = 0.0;
+ protected string $textRenderMode = 'block';
public function __construct(
float $width = 50.0,
float $height = 24.0,
- float $gap = 0,
+ float $labelGap = 0,
)
{
$this->width = $width;
$this->height = $height;
- $this->gap = $gap;
+ $this->labelGap = $labelGap;
}
}
\ No newline at end of file
diff --git a/resources/views/partials/custom-label-preview.blade.php b/resources/views/partials/custom-label-preview.blade.php
index f103a95c8e..03f2d403d9 100644
--- a/resources/views/partials/custom-label-preview.blade.php
+++ b/resources/views/partials/custom-label-preview.blade.php
@@ -82,8 +82,6 @@
this.previewURL = '{{ route("labels.customizer-preview", ["labelName" => ":label"]) }}'
.replace(':label', template.replaceAll('\\', '/'))
.concat('?' + $.param(payload) + '#toolbar=0');
-
- console.log('custom_label_preview url:', this.previewURL);
},
_previewURL: '',
diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.php
index 15506bea3e..e08f45e3fa 100644
--- a/resources/views/settings/label-edit.blade.php
+++ b/resources/views/settings/label-edit.blade.php
@@ -129,7 +129,9 @@
@php
$printable = $config['label_printable_area'] ?? $config['printable_area'] ?? null;
@endphp
- <input type="hidden" name="template" value="{{ $selectedLabel ?: 'DefaultLabel' }}">
+ <input type="hidden"
+ name="template"
+ value="{{ $selectedLabel ?: (($selectedType ?? null) === 'tape' ? 'StandardTape' : 'DefaultLabel') }}">
<input
type="hidden"
name="type"