Skip to content

A free open source IT asset/license management system

add label gap for continous tape labels

Godfrey Mb859a7b83621
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php
index 591c0dc694..fee6d1e65e 100755
--- a/app/Http/Controllers/LabelsController.php
+++ b/app/Http/Controllers/LabelsController.php
@@ -333,8 +333,9 @@ 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())),],
- 'rows' => ['required', 'numeric', 'min:1'],
- 'columns' => ['required', 'numeric', 'min:1'],
+ 'label_gap' => ['nullable', 'numeric', 'min:0'],
+ 'rows' => ['required_if:type,sheet', 'numeric', 'min:1'],
+ 'columns' => ['required_if:type,sheet', 'numeric', 'min:1'],
'label_width' => ['required', 'numeric', 'gt:0'],
'label_height' => ['required', 'numeric', 'gt:0'],
]);
@@ -353,9 +354,11 @@ class LabelsController extends Controller
$label->applyEditorConfig($config);
} else {
+
$label = new PreviewTapeLabel(
width: (float)$validated['label_width'],
height: (float)$validated['label_height'],
+ gap: (float)$validated['label_gap'] ?? 0,
);
}
diff --git a/app/Livewire/Labels/NewLabelSetup.php b/app/Livewire/Labels/NewLabelSetup.php
index cc1f884ee2..b8ae22dbde 100644
--- a/app/Livewire/Labels/NewLabelSetup.php
+++ b/app/Livewire/Labels/NewLabelSetup.php
@@ -11,6 +11,7 @@ class NewLabelSetup extends Component
public string $pageSize = 'letter';
public ?float $labelWidth = null;
public ?float $labelHeight = null;
+ public ?float $labelGap = null;
public ?int $columns = null;
public ?int $rows = null;
diff --git a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
index 67424771a3..d1ca66084b 100644
--- a/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
+++ b/app/Models/Labels/CustomLabels/Concerns/HasCustomLabelEditorSections.php
@@ -2,14 +2,18 @@
namespace App\Models\Labels\CustomLabels\Concerns;
+
trait HasCustomLabelEditorSections
{
public function getEditorSections(): array
{
- return $this->editorSections();
+ return array_replace_recursive(
+ $this->baseEditorSections(),
+ $this->layoutEditorSections()
+ );
}
- protected function editorSections(): array
+ protected function baseEditorSections(): array
{
return [
'supports' => [
@@ -138,6 +142,28 @@ trait HasCustomLabelEditorSections
],
],
],
+ ];
+ }
+
+ protected function layoutEditorSections(): array
+ {
+ if ($this->isTapeLabel()) {
+ return $this->tapeLayoutEditorSections();
+ }
+
+ return $this->sheetLayoutEditorSections();
+ }
+
+ protected function isTapeLabel(): bool
+ {
+ return str_contains(static::class, 'Tape')
+ || method_exists($this, 'getTapeWidth')
+ || method_exists($this, 'getTapeHeight');
+ }
+
+ protected function sheetLayoutEditorSections(): array
+ {
+ return [
'layout' => [
'label' => 'admin/labels/general.sections.layout',
'column_span' => 2,
@@ -183,4 +209,25 @@ trait HasCustomLabelEditorSections
],
];
}
+
+ protected function tapeLayoutEditorSections(): array
+ {
+ return [
+ 'layout' => [
+ 'label' => 'admin/labels/general.sections.layout',
+ 'column_span' => 2,
+ 'groups' => [
+ 'label' => [
+ 'label' => 'admin/labels/general.sections.label',
+ 'section_key' => 'dimensions',
+ 'fields' => [
+ 'width' => ['type' => 'number'],
+ 'height' => ['type' => 'number'],
+ 'label_gap' => ['type' => 'number'],
+ ],
+ ],
+ ],
+ ],
+ ];
+ }
}
\ No newline at end of file
diff --git a/app/Models/Labels/CustomLabels/CustomTapeLabel.php b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
index ee075f29e4..c9bd008307 100644
--- a/app/Models/Labels/CustomLabels/CustomTapeLabel.php
+++ b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
@@ -29,7 +29,7 @@ abstract class CustomTapeLabel extends Label
protected float $width = 50.0;
protected float $height = 12.0;
-
+ protected float $labelGap = 0.0;
protected float $marginTop = 3.2;
protected float $marginRight = 3.2;
protected float $marginBottom = 3.2;
@@ -52,6 +52,10 @@ abstract class CustomTapeLabel extends Label
return $this->height;
}
+ public function getLabelGap()
+ {
+ return $this->labelGap;
+ }
public function getMarginTop()
{
return $this->marginTop;
@@ -157,6 +161,16 @@ abstract class CustomTapeLabel extends Label
);
}
+ public function toEditorConfig(): array
+ {
+ return array_merge(parent::toEditorConfig(), [
+ 'dimensions' => [
+ 'width' => $this->getWidth(),
+ 'height' => $this->getHeight(),
+ 'label_gap' => $this->getLabelGap(),
+ ],
+ ]);
+ }
public function getEditorConfigSections(): array
{
return [
@@ -199,11 +213,11 @@ abstract class CustomTapeLabel extends Label
$this->hydrateSupports($config['supports'] ?? []);
$this->hydrateContent($config['content'] ?? []);
+ $dimensions = $config['dimensions'] ?? [];
+ $this->labelGap = isset($dimensions['label_gap']) ? (float)$dimensions['label_gap'] : $this->labelGap;
$meta = $config['meta'] ?? [];
- $this->rotation = isset($meta['rotation'])
- ? (int)$meta['rotation']
- : $this->rotation;
+ $this->rotation = isset($meta['rotation']) ? (int)$meta['rotation'] : $this->rotation;
}
public function write($pdf, $record)
diff --git a/app/Models/Labels/CustomLabels/PreviewTapeLabel.php b/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
index 734ee7bed1..40d6fac92b 100644
--- a/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
+++ b/app/Models/Labels/CustomLabels/PreviewTapeLabel.php
@@ -4,5 +4,25 @@ namespace App\Models\Labels\CustomLabels;
class PreviewTapeLabel extends CustomTapeLabel
{
+ protected float $width = 50.0;
+ protected float $height = 24.0;
+ protected ?float $gap = 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;
+
+ public function __construct(
+ float $width = 50.0,
+ float $height = 24.0,
+ float $gap = 0,
+ )
+ {
+ $this->width = $width;
+ $this->height = $height;
+ $this->gap = $gap;
+ }
}
\ No newline at end of file
diff --git a/app/View/Label.php b/app/View/Label.php
index 1e7b1c7c12..9520a7eadc 100644
--- a/app/View/Label.php
+++ b/app/View/Label.php
@@ -3,6 +3,7 @@
namespace App\View;
use App\Models\Labels\CustomLabels\PreviewSheetLabel;
+use App\Models\Labels\CustomLabels\PreviewTapeLabel;
use App\Models\Labels\CustomUserLabel;
use App\Models\Labels\Field;
use App\Models\Labels\Label as LabelModel;
@@ -59,7 +60,9 @@ class Label implements View
data_get($customLabel->config_snapshot, 'template', $customLabel->base_label)
);
- $template = new PreviewSheetLabel;
+ $template = data_get($customLabel->config_snapshot, 'type') === 'tape'
+ ? new PreviewTapeLabel
+ : new PreviewSheetLabel;
if ($baseLabel) {
$template->seedFromTemplate($baseLabel);
@@ -90,10 +93,14 @@ class Label implements View
$template->validate();
+ $labelGap = method_exists($template, 'getLabelGap')
+ ? (float)$template->getLabelGap()
+ : 0.0;
+
$pdf = new TCPDF(
$template->getOrientation(),
$template->getUnit(),
- [0 => $template->getWidth(), 1 => $template->getHeight(), 'Rotate' => $template->getRotation()]
+ [0 => $template->getWidth() + $labelGap, 1 => $template->getHeight(), 'Rotate' => $template->getRotation()]
);
// Required for CJK languages, otherwise the embedded font can get too massive
diff --git a/resources/lang/en-US/admin/labels/general.php b/resources/lang/en-US/admin/labels/general.php
index 543c9df698..da0a57bdf9 100644
--- a/resources/lang/en-US/admin/labels/general.php
+++ b/resources/lang/en-US/admin/labels/general.php
@@ -23,6 +23,7 @@ return [
'fields' => [
'width' => 'Label Width',
'height' => 'Label Height',
+ 'label_gap' => 'Label Gap',
'margin_top' => 'Top Margin',
'margin_right' => 'Right Margin',
'margin_bottom' => 'Bottom Margin',
diff --git a/resources/views/livewire/labels/new-label-setup.blade.php b/resources/views/livewire/labels/new-label-setup.blade.php
index 20699da6e5..b90fd9b3b2 100644
--- a/resources/views/livewire/labels/new-label-setup.blade.php
+++ b/resources/views/livewire/labels/new-label-setup.blade.php
@@ -94,7 +94,7 @@
</div>
@endif
- <div class="row">
+ <div class="row" style="margin-top: 15px;">
<div class="col-md-6">
<label>{{ trans('admin/labels/general.fields.width') }}</label>
@@ -123,6 +123,23 @@
>
</div>
</div>
+ @if ($type === 'tape')
+ <div class="row" style="margin-top: 15px;">
+ <div class="col-md-6">
+ <label>{{ trans('admin/labels/general.fields.label_gap') }}</label>
+ <input
+ type="number"
+ step="0.1"
+ min="0"
+ name="label_gap"
+ class="form-control"
+ placeholder="0"
+ wire:model.live.debounce.300ms="labelGap"
+ value="0"
+ >
+ </div>
+ </div>
+ @endif
@if ($type === 'sheet')
<hr>
diff --git a/resources/views/modals/new-label-setup.blade.php b/resources/views/modals/new-label-setup.blade.php
index a75d626733..a6c1f9c0b9 100644
--- a/resources/views/modals/new-label-setup.blade.php
+++ b/resources/views/modals/new-label-setup.blade.php
@@ -80,6 +80,20 @@
>
</div>
</div>
+ <div class="row">
+ <div class="col-md-6">
+ <label>{{trans('admin/labels/general.fields.label_gap')}}</label>
+ <input
+ type="number"
+ step="0.1"
+ min="0.1"
+ name="label_gap"
+ class="form-control"
+ value="0"
+ >
+ </div>
+ </div>
+
</div>
<div id="sheet-summary" class="text-center">