Переглянути джерело

feat: ✨ Added System Settings & Added open correct tab after settings save

IceToast 3 роки тому
батько
коміт
f4f6834e28

+ 2 - 5
app/Classes/Settings/Invoices.php

@@ -8,16 +8,13 @@ use Illuminate\Support\Facades\Cache;
 
 class Invoices
 {
-    public $tabTitle = 'Invoice Settings';
-    public $invoiceSettings;
-
     public function __construct()
     {
         return;
     }
 
 
-    public function updateInvoiceSettings(Request $request)
+    public function updateSettings(Request $request)
     {
         $request->validate([
             'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
@@ -49,6 +46,6 @@ class Invoices
         }
 
 
-        return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
+        return redirect(route('admin.settings.index') . '#invoices')->with('success', 'Invoice settings updated!');
     }
 }

+ 2 - 5
app/Classes/Settings/Language.php

@@ -9,16 +9,13 @@ use Illuminate\Support\Facades\Session;
 
 class Language
 {
-    public $tabTitle = 'Language Settings';
-    public $languageSettings;
-
     public function __construct()
     {
         return;
     }
 
 
-    public function updateLanguageSettings(Request $request)
+    public function updateSettings(Request $request)
     {
 
         $values = [
@@ -42,6 +39,6 @@ class Language
         }
 
 
-        return redirect()->route('admin.settings.index')->with('success', 'Language settings updated!');
+        return redirect(route('admin.settings.index') . '#language')->with('success', 'Language settings updated!');
     }
 }

+ 2 - 5
app/Classes/Settings/Misc.php

@@ -10,9 +10,6 @@ use Illuminate\Support\Facades\Session;
 
 class Misc
 {
-    public $tabTitle = 'Misc Settings';
-    public $miscSettings;
-
     public function __construct()
     {
         return;
@@ -20,7 +17,7 @@ class Misc
 
 
 
-    public function updateMiscSettings(Request $request)
+    public function updateSettings(Request $request)
     {
         $request->validate([
             'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
@@ -61,6 +58,6 @@ class Misc
         }
 
 
-        return redirect()->route('admin.settings.index')->with('success', 'Misc settings updated!');
+        return redirect(route('admin.settings.index') . '#misc')->with('success', 'Misc settings updated!');
     }
 }

+ 2 - 5
app/Classes/Settings/Payments.php

@@ -9,16 +9,13 @@ use Illuminate\Support\Facades\Session;
 
 class Payments
 {
-    public $tabTitle = 'Payment Settings';
-    public $paymentSettings;
-
     public function __construct()
     {
         return;
     }
 
 
-    public function updatePaymentSettings(Request $request)
+    public function updateSettings(Request $request)
     {
 
         $values = [
@@ -46,6 +43,6 @@ class Payments
         }
 
 
-        return redirect()->route('admin.settings.index')->with('success', 'Payment settings updated!');
+        return redirect(route('admin.settings.index') . '#payment')->with('success', 'Payment settings updated!');
     }
 }

+ 48 - 0
app/Classes/Settings/System.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace App\Classes\Settings;
+
+use App\Models\Settings;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Config;
+
+class System
+{
+
+
+    public function __construct()
+    {
+        return;
+    }
+
+
+
+    public function updateSettings(Request $request)
+    {
+        $request->validate([
+            'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
+            'favicon' => 'nullable|max:10000|mimes:ico',
+        ]);
+
+
+        $values = [
+            //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
+            "SETTINGS::MISC:PHPMYADMIN:URL" => "phpmyadmin-url",
+
+
+        ];
+
+
+        foreach ($values as $key => $value) {
+            $param = $request->get($value);
+            if (!$param) {
+                $param = "";
+            }
+            Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
+            Cache::forget("setting" . ':' . $key);
+        }
+
+        return redirect(route('admin.settings.index') . '#system')->with('success', 'System settings updated!');
+    }
+}

+ 5 - 0
resources/views/admin/settings/index.blade.php

@@ -67,11 +67,16 @@
 
     <script>
         // Add the following code if you want the name of the file appear on select
+        const tabPaneHash = window.location.hash;
+
         document.addEventListener('DOMContentLoaded', () => {
             $(".custom-file-input").on("change", function() {
                 var fileName = $(this).val().split("\\").pop();
                 $(this).siblings(".custom-file-label").addClass("selected").html(fileName);
             });
+            if (tabPaneHash) {
+                $('.nav-tabs a[href="' + tabPaneHash + '"]').tab('show');
+            }
         })
     </script>
 

+ 0 - 2
resources/views/admin/settings/tabs/invoices.blade.php

@@ -1,5 +1,3 @@
-@inject('Invoices', 'App\Classes\Settings\Invoices')
-
 <div class="tab-pane mt-3" id="invoices">
     <form method="POST" enctype="multipart/form-data" class="mb-3"
         action="{{ route('admin.settings.update.invoicesettings') }}">

+ 0 - 15
resources/views/admin/settings/tabs/misc.blade.php

@@ -6,21 +6,6 @@
 
         <div class="row">
             <div class="col-md-6 col-lg-4 col-12">
-
-                <!-- PHPMYADMIN -->
-
-                <!-- Icetoast das sieht auch kacke aus... -->
-
-                <div class="form-group">
-                    <div class="custom-control mb-3">
-                        <label
-                            for="phpmyadmin-url">{{ __('The URL to your PHPMYADMIN Panel. Must not end with a /, leave blank to remove database button') }}</label>
-                        <input x-model="phpmyadmin-url" id="phpmyadmin-url" name="phpmyadmin-url" type="text"
-                            value="{{ config('SETTINGS::MISC:PHPMYADMIN:URL') }}"
-                            class="form-control @error('phpmyadmin-url') is-invalid @enderror">
-                    </div>
-                </div>
-
                 <div class="form-group">
                     <div class="custom-file mb-3 mt-3">
                         <input type="file" accept="image/png,image/jpeg,image/jpg" class="custom-file-input" name="icon"

+ 16 - 0
resources/views/admin/settings/tabs/system.blade.php

@@ -0,0 +1,16 @@
+<div class="tab-pane mt-3" id="system">
+    <form method="POST" enctype="multipart/form-data" class="mb-3"
+        action="{{ route('admin.settings.update.systemsettings') }}">
+        @csrf
+        @method('PATCH')
+
+        <div class="form-group">
+            <div class="custom-control mb-3">
+                <label for="phpmyadmin-url">{{ __('PHPMyAdmin URL') }}</label>
+                <input x-model="phpmyadmin-url" id="phpmyadmin-url" name="phpmyadmin-url" type="text"
+                    value="{{ config('SETTINGS::MISC:PHPMYADMIN:URL') }}"
+                    class="form-control @error('phpmyadmin-url') is-invalid @enderror">
+            </div>
+        </div>
+
+</div>

+ 6 - 4
routes/web.php

@@ -27,6 +27,7 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Route;
 use App\Classes\Settings\Language;
 use App\Classes\Settings\Invoices;
+use App\Classes\Settings\System;
 
 /*
 |--------------------------------------------------------------------------
@@ -134,10 +135,11 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
         Route::patch('settings/updatevalue', [SettingsController::class, 'updatevalue'])->name('settings.updatevalue');
 
         #settings
-        Route::patch('settings/update/invoice-settings', [Invoices::class, 'updateInvoiceSettings'])->name('settings.update.invoicesettings');
-        Route::patch('settings/update/language', [Language::class, 'updateLanguageSettings'])->name('settings.update.languagesettings');
-        Route::patch('settings/update/payment', [Payments::class, 'updatePaymentSettings'])->name('settings.update.paymentsettings');
-        Route::patch('settings/update/misc', [Misc::class, 'updateMiscSettings'])->name('settings.update.miscsettings');
+        Route::patch('settings/update/invoice-settings', [Invoices::class, 'updateSettings'])->name('settings.update.invoicesettings');
+        Route::patch('settings/update/language', [Language::class, 'updateSettings'])->name('settings.update.languagesettings');
+        Route::patch('settings/update/payment', [Payments::class, 'updateSettings'])->name('settings.update.paymentsettings');
+        Route::patch('settings/update/misc', [Misc::class, 'updateSettings'])->name('settings.update.miscsettings');
+        Route::patch('settings/update/system', [System::class, 'updateSettings'])->name('settings.update.systemsettings');
         Route::resource('settings', SettingsController::class)->only('index');
 
         #invoices