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; $setting->labels_display_model = 0;
} }
if ($setting->save()) { 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') return redirect()->route('settings.labels.index')
->with('success', trans('admin/settings/message.update.success')); ->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 App\Models\Labels\Sheet;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Macroable;
use TCPDF; use TCPDF;
@ -39,6 +40,7 @@ class Label implements View
$assets = $this->data->get('assets'); $assets = $this->data->get('assets');
$offset = $this->data->get('offset'); $offset = $this->data->get('offset');
// If disabled, pass to legacy view // If disabled, pass to legacy view
if ((!$settings->label2_enable)) { if ((!$settings->label2_enable)) {
return view('hardware/labels') return view('hardware/labels')
@ -51,21 +53,22 @@ class Label implements View
try { try {
$template = LabelModel::find($settings->label2_template); $template = LabelModel::find($settings->label2_template);
if ($template === null) { if ($template === null) {
throw new \UnexpectedValueException('Template is 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();
} 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( $pdf = new TCPDF(
$template->getOrientation(), $template->getOrientation(),

View file

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

View file

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