From ebf11d38ed8e81623deafa691c794d7399264156 Mon Sep 17 00:00:00 2001 From: Kwesi Banson Date: Fri, 25 Sep 2026 16:44:37 +0000 Subject: [PATCH] added sync button, improved UI --- app/Http/Controllers/DashboardController.php | 4 - info.md | 6 + public/assets/js/dashboard.js | 50 ++++++- resources/views/dashboard/index.blade.php | 10 +- resources/views/layouts/app.blade copy.php | 81 +++++++++++ resources/views/layouts/app.blade.php | 142 ++++++++++++------- routes/web.php | 51 +++++-- 7 files changed, 277 insertions(+), 67 deletions(-) create mode 100644 resources/views/layouts/app.blade copy.php diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index e33bd5a..0f094cf 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -9,7 +9,6 @@ class DashboardController extends Controller { public function index(){ - // dd('public insanity'); return view('dashboard.index'); } @@ -50,8 +49,6 @@ class DashboardController extends Controller 'services' => $stats ]); } - // app/Http/Controllers/DashboardController.php - // app/Http/Controllers/DashboardController.php public function details(Request $request, $id) { $service = DB::table('subscription_services')->where('id', $id)->first(); @@ -77,7 +74,6 @@ class DashboardController extends Controller return view('dashboard.details', compact('service', 'subscribers')); } - // app/Http/Controllers/DashboardController.php public function subscriberProfile(Request $request, $serviceId, $msisdn) { $service = DB::table('subscription_services')->where('id', $serviceId)->first(); diff --git a/info.md b/info.md index 411b532..4e8d463 100644 --- a/info.md +++ b/info.md @@ -35,3 +35,9 @@ techappsuser@206.225.84.201:/home/techappsuser/DockerProjects/subscription_services/src/ + +\App\Models\User::create([ + 'name' => 'Admin User', + 'email' => 'kwesi@click-mobile.com', + 'password' => Hash::make('franctic@233') +]); diff --git a/public/assets/js/dashboard.js b/public/assets/js/dashboard.js index 3fb852d..e61465f 100644 --- a/public/assets/js/dashboard.js +++ b/public/assets/js/dashboard.js @@ -1,6 +1,5 @@ // public/js/dashboard.js $(document).ready(function() { - console.log(base_url); function fetchDashboardStats() { $.ajax({ url: base_url + '/api/dashboard/stats', @@ -83,4 +82,53 @@ $(document).ready(function() { // Todo: Refresh data every 5 minutes (300000 ms) automatically without page reload // setInterval(fetchDashboardStats, 300000); + + $('#syncTriggerBtn').on('click', function() { + let btn = $(this); + let icon = $('#syncIcon'); + let text = $('#syncText'); + + // Disable button and add spinning effect + btn.prop('disabled', true); + icon.addClass('spinner-border spinner-border-sm'); + text.text('Syncing...'); + + $.ajax({ + url: base_url + '/api/subscriptions/sync', + method: 'POST', + data: { + _token: $('meta[name="csrf-token"]').attr('content') + }, + success: function(response) { + // Use SweetAlert2 for a clean success alert + Swal.fire({ + icon: 'success', + title: 'Synchronized!', + text: response.message, + timer: 2000, + showConfirmButton: false + }); + + // Refresh dashboard data instantly to reflect updated counts + fetchDashboardStats(); + }, + error: function(xhr) { + let errorMsg = xhr.responseJSON && xhr.responseJSON.message + ? xhr.responseJSON.message + : 'An unexpected error occurred during synchronization.'; + + Swal.fire({ + icon: 'error', + title: 'Sync Failed', + text: errorMsg + }); + }, + complete: function() { + // Restore button state + btn.prop('disabled', false); + icon.removeClass('spinner-border spinner-border-sm'); + text.text('Sync Now'); + } + }); + }); }); \ No newline at end of file diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 2b9a9a8..df6b3bf 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -2,7 +2,15 @@ @section('content')
-

Subscriptions Overview

+
+

Subscriptions Overview

+ + + +
diff --git a/resources/views/layouts/app.blade copy.php b/resources/views/layouts/app.blade copy.php new file mode 100644 index 0000000..aa1e8cc --- /dev/null +++ b/resources/views/layouts/app.blade copy.php @@ -0,0 +1,81 @@ + + + + + + + + + + Click Content Management + + + + + + + + +@stack('styles') + + + +
+ + + + +
+ @yield('content') +
+
+ @stack('modals') + + + + + @stack('scripts') + + diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index aa1e8cc..46e8d4a 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -11,66 +11,110 @@ - + - + -@stack('styles') - + + + + + @stack('styles') +
- - - + -
+
@yield('content')
+ @stack('modals') @@ -78,4 +122,4 @@ @stack('scripts') - + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index d25fd47..bc7e04e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,12 +1,19 @@ false, // Disables the registration routes + 'reset' => false, // Disables the password reset routes + 'verify' => false, // Disables the email verification routes +]); + + + Route::get('/home', [App\Http\Controllers\DashboardController::class, 'index'])->name('home'); @@ -15,18 +22,38 @@ Route::get('/', [App\Http\Controllers\DashboardController::class, 'index'])->nam -// The main dashboard view -Route::get('/', [App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard.index'); +Route::post('/api/subscriptions/sync', function () { + try { + // Run the artisan command programmatically + Artisan::call('subscriptions:sync'); -// The AJAX endpoint for jQuery to consume -Route::get('/api/dashboard/stats', [App\Http\Controllers\DashboardController::class, 'getStats'])->name('api.dashboard.stats'); + return response()->json([ + 'status' => 'success', + 'message' => 'Subscriptions synchronized successfully!' + ]); + } catch (\Exception $e) { + return response()->json([ + 'status' => 'error', + 'message' => 'Sync failed: ' . $e->getMessage() + ], 500); + } +})->name('api.subscriptions.sync'); -Route::get('/services/create', [App\Http\Controllers\SubscriptionServiceController::class, 'create'])->name('services.create'); -Route::post('/services', [App\Http\Controllers\SubscriptionServiceController::class, 'store'])->name('services.store'); -Route::post('/services/test-connection', [App\Http\Controllers\SubscriptionServiceController::class, 'testConnection'])->name('services.test'); +Route::middleware(['auth'])->group(function () { + Route::get('/', [App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard.index'); -// routes/web.php -Route::get('/services/{id}/details', [App\Http\Controllers\DashboardController::class, 'details'])->name('services.details'); -Route::get('/services/{serviceId}/subscriber/{msisdn}', [App\Http\Controllers\DashboardController::class, 'subscriberProfile'])->name('services.subscriber.profile'); \ No newline at end of file + + Route::get('/api/dashboard/stats', [App\Http\Controllers\DashboardController::class, 'getStats'])->name('api.dashboard.stats'); + + + Route::get('/services/create', [App\Http\Controllers\SubscriptionServiceController::class, 'create'])->name('services.create'); + Route::post('/services', [App\Http\Controllers\SubscriptionServiceController::class, 'store'])->name('services.store'); + + Route::post('/services/test-connection', [App\Http\Controllers\SubscriptionServiceController::class, 'testConnection'])->name('services.test'); + + Route::get('/services/{id}/details', [App\Http\Controllers\DashboardController::class, 'details'])->name('services.details'); + Route::get('/services/{serviceId}/subscriber/{msisdn}', [App\Http\Controllers\DashboardController::class, 'subscriberProfile'])->name('services.subscriber.profile'); + +}); \ No newline at end of file