diff --git a/app/Http/Controllers/Common/Notifications.php b/app/Http/Controllers/Common/Notifications.php new file mode 100644 index 000000000..cb0f38a89 --- /dev/null +++ b/app/Http/Controllers/Common/Notifications.php @@ -0,0 +1,70 @@ +getNotifications($path); + + foreach ($notifications as $notification) { + if ($notification->id == $id) { + setting()->set('notifications.'. $path . '.' . $id . '.name', $notification->name); + setting()->set('notifications.'. $path . '.' . $id . '.message', $notification->message); + setting()->set('notifications.'. $path . '.' . $id . '.date', Date::now()); + setting()->set('notifications.'. $path . '.' . $id . '.status', '0'); + + setting()->save(); + break; + } + } + + return response()->json([ + 'success' => true, + 'error' => false, + 'data' => null, + ]); + } +} diff --git a/app/Http/Requests/Common/Notification.php b/app/Http/Requests/Common/Notification.php new file mode 100644 index 000000000..3dedd3db8 --- /dev/null +++ b/app/Http/Requests/Common/Notification.php @@ -0,0 +1,31 @@ + 'required|string', + 'id' => 'required|integer', + ]; + } +} diff --git a/app/Http/ViewComposers/Notifications.php b/app/Http/ViewComposers/Notifications.php index 58bbfb2fa..1d8383894 100644 --- a/app/Http/ViewComposers/Notifications.php +++ b/app/Http/ViewComposers/Notifications.php @@ -37,7 +37,16 @@ class Notifications // Push to a stack foreach ($notifications as $notification) { - $view->getFactory()->startPush('content_content_start', $notification->message); + $setting = 'notifications.'. $notification->path . '.' . $notification->id . '.status'; + + $path = str_replace('/', '#', $notification->path); + + $message = str_replace('#path#', $path, $notification->message); + $message = str_replace('#token#', csrf_token(), $message); + + if (setting($setting, 1)) { + $view->getFactory()->startPush('content_content_start', $message); + } } } } diff --git a/app/Listeners/Updates/Version132.php b/app/Listeners/Updates/Version132.php new file mode 100644 index 000000000..094a71be3 --- /dev/null +++ b/app/Listeners/Updates/Version132.php @@ -0,0 +1,79 @@ +check($event)) { + return; + } + + $this->updatePermissions(); + + // Update database + Artisan::call('migrate', ['--force' => true]); + } + + protected function updatePermissions() + { + $permissions = []; + + // Banking Reconciliations + $permissions[] = Permission::firstOrCreate([ + 'name' => 'read-common-notifications', + 'display_name' => 'Read Common Notifications', + 'description' => 'Read Common Notifications', + ]); + + $permissions[] = Permission::firstOrCreate([ + 'name' => 'create-common-notifications', + 'display_name' => 'Create Common Notifications', + 'description' => 'Create Common Notifications', + ]); + + $permissions[] = Permission::firstOrCreate([ + 'name' => 'update-common-notifications', + 'display_name' => 'Update Common Notifications', + 'description' => 'Update Common Notifications', + ]); + + $permissions[] = Permission::firstOrCreate([ + 'name' => 'delete-common-notifications', + 'display_name' => 'Delete Common Notifications', + 'description' => 'Delete Common Notifications', + ]); + + // Attach permission to roles + $roles = Role::all(); + + foreach ($roles as $role) { + $allowed = ['admin', 'manager']; + + if (!in_array($role->name, $allowed)) { + continue; + } + + foreach ($permissions as $permission) { + $role->attachPermission($permission); + } + } + } +} diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index 7afc5a8d8..088d369ac 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -37,6 +37,7 @@ class Roles extends Seeder 'common-import' => 'c', 'common-items' => 'c,r,u,d', 'common-uploads' => 'd', + 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', 'incomes-customers' => 'c,r,u,d', @@ -75,6 +76,7 @@ class Roles extends Seeder 'common-companies' => 'c,r,u,d', 'common-import' => 'c', 'common-items' => 'c,r,u,d', + 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', 'incomes-customers' => 'c,r,u,d', diff --git a/public/js/app.js b/public/js/app.js index ae095c5bb..52e017bb4 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -340,3 +340,18 @@ function itemTableResize() { $('#items.table.table-bordered tbody #tr-tax .text-right:first').attr('colspan', colspan); $('#items.table.table-bordered tbody #tr-total .text-right:first').attr('colspan', colspan); } + +function notificationHide(path, id, token) { + $.ajax({ + url: app_url + '/common/notifications/disable', + type: 'POST', + dataType: 'JSON', + data: {path: path, id: id}, + headers: { 'X-CSRF-TOKEN': token }, + success: function(json) { + if (json['success']) { + $('#notification-' + id).remove(); + } + } + }); +} diff --git a/resources/views/common/notifications/index.blade.php b/resources/views/common/notifications/index.blade.php new file mode 100644 index 000000000..b21ceea47 --- /dev/null +++ b/resources/views/common/notifications/index.blade.php @@ -0,0 +1,32 @@ +@extends('layouts.admin') + +@section('title', trans_choice('general.notifications', 2)) + +@section('content') + + +
+
+
+ + +
+
+ + + + + +
+
+
+ + + + +
+ +@endsection + diff --git a/resources/views/partials/admin/head.blade.php b/resources/views/partials/admin/head.blade.php index 682fe3367..d2f559b71 100644 --- a/resources/views/partials/admin/head.blade.php +++ b/resources/views/partials/admin/head.blade.php @@ -60,6 +60,7 @@ diff --git a/resources/views/partials/customer/head.blade.php b/resources/views/partials/customer/head.blade.php index 8bef6ff57..b61171dce 100644 --- a/resources/views/partials/customer/head.blade.php +++ b/resources/views/partials/customer/head.blade.php @@ -66,6 +66,7 @@ diff --git a/resources/views/partials/link/head.blade.php b/resources/views/partials/link/head.blade.php index 8bef6ff57..b61171dce 100644 --- a/resources/views/partials/link/head.blade.php +++ b/resources/views/partials/link/head.blade.php @@ -66,6 +66,7 @@ diff --git a/resources/views/partials/modules/head.blade.php b/resources/views/partials/modules/head.blade.php index 737733d59..edb945fa3 100644 --- a/resources/views/partials/modules/head.blade.php +++ b/resources/views/partials/modules/head.blade.php @@ -60,6 +60,7 @@