Skip to content

Commit cc5ac65

Browse files
committed
Re-apply #18020, fixed #15107 (mostly) - added prefix and more options to label 2D tags
1 parent 4a39d7c commit cc5ac65

File tree

8 files changed

+126
-34
lines changed

8 files changed

+126
-34
lines changed

app/Http/Controllers/SettingsController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ public function postLabels(StoreLabelSettings $request) : RedirectResponse
772772
$setting->label2_asset_logo = $request->input('label2_asset_logo');
773773
$setting->label2_1d_type = $request->input('label2_1d_type');
774774
$setting->label2_2d_type = $request->input('label2_2d_type');
775+
$setting->label2_2d_prefix = $request->input('label2_2d_prefix');
775776
$setting->label2_2d_target = $request->input('label2_2d_target');
776777
$setting->label2_fields = $request->input('label2_fields');
777778
$setting->label2_empty_row_count = $request->input('label2_empty_row_count');

app/Http/Requests/StoreLabelSettings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function rules(): array
4949
'labels_pagewidth' => 'numeric|nullable',
5050
'labels_pageheight' => 'numeric|nullable',
5151
'qr_text' => 'max:31|nullable',
52+
'label2_2d_prefix' => 'nullable|max:191',
5253
'label2_template' => [
5354
'required',
5455
Rule::in($names),

app/View/Label.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,32 @@ public function render(callable $callback = null)
140140
if ($template->getSupport2DBarcode()) {
141141
$barcode2DType = $settings->label2_2d_type;
142142
if (($barcode2DType != 'none') && (!is_null($barcode2DType))) {
143+
144+
$label2_2d_prefix = $settings->label2_2d_prefix ? e($settings->label2_2d_prefix) : '';
143145
switch ($settings->label2_2d_target) {
144146
case 'ht_tag':
145147
$barcode2DTarget = route('ht/assetTag', $asset->asset_tag);
146148
break;
147149
case 'plain_asset_id':
148-
$barcode2DTarget = (string) $asset->id;
150+
$barcode2DTarget = $label2_2d_prefix.(string) $asset->id;
149151
break;
150152
case 'plain_asset_tag':
151-
$barcode2DTarget = $asset->asset_tag;
153+
$barcode2DTarget = $label2_2d_prefix.$asset->asset_tag;
152154
break;
153155
case 'plain_serial_number':
154-
$barcode2DTarget = $asset->serial;
156+
$barcode2DTarget = $label2_2d_prefix.$asset->serial;
157+
break;
158+
case 'plain_model_number':
159+
$barcode2DTarget = $label2_2d_prefix.$asset->model->model_number ?? '';
160+
break;
161+
case 'plain_model_name':
162+
$barcode2DTarget = $label2_2d_prefix.$asset->model->display_name ?? '';
163+
break;
164+
case 'plain_manufacturer_name':
165+
$barcode2DTarget = $label2_2d_prefix.$asset->model->display_name;
166+
break;
167+
case 'plain_location_name':
168+
$barcode2DTarget = $label2_2d_prefix.$asset->location->name;
155169
break;
156170
case 'location':
157171
$barcode2DTarget = $asset->location_id
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('settings', function (Blueprint $table) {
15+
if (!Schema::hasColumn('settings', 'label2_2d_prefix')) {
16+
$table->char('label2_2d_prefix', 191)->after('label2_2d_type')->nullable()->default(null);
17+
}
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*/
24+
public function down(): void
25+
{
26+
Schema::table('settings', function (Blueprint $table) {
27+
if (Schema::hasColumn('settings', 'label2_2d_prefix')) {
28+
$table->dropColumn('label2_2d_prefix');
29+
}
30+
});
31+
}
32+
};

resources/lang/en-US/admin/settings/general.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
'asset_tags_help' => 'Incrementing and prefixes',
348348
'labels' => 'Labels',
349349
'labels_title' => 'Update Label Settings',
350+
'labels_title_help' => 'Changes made here must be saved before they will be reflected in the labels or the preview below.',
350351
'labels_help' => 'Barcodes &amp; label settings',
351352
'purge_help' => 'Purge Deleted Records',
352353
'ldap_extension_warning' => 'It does not look like the LDAP extension is installed or enabled on this server. You can still save your settings, but you will need to enable the LDAP extension for PHP before LDAP syncing or login will work.',
@@ -381,14 +382,17 @@
381382
'label2_1d_type_help' => 'Format for 1D barcodes',
382383
'label2_2d_type' => '2D Barcode Type',
383384
'label2_2d_type_help' => 'Format for 2D barcodes',
384-
'label2_2d_target' => '2D Barcode Target',
385-
'label2_2d_target_help' => 'The data that will be contained in the 2D barcode',
385+
'label2_2d_prefix' => '2D Barcode Prefix',
386+
'label2_2d_prefix_help' => 'This text will be prepended to the 2D Barcode Target value selected below when the 2D code is scanned. This can be used to prepend an external URL or any other value that you might need.',
387+
'label2_2d_target' => '2D Barcode Content',
388+
'label2_2d_target_help' => 'The data that will be contained in the 2D barcode. This can link to the asset directly in Snipe-IT or can be one of the non-linked field values. If you use the prefix above, it will be prepended to this value.',
389+
'select_template' => 'Select a Template',
386390
'label2_fields' => 'Field Definitions',
387-
'label2_fields_help' => 'Fields can be added, removed, and reordered in the left column. For each field, multiple options for Label and DataSource can be added, removed, and reordered in the right column.',
391+
'label2_fields_help' => 'Fields can be added, removed, and reordered in the left column. For each field, multiple options for Label and DataSource can be added, removed, and reordered in the right column. Field changes made here will be reflected immediately in the preview below but must be saved for them to apply to new labels.',
388392
'purge_barcodes' => 'Purge Barcodes',
389393
'help_asterisk_bold' => 'Text entered as <code>**text**</code> will be displayed as bold',
390394
'help_blank_to_use' => 'Leave blank to use the value from <code>:setting_name</code>',
391-
'help_default_will_use' => '<code>:default</code> will use the value from <code>:setting_name</code>. <br>Note that the value of the barcodes must comply with the respective barcode spec in order to be successfully generated. Please see <a href="https://snipe-it.readme.io/docs/barcodes">the documentation <i class="fa fa-external-link"></i></a> for more details. ',
395+
'help_default_will_use' => 'Note that the value of the barcodes must comply with the respective barcode spec in order to be successfully generated. Please see <a href="https://snipe-it.readme.io/docs/barcodes">the documentation <i class="fa fa-external-link"></i></a> for more details. ',
392396
'asset_id' => 'Asset ID',
393397
'data' => 'Data',
394398
'default' => 'Default',

resources/views/partials/label2-field-definitions.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
}
4444
4545
.l2fd-root {
46-
height: 400px;
46+
height: 300px;
4747
display: flex;
4848
flex-direction: column;
49+
overflow:auto!important;
50+
max-height:400px;
4951
}
5052
5153
.l2fd-title {

resources/views/partials/label2-preview.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191

9292
<div x-data="label2_preview" x-init="_init" class="l2p-root">
9393
<div class="l2p-top">
94-
<label for="label2-preview">{{trans('general.preview')}}</label>
9594
<button class="l2p-pop-button btn btn-default" x-on:click.prevent="popout" title="Pop Out"><i class="fa-solid fa-maximize"></i></button>
9695
</div>
9796
<iframe id="label2-preview" x-bind:src="previewURL"></iframe>

resources/views/settings/labels.blade.php

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{{csrf_field()}}
2626

2727
<div class="row">
28-
<div class="col-sm-10 col-sm-offset-1 col-md-10">
28+
<div class="col-sm-8 col-sm-offset-2 col-md-8 col-md-offset-2">
2929

3030
<div class="panel box box-default">
3131
<div class="box-header with-border">
@@ -41,9 +41,9 @@
4141
<!-- New Label Engine -->
4242
<div class="form-group" {{ $errors->has('label2_enable') ? 'error' : '' }}">
4343
44-
<div class="col-md-7 col-md-offset-3">
44+
<div class="col-md-9 col-md-offset-3">
4545
46-
<label class="form-control">
46+
<label class="form-control col-md-3">
4747
<input type="checkbox" value="1" name="label2_enable"{{ ((old('label2_enable') == '1') || ($setting->label2_enable) == '1') ? ' checked="checked"' : '' }} aria-label="label2_enable">
4848
<label for="label2_enable">{{ trans('admin/settings/general.label2_enable') }}</label>
4949
</label>
@@ -63,23 +63,23 @@
6363
@if ($setting->label2_enable)
6464
<!-- New Settings -->
6565
66+
<fieldset name="select-template">
67+
<x-form-legend>
68+
{{ trans('admin/settings/general.select_template') }}
69+
</x-form-legend>
70+
6671
<!-- Template -->
6772
<div class="form-group{{ $errors->has('label2_template') ? ' has-error' : '' }}">
6873

69-
<div class="col-md-9 col-md-offset-3">
74+
<div class="col-md-12">
7075
<table
7176

7277
data-columns="{{ \App\Presenters\LabelPresenter::dataTableLayout() }}"
7378
data-cookie="true"
7479
data-cookie-id-table="label2TemplateTable"
7580
data-id-table="label2TemplateTable"
76-
77-
7881
data-select-item-name="label2_template"
7982
data-id-field="name"
80-
81-
82-
8383
data-side-pagination="server"
8484
data-sort-name="name"
8585
data-sort-order="asc"
@@ -101,6 +101,12 @@ class="table table-striped snipe-table"
101101
</script>
102102
</div>
103103
</div>
104+
</fieldset>
105+
106+
<fieldset name="label-settings">
107+
<x-form-legend help_text="{{ trans('admin/settings/general.labels_title_help') }}">
108+
{{ trans('admin/settings/general.labels_title') }}
109+
</x-form-legend>
104110

105111
<!-- Title -->
106112
<div class="form-group{{ $errors->has('label2_title') ? ' has-error' : '' }}">
@@ -132,7 +138,7 @@ class="table table-striped snipe-table"
132138
<label for="label2_asset_logo">{{ trans('admin/settings/general.label2_asset_logo') }}</label>
133139
</label>
134140
<p class="help-block">
135-
{!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.label_logo')]) !!}
141+
{!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.logo_labels.logo')]) !!}
136142
</p>
137143
138144
</div>
@@ -231,9 +237,7 @@ class="col-md-4"
231237
{!! $errors->first('label2_2d_type', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
232238
<p class="help-block">
233239
{{ trans('admin/settings/general.label2_2d_type_help', ['current' => $setting->barcode_type]) }}.
234-
{!!
235-
trans('admin/settings/general.help_default_will_use')
236-
!!}
240+
{!! trans('admin/settings/general.help_default_will_use') !!}
237241
</p>
238242
</div>
239243
</div>
@@ -292,6 +296,20 @@ class="form-control"
292296
</div>
293297
@endif
294298
@if ($setting->label2_enable)
299+
300+
<!-- 2D prefix -->
301+
<div class="form-group{{ $errors->has('label2_2d_prefix') ? ' has-error' : '' }}">
302+
<div class="col-md-3 text-right">
303+
<label for="label2_2d_prefix" class="control-label">{{trans('admin/settings/general.label2_2d_prefix')}}</label>
304+
</div>
305+
<div class="col-md-7">
306+
<input class="form-control" aria-label="label2_2d_prefix" name="label2_2d_prefix" type="text" id="label2_2d_prefix" value="{{ old('label2_2d_prefix', $setting->label2_2d_prefix) }}">
307+
{!! $errors->first('label2_2d_prefix', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
308+
<p class="help-block">{!! trans('admin/settings/general.label2_2d_prefix_help') !!}</p>
309+
</div>
310+
</div>
311+
312+
295313
<!-- 2D Barcode Target -->
296314
<div class="form-group{{ $errors->has('label2_2d_target') ? ' has-error' : '' }}">
297315
<div class="col-md-3 text-right">
@@ -301,9 +319,18 @@ class="form-control"
301319
<x-input.select
302320
name="label2_2d_target"
303321
id="label2_2d_target"
304-
:options="['hardware_id'=>'/hardware/{id} ('.trans('admin/settings/general.default').')',
305-
'ht_tag'=>'/ht/{asset_tag}',
306-
'location' => '/location/{location_id}',
322+
style="min-width:50%"
323+
:options="[
324+
'hardware_id'=> config('app.url').'/hardware/{id} ('.trans('admin/settings/general.default').')',
325+
'ht_tag'=> config('app.url').'/ht/{asset_tag}',
326+
'location' => config('app.url').'/locations/{location_id}',
327+
'plain_asset_id'=> trans('admin/settings/general.asset_id'),
328+
'plain_asset_tag'=> trans('general.asset_tag'),
329+
'plain_serial_number'=> trans('general.serial_number'),
330+
'plain_model_number'=> trans('general.model_no'),
331+
'plain_model_name'=> trans('general.asset_model'),
332+
'plain_manufacturer_name'=> trans('general.manufacturer'),
333+
'plain_location_name'=> trans('general.location'),
307334
]"
308335
:selected="old('label2_2d_target', $setting->label2_2d_target)"
309336
class="col-md-4"
@@ -336,21 +363,32 @@ class="form-control"
336363
{!! $errors->first('label2_empty_row_count', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
337364
</div>
338365
</div>
339-
<div class="col-md-9 col-md-offset-3" style="margin-bottom: 10px;">
340-
@include('partials.label2-preview')
341-
</div>
366+
</fieldset>
367+
368+
369+
<fieldset name="field-definitions">
370+
<x-form-legend help_text="{!! trans('admin/settings/general.label2_fields_help') !!}">
371+
Label Fields
372+
</x-form-legend>
342373
<!-- Fields -->
343374
<div class="form-group {{ $errors->has('label2_fields') ? 'error' : '' }}">
344-
<div class="col-md-3 text-right">
345-
<label for="label2_fields">{{ trans('admin/settings/general.label2_fields') }}</label>
346-
</div>
347-
<div class="col-md-9">
375+
<div class="col-md-12">
348376
@include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields), 'customFields' => $customFields, 'template' => $setting->label2_template])
349377
{!! $errors->first('label2_fields', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
350-
<p class="help-block">{{ trans('admin/settings/general.label2_fields_help') }}</p>
351378
</div>
352379
</div>
353380

381+
</fieldset>
382+
383+
<fieldset name="label-preview">
384+
<x-form-legend>
385+
Label Preview
386+
</x-form-legend>
387+
<div class="col-md-12" style="margin-bottom: 10px;">
388+
@include('partials.label2-preview')
389+
</div>
390+
</fieldset>
391+
354392
@include('partials.bootstrap-table')
355393

356394
@else
@@ -510,7 +548,7 @@ class="form-control"
510548
@endif
511549
@if(!$setting->label2_enable)
512550
<div class="form-group">
513-
<div class="col-md-3 text-right">
551+
<div class="col-md-3">
514552
<label for="labels_display" class="control-label">{{ trans('admin/settings/general.label_fields') }}</label>
515553
</div>
516554
<div class="col-md-9">
@@ -537,6 +575,7 @@ class="form-control"
537575
</div> <!--/.col-md-9-->
538576
</div> <!--/.form-group-->
539577
@endif
578+
</fieldset>
540579
</div>
541580

542581
</div> <!--/.box-body-->

0 commit comments

Comments
 (0)