From 33cc1089003599ad9c7b7173b321f1ddabc5cfff Mon Sep 17 00:00:00 2001 From: IceToast Date: Mon, 6 Feb 2023 11:32:19 +0100 Subject: [PATCH 01/20] =?UTF-8?q?fix:=20=F0=9F=90=9B=20getCsrfIgnoredRoute?= =?UTF-8?q?s=20map=20all=20routes=20just=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/ExtensionHelper.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Helpers/ExtensionHelper.php b/app/Helpers/ExtensionHelper.php index fdf880ab..7e1bbda3 100644 --- a/app/Helpers/ExtensionHelper.php +++ b/app/Helpers/ExtensionHelper.php @@ -51,13 +51,11 @@ public static function getAllCsrfIgnoredRoutes() $routes = array_merge($routes, $config['RoutesIgnoreCsrf']); } - // add extension/ infront of every route - foreach ($routes as $key => $route) { - $routes[$key] = 'extensions/' . $route; - } + // map over the routes and add the extension name as prefix + $result = array_map(fn ($item) => "extensions/{$item}", $routes); } - return $routes; + return $result; } /** From 29e9ed6e4ab86af376fae7ae512174e28196adcf Mon Sep 17 00:00:00 2001 From: IceToast Date: Mon, 6 Feb 2023 11:57:14 +0100 Subject: [PATCH 02/20] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Wrong=20class=20nam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/CleanupOpenPayments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/CleanupOpenPayments.php b/app/Console/Commands/CleanupOpenPayments.php index 31510b6a..6fd96a7a 100644 --- a/app/Console/Commands/CleanupOpenPayments.php +++ b/app/Console/Commands/CleanupOpenPayments.php @@ -5,7 +5,7 @@ use App\Models\Payment; use Illuminate\Console\Command; -class CleanupPayments extends Command +class CleanupOpenPayments extends Command { /** * The name and signature of the console command. From 01fc6333032f1726a828eecbb135631174d0bb1a Mon Sep 17 00:00:00 2001 From: IceToast Date: Mon, 6 Feb 2023 20:42:17 +0100 Subject: [PATCH 03/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Set=20Them?= =?UTF-8?q?e=20to=20default=20when=20no=20setting=20or=20setting=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Providers/AppServiceProvider.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8fae42a6..6299bf4f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -46,9 +46,9 @@ public function boot() } //if none of result array is true. it sets ok to false - if (! in_array(true, $result)) { + if (!in_array(true, $result)) { $ok = false; - $validator->setCustomMessages(['multiple_date_format' => 'The format must be one of '.implode(',', $parameters)]); + $validator->setCustomMessages(['multiple_date_format' => 'The format must be one of ' . implode(',', $parameters)]); } return $ok; @@ -60,7 +60,7 @@ public function boot() view()->share('useful_links', $useful_links); } } catch (Exception $e) { - Log::error("Couldnt find useful_links. Probably the installation is not completet. ".$e); + Log::error("Couldnt find useful_links. Probably the installation is not completet. " . $e); } //only run if the installer has been executed @@ -71,12 +71,14 @@ public function boot() config([$setting->key => $setting->value]); } - if(!file_exists(base_path('themes') . "/" . config("SETTINGS::SYSTEM:THEME"))){ + if (!file_exists(base_path('themes') . "/" . config("SETTINGS::SYSTEM:THEME"))) { config(['SETTINGS::SYSTEM:THEME' => "default"]); } - if(config('SETTINGS::SYSTEM:THEME') !== config('theme.active')){ - Theme::set(config("SETTINGS::SYSTEM:THEME"), "default"); + if (config('SETTINGS::SYSTEM:THEME') && config('SETTINGS::SYSTEM:THEME') !== config('theme.active')) { + Theme::set(config("SETTINGS::SYSTEM:THEME", "default"), "default"); + } else { + Theme::set("default", "default"); } // Set Mail Config @@ -126,7 +128,7 @@ public function boot() } try { - $stringfromfile = file(base_path().'/.git/HEAD'); + $stringfromfile = file(base_path() . '/.git/HEAD'); $firstLine = $stringfromfile[0]; //get the string from the array From b8946d8666b8b42ca9016da7597b133a4ae2f4b7 Mon Sep 17 00:00:00 2001 From: IceToast Date: Tue, 7 Feb 2023 13:59:09 +0100 Subject: [PATCH 04/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Paypal=20a?= =?UTF-8?q?uthentication=20error=20->=20blank=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PaymentGateways/PayPal/index.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Extensions/PaymentGateways/PayPal/index.php b/app/Extensions/PaymentGateways/PayPal/index.php index 88abc809..11ac4473 100644 --- a/app/Extensions/PaymentGateways/PayPal/index.php +++ b/app/Extensions/PaymentGateways/PayPal/index.php @@ -9,6 +9,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; +use Illuminate\Support\Facades\Log; use PayPalCheckoutSdk\Core\PayPalHttpClient; use PayPalCheckoutSdk\Core\ProductionEnvironment; use PayPalCheckoutSdk\Core\SandboxEnvironment; @@ -74,7 +75,7 @@ function PaypalPay(Request $request) "application_context" => [ "cancel_url" => route('payment.Cancel'), "return_url" => route('payment.PayPalSuccess', ['payment' => $payment->id]), - 'brand_name' => config('app.name', 'Laravel'), + 'brand_name' => config('app.name', 'Controlpanel.GG'), 'shipping_preference' => 'NO_SHIPPING' ] @@ -85,14 +86,23 @@ function PaypalPay(Request $request) // Call API with your client and get a response for your call $response = getPayPalClient()->execute($request); + // check for any errors in the response + if ($response->statusCode != 201) { + throw new \Exception($response->statusCode); + } + + // make sure the link is not empty + if (empty($response->result->links[1]->href)) { + throw new \Exception('No redirect link found'); + } + Redirect::away($response->result->links[1]->href)->send(); return; } catch (HttpException $ex) { - error_log($ex->statusCode); - error_log($ex->getMessage()); - + Log::error('PayPal Payment: ' . $ex->getMessage()); $payment->delete(); - Redirect::route('payment.Cancel'); + + Redirect::route('store.index')->with('error', 'Payment failed')->send(); return; } } From 128015f0fae38b9d1e7190f803291e6d39581278 Mon Sep 17 00:00:00 2001 From: IceToast Date: Tue, 7 Feb 2023 14:18:22 +0100 Subject: [PATCH 05/20] =?UTF-8?q?chore:=20=F0=9F=8C=90=20localization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Extensions/PaymentGateways/PayPal/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Extensions/PaymentGateways/PayPal/index.php b/app/Extensions/PaymentGateways/PayPal/index.php index 11ac4473..648913ae 100644 --- a/app/Extensions/PaymentGateways/PayPal/index.php +++ b/app/Extensions/PaymentGateways/PayPal/index.php @@ -102,7 +102,7 @@ function PaypalPay(Request $request) Log::error('PayPal Payment: ' . $ex->getMessage()); $payment->delete(); - Redirect::route('store.index')->with('error', 'Payment failed')->send(); + Redirect::route('store.index')->with('error', __('Payment failed'))->send(); return; } } From 040bcf2fa0bcea22092f319bb5d4894c9f12876d Mon Sep 17 00:00:00 2001 From: Johannes F Date: Sat, 11 Feb 2023 22:17:42 +0100 Subject: [PATCH 06/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Wrong=20ti?= =?UTF-8?q?cket=20priority=20getting=20displayed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/default/views/moderator/ticket/show.blade.php | 4 ++-- themes/default/views/ticket/show.blade.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/default/views/moderator/ticket/show.blade.php b/themes/default/views/moderator/ticket/show.blade.php index 13711dd0..2d51c5dd 100644 --- a/themes/default/views/moderator/ticket/show.blade.php +++ b/themes/default/views/moderator/ticket/show.blade.php @@ -61,10 +61,10 @@ {{__("Low")}} @break @case("Medium") - {{__("Closed")}} + {{__("Medium")}} @break @case("High") - {{__("Answered")}} + {{__("High")}} @break @endswitch

