Skip to content

A free open source IT asset/license management system

attempting to get the preview working

Godfrey Mf948f298501d
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php
index 478c879241..209148d43e 100755
--- a/app/Http/Controllers/LabelsController.php
+++ b/app/Http/Controllers/LabelsController.php
@@ -7,6 +7,7 @@ use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company;
use App\Models\CustomField;
+use App\Models\Labels\DefaultLabel;
use App\Models\Labels\Label;
use App\Models\Location;
use App\Models\Manufacturer;
@@ -87,7 +88,7 @@ class LabelsController extends Controller
}
}
- return (new LabelView)
+ return (new LabelView($template->getName()))
->with('assets', collect([$exampleAsset]))
->with('settings', $settings)
->with('template', $template)
@@ -100,18 +101,116 @@ class LabelsController extends Controller
{
$selectedLabel = $request->get('label');
+ if ($selectedLabel) {
+ $selectedLabel = str_replace('/', '\\', $selectedLabel);
+ }
+
try {
$label = $selectedLabel
? Label::find($selectedLabel)
: new \App\Models\Labels\DefaultLabel();
} catch (\Throwable $e) {
$label = new \App\Models\Labels\DefaultLabel();
- $selectedLabel = null;
}
return view('settings.label-edit', [
'config' => $label->toEditorConfig(),
- 'selectedLabel' => $selectedLabel,
+ 'selectedLabel' => Label::find(),
]);
}
+
+ public function customLabelPreview(Request $request, string $labelName)
+ {
+ $labelName = str_replace('/', '\\', $labelName);
+
+ $template = $labelName === 'DefaultLabel'
+ ? new DefaultLabel()
+ : Label::find($labelName);
+
+ $exampleAsset = new Asset;
+ $exampleAsset->id = 999999;
+ $exampleAsset->name = 'JEN-867-5309';
+ $exampleAsset->asset_tag = '100001';
+ $exampleAsset->serial = 'SN9876543210';
+ $exampleAsset->asset_eol_date = '2025-01-01';
+ $exampleAsset->order_number = '12345';
+ $exampleAsset->purchase_date = '2023-01-01';
+ $exampleAsset->status_id = 1;
+ $exampleAsset->location_id = 1;
+
+ $exampleAsset->company = new Company([
+ 'name' => trans('admin/labels/table.example_company'),
+ 'phone' => '1-555-555-5555',
+ 'email' => '[email protected]',
+ ]);
+
+ $exampleAsset->setRelation('assignedTo', new User([
+ 'first_name' => 'Luke',
+ 'last_name' => 'Skywalker',
+ ]));
+
+ $exampleAsset->defaultLoc = new Location([
+ 'name' => trans('admin/labels/table.example_defaultloc'),
+ 'phone' => '1-555-555-5555',
+ ]);
+
+ $exampleAsset->location = new Location([
+ 'name' => trans('admin/labels/table.example_location'),
+ 'phone' => '1-555-555-5555',
+ ]);
+
+ $exampleAsset->model = new AssetModel;
+ $exampleAsset->model->id = 999999;
+ $exampleAsset->model->name = trans('admin/labels/table.example_model');
+ $exampleAsset->model->model_number = 'MDL5678';
+
+ $exampleAsset->model->manufacturer = new Manufacturer;
+ $exampleAsset->model->manufacturer->id = 999999;
+ $exampleAsset->model->manufacturer->name = trans('admin/labels/table.example_manufacturer');
+ $exampleAsset->model->manufacturer->support_email = '[email protected]';
+ $exampleAsset->model->manufacturer->support_phone = '1-555-555-5555';
+ $exampleAsset->model->manufacturer->support_url = 'https://example.com';
+
+ $exampleAsset->supplier = new Supplier([
+ 'name' => trans('admin/labels/table.example_company'),
+ ]);
+
+ $exampleAsset->model->category = new Category;
+ $exampleAsset->model->category->id = 999999;
+ $exampleAsset->model->category->name = trans('admin/labels/table.example_category');
+
+ $customFieldColumns = CustomField::where('field_encrypted', 0)->pluck('db_column');
+
+ collect(explode(';', Setting::getSettings()->label2_fields))
+ ->filter()
+ ->each(function ($item) use ($customFieldColumns, $exampleAsset) {
+ $pair = explode('=', $item);
+
+ if (isset($pair[0], $pair[1]) && $customFieldColumns->contains($pair[1])) {
+ $exampleAsset->{$pair[1]} = "{{$pair[0]}}";
+ }
+ });
+
+ $settings = Setting::getSettings();
+
+ $overrides = array_replace_recursive(
+ $request->input('page', []),
+ $request->input('grid', []),
+ $request->input('label', []),
+ $request->input('content', []),
+ $request->input('supports', [])
+ );
+
+
+ foreach ($overrides as $key => $value) {
+ $settings->{$key} = $value;
+ }
+
+ return (new LabelView)
+ ->with('assets', collect([$exampleAsset]))
+ ->with('settings', $settings)
+ ->with('template', $template)
+ ->with('bulkedit', false)
+ ->with('count', 0);
+ }
}
diff --git a/resources/views/partials/custom-label-preview.blade.php b/resources/views/partials/custom-label-preview.blade.php
new file mode 100644
index 0000000000..8b138774c1
--- /dev/null
+++ b/resources/views/partials/custom-label-preview.blade.php
@@ -0,0 +1,121 @@
+@once
+ @push('css')
+ <style>
+ :root {
+ --clp-height: 400px;
+ --clp-background-color: aliceblue;
+ }
+
+ .clp-root,
+ .clp-root * {
+ box-sizing: border-box;
+ }
+
+ .clp-root {
+ width: 100%;
+ height: var(--clp-height);
+ display: flex;
+ flex-direction: column;
+ }
+
+ .clp-root > .clp-top {
+ display: flex;
+ flex-direction: row;
+ align-items: end;
+ justify-content: flex-end;
+ margin-bottom: 6px;
+ }
+
+ .clp-root > .clp-top > .clp-pop-button {
+ padding: 3px 6px;
+ }
+
+ .clp-root > iframe {
+ flex: 1;
+ width: 100%;
+ border: 0;
+ overflow: auto;
+ background-color: var(--clp-background-color);
+ }
+ </style>
+ @endpush
+@endonce
+
+@push('js')
+ <script>
+ document.addEventListener('alpine:init', () => {
+ Alpine.data('custom_label_preview', () => ({
+ _form: null,
+ _popped: null,
+ _previewURL: '',
+
+ get previewURL() {
+ return this._previewURL;
+ },
+
+ set previewURL(url) {
+ this._previewURL = url;
+
+ if (this._popped && !this._popped.closed) {
+ this._popped.location = url;
+ }
+ },
+
+ _init() {
+ this._form = document.getElementById('label-customizer-form');
+
+ if (!this._form) {
+ return;
+ }
+
+ this.updateURL();
+
+ this._form.addEventListener('input', this.updateURL.bind(this));
+ this._form.addEventListener('change', this.updateURL.bind(this));
+ },
+
+ updateURL() {
+ const fields = $(this._form).serializeArray();
+
+ const templateField = fields.find(field => field.name === 'template');
+ if (!templateField || !templateField.value) {
+ return;
+ }
+
+ const payload = {};
+
+ fields.forEach(field => {
+ if (['_token'].includes(field.name)) {
+ return;
+ }
+
+ payload[field.name] = field.value;
+ });
+
+ const template = templateField.value;
+
+ this.previewURL = '{{ route("labels.customizer-preview", ["labelName" => ":label"]) }}'
+ .replace(':label', template.replaceAll('\\', '/'))
+ .concat('?' + $.param(payload) + '#toolbar=0');
+ },
+
+ popout() {
+ if (!this.previewURL) {
+ return;
+ }
+
+ this._popped = window.open(this.previewURL);
+ }
+ }));
+ });
+ </script>
+@endpush
+
+<div x-data="custom_label_preview" x-init="_init" class="clp-root">
+ <div class="clp-top">
+ <button class="clp-pop-button btn btn-default" x-on:click.prevent="popout" title="Pop Out">
+ <i class="fa-solid fa-maximize"></i>
+ </button>
+ </div>
+ <iframe x-bind:src="previewURL"></iframe>
+</div>
\ No newline at end of file
diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.php
index 9460f1d784..26696669e8 100644
--- a/resources/views/settings/label-edit.blade.php
+++ b/resources/views/settings/label-edit.blade.php
@@ -14,266 +14,275 @@
{{-- Page content --}}
@section('content')
<style>
- .label-customizer-layout {
+ .label-customizer-shell {
+ height: calc(100vh - 120px);
display: flex;
flex-direction: column;
- height: calc(100vh - 140px);
- min-height: 600px;
+ min-height: 0;
}
- .label-preview-panel {
+ .label-preview-sticky {
position: sticky;
top: 0;
- z-index: 10;
- background: #fff;
+ z-index: 20;
+ background: #222d32;
padding-bottom: 12px;
- border-bottom: 1px solid #ddd;
- flex-shrink: 0;
+ flex: 0 0 auto;
}
- .label-form-panel {
+ .label-form-scroll {
flex: 1 1 auto;
- overflow-y: auto;
- padding-top: 15px;
min-height: 0;
+ overflow-y: auto;
+ padding-top: 10px;
}
- .label-config-section {
- margin-bottom: 24px;
+ .label-config-grid {
+ display: grid;
+ grid-template-columns: repeat(1, minmax(320px, 1fr));
+ gap: 16px;
+ align-items: start;
}
- .label-config-section h3 {
- margin-top: 0;
- margin-bottom: 12px;
+ @media (min-width: 992px) {
+ .label-config-grid {
+ grid-template-columns: repeat(2, minmax(320px, 1fr));
+ }
}
- .label-config-row {
- display: flex;
- align-items: center;
- gap: 12px;
- margin-bottom: 10px;
+ .label-config-panel {
+ margin-bottom: 0;
+ }
+
+ .label-config-panel .box-body {
+ padding-right: 15px;
}
- .label-config-row label {
- min-width: 180px;
+ .label-config-panel .form-group:last-child {
margin-bottom: 0;
- font-weight: 600;
}
- .label-config-row input[type="number"],
- .label-config-row input[type="text"] {
- max-width: 220px;
+ .label-config-panel .form-control {
+ width: 120px;
+ max-width: 120px;
+ }
+
+ .label-form-header,
+ .label-form-footer {
+ grid-column: 1 / -1;
}
</style>
- <div class="col-sm-8 col-sm-offset-2 col-md-8 col-md-offset-2">
- <div class="label-customizer-layout">
- <fieldset name="label-preview" class="label-preview-panel">
+
+ <div class="col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1">
+ <div class="label-customizer-shell">
+
+ <fieldset name="label-preview" class="label-preview-sticky">
<div class="col-md-12" style="margin-bottom: 10px;">
- @include('partials.label2-preview')
+ @include('partials.custom-label-preview')
</div>
</fieldset>
-
- <div class="label-form-panel">
- <form method="POST" action="#">
+ <div class="label-form-scroll">
+ <form id="label-customizer-form" method="POST" action="#" class="form-horizontal">
@csrf
- <h2>{{ $selectedLabel ?: 'Default Label' }}</h2>
- <p>Unit: {{ $config['unit'] }}</p>
+ @php
+ $printable = $config['label_printable_area'] ?? $config['printable_area'] ?? null;
+ @endphp
+ <input type="hidden" name="template" value="{{ $selectedLabel ?: 'DefaultLabel' }}">
+ <div class="label-config-grid">
+ <div class="label-form-header">
+ @php
+ $defaultName = $selectedLabel ? 'Copy of '.$selectedLabel : 'Custom Label';
+ @endphp
- @if(!empty($config['page']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#page-config"
- aria-expanded="true"
- aria-controls="page-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Page</strong>
- </button>
+ <div class="form-group" style="margin-left: 0; margin-right: 0;">
+ <label for="name" style="display:block; margin-bottom:6px;">
+ Label Name
+ </label>
+
+ <input
+ id="name"
+ type="text"
+ name="name"
+ class="form-control"
+ value="{{ old('name', $defaultName) }}"
+ placeholder="Enter label name"
+ style="max-width: 320px;"
+ >
</div>
- <div id="page-config" class="panel-collapse collapse in">
- <div class="panel-body">
+ <p class="text-muted">
+ Unit: {{ $config['unit'] }} (applies to all dimensions)
+ </p>
+ </div>
+
+ @if(!empty($config['page']))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Page</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#page-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
+ </div>
+ <div id="page-config" class="box-body collapse in">
@foreach($config['page'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" name="page[{{ $key }}]"
- value="{{ $value }}" class="form-control">
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ <input type="number" step="0.001" name="page[{{ $key }}]"
+ value="{{ $value }}" class="form-control">
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- @if(!empty($config['grid']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#grid-config"
- aria-expanded="false"
- aria-controls="grid-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Grid</strong>
- </button>
- </div>
- <div id="grid-config" class="panel-collapse collapse in">
- <div class="panel-body">
+ @if(!empty($config['grid']))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Grid</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#grid-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
+ </div>
+ <div id="grid-config" class="box-body collapse in">
@foreach($config['grid'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" name="grid[{{ $key }}]"
- value="{{ $value }}" class="form-control">
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ <input type="number" step="0.001" name="grid[{{ $key }}]"
+ value="{{ $value }}" class="form-control">
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- @if(!empty($config['label']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#label-config"
- aria-expanded="false"
- aria-controls="label-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Label</strong>
- </button>
- </div>
- <div id="label-config" class="panel-collapse collapse in">
- <div class="panel-body">
+ @if(!empty($config['label']))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Label</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#label-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
+ </div>
+ <div id="label-config" class="box-body collapse in">
@foreach($config['label'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" name="label[{{ $key }}]"
- value="{{ $value }}" class="form-control">
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ <input type="number" step="0.001" name="label[{{ $key }}]"
+ value="{{ $value }}" class="form-control">
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- @if(!empty($config['label_printable_area'] ?? null))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#printable-area-config"
- aria-expanded="false"
- aria-controls="printable-area-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Printable Area</strong>
- </button>
- </div>
- <div id="printable-area-config" class="panel-collapse collapse in">
- <div class="panel-body">
- @foreach($config['label_printable_area'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" value="{{ $value }}" class="form-control"
- disabled>
- </div>
- @endforeach
+ @if(!empty($printable))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Printable Area</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#printable-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
</div>
- </div>
- </div>
- @elseif(!empty($config['printable_area']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#printable-area-config"
- aria-expanded="false"
- aria-controls="printable-area-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Printable Area</strong>
- </button>
- </div>
- <div id="printable-area-config" class="panel-collapse collapse in">
- <div class="panel-body">
- @foreach($config['printable_area'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" value="{{ $value }}" class="form-control"
- disabled>
+ <div id="printable-config" class="box-body collapse in">
+ @foreach($printable as $key => $value)
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ <input type="number" step="0.001" value="{{ $value }}"
+ class="form-control" disabled>
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- @if(!empty($config['content']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#content-config"
- aria-expanded="false"
- aria-controls="content-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Content</strong>
- </button>
- </div>
- <div id="content-config" class="panel-collapse collapse in">
- <div class="panel-body">
+ @if(!empty($config['content']))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Content</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#content-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
+ </div>
+ <div id="content-config" class="box-body collapse in">
@foreach($config['content'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
- <input type="number" step="0.001" name="content[{{ $key }}]"
- value="{{ $value }}" class="form-control">
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ <input type="number" step="0.001" name="content[{{ $key }}]"
+ value="{{ $value }}" class="form-control">
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- @if(!empty($config['supports']))
- <div class="label-config-section panel panel-default">
- <div class="panel-heading" style="padding: 0;">
- <button type="button"
- class="btn btn-link btn-block text-left"
- data-toggle="collapse"
- data-target="#supports-config"
- aria-expanded="false"
- aria-controls="supports-config"
- style="padding: 12px 15px; text-decoration: none;">
- <strong>Supports</strong>
- </button>
- </div>
- <div id="supports-config" class="panel-collapse collapse in">
- <div class="panel-body">
+ @if(!empty($config['supports']))
+ <div class="panel box box-default label-config-panel">
+ <div class="box-header with-border">
+ <h3 class="box-title">Supports</h3>
+ <div class="box-tools pull-right">
+ <button type="button" class="btn btn-box-tool" data-toggle="collapse"
+ data-target="#supports-config">
+ <i class="fa fa-minus"></i>
+ </button>
+ </div>
+ </div>
+ <div id="supports-config" class="box-body collapse in">
@foreach($config['supports'] as $key => $value)
- <div class="label-config-row">
- <label>{{ $key }}</label>
-
- @if(is_bool($value))
- <input type="checkbox" name="supports[{{ $key }}]"
- value="1" {{ $value ? 'checked' : '' }}>
- @else
- <input type="number" step="1" name="supports[{{ $key }}]"
- value="{{ $value }}" class="form-control">
- @endif
+ <div class="form-group">
+ <label class="col-md-5 control-label">{{ $key }}</label>
+ <div class="col-md-7">
+ @if(is_bool($value))
+ <label class="form-control" style="height:auto; min-height:34px;">
+ <input type="checkbox" name="supports[{{ $key }}]"
+ value="1" {{ $value ? 'checked' : '' }}>
+ {{ $key }}
+ </label>
+ @else
+ <input type="number" step="1" name="supports[{{ $key }}]"
+ value="{{ $value }}" class="form-control">
+ @endif
+ </div>
</div>
@endforeach
</div>
</div>
- </div>
- @endif
+ @endif
- <button type="submit" class="btn btn-primary">Save</button>
+ <div class="label-form-footer">
+ <div class="box-footer clearfix" style="padding-left: 0; padding-right: 0;">
+ <div class="pull-right">
+ <button type="submit" class="btn btn-success">
+ <i class="fa fa-check"></i> Save
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
</form>
</div>
</div>
diff --git a/routes/web.php b/routes/web.php
index e4fc64ff4e..ba68cb7f6b 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -216,12 +216,15 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser
->breadcrumbs(fn (Trail $trail) =>
$trail->parent('settings.index')
->push(trans('admin/settings/general.labels_title'), route('settings.labels.index')));
+ Route::get('/labels/customizer-preview/{labelName}', [LabelsController::class, 'customLabelPreview'])
+ ->where('labelName', '.*')
+ ->name('labels.customizer-preview');
Route::post('labels', [SettingsController::class, 'postLabels'])
->name('settings.labels.save');
- Route::get('/settings/label/edit', [LabelsController::class, 'edit'])
- ->name('settings.label.edit');
+ Route::get('/settings/labels/edit', [LabelsController::class, 'edit'])
+ ->name('settings.labels.edit');
Route::get('ldap', [SettingsController::class, 'getLdapSettings'])
->name('settings.ldap.index')