Notification hide.
This commit is contained in:
parent
8b5fd52d3d
commit
e78b786e42
70
app/Http/Controllers/Common/Notifications.php
Normal file
70
app/Http/Controllers/Common/Notifications.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Common;
|
||||
|
||||
use Date;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\Modules as RemoteModules;
|
||||
use App\Http\Requests\Common\Notification as Request;
|
||||
|
||||
class Notifications extends Controller
|
||||
{
|
||||
use RemoteModules;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$notifications = setting('notifications');
|
||||
|
||||
return view('common.notifications.index', compact('notifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for viewing the specified resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show($path, $id)
|
||||
{
|
||||
$notification = setting('notifications.' . $path . '.' . $id);
|
||||
|
||||
return view('common.notifications.show', compact('notification'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource.
|
||||
*
|
||||
* @param Company $company
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function disable(Request $request)
|
||||
{
|
||||
$id = $request['id'];
|
||||
$path = str_replace('#', '/', $request['path']);
|
||||
|
||||
$notifications = $this->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,
|
||||
]);
|
||||
}
|
||||
}
|
31
app/Http/Requests/Common/Notification.php
Normal file
31
app/Http/Requests/Common/Notification.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Common;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class Notification extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'path' => 'required|string',
|
||||
'id' => 'required|integer',
|
||||
];
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
79
app/Listeners/Updates/Version132.php
Normal file
79
app/Listeners/Updates/Version132.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Updates;
|
||||
|
||||
use App\Events\UpdateFinished;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
use Artisan;
|
||||
|
||||
class Version132 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '1.3.2';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(UpdateFinished $event)
|
||||
{
|
||||
// Check if should listen
|
||||
if (!$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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',
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
32
resources/views/common/notifications/index.blade.php
Normal file
32
resources/views/common/notifications/index.blade.php
Normal file
@ -0,0 +1,32 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', trans_choice('general.notifications', 2))
|
||||
|
||||
@section('content')
|
||||
<!-- Default box -->
|
||||
|
||||
<div class="box box-success">
|
||||
<div class="box-header with-border">
|
||||
</div>
|
||||
<!-- /.box-header -->
|
||||
|
||||
<div class="box-body">
|
||||
<div class="table table-responsive">
|
||||
<table class="table table-striped table-hover" id="tbl-notifications">
|
||||
<thead>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
|
||||
<div class="box-footer">
|
||||
@include('partials.admin.pagination', ['items' => $notifications, 'type' => 'notifications'])
|
||||
</div>
|
||||
<!-- /.box-footer -->
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
@endsection
|
||||
|
@ -60,6 +60,7 @@
|
||||
<script src="{{ asset('public/js/app.js?v=' . version('short')) }}"></script>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
var app_url = '{{ env("APP_URL") }}';
|
||||
var url_search = '{{ url("common/search/search") }}';
|
||||
//--></script>
|
||||
|
||||
|
@ -66,6 +66,7 @@
|
||||
<script src="{{ asset('public/js/app.js?v=' . version('short')) }}"></script>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
var app_url = '{{ env("APP_URL") }}';
|
||||
var url_search = '{{ url("common/search/search") }}';
|
||||
//--></script>
|
||||
|
||||
|
@ -66,6 +66,7 @@
|
||||
<script src="{{ asset('public/js/app.js?v=' . version('short')) }}"></script>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
var app_url = '{{ env("APP_URL") }}';
|
||||
var url_search = '{{ url("common/search/search") }}';
|
||||
//--></script>
|
||||
|
||||
|
@ -60,6 +60,7 @@
|
||||
<script src="{{ asset('public/js/app.js?v=' . version('short')) }}"></script>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
var app_url = '{{ env("APP_URL") }}';
|
||||
var url_search = '{{ url("common/search/search") }}';
|
||||
//--></script>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user