Skip to content

A free open source IT asset/license management system

Re-apply #18020, fixed #15107 (mostly) - added prefix and more options to label 2D tags

snipecc5ac65909a8
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index 8c57efa5eb..dac6fb4969 100644
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -772,6 +772,7 @@ class SettingsController extends Controller
$setting->label2_asset_logo = $request->input('label2_asset_logo');
$setting->label2_1d_type = $request->input('label2_1d_type');
$setting->label2_2d_type = $request->input('label2_2d_type');
+ $setting->label2_2d_prefix = $request->input('label2_2d_prefix');
$setting->label2_2d_target = $request->input('label2_2d_target');
$setting->label2_fields = $request->input('label2_fields');
$setting->label2_empty_row_count = $request->input('label2_empty_row_count');
diff --git a/app/Http/Requests/StoreLabelSettings.php b/app/Http/Requests/StoreLabelSettings.php
index 2b6fd83c6f..1f0e2a03ee 100644
--- a/app/Http/Requests/StoreLabelSettings.php
+++ b/app/Http/Requests/StoreLabelSettings.php
@@ -49,6 +49,7 @@ class StoreLabelSettings extends FormRequest
'labels_pagewidth' => 'numeric|nullable',
'labels_pageheight' => 'numeric|nullable',
'qr_text' => 'max:31|nullable',
+ 'label2_2d_prefix' => 'nullable|max:191',
'label2_template' => [
'required',
Rule::in($names),
diff --git a/app/View/Label.php b/app/View/Label.php
index 96f88e0f5f..684618e0f0 100644
--- a/app/View/Label.php
+++ b/app/View/Label.php
@@ -140,18 +140,32 @@ class Label implements View
if ($template->getSupport2DBarcode()) {
$barcode2DType = $settings->label2_2d_type;
if (($barcode2DType != 'none') && (!is_null($barcode2DType))) {
+
+ $label2_2d_prefix = $settings->label2_2d_prefix ? e($settings->label2_2d_prefix) : '';
switch ($settings->label2_2d_target) {
case 'ht_tag':
$barcode2DTarget = route('ht/assetTag', $asset->asset_tag);
break;
case 'plain_asset_id':
- $barcode2DTarget = (string) $asset->id;
+ $barcode2DTarget = $label2_2d_prefix.(string) $asset->id;
break;
case 'plain_asset_tag':
- $barcode2DTarget = $asset->asset_tag;
+ $barcode2DTarget = $label2_2d_prefix.$asset->asset_tag;
break;
case 'plain_serial_number':
- $barcode2DTarget = $asset->serial;
+ $barcode2DTarget = $label2_2d_prefix.$asset->serial;
+ break;
+ case 'plain_model_number':
+ $barcode2DTarget = $label2_2d_prefix.$asset->model->model_number ?? '';
+ break;
+ case 'plain_model_name':
+ $barcode2DTarget = $label2_2d_prefix.$asset->model->display_name ?? '';
+ break;
+ case 'plain_manufacturer_name':
+ $barcode2DTarget = $label2_2d_prefix.$asset->model->display_name;
+ break;
+ case 'plain_location_name':
+ $barcode2DTarget = $label2_2d_prefix.$asset->location->name;
break;
case 'location':
$barcode2DTarget = $asset->location_id
diff --git a/database/migrations/2025_11_04_173713_add_2d_label_prefix.php b/database/migrations/2025_11_04_173713_add_2d_label_prefix.php
new file mode 100644
index 0000000000..3a8c737633
--- /dev/null
+++ b/database/migrations/2025_11_04_173713_add_2d_label_prefix.php
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('settings', function (Blueprint $table) {
+ if (!Schema::hasColumn('settings', 'label2_2d_prefix')) {
+ $table->char('label2_2d_prefix', 191)->after('label2_2d_type')->nullable()->default(null);
+ }
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('settings', function (Blueprint $table) {
+ if (Schema::hasColumn('settings', 'label2_2d_prefix')) {
+ $table->dropColumn('label2_2d_prefix');
+ }
+ });
+ }
+};
diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php
index ceb34e1449..41c608c7ba 100644
--- a/resources/lang/en-US/admin/settings/general.php
+++ b/resources/lang/en-US/admin/settings/general.php
@@ -347,6 +347,7 @@ return [
'asset_tags_help' => 'Incrementing and prefixes',
'labels' => 'Labels',
'labels_title' => 'Update Label Settings',
+ 'labels_title_help' => 'Changes made here must be saved before they will be reflected in the labels or the preview below.',
'labels_help' => 'Barcodes &amp; label settings',
'purge_help' => 'Purge Deleted Records',
'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 @@ return [
'label2_1d_type_help' => 'Format for 1D barcodes',
'label2_2d_type' => '2D Barcode Type',
'label2_2d_type_help' => 'Format for 2D barcodes',
- 'label2_2d_target' => '2D Barcode Target',
- 'label2_2d_target_help' => 'The data that will be contained in the 2D barcode',
+ 'label2_2d_prefix' => '2D Barcode Prefix',
+ '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.',
+ 'label2_2d_target' => '2D Barcode Content',
+ '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.',
+ 'select_template' => 'Select a Template',
'label2_fields' => 'Field Definitions',
- '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.',
+ '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.',
'purge_barcodes' => 'Purge Barcodes',
'help_asterisk_bold' => 'Text entered as <code>**text**</code> will be displayed as bold',
'help_blank_to_use' => 'Leave blank to use the value from <code>:setting_name</code>',
- '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. ',
+ '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. ',
'asset_id' => 'Asset ID',
'data' => 'Data',
'default' => 'Default',
diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php
index bcb979d01e..5bb9668e8f 100644
--- a/resources/views/partials/label2-field-definitions.blade.php
+++ b/resources/views/partials/label2-field-definitions.blade.php
@@ -43,9 +43,11 @@
}
.l2fd-root {
- height: 400px;
+ height: 300px;
display: flex;
flex-direction: column;
+ overflow:auto!important;
+ max-height:400px;
}
.l2fd-title {
diff --git a/resources/views/partials/label2-preview.blade.php b/resources/views/partials/label2-preview.blade.php
index 084104aebe..fb8bc623ab 100644
--- a/resources/views/partials/label2-preview.blade.php
+++ b/resources/views/partials/label2-preview.blade.php
@@ -91,7 +91,6 @@
<div x-data="label2_preview" x-init="_init" class="l2p-root">
<div class="l2p-top">
- <label for="label2-preview">{{trans('general.preview')}}</label>
<button class="l2p-pop-button btn btn-default" x-on:click.prevent="popout" title="Pop Out"><i class="fa-solid fa-maximize"></i></button>
</div>
<iframe id="label2-preview" x-bind:src="previewURL"></iframe>
diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php
index e3e9a52f0c..f20ec46c54 100644
--- a/resources/views/settings/labels.blade.php
+++ b/resources/views/settings/labels.blade.php
@@ -25,7 +25,7 @@
{{csrf_field()}}
<div class="row">
- <div class="col-sm-10 col-sm-offset-1 col-md-10">
+ <div class="col-sm-8 col-sm-offset-2 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-header with-border">
@@ -41,9 +41,9 @@
<!-- New Label Engine -->
<div class="form-group" {{ $errors->has('label2_enable') ? 'error' : '' }}">
- <div class="col-md-7 col-md-offset-3">
+ <div class="col-md-9 col-md-offset-3">
- <label class="form-control">
+ <label class="form-control col-md-3">
<input type="checkbox" value="1" name="label2_enable"{{ ((old('label2_enable') == '1') || ($setting->label2_enable) == '1') ? ' checked="checked"' : '' }} aria-label="label2_enable">
<label for="label2_enable">{{ trans('admin/settings/general.label2_enable') }}</label>
</label>
@@ -63,23 +63,23 @@
@if ($setting->label2_enable)
<!-- New Settings -->
+ <fieldset name="select-template">
+ <x-form-legend>
+ {{ trans('admin/settings/general.select_template') }}
+ </x-form-legend>
+
<!-- Template -->
<div class="form-group{{ $errors->has('label2_template') ? ' has-error' : '' }}">
- <div class="col-md-9 col-md-offset-3">
+ <div class="col-md-12">
<table
data-columns="{{ \App\Presenters\LabelPresenter::dataTableLayout() }}"
data-cookie="true"
data-cookie-id-table="label2TemplateTable"
data-id-table="label2TemplateTable"
-
-
data-select-item-name="label2_template"
data-id-field="name"
-
-
-
data-side-pagination="server"
data-sort-name="name"
data-sort-order="asc"
@@ -101,6 +101,12 @@
</script>
</div>
</div>
+ </fieldset>
+
+ <fieldset name="label-settings">
+ <x-form-legend help_text="{{ trans('admin/settings/general.labels_title_help') }}">
+ {{ trans('admin/settings/general.labels_title') }}
+ </x-form-legend>
<!-- Title -->
<div class="form-group{{ $errors->has('label2_title') ? ' has-error' : '' }}">
@@ -132,7 +138,7 @@
<label for="label2_asset_logo">{{ trans('admin/settings/general.label2_asset_logo') }}</label>
</label>
<p class="help-block">
- {!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.label_logo')]) !!}
+ {!! trans('admin/settings/general.label2_asset_logo_help', ['setting_name' => trans('admin/settings/general.brand').' &gt; '.trans('admin/settings/general.logo_labels.logo')]) !!}
</p>
</div>
@@ -231,9 +237,7 @@
{!! $errors->first('label2_2d_type', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
<p class="help-block">
{{ trans('admin/settings/general.label2_2d_type_help', ['current' => $setting->barcode_type]) }}.
- {!!
- trans('admin/settings/general.help_default_will_use')
- !!}
+ {!! trans('admin/settings/general.help_default_will_use') !!}
</p>
</div>
</div>
@@ -292,6 +296,20 @@
</div>
@endif
@if ($setting->label2_enable)
+
+ <!-- 2D prefix -->
+ <div class="form-group{{ $errors->has('label2_2d_prefix') ? ' has-error' : '' }}">
+ <div class="col-md-3 text-right">
+ <label for="label2_2d_prefix" class="control-label">{{trans('admin/settings/general.label2_2d_prefix')}}</label>
+ </div>
+ <div class="col-md-7">
+ <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) }}">
+ {!! $errors->first('label2_2d_prefix', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
+ <p class="help-block">{!! trans('admin/settings/general.label2_2d_prefix_help') !!}</p>
+ </div>
+ </div>
+
+
<!-- 2D Barcode Target -->
<div class="form-group{{ $errors->has('label2_2d_target') ? ' has-error' : '' }}">
<div class="col-md-3 text-right">
@@ -301,9 +319,18 @@
<x-input.select
name="label2_2d_target"
id="label2_2d_target"
- :options="['hardware_id'=>'/hardware/{id} ('.trans('admin/settings/general.default').')',
- 'ht_tag'=>'/ht/{asset_tag}',
- 'location' => '/location/{location_id}',
+ style="min-width:50%"
+ :options="[
+ 'hardware_id'=> config('app.url').'/hardware/{id} ('.trans('admin/settings/general.default').')',
+ 'ht_tag'=> config('app.url').'/ht/{asset_tag}',
+ 'location' => config('app.url').'/locations/{location_id}',
+ 'plain_asset_id'=> trans('admin/settings/general.asset_id'),
+ 'plain_asset_tag'=> trans('general.asset_tag'),
+ 'plain_serial_number'=> trans('general.serial_number'),
+ 'plain_model_number'=> trans('general.model_no'),
+ 'plain_model_name'=> trans('general.asset_model'),
+ 'plain_manufacturer_name'=> trans('general.manufacturer'),
+ 'plain_location_name'=> trans('general.location'),
]"
:selected="old('label2_2d_target', $setting->label2_2d_target)"
class="col-md-4"
@@ -336,21 +363,32 @@
{!! $errors->first('label2_empty_row_count', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
- <div class="col-md-9 col-md-offset-3" style="margin-bottom: 10px;">
- @include('partials.label2-preview')
- </div>
+ </fieldset>
+
+
+ <fieldset name="field-definitions">
+ <x-form-legend help_text="{!! trans('admin/settings/general.label2_fields_help') !!}">
+ Label Fields
+ </x-form-legend>
<!-- Fields -->
<div class="form-group {{ $errors->has('label2_fields') ? 'error' : '' }}">
- <div class="col-md-3 text-right">
- <label for="label2_fields">{{ trans('admin/settings/general.label2_fields') }}</label>
- </div>
- <div class="col-md-9">
+ <div class="col-md-12">
@include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields), 'customFields' => $customFields, 'template' => $setting->label2_template])
{!! $errors->first('label2_fields', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
- <p class="help-block">{{ trans('admin/settings/general.label2_fields_help') }}</p>
</div>
</div>
+ </fieldset>
+
+ <fieldset name="label-preview">
+ <x-form-legend>
+ Label Preview
+ </x-form-legend>
+ <div class="col-md-12" style="margin-bottom: 10px;">
+ @include('partials.label2-preview')
+ </div>
+ </fieldset>
+
@include('partials.bootstrap-table')
@else
@@ -510,7 +548,7 @@
@endif
@if(!$setting->label2_enable)
<div class="form-group">
- <div class="col-md-3 text-right">
+ <div class="col-md-3">
<label for="labels_display" class="control-label">{{ trans('admin/settings/general.label_fields') }}</label>
</div>
<div class="col-md-9">
@@ -537,6 +575,7 @@
</div> <!--/.col-md-9-->
</div> <!--/.form-group-->
@endif
+ </fieldset>
</div>
</div> <!--/.box-body-->