diff --git a/themes/default/views/ticket/show.blade.php b/themes/default/views/ticket/show.blade.php index 96a3b46b..8d9afa26 100644 --- a/themes/default/views/ticket/show.blade.php +++ b/themes/default/views/ticket/show.blade.php @@ -61,10 +61,10 @@ {{__("Low")}} @break @case("Medium") - {{__("Closed")}} + {{__("Medium")}} @break @case("High") - {{__("Answered")}} + {{__("High")}} @break @endswitch

From faf99505628e2267b9d2dcbfa30590b53ba68f83 Mon Sep 17 00:00:00 2001 From: 2IceCube <95680355+2IceCube@users.noreply.github.com> Date: Mon, 13 Feb 2023 22:54:21 +0100 Subject: [PATCH 07/20] Add Theme Watermark --- themes/BlueInfinity/views/layouts/main.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/BlueInfinity/views/layouts/main.blade.php b/themes/BlueInfinity/views/layouts/main.blade.php index c4ba7cd8..f5d888d5 100644 --- a/themes/BlueInfinity/views/layouts/main.blade.php +++ b/themes/BlueInfinity/views/layouts/main.blade.php @@ -441,7 +441,7 @@ class="nav-link @if (Request::routeIs('admin.activitylogs.*')) active @endif"> Copyright © 2021-{{ date('Y') }} {{ env('APP_NAME', 'Laravel') }}. All rights - reserved. Powered by ControlPanel. + reserved. Powered by ControlPanel. | Theme by 2IceCube @if (!str_contains(config('BRANCHNAME'), 'main') && !str_contains(config('BRANCHNAME'), 'unknown')) Version {{ config('app')['version'] }} - {{ config('BRANCHNAME') }} @endif From 60359a19baffe45bb10a459977f5d79153ca7451 Mon Sep 17 00:00:00 2001 From: 2IceCube <95680355+2IceCube@users.noreply.github.com> Date: Mon, 13 Feb 2023 22:57:31 +0100 Subject: [PATCH 08/20] Fixed Mobile View --- public/themes/BlueInfinity/app.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/themes/BlueInfinity/app.css b/public/themes/BlueInfinity/app.css index 898ee94c..7ad8941f 100644 --- a/public/themes/BlueInfinity/app.css +++ b/public/themes/BlueInfinity/app.css @@ -1 +1 @@ -@import "default.css";.layout-fixed .wrapper .sidebar{ height:calc(100vh - 3.5rem - 1px);background:radial-gradient(#061b29,black);}body:not(.sidebar-mini-md) .content-wrapper,body:not(.sidebar-mini-md) .main-footer,body:not(.sidebar-mini-md) .main-header{ transition:margin-left .3s ease-in-out;margin-left:250px;background:radial-gradient(#061b29,black);}[class*=sidebar-dark] .brand-link,[class*=sidebar-dark] .brand-link .pushmenu{ color:hsla(0,0%,100%,.8);background:radial-gradient(#061b29,black);}.main-sidebar .brand-text,.main-sidebar .logo-xl,.main-sidebar .logo-xs,.sidebar .nav-link p,.sidebar .user-panel .info{ transition:margin-left .3s linear,opacity .3s ease,visibility .3s ease;color:#d3d3d3;}.sidebar-dark-primary .nav-sidebar>.nav-item>.nav-link.active,.sidebar-light-primary .nav-sidebar>.nav-item>.nav-link.active{ color:#fff;background:radial-gradient(#1b4b61,#fd030300);border-radius:50px;}.dark-mode .card{ background-color:#00000000;color:#ffffff99;border-width:3px;border-color:#f7f7f7;border-style:double;border-radius:15px;}.btn-info{ color:#ffffff;background-color:#b8171700;border-color:#ffffff;box-shadow:none;}.btn-warning{ color:#ffffff;background-color:#ffc10700;border-color:#ffffff;box-shadow:none;}.card-title{ float:left;font-size:1.1rem;font-weight:400;margin:0;color:white;}.dark-mode .text-muted{ color:#ffffff99!important;}.dark-mode .list-group-item{ background-color:#343a4000;border-color:#ffffff99;}.dark-mode .info-box{ background-color:#343a4000;color:#fff;border:3px;border-style:double;border-radius:15px;border-color:white;}label:not(.form-check-label):not(.custom-file-label){ font-weight:700;color:#ffffffc2;}.dark-mode .custom-control-label:before,.dark-mode .custom-file-label,.dark-mode .custom-file-label:after,.dark-mode .custom-select,.dark-mode .form-control,.dark-mode .input-group-text{ background-color:#007af400;color:#828282;}.alert-success{ color:#fff;background-color:#28a745;border-color:#ffffff;border-radius:15px;border-style:double;}.dark-mode{ color:#fff;background:radial-gradient(#061b29,black);}.dark-mode .invoice{ background-color:#343a4000;border:3px;border-radius:15px;border-color:white;border:double;}.dark-mode .nav-tabs .nav-item.show .nav-link,.dark-mode .nav-tabs .nav-link.active{ background-color:#ffffff1c;color:#fff;}.slim-crop-area img,.slim-image-editor img,.slim-popover img,.slim img{ background:black;}.dark-mode .callout{ background-color:#00ff0333;}.callout.callout-info{ border-left-color:#00e11d;}.p-3{ padding:1rem!important;background:#061b29;}.small-box>.small-box-footer{ color:hsla(0,0%,100%,.8);display:block;padding:3px 0;position:relative;text-align:center;text-decoration:none;z-index:10;background:#061b29;}.dark-mode .dropdown-menu{ background-color:#061b29;border-color:white;}.card-header:first-child{ border-radius:14px 14px 0px 0px;background:#061b29;}.card-body{ flex:1 1 auto;min-height:1px;padding:1.25rem;background:#061b29;}.justify-content-between{ justify-content:space-between!important;background:#061b29;}.dark-mode .card .card-footer{ background-color:#061b29;border-radius:0px 0px 14px 14px;}.dark-mode .select2-selection--single{ background-color:#061b29;border-color:#6c757d;}.select2-search--dropdown{ display:block;padding:4px;background:#061b29;}.select2-container--default .select2-results__option{ padding:6px 12px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background:blue;background:#061b29;}.dark-mode .select2-dropdown,.dark-mode .select2-dropdown .select2-search__field,.dark-mode .select2-search--inline .select2-search__field{ background-color:#061b29;border-color:#ffffff;color:#fff;}.modal-header{ background:#061b29;}.modal-body{ position:relative;flex:1 1 auto;padding:1rem;background:#061b29;}.dark-mode .modal-footer,.dark-mode .modal-header{ border-color:#ffffff;background:#061b29;} +@import "default.css";.layout-fixed .wrapper .sidebar{ height:calc(100vh - 3.5rem - 1px);background:radial-gradient(#061b29,black);}body:not(.sidebar-mini-md) .content-wrapper,body:not(.sidebar-mini-md) .main-footer,body:not(.sidebar-mini-md) .main-header{ transition:margin-left .3s ease-in-out;background:radial-gradient(#061b29,black);}[class*=sidebar-dark] .brand-link,[class*=sidebar-dark] .brand-link .pushmenu{ color:hsla(0,0%,100%,.8);background:radial-gradient(#061b29,black);}.main-sidebar .brand-text,.main-sidebar .logo-xl,.main-sidebar .logo-xs,.sidebar .nav-link p,.sidebar .user-panel .info{ transition:margin-left .3s linear,opacity .3s ease,visibility .3s ease;color:#d3d3d3;}.sidebar-dark-primary .nav-sidebar>.nav-item>.nav-link.active,.sidebar-light-primary .nav-sidebar>.nav-item>.nav-link.active{ color:#fff;background:radial-gradient(#1b4b61,#fd030300);border-radius:50px;}.dark-mode .card{ background-color:#00000000;color:#ffffff99;border-width:3px;border-color:#f7f7f7;border-style:double;border-radius:15px;}.btn-info{ color:#ffffff;background-color:#b8171700;border-color:#ffffff;box-shadow:none;}.btn-warning{ color:#ffffff;background-color:#ffc10700;border-color:#ffffff;box-shadow:none;}.card-title{ float:left;font-size:1.1rem;font-weight:400;margin:0;color:white;}.dark-mode .text-muted{ color:#ffffff99!important;}.dark-mode .list-group-item{ background-color:#343a4000;border-color:#ffffff99;}.dark-mode .info-box{ background-color:#343a4000;color:#fff;border:3px;border-style:double;border-radius:15px;border-color:white;}label:not(.form-check-label):not(.custom-file-label){ font-weight:700;color:#ffffffc2;}.dark-mode .custom-control-label:before,.dark-mode .custom-file-label,.dark-mode .custom-file-label:after,.dark-mode .custom-select,.dark-mode .form-control,.dark-mode .input-group-text{ background-color:#007af400;color:#828282;}.alert-success{ color:#fff;background-color:#28a745;border-color:#ffffff;border-radius:15px;border-style:double;}.dark-mode{ color:#fff;background:radial-gradient(#061b29,black);}.dark-mode .invoice{ background-color:#343a4000;border:3px;border-radius:15px;border-color:white;border:double;}.dark-mode .nav-tabs .nav-item.show .nav-link,.dark-mode .nav-tabs .nav-link.active{ background-color:#ffffff1c;color:#fff;}.slim-crop-area img,.slim-image-editor img,.slim-popover img,.slim img{ background:black;}.dark-mode .callout{ background-color:#00ff0333;}.callout.callout-info{ border-left-color:#00e11d;}.p-3{ padding:1rem!important;background:#061b29;}.small-box>.small-box-footer{ color:hsla(0,0%,100%,.8);display:block;padding:3px 0;position:relative;text-align:center;text-decoration:none;z-index:10;background:#061b29;}.dark-mode .dropdown-menu{ background-color:#061b29;border-color:white;}.card-header:first-child{ border-radius:14px 14px 0px 0px;background:#061b29;}.card-body{ flex:1 1 auto;min-height:1px;padding:1.25rem;background:#061b29;}.justify-content-between{ justify-content:space-between!important;background:#061b29;}.dark-mode .card .card-footer{ background-color:#061b29;border-radius:0px 0px 14px 14px;}.dark-mode .select2-selection--single{ background-color:#061b29;border-color:#6c757d;}.select2-search--dropdown{ display:block;padding:4px;background:#061b29;}.select2-container--default .select2-results__option{ padding:6px 12px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background:blue;background:#061b29;}.dark-mode .select2-dropdown,.dark-mode .select2-dropdown .select2-search__field,.dark-mode .select2-search--inline .select2-search__field{ background-color:#061b29;border-color:#ffffff;color:#fff;}.modal-header{ background:#061b29;}.modal-body{ position:relative;flex:1 1 auto;padding:1rem;background:#061b29;}.dark-mode .modal-footer,.dark-mode .modal-header{ border-color:#ffffff;background:#061b29;} From 8c2289ed74582b3579eea78934a7058559681843 Mon Sep 17 00:00:00 2001 From: Johannes F Date: Sat, 11 Feb 2023 22:54:35 +0100 Subject: [PATCH 09/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Wrong=20St?= =?UTF-8?q?ore=20Page=20Name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/default/views/store/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/default/views/store/index.blade.php b/themes/default/views/store/index.blade.php index 7d105867..5f024d48 100644 --- a/themes/default/views/store/index.blade.php +++ b/themes/default/views/store/index.blade.php @@ -36,7 +36,7 @@
-
{{ CREDITS_DISPLAY_NAME }}
+
{{ config('app.name', 'Controlpanel.gg') }} Store
From af5d28e2a50654e3417870df538fc445288a20f6 Mon Sep 17 00:00:00 2001 From: Johannes F Date: Sun, 12 Feb 2023 00:15:36 +0100 Subject: [PATCH 10/20] =?UTF-8?q?feat:=20=E2=9C=A8=20Reopen=20tickets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Moderation/TicketsController.php | 16 +- app/Http/Controllers/TicketsController.php | 16 +- routes/web.php | 4 +- .../views/moderator/ticket/show.blade.php | 31 +++- themes/default/views/store/index.blade.php | 2 +- themes/default/views/ticket/show.blade.php | 157 ++++++++++-------- 6 files changed, 141 insertions(+), 85 deletions(-) diff --git a/app/Http/Controllers/Moderation/TicketsController.php b/app/Http/Controllers/Moderation/TicketsController.php index be974ad2..a020098e 100644 --- a/app/Http/Controllers/Moderation/TicketsController.php +++ b/app/Http/Controllers/Moderation/TicketsController.php @@ -33,9 +33,14 @@ public function show($ticket_id) return view('moderator.ticket.show', compact('ticket', 'ticketcategory', 'ticketcomments', 'server')); } - public function close($ticket_id) + public function changeStatus($ticket_id) { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + if($ticket->status == "Closed"){ + $ticket->status = "Reopened"; + $ticket->save(); + return redirect()->back()->with('success', __('A ticket has been reopened, ID: #') . $ticket->ticket_id); + } $ticket->status = 'Closed'; $ticket->save(); $ticketOwner = $ticket->user; @@ -85,12 +90,16 @@ public function dataTable() return ''.$tickets->user->name.''; }) ->addColumn('actions', function (Ticket $tickets) { + $statusButtonColor = ($tickets->status == "Closed") ? 'btn-success' : 'btn-warning'; + $statusButtonIcon = ($tickets->status == "Closed") ? 'fa-redo' : 'fa-times'; + $statusButtonText = ($tickets->status == "Closed") ? __('Reopen') : __('Close'); + return ' -
+ '.csrf_field().' '.method_field('POST').' - +
'.csrf_field().' @@ -101,6 +110,7 @@ public function dataTable() }) ->editColumn('status', function (Ticket $tickets) { switch ($tickets->status) { + case 'Reopened': case 'Open': $badgeColor = 'badge-success'; break; diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index 2477d729..a2b55e43 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -104,9 +104,14 @@ public function reply(Request $request) return redirect()->back()->with('success', __('Your comment has been submitted')); } - public function close($ticket_id) + public function changeStatus($ticket_id) { $ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail(); + if($ticket->status == "Closed"){ + $ticket->status = "Reopened"; + $ticket->save(); + return redirect()->back()->with('success', __('A ticket has been reopened, ID: #') . $ticket->ticket_id); + } $ticket->status = "Closed"; $ticket->save(); return redirect()->back()->with('success', __('A ticket has been closed, ID: #') . $ticket->ticket_id); @@ -125,6 +130,7 @@ public function dataTable() }) ->editColumn('status', function (Ticket $tickets) { switch ($tickets->status) { + case 'Reopened': case 'Open': $badgeColor = 'badge-success'; break; @@ -149,12 +155,16 @@ public function dataTable() 'raw' => $tickets->updated_at ? strtotime($tickets->updated_at) : '']; }) ->addColumn('actions', function (Ticket $tickets) { + $statusButtonColor = ($tickets->status == "Closed") ? 'btn-success' : 'btn-warning'; + $statusButtonIcon = ($tickets->status == "Closed") ? 'fa-redo' : 'fa-times'; + $statusButtonText = ($tickets->status == "Closed") ? __('Reopen') : __('Close'); + return ' - + '.csrf_field().' '.method_field('POST').' - + diff --git a/routes/web.php b/routes/web.php index c86a0c66..fbbdb028 100644 --- a/routes/web.php +++ b/routes/web.php @@ -113,7 +113,7 @@ Route::post('ticket/new', [TicketsController::class, 'store'])->middleware(['throttle:ticket-new'])->name('ticket.new.store'); Route::get('ticket/show/{ticket_id}', [TicketsController::class, 'show'])->name('ticket.show'); Route::post('ticket/reply', [TicketsController::class, 'reply'])->middleware(['throttle:ticket-reply'])->name('ticket.reply'); - Route::post('ticket/close/{ticket_id}', [TicketsController::class, 'close'])->name('ticket.close'); + Route::post('ticket/status/{ticket_id}', [TicketsController::class, 'changeStatus'])->name('ticket.changeStatus'); } //admin @@ -211,7 +211,7 @@ Route::get('ticket/datatable', [ModTicketsController::class, 'datatable'])->name('ticket.datatable'); Route::get('ticket/show/{ticket_id}', [ModTicketsController::class, 'show'])->name('ticket.show'); Route::post('ticket/reply', [ModTicketsController::class, 'reply'])->name('ticket.reply'); - Route::post('ticket/close/{ticket_id}', [ModTicketsController::class, 'close'])->name('ticket.close'); + Route::post('ticket/status/{ticket_id}', [ModTicketsController::class, 'changeStatus'])->name('ticket.changeStatus'); Route::post('ticket/delete/{ticket_id}', [ModTicketsController::class, 'delete'])->name('ticket.delete'); //ticket moderation blacklist Route::get('ticket/blacklist', [ModTicketsController::class, 'blacklist'])->name('ticket.blacklist'); diff --git a/themes/default/views/moderator/ticket/show.blade.php b/themes/default/views/moderator/ticket/show.blade.php index 2d51c5dd..dda8c1f9 100644 --- a/themes/default/views/moderator/ticket/show.blade.php +++ b/themes/default/views/moderator/ticket/show.blade.php @@ -44,6 +44,9 @@ @case("Open") {{__("Open")}} @break + @case("Reopened") + {{__("Reopened")}} + @break @case("Closed") {{__("Closed")}} @break @@ -69,13 +72,27 @@ @endswitch

{{__("Created on")}}: {{ $ticket->created_at->diffForHumans() }}

- @if($ticket->status!='Closed') -
- {{csrf_field()}} - {{method_field("POST") }} - - - @endif + @if($ticket->status=='Closed') +
+ {{csrf_field()}} + {{method_field("POST") }} + + + @else +
+ {{csrf_field()}} + {{method_field("POST") }} + + + @endif diff --git a/themes/default/views/store/index.blade.php b/themes/default/views/store/index.blade.php index 5f024d48..7d105867 100644 --- a/themes/default/views/store/index.blade.php +++ b/themes/default/views/store/index.blade.php @@ -36,7 +36,7 @@
-
{{ config('app.name', 'Controlpanel.gg') }} Store
+
{{ CREDITS_DISPLAY_NAME }}
diff --git a/themes/default/views/ticket/show.blade.php b/themes/default/views/ticket/show.blade.php index 8d9afa26..7401038f 100644 --- a/themes/default/views/ticket/show.blade.php +++ b/themes/default/views/ticket/show.blade.php @@ -35,43 +35,58 @@
@if(!empty($server)) -

{{__("Server")}}: {{ $server->name }}

+

{{__("Server")}}: {{ $server->name }}

@endif -

{{__("Title")}}: {{ $ticket->title }}

-

{{__("Category")}}: {{ $ticketcategory->name }}

-

{{__("Status")}}: - @switch($ticket->status) - @case("Open") - {{__("Open")}} - @break - @case("Closed") - {{__("Closed")}} - @break - @case("Answered") - {{__("Answered")}} - @break - @case("Client Reply") - {{__("Client Reply")}} - @break - @endswitch -

-

Priority: - @switch($ticket->priority) - @case("Low") - {{__("Low")}} - @break - @case("Medium") - {{__("Medium")}} - @break - @case("High") - {{__("High")}} - @break - @endswitch -

+

{{__("Title")}}: {{ $ticket->title }}

+

{{__("Category")}}: {{ $ticketcategory->name }}

+

{{__("Status")}}: + @switch($ticket->status) + @case("Open") + {{__("Open")}} + @break + @case("Reopened") + {{__("Reopened")}} + @break + @case("Closed") + {{__("Closed")}} + @break + @case("Answered") + {{__("Answered")}} + @break + @case("Client Reply") + {{__("Client Reply")}} + @break + @endswitch +

+

Priority: + @switch($ticket->priority) + @case("Low") + {{__("Low")}} + @break + @case("Medium") + {{__("Medium")}} + @break + @case("High") + {{__("High")}} + @break + @endswitch +

{{__("Created on")}}: {{ $ticket->created_at->diffForHumans() }}

- @if($ticket->status!='Closed') + @if($ticket->status=='Closed')
+ action="{{route('ticket.changeStatus', ['ticket_id' => $ticket->ticket_id ])}}"> + {{csrf_field()}} + {{method_field("POST") }} + + + @else +
{{csrf_field()}} {{method_field("POST") }}
User Image - {{ $ticket->user->name }} - @if($ticket->user->role === "member") - Member - @elseif ($ticket->user->role === "client") - Client - @elseif ($ticket->user->role === "moderator") - Moderator - @elseif ($ticket->user->role === "admin") - Admin - @endif + src="https://www.gravatar.com/avatar/{{ md5(strtolower($ticket->user->email)) }}?s=25" + class="user-image" alt="User Image"> + {{ $ticket->user->name }} + @if($ticket->user->role === "member") + Member + @elseif ($ticket->user->role === "client") + Client + @elseif ($ticket->user->role === "moderator") + Moderator + @elseif ($ticket->user->role === "admin") + Admin + @endif
- {{ $ticket->created_at->diffForHumans() }} + {{ $ticket->created_at->diffForHumans() }}
{{ $ticket->message }}
@foreach ($ticketcomments as $ticketcomment) -
-
-
-
User Image - {{ $ticketcomment->user->name }} - @if($ticketcomment->user->role === "member") - Member - @elseif ($ticketcomment->user->role === "client") - Client - @elseif ($ticketcomment->user->role === "moderator") - Moderator - @elseif ($ticketcomment->user->role === "admin") - Admin - @endif -
- {{ $ticketcomment->created_at->diffForHumans() }} +
+
+
+
User Image + {{ $ticketcomment->user->name }} + @if($ticketcomment->user->role === "member") + Member + @elseif ($ticketcomment->user->role === "client") + Client + @elseif ($ticketcomment->user->role === "moderator") + Moderator + @elseif ($ticketcomment->user->role === "admin") + Admin + @endif +
+ {{ $ticketcomment->created_at->diffForHumans() }} +
+
{{ $ticketcomment->ticketcomment }}
-
{{ $ticketcomment->ticketcomment }}
-
@endforeach
{!! csrf_field() !!}
- + @if ($errors->has('ticketcomment')) - + {{ $errors->first('ticketcomment') }} @endif From 371a37df7aa1f04fc6ad5453e9fa5a1c435fd8e7 Mon Sep 17 00:00:00 2001 From: LogischJo <66436499+LogischJo@users.noreply.github.com> Date: Tue, 14 Feb 2023 14:02:05 +0000 Subject: [PATCH 11/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Use=20try?= =?UTF-8?q?=20catch=20to=20prevent=20500=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Moderation/TicketsController.php | 40 ++++++++++++++++++- app/Http/Controllers/TicketsController.php | 17 +++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Moderation/TicketsController.php b/app/Http/Controllers/Moderation/TicketsController.php index a020098e..35674e1b 100644 --- a/app/Http/Controllers/Moderation/TicketsController.php +++ b/app/Http/Controllers/Moderation/TicketsController.php @@ -25,7 +25,12 @@ public function index() public function show($ticket_id) { + try { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + } catch (Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } $ticketcomments = $ticket->ticketcomments; $ticketcategory = $ticket->ticketcategory; $server = Server::where('id', $ticket->server)->first(); @@ -34,8 +39,14 @@ public function show($ticket_id) } public function changeStatus($ticket_id) - { + { + try { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + } catch(Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } + if($ticket->status == "Closed"){ $ticket->status = "Reopened"; $ticket->save(); @@ -50,7 +61,14 @@ public function changeStatus($ticket_id) public function delete($ticket_id) { + try { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + } catch (Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + + } + TicketComment::where('ticket_id', $ticket->id)->delete(); $ticket->delete(); @@ -60,7 +78,14 @@ public function delete($ticket_id) public function reply(Request $request) { $this->validate($request, ['ticketcomment' => 'required']); - $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); + try { + $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); + + } + catch (Exception $e){ + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + + } $ticket->status = 'Answered'; $ticket->update(); TicketComment::create([ @@ -68,7 +93,12 @@ public function reply(Request $request) 'user_id' => Auth::user()->id, 'ticketcomment' => $request->input('ticketcomment'), ]); + try { $user = User::where('id', $ticket->user_id)->firstOrFail(); + } catch(Exception $e) + { + return redirect()->back()->with('warning', __('User not found on the server. Check on the admin database or try again later.')); + } $newmessage = $request->input('ticketcomment'); $user->notify(new ReplyNotification($ticket, $user, $newmessage)); @@ -145,7 +175,13 @@ public function blacklist() public function blacklistAdd(Request $request) { + try { $user = User::where('id', $request->user_id)->first(); + } + catch (Exception $e){ + return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.')); + + } $check = TicketBlacklist::where('user_id', $user->id)->first(); if ($check) { $check->reason = $request->reason; diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index a2b55e43..b8dc96be 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -72,7 +72,12 @@ public function store(Request $request) public function show($ticket_id) { + try { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + } catch (Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } $ticketcomments = $ticket->ticketcomments; $ticketcategory = $ticket->ticketcategory; $server = Server::where('id', $ticket->server)->first(); @@ -88,7 +93,12 @@ public function reply(Request $request) return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator")); } $this->validate($request, ['ticketcomment' => 'required']); + try { $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); + } catch (Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } $ticket->status = 'Client Reply'; $ticket->update(); $ticketcomment = TicketComment::create([ @@ -105,8 +115,13 @@ public function reply(Request $request) return redirect()->back()->with('success', __('Your comment has been submitted')); } public function changeStatus($ticket_id) - { + { + try { $ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail(); + } catch (Exception $e) + { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } if($ticket->status == "Closed"){ $ticket->status = "Reopened"; $ticket->save(); From e78bd37da0064ecbdc514ff0972ab8be0fa53f13 Mon Sep 17 00:00:00 2001 From: Johannes F Date: Tue, 14 Feb 2023 18:33:43 +0100 Subject: [PATCH 12/20] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Harmonize?= =?UTF-8?q?=20formatting=20and=20merge=20some=20try=20catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Moderation/TicketsController.php | 20 ++-- app/Http/Controllers/TicketsController.php | 108 +++++++++--------- 2 files changed, 66 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/Moderation/TicketsController.php b/app/Http/Controllers/Moderation/TicketsController.php index 35674e1b..c927e685 100644 --- a/app/Http/Controllers/Moderation/TicketsController.php +++ b/app/Http/Controllers/Moderation/TicketsController.php @@ -39,7 +39,7 @@ public function show($ticket_id) } public function changeStatus($ticket_id) - { + { try { $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); } catch(Exception $e) @@ -66,7 +66,6 @@ public function delete($ticket_id) } catch (Exception $e) { return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); - } TicketComment::where('ticket_id', $ticket->id)->delete(); @@ -80,11 +79,8 @@ public function reply(Request $request) $this->validate($request, ['ticketcomment' => 'required']); try { $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); - - } - catch (Exception $e){ + } catch (Exception $e){ return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); - } $ticket->status = 'Answered'; $ticket->update(); @@ -176,13 +172,12 @@ public function blacklist() public function blacklistAdd(Request $request) { try { - $user = User::where('id', $request->user_id)->first(); + $user = User::where('id', $request->user_id)->firstOrFail(); + $check = TicketBlacklist::where('user_id', $user->id)->first(); } catch (Exception $e){ return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.')); - } - $check = TicketBlacklist::where('user_id', $user->id)->first(); if ($check) { $check->reason = $request->reason; $check->status = 'True'; @@ -209,7 +204,12 @@ public function blacklistDelete($id) public function blacklistChange($id) { - $blacklist = TicketBlacklist::where('id', $id)->first(); + try { + $blacklist = TicketBlacklist::where('id', $id)->first(); + } + catch (Exception $e){ + return redirect()->back()->with('warning', __('User not found on the server. Check the admin database or try again later.')); + } if ($blacklist->status == 'True') { $blacklist->status = 'False'; } else { diff --git a/app/Http/Controllers/TicketsController.php b/app/Http/Controllers/TicketsController.php index b8dc96be..3b2571c0 100644 --- a/app/Http/Controllers/TicketsController.php +++ b/app/Http/Controllers/TicketsController.php @@ -26,58 +26,50 @@ public function index() return view('ticket.index', compact('tickets', 'ticketcategories')); } - public function create() - { - //check in blacklist - $check = TicketBlacklist::where('user_id', Auth::user()->id)->first(); - if ($check && $check->status == 'True') { - return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator")); - } - $ticketcategories = TicketCategory::all(); - $servers = Auth::user()->servers; - - return view('ticket.create', compact('ticketcategories', 'servers')); - } - public function store(Request $request) { $this->validate($request, [ - 'title' => 'required', - 'ticketcategory' => 'required', - 'priority' => 'required', - 'message' => 'required', ] + 'title' => 'required', + 'ticketcategory' => 'required', + 'priority' => 'required', + 'message' => 'required',] ); $ticket = new Ticket([ - 'title' => $request->input('title'), - 'user_id' => Auth::user()->id, - 'ticket_id' => strtoupper(Str::random(8)), - 'ticketcategory_id' => $request->input('ticketcategory'), - 'priority' => $request->input('priority'), - 'message' => $request->input('message'), - 'status' => 'Open', - 'server' => $request->input('server'), ] + 'title' => $request->input('title'), + 'user_id' => Auth::user()->id, + 'ticket_id' => strtoupper(Str::random(8)), + 'ticketcategory_id' => $request->input('ticketcategory'), + 'priority' => $request->input('priority'), + 'message' => $request->input('message'), + 'status' => 'Open', + 'server' => $request->input('server'),] ); $ticket->save(); $user = Auth::user(); - if(config('SETTINGS::TICKET:NOTIFY') == "all"){ $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get();} - if(config('SETTINGS::TICKET:NOTIFY') == "admin"){ $admin = User::where('role', 'admin')->get();} - if(config('SETTINGS::TICKET:NOTIFY') == "moderator"){ $admin = User::where('role', 'mod')->get();} + if (config('SETTINGS::TICKET:NOTIFY') == "all") { + $admin = User::where('role', 'admin')->orWhere('role', 'mod')->get(); + } + if (config('SETTINGS::TICKET:NOTIFY') == "admin") { + $admin = User::where('role', 'admin')->get(); + } + if (config('SETTINGS::TICKET:NOTIFY') == "moderator") { + $admin = User::where('role', 'mod')->get(); + } $user->notify(new CreateNotification($ticket)); - if(config('SETTINGS::TICKET:NOTIFY') != "none"){ + if (config('SETTINGS::TICKET:NOTIFY') != "none") { Notification::send($admin, new AdminCreateNotification($ticket, $user)); } - return redirect()->route('ticket.index')->with('success', __('A ticket has been opened, ID: #').$ticket->ticket_id); + return redirect()->route('ticket.index')->with('success', __('A ticket has been opened, ID: #') . $ticket->ticket_id); } public function show($ticket_id) { - try { - $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); - } catch (Exception $e) - { - return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); - } + try { + $ticket = Ticket::where('ticket_id', $ticket_id)->firstOrFail(); + } catch (Exception $e) { + return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); + } $ticketcomments = $ticket->ticketcomments; $ticketcategory = $ticket->ticketcategory; $server = Server::where('id', $ticket->server)->first(); @@ -90,13 +82,12 @@ public function reply(Request $request) //check in blacklist $check = TicketBlacklist::where('user_id', Auth::user()->id)->first(); if ($check && $check->status == 'True') { - return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '".$check->reason."', please contact the administrator")); + return redirect()->route('ticket.index')->with('error', __("You can't reply a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator")); } $this->validate($request, ['ticketcomment' => 'required']); try { - $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); - } catch (Exception $e) - { + $ticket = Ticket::where('id', $request->input('ticket_id'))->firstOrFail(); + } catch (Exception $e) { return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); } $ticket->status = 'Client Reply'; @@ -114,15 +105,28 @@ public function reply(Request $request) return redirect()->back()->with('success', __('Your comment has been submitted')); } + + public function create() + { + //check in blacklist + $check = TicketBlacklist::where('user_id', Auth::user()->id)->first(); + if ($check && $check->status == 'True') { + return redirect()->route('ticket.index')->with('error', __("You can't make a ticket because you're on the blacklist for a reason: '" . $check->reason . "', please contact the administrator")); + } + $ticketcategories = TicketCategory::all(); + $servers = Auth::user()->servers; + + return view('ticket.create', compact('ticketcategories', 'servers')); + } + public function changeStatus($ticket_id) - { + { try { - $ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail(); - } catch (Exception $e) - { + $ticket = Ticket::where('user_id', Auth::user()->id)->where("ticket_id", $ticket_id)->firstOrFail(); + } catch (Exception $e) { return redirect()->back()->with('warning', __('Ticket not found on the server. It potentially got deleted earlier')); } - if($ticket->status == "Closed"){ + if ($ticket->status == "Closed") { $ticket->status = "Reopened"; $ticket->save(); return redirect()->back()->with('success', __('A ticket has been reopened, ID: #') . $ticket->ticket_id); @@ -141,7 +145,7 @@ public function dataTable() return $tickets->ticketcategory->name; }) ->editColumn('title', function (Ticket $tickets) { - return ''.'#'.$tickets->ticket_id.' - '.htmlspecialchars($tickets->title).''; + return '' . '#' . $tickets->ticket_id . ' - ' . htmlspecialchars($tickets->title) . ''; }) ->editColumn('status', function (Ticket $tickets) { switch ($tickets->status) { @@ -160,7 +164,7 @@ public function dataTable() break; } - return ''.$tickets->status.''; + return '' . $tickets->status . ''; }) ->editColumn('priority', function (Ticket $tickets) { return __($tickets->priority); @@ -175,11 +179,11 @@ public function dataTable() $statusButtonText = ($tickets->status == "Closed") ? __('Reopen') : __('Close'); return ' - - - '.csrf_field().' - '.method_field('POST').' - + + + ' . csrf_field() . ' + ' . method_field('POST') . ' + From b25ce96efbaa88a507d5fdf9f9ca7621eaa1bd3f Mon Sep 17 00:00:00 2001 From: IceToast Date: Wed, 15 Feb 2023 00:25:27 +0100 Subject: [PATCH 13/20] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20Datatables=20So?= =?UTF-8?q?rtable=20trait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Traits/DatatablesSortable.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/Traits/DatatablesSortable.php diff --git a/app/Traits/DatatablesSortable.php b/app/Traits/DatatablesSortable.php new file mode 100644 index 00000000..cf7e87c2 --- /dev/null +++ b/app/Traits/DatatablesSortable.php @@ -0,0 +1,21 @@ +orderBy($column, $direction); + } + + return $query; + } +} From a0268f1c47ea77a05158b352a1ac750be116f949 Mon Sep 17 00:00:00 2001 From: IceToast Date: Wed, 15 Feb 2023 00:25:59 +0100 Subject: [PATCH 14/20] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Sorting=20on=20admi?= =?UTF-8?q?n/users=20datatable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/UserController.php | 71 ++++++---- .../default/views/admin/users/index.blade.php | 126 ++++++++++++------ 2 files changed, 124 insertions(+), 73 deletions(-) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 329fe04c..74453c6f 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Models\User; use App\Notifications\DynamicNotification; +use App\Traits\DatatablesSortable; use Exception; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -26,6 +27,8 @@ class UserController extends Controller { + use DatatablesSortable; + private Pterodactyl $pterodactyl; public function __construct(Pterodactyl $pterodactyl) @@ -132,7 +135,7 @@ public function update(Request $request, User $user) ]); } - if (! is_null($request->input('new_password'))) { + if (!is_null($request->input('new_password'))) { $request->validate([ 'new_password' => 'required|string|min:8', 'new_password_confirmation' => 'required|same:new_password', @@ -259,7 +262,7 @@ public function notify(Request $request) public function toggleSuspended(User $user) { try { - ! $user->isSuspended() ? $user->suspend() : $user->unSuspend(); + !$user->isSuspended() ? $user->suspend() : $user->unSuspend(); } catch (Exception $exception) { return redirect()->back()->with('error', $exception->getMessage()); } @@ -270,32 +273,42 @@ public function toggleSuspended(User $user) /** * @throws Exception */ - public function dataTable() + public function dataTable(Request $request) { - $query = User::with(['discordUser', 'servers'])->select('users.*'); + $query = User::withCount(['servers'])->with('discordUser'); + // manually count referrals in user_referrals table + $query->addSelect(DB::raw('(SELECT COUNT(*) FROM user_referrals WHERE user_referrals.referral_id = users.id) as referrals_count')); + + + if ($request->has('order')) { + $query = $this->sortByColumn($request->input('order'), $request->input('columns'), $query); + } + return datatables($query) ->addColumn('avatar', function (User $user) { - return ''; + return ''; }) ->addColumn('credits', function (User $user) { - return ' '.$user->credits(); + return ' ' . $user->credits(); }) ->addColumn('verified', function (User $user) { return $user->getVerifiedStatus(); }) - ->addColumn('servers', function (User $user) { - return $user->servers->count(); + ->addColumn('servers_count', function (User $user) { + return $user->servers_count; }) - ->addColumn('referrals', function (User $user) { - return DB::table('user_referrals')->where('referral_id', '=', $user->id)->count(); + ->addColumn('referrals_count', function (User $user) { + return $user->referrals_count; }) ->addColumn('discordId', function (User $user) { return $user->discordUser ? $user->discordUser->id : ''; }) ->addColumn('last_seen', function (User $user) { - return ['display' => $user->last_seen ? $user->last_seen->diffForHumans() : '', - 'raw' => $user->last_seen ? strtotime($user->last_seen) : '', ]; + return [ + 'display' => $user->last_seen ? $user->last_seen->diffForHumans() : __('Never'), + 'raw' => $user->last_seen ? strtotime($user->last_seen) : '', + ]; }) ->addColumn('actions', function (User $user) { $suspendColor = $user->isSuspended() ? 'btn-success' : 'btn-warning'; @@ -303,19 +316,19 @@ public function dataTable() $suspendText = $user->isSuspended() ? __('Unsuspend') : __('Suspend'); return ' - - - - -
- '.csrf_field().' - - -
- '.csrf_field().' - '.method_field('DELETE').' - - + + + + +
+ ' . csrf_field() . ' + + +
+ ' . csrf_field() . ' + ' . method_field('DELETE') . ' + + '; }) ->editColumn('role', function (User $user) { @@ -334,14 +347,14 @@ public function dataTable() break; } - return ''.$user->role.''; + return '' . $user->role . ''; }) ->editColumn('name', function (User $user) { - return ''.strip_tags($user->name).''; + return '' . strip_tags($user->name) . ''; }) - /*->orderColumn('last_seen', function ($query) { + ->orderColumn('last_seen', function ($query) { $query->orderBy('last_seen', "desc"); - })*/ + }) ->rawColumns(['avatar', 'name', 'credits', 'role', 'usage', 'referrals', 'actions', 'last_seen']) ->make(true); } diff --git a/themes/default/views/admin/users/index.blade.php b/themes/default/views/admin/users/index.blade.php index b6be7a74..de2dc76e 100644 --- a/themes/default/views/admin/users/index.blade.php +++ b/themes/default/views/admin/users/index.blade.php @@ -6,12 +6,13 @@
-

{{__('Users')}}

+

{{ __('Users') }}

@@ -27,9 +28,9 @@
-
{{__('Users')}}
- {{__('Notify')}} +
{{ __('Users') }}
+ {{ __('Notify') }}
@@ -37,21 +38,21 @@ class="fas fa-paper-plane mr-1">{{__('Notify')}}
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -68,41 +69,78 @@ class="fas fa-paper-plane mr-1">{{__('Notify')}} - - - @endsection From d905171fcbd1283de4666f298973869da79ebe17 Mon Sep 17 00:00:00 2001 From: IceToast Date: Wed, 15 Feb 2023 21:22:16 +0100 Subject: [PATCH 15/20] =?UTF-8?q?fix:=20=F0=9F=90=9B=20admin/store=20sorti?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/ShopProductController.php | 46 +++++++++---------- .../default/views/admin/store/index.blade.php | 9 ++-- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/Admin/ShopProductController.php b/app/Http/Controllers/Admin/ShopProductController.php index 0ff534fd..d308c41c 100644 --- a/app/Http/Controllers/Admin/ShopProductController.php +++ b/app/Http/Controllers/Admin/ShopProductController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Admin; use App\Models\ShopProduct; +use App\Traits\DatatablesSortable; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; @@ -14,6 +15,8 @@ class ShopProductController extends Controller { + use DatatablesSortable; + /** * Display a listing of the resource. * @@ -66,23 +69,12 @@ public function store(Request $request) 'display' => 'required|string|max:60', ]); - $disabled = ! is_null($request->input('disabled')); + $disabled = !is_null($request->input('disabled')); ShopProduct::create(array_merge($request->all(), ['disabled' => $disabled])); return redirect()->route('admin.store.index')->with('success', __('Store item has been created!')); } - /** - * Display the specified resource. - * - * @param ShopProduct $shopProduct - * @return Response - */ - public function show(ShopProduct $shopProduct) - { - // - } - /** * Show the form for editing the specified resource. * @@ -116,7 +108,7 @@ public function update(Request $request, ShopProduct $shopProduct) 'display' => 'required|string|max:60', ]); - $disabled = ! is_null($request->input('disabled')); + $disabled = !is_null($request->input('disabled')); $shopProduct->update(array_merge($request->all(), ['disabled' => $disabled])); return redirect()->route('admin.store.index')->with('success', __('Store item has been updated!')); @@ -129,7 +121,7 @@ public function update(Request $request, ShopProduct $shopProduct) */ public function disable(Request $request, ShopProduct $shopProduct) { - $shopProduct->update(['disabled' => ! $shopProduct->disabled]); + $shopProduct->update(['disabled' => !$shopProduct->disabled]); return redirect()->route('admin.store.index')->with('success', __('Product has been updated!')); } @@ -147,19 +139,23 @@ public function destroy(ShopProduct $shopProduct) return redirect()->back()->with('success', __('Store item has been removed!')); } - public function dataTable() + public function dataTable(Request $request) { $query = ShopProduct::query(); + if ($request->has('order')) { + $query = $this->sortByColumn($request->input('order'), $request->input('columns'), $query); + } + return datatables($query) ->addColumn('actions', function (ShopProduct $shopProduct) { return ' - + -
- '.csrf_field().' - '.method_field('DELETE').' - + + ' . csrf_field() . ' + ' . method_field('DELETE') . ' + '; }) @@ -167,12 +163,12 @@ public function dataTable() $checked = $shopProduct->disabled == false ? 'checked' : ''; return ' -
- '.csrf_field().' - '.method_field('PATCH').' + + ' . csrf_field() . ' + ' . method_field('PATCH') . '
- - + +
'; diff --git a/themes/default/views/admin/store/index.blade.php b/themes/default/views/admin/store/index.blade.php index 161b911e..66647030 100644 --- a/themes/default/views/admin/store/index.blade.php +++ b/themes/default/views/admin/store/index.blade.php @@ -102,10 +102,12 @@ function submitResult() { data: 'price' }, { - data: 'display' + data: 'display', + sortable: false }, { - data: 'description' + data: 'description', + sortable: false }, { data: 'created_at' @@ -121,7 +123,4 @@ function submitResult() { }); }); - - - @endsection From 459069c5ee39be6881129616bb4c23778173d979 Mon Sep 17 00:00:00 2001 From: IceToast Date: Wed, 15 Feb 2023 21:41:24 +0100 Subject: [PATCH 16/20] =?UTF-8?q?feat:=20=F0=9F=90=9B=20admin/servers=20so?= =?UTF-8?q?rtable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/ServerController.php | 44 +++-------- .../views/admin/servers/table.blade.php | 74 ++++++++++++------- 2 files changed, 60 insertions(+), 58 deletions(-) diff --git a/app/Http/Controllers/Admin/ServerController.php b/app/Http/Controllers/Admin/ServerController.php index 06d2cc22..14b594ab 100644 --- a/app/Http/Controllers/Admin/ServerController.php +++ b/app/Http/Controllers/Admin/ServerController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Models\Server; use App\Models\User; +use App\Traits\DatatablesSortable; use Exception; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; @@ -14,9 +15,12 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Log; class ServerController extends Controller { + use DatatablesSortable; + /** * Display a listing of the resource. * @@ -27,38 +31,6 @@ public function index() return view('admin.servers.index'); } - /** - * Show the form for creating a new resource. - * - * @return Response - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - * - * @param Request $request - * @return Response - */ - public function store(Request $request) - { - // - } - - /** - * Display the specified resource. - * - * @param Server $server - * @return Response - */ - public function show(Server $server) - { - // - } - /** * Show the form for editing the specified resource. * @@ -196,6 +168,7 @@ public function syncServers() public function dataTable(Request $request) { $query = Server::with(['user', 'product']); + if ($request->has('product')) { $query->where('product_id', '=', $request->input('product')); } @@ -204,6 +177,11 @@ public function dataTable(Request $request) } $query->select('servers.*'); + + if ($request->has('order')) { + $query = $this->sortByColumn($request->input('order'), $request->input('columns'), $query); + } + return datatables($query) ->addColumn('user', function (Server $server) { return '' . $server->user->name . ''; @@ -232,7 +210,7 @@ public function dataTable(Request $request) '; }) ->addColumn('status', function (Server $server) { - $labelColor = $server->isSuspended() ? 'text-danger' : 'text-success'; + $labelColor = $server->suspended ? 'text-danger' : 'text-success'; return ''; }) diff --git a/themes/default/views/admin/servers/table.blade.php b/themes/default/views/admin/servers/table.blade.php index b71671de..219ef47c 100644 --- a/themes/default/views/admin/servers/table.blade.php +++ b/themes/default/views/admin/servers/table.blade.php @@ -1,15 +1,15 @@
discordIdippterodactyl_id{{__('Avatar')}}{{__('Name')}}{{__('Role')}}{{__('Email')}}{{CREDITS_DISPLAY_NAME}}{{__('Servers')}}{{__("Referrals")}}{{__('Verified')}}{{__('Last seen')}}
discordIdippterodactyl_id{{ __('Avatar') }}{{ __('Name') }}{{ __('Role') }}{{ __('Email') }}{{ CREDITS_DISPLAY_NAME }}{{ __('Servers') }}{{ __('Referrals') }}{{ __('Verified') }}{{ __('Last seen') }}
- - - - - - - - - - + + + + + + + + + + @@ -17,30 +17,54 @@
{{__('Name')}}{{__('User')}}{{__('Server id')}}{{__('Config')}}{{__('Suspended at')}}{{__('Created at')}}
{{ __('Name') }}{{ __('User') }}{{ __('Server id') }}{{ __('Config') }}{{ __('Suspended at') }}{{ __('Created at') }}