adds redirect to render and save if template is null

This commit is contained in:
Godfrey M 2025-01-08 15:32:23 -08:00
parent f4e69679ca
commit 0118504cd3
4 changed files with 24 additions and 16 deletions

View file

@ -798,7 +798,12 @@ class SettingsController extends Controller
$setting->labels_display_model = 0;
}
if ($setting->save()) {
if ($setting->label2_template === null) {
return redirect()->route('settings.labels.index')->with('error', trans('admin/settings/message.labels.null_template'));
}
return redirect()->route('settings.labels.index')
->with('success', trans('admin/settings/message.update.success'));
}

View file

@ -7,6 +7,7 @@ use App\Models\Labels\Label as LabelModel;
use App\Models\Labels\Sheet;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Traits\Macroable;
use TCPDF;
@ -39,6 +40,7 @@ class Label implements View
$assets = $this->data->get('assets');
$offset = $this->data->get('offset');
// If disabled, pass to legacy view
if ((!$settings->label2_enable)) {
return view('hardware/labels')
@ -51,21 +53,22 @@ class Label implements View
try {
$template = LabelModel::find($settings->label2_template);
if ($template === null) {
throw new \UnexpectedValueException('Template is null.');
}
$template->validate();
} catch (\UnexpectedValueException $e) {
\Log::error('Validation failed: ' . $e->getMessage());
} catch (\Throwable $e) {
\Log::error('An unexpected error occurred: ' . $e->getMessage());
if ($template === null) {
return redirect()->route('settings.labels.index')->with('error', trans('admin/settings/message.labels.null_template'));
}
$template->validate();
} catch (\UnexpectedValueException $e) {
\Log::error('Validation failed: ' . $e->getMessage());
} catch (\Throwable $e) {
\Log::error('An unexpected error occurred: ' . $e->getMessage());
}
$template->validate();
$pdf = new TCPDF(
$template->getOrientation(),

View file

@ -36,6 +36,9 @@ return [
'testing_authentication' => 'Testing LDAP Authentication...',
'authentication_success' => 'User authenticated against LDAP successfully!'
],
'labels' => [
'null_template' => 'Label template not found, Please select a template.',
],
'webhook' => [
'sending' => 'Sending :app test message...',
'success' => 'Your :webhook_name Integration works!',

View file

@ -26,7 +26,6 @@
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-10">
<div class="panel box box-default">
<div class="box-header with-border">
<h2 class="box-title">
@ -35,8 +34,6 @@
</h2>
</div>
<div class="box-body">
<div class="col-md-12">
<!-- New Label Engine -->