Skip to content

A free open source IT asset/license management system

removed unused methods/fields, updated create/store methods for tapes

Godfrey Me85237717373
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php
index 1e936cff25..7bd461ca4d 100755
--- a/app/Http/Controllers/LabelsController.php
+++ b/app/Http/Controllers/LabelsController.php
@@ -221,17 +221,22 @@ class LabelsController extends Controller
public function store(Request $request)
{
+ $type = $request->input('type', 'sheet');
- $validated = $request->validate([
+ $rules = [
'name' => ['required', 'string', 'max:255'],
'template' => ['nullable', 'string'],
'type' => ['nullable', 'string'],
- 'page' => ['required', 'array'],
- 'grid' => ['required', 'array'],
- 'label' => ['required', 'array'],
'content' => ['required', 'array'],
'supports' => ['required', 'array'],
- ]);
+ ];
+ if ($type === 'sheet') {
+ $rules['page'] = ['required', 'array'];
+ $rules['grid'] = ['required', 'array'];
+ $rules['label'] = ['required', 'array'];
+ }
+
+ $validated = $request->validate($rules);
$supports = collect($validated['supports'])
->map(function ($value, $key) {
@@ -247,41 +252,45 @@ class LabelsController extends Controller
$castNumeric = function ($array) {
return collect($array)->map(function ($value) {
- if (is_numeric($value)) {
- return (float)$value;
- }
-
- return $value;
+ return is_numeric($value) ? (float)$value : $value;
})->toArray();
};
- $page = $castNumeric($validated['page']);
- $grid = $castNumeric($validated['grid']);
- $labelConfig = $castNumeric($validated['label']);
$content = $castNumeric($validated['content']);
$baseLabel = CustomUserLabel::makeBaseLabel($validated['template'] ?? null);
if (!$baseLabel) {
- return redirect()->back()->with('error', trans('admin/labels/labels.base_label_missing'));
+ return redirect()->back()
+ ->with('error', trans('admin/labels/labels.base_label_missing'));
+ }
+
+ if ($type === 'tape') {
+ $baseWorkingLabel = new PreviewTapeLabel;
+ $workingLabel = new PreviewTapeLabel;
+
+ $submittedConfig = [
+ 'content' => $content,
+ 'supports' => $supports,
+ ];
+ } else {
+ $baseWorkingLabel = new PreviewSheetLabel;
+ $workingLabel = new PreviewSheetLabel;
+
+ $submittedConfig = [
+ 'page' => $castNumeric($validated['page']),
+ 'grid' => $castNumeric($validated['grid']),
+ 'label' => $castNumeric($validated['label']),
+ 'content' => $content,
+ 'supports' => $supports,
+ ];
}
- // Loading both base and working label in the preview to ensure millimeter-based comparisons for overrides.
- $baseWorkingLabel = new PreviewSheetLabel;
$baseWorkingLabel->seedFromTemplate($baseLabel);
$baseConfig = $baseWorkingLabel->getEditorConfigSections();
- $submittedConfig = [
- 'page' => $page,
- 'grid' => $grid,
- 'label' => $labelConfig,
- 'content' => $content,
- 'supports' => $supports,
- ];
-
$mergedConfig = array_replace_recursive($baseConfig, $submittedConfig);
- $workingLabel = new PreviewSheetLabel;
$workingLabel->seedFromTemplate($baseLabel);
$workingLabel->applyEditorConfig($mergedConfig);
@@ -289,8 +298,8 @@ class LabelsController extends Controller
$configSnapshot = [
'unit' => 'mm',
- 'template' => $validated['template'],
- 'type' => $validated['type'] ?? 'sheet',
+ 'template' => $validated['template'] ?? null,
+ 'type' => $type,
'name' => $validated['name'],
...$finalConfig,
];
@@ -300,13 +309,13 @@ class LabelsController extends Controller
$customLabel = CustomUserLabel::create([
'name' => $validated['name'],
'base_label' => $validated['template'] ?? null,
- 'type' => $validated['type'] ?? 'sheet',
+ 'type' => $type,
'overrides' => $overrides,
'config_snapshot' => $configSnapshot,
'is_default' => false,
]);
- return app(SettingsController::class)->getLabels()
+ return redirect()->route('settings.labels.index')
->with('success', $customLabel->name . ' created successfully.');
}
@@ -352,7 +361,13 @@ class LabelsController extends Controller
$label = $this->previewLabelForTemplate($template);
$config = $importedConfig ?: $label->toEditorConfig();
- $type = str_starts_with($template->getName(), 'Tapes\\') ? 'tape' : 'sheet';
+ $type = data_get($importedConfig, 'type');
+
+ if ($type === null) {
+ $type = str_starts_with($selectedLabel ?? '', 'Tapes\\')
+ ? 'tape'
+ : 'sheet';
+ }
return view('settings.label-edit', [
'config' => $config,
diff --git a/app/Models/Labels/CustomLabels/CustomTapeLabel.php b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
index e084382e31..a80a2f4067 100644
--- a/app/Models/Labels/CustomLabels/CustomTapeLabel.php
+++ b/app/Models/Labels/CustomLabels/CustomTapeLabel.php
@@ -311,18 +311,6 @@ abstract class CustomTapeLabel extends Label
$pdf->SetAutoPageBreak(false, 0);
}
- protected function getDimensionsEditorConfig(): array
- {
- return [
- 'width' => $this->getWidth(),
- 'height' => $this->getHeight(),
- 'margin_top' => $this->getMarginTop(),
- 'margin_right' => $this->getMarginRight(),
- 'margin_bottom' => $this->getMarginBottom(),
- 'margin_left' => $this->getMarginLeft(),
- ];
- }
-
protected function getContentEditorConfig(): array
{
return [
@@ -356,11 +344,9 @@ abstract class CustomTapeLabel extends Label
{
return [
'unit' => 'mm',
- 'tape' => $this->getDimensionsEditorConfig(),
'printable_area' => $this->getPrintableAreaEditorConfig(),
'content' => $this->getContentEditorConfig(),
'supports' => $this->getSupportsEditorConfig(),
- 'meta' => $this->getMetaEditorConfig(),
];
}
@@ -476,15 +462,8 @@ abstract class CustomTapeLabel extends Label
}
}
- $this->rotation = method_exists($template, 'getRotation')
- ? (int)$template->getRotation()
- : $this->rotation;
- logger()->debug('Template dimensions', [
- 'class' => get_class($template),
- 'unit' => $template->getUnit(),
- 'width' => $template->getWidth(),
- 'height' => $template->getHeight(),
- ]);
+ $this->rotation = method_exists($template, 'getRotation') ? (int)$template->getRotation() : $this->rotation;
+
return $this;
}
@@ -498,18 +477,8 @@ abstract class CustomTapeLabel extends Label
protected function hydrateFromEditorConfig(array $config): void
{
- $tape = $config['tape'] ?? [];
$content = $config['content'] ?? [];
$supports = $config['supports'] ?? [];
- $meta = $config['meta'] ?? [];
-
- $this->width = isset($tape['width']) ? (float)$tape['width'] : $this->width;
- $this->height = isset($tape['height']) ? (float)$tape['height'] : $this->height;
-
- $this->marginTop = isset($tape['margin_top']) ? (float)$tape['margin_top'] : $this->marginTop;
- $this->marginRight = isset($tape['margin_right']) ? (float)$tape['margin_right'] : $this->marginRight;
- $this->marginBottom = isset($tape['margin_bottom']) ? (float)$tape['margin_bottom'] : $this->marginBottom;
- $this->marginLeft = isset($tape['margin_left']) ? (float)$tape['margin_left'] : $this->marginLeft;
$this->supportFields = isset($supports['fields']) ? (int)$supports['fields'] : $this->supportFields;
$this->supportAssetTag = (bool)($supports['asset_tag'] ?? $this->supportAssetTag);
@@ -565,11 +534,7 @@ abstract class CustomTapeLabel extends Label
$pa = $this->getPrintableArea();
$layout = $this->buildLayout($pdf, $record, $pa);
- logger()->debug('Tape dimensions', [
- 'unit' => $this->getUnit(),
- 'width' => $this->getWidth(),
- 'height' => $this->getHeight(),
- ]);
+
$this->render1DBarcode($pdf, $record, $layout);
$this->renderLogo($pdf, $record, $layout);
$this->render2DBarcode($pdf, $record, $layout);
diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.php
index 9a04d0c8d8..6dde2bdf6a 100644
--- a/resources/views/settings/label-edit.blade.php
+++ b/resources/views/settings/label-edit.blade.php
@@ -265,6 +265,10 @@
</div>
<div id="content-config" class="box-body collapse in">
@foreach($config['content'] as $key => $value)
+ @if(in_array($key, ['barcode1D_placement', 'barcode2D_placement', 'logo_placement']))
+ <input type="hidden" name="content[{{ $key }}]" value="{{ $value }}">
+ @continue
+ @endif
<div class="form-group">
<label class="col-md-5 control-label">{{ $key }}</label>
<div class="col-md-7">