From cc5ac65909a8f028b32ce2905cd63d392cbe8507 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Nov 2025 18:43:35 +0000 Subject: [PATCH] Re-apply #18020, fixed #15107 (mostly) - added prefix and more options to label 2D tags --- app/Http/Controllers/SettingsController.php | 1 + app/Http/Requests/StoreLabelSettings.php | 1 + app/View/Label.php | 20 ++++- .../2025_11_04_173713_add_2d_label_prefix.php | 32 +++++++ .../lang/en-US/admin/settings/general.php | 12 ++- .../label2-field-definitions.blade.php | 4 +- .../views/partials/label2-preview.blade.php | 1 - resources/views/settings/labels.blade.php | 89 +++++++++++++------ 8 files changed, 126 insertions(+), 34 deletions(-) create mode 100644 database/migrations/2025_11_04_173713_add_2d_label_prefix.php 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 @@ +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 & 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 **text** will be displayed as bold', 'help_blank_to_use' => 'Leave blank to use the value from :setting_name', - 'help_default_will_use' => ':default will use the value from :setting_name.
Note that the value of the barcodes must comply with the respective barcode spec in order to be successfully generated. Please see the documentation 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 the documentation 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 @@
-
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()}}
-
+
@@ -41,9 +41,9 @@
has('label2_enable') ? 'error' : '' }}"> -
+
-