]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5835 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 29 Mar 2023 16:47:08 +0000 (18:47 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 29 Mar 2023 16:47:08 +0000 (18:47 +0200)
app/Console/Kernel.php
app/Http/Controllers/Admin/TasksController.php [new file with mode: 0644]
app/Jobs/Maintenance/CleanDownloads.php
app/Jobs/MarkUserNotificationsAsRead.php [new file with mode: 0644]
app/Models/ELearningMedia.php
app/Models/Notification.php [new file with mode: 0644]
app/Models/User.php
public/packages/fluidbook/toolbox/css/style.less
resources/views/tasks/index.blade.php [new file with mode: 0644]
resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
routes/web.php

index 21ce254bc217fe67104687b80f9818e5c965c43d..b128bcf2c35bde728df7c438ccc57480ffa46c88 100644 (file)
@@ -25,8 +25,9 @@ class Kernel extends \Cubist\Backpack\Console\Kernel
     protected function schedule(Schedule $schedule)
     {
         $schedule->command('queue:prune-failed --hours=24')->daily()->at('03:50');
-        $schedule->command('job:dispatch Maintenance\\\\CleanDownloads')->dailyAt('4:00');
-        $schedule->command('job:dispatch Maintenance\\\\CleanFTP')->dailyAt('4:30');
+        $schedule->command('job:dispatchNow Maintenance\\\\CleanDownloads')->dailyAt('4:00');
+        $schedule->command('job:dispatchNow Maintenance\\\\CleanFTP')->dailyAt('4:30');
+        $schedule->command('model:prune')->dailyAt('5:00');
         // $schedule->command('backup:clean')->daily()->at('04:00');
         // $schedule->command('backup:run')->daily()->at('05:00');
 
diff --git a/app/Http/Controllers/Admin/TasksController.php b/app/Http/Controllers/Admin/TasksController.php
new file mode 100644 (file)
index 0000000..55d7286
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Controllers\Controller;
+use App\Jobs\MarkUserNotificationsAsRead;
+use App\Models\User;
+
+class TasksController extends Controller
+{
+    public function index()
+    {
+        /** @var User $user */
+        $user = backpack_user();
+        $notifications = $user->notifications;
+        $res = view('tasks.index', ['notifications' => clone $notifications]);
+        MarkUserNotificationsAsRead::dispatchSync($user)/*->delay(now()->addSeconds(15))*/;
+        return $res;
+    }
+
+    public function countUnread()
+    {
+        return response()->json(['unread' => backpack_user()->unreadNotifications()->count()]);
+    }
+
+    public function deleteNotification($id)
+    {
+        foreach (backpack_user()->notifications as $notification) {
+            if ($notification->id === $id) {
+                $notification->delete();
+            }
+        }
+    }
+}
index 78cd628a172b7cd8c2c8ef981289a8c4750a7c1a..d2fc1117f99eed65e7b6b358fe052ec7b0da2e91 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Jobs\Maintenance;
 
 use App\Jobs\Base;
 use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Notification;
 
 class CleanDownloads extends Base
 {
diff --git a/app/Jobs/MarkUserNotificationsAsRead.php b/app/Jobs/MarkUserNotificationsAsRead.php
new file mode 100644 (file)
index 0000000..5f4444c
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Models\User;
+
+class MarkUserNotificationsAsRead extends Base
+{
+    /** @var User */
+    protected $user;
+
+    public function __construct(User $user)
+    {
+        $this->user = $user;
+    }
+
+    public function handle()
+    {
+        foreach ($this->user->notifications as $notification) {
+            if ($notification->read_at === null) {
+                $notification->markAsRead();
+            }
+        }
+    }
+}
index 3bda56cca67fc7f42f4e2fe9244a59292ec3d226..a455ad988d0ac2a9ca6a51911d58c32bacb43a8a 100644 (file)
@@ -17,6 +17,7 @@ use Cubist\Scorm\Manifest;
 use Cubist\Scorm\Version;
 use Cubist\Util\Files\VirtualDirectory;
 use Spatie\MediaLibrary\MediaCollections\Models\Media;
+
 // __('!! e-Learning')
 class ELearningMedia extends ToolboxModel
 {
@@ -32,7 +33,7 @@ class ELearningMedia extends ToolboxModel
 
     public const MEDIA_TYPES = ['audio/mpeg', 'video/mp4', 'application/pdf'];
 
-    protected $_operations = [ImportOperation::class, PreviewOperation::class, DownloadOperation::class,ChangeownerOperation::class];
+    protected $_operations = [ImportOperation::class, PreviewOperation::class, DownloadOperation::class, ChangeownerOperation::class];
 
     public function setFields()
     {
@@ -73,9 +74,10 @@ class ELearningMedia extends ToolboxModel
     public function preSave()
     {
         $file = $this->getMediaInField('file')->first();
-        $spl = new \SplFileInfo($file->getPath());
-
-        $this->setAttribute('type', self::getType($spl->getExtension()));
+        if ($file !== null) {
+            $spl = new \SplFileInfo($file->getPath());
+            $this->setAttribute('type', self::getType($spl->getExtension()));
+        }
         return parent::preSave();
     }
 
diff --git a/app/Models/Notification.php b/app/Models/Notification.php
new file mode 100644 (file)
index 0000000..ffdaf3a
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\MassPrunable;
+use Illuminate\Notifications\DatabaseNotification;
+
+class Notification extends DatabaseNotification
+{
+    use MassPrunable;
+
+    protected $table = 'extranet_users.notifications';
+
+    public function prunable(): Builder
+    {
+        return static::where('created_at', '<=', now()->subDays(15));
+    }
+}
+
index 82e0f59000ef419871c9ae82dcebe0eb02b05307..81d3b92c2de1b10e724190be26a2d52799a315d5 100644 (file)
@@ -10,5 +10,7 @@ class User extends \Cubedesigners\UserDatabase\Models\User
         $query->where('company', 7);
         $query->orderBy('enabled', 'ASC');
         $query->orderBy('id', 'ASC');
+
     }
+
 }
index c2bbd6013a69cd8b5241c6401299a796da55b95d..7bd94ff2246a5b1674137e13ed3205a2626f4486 100644 (file)
@@ -442,11 +442,29 @@ body.embeded {
     right: 80%;
 }
 
-.user_disabled a{
+.user_disabled a {
     color: #999;
     text-decoration: line-through;
 }
 
+.la-bell {
+
+    &.unread {
+        position: relative;
+
+        &:after {
+            content: "";
+            position: absolute;
+            width: 5px;
+            height: 5px;
+            border-radius: 50%;
+            top: -1px;
+            right: -1px;
+            background-color: #f00;
+        }
+    }
+}
+
 @import "context-menu";
 @import "loader";
 
diff --git a/resources/views/tasks/index.blade.php b/resources/views/tasks/index.blade.php
new file mode 100644 (file)
index 0000000..23fc162
--- /dev/null
@@ -0,0 +1,91 @@
+{{-- __('!! Équipe') --}}
+@extends(backpack_view('blank'))
+
+@push('after_scripts')
+    <script>
+        (function ($) {
+            $(function () {
+                $(document).on('click', '[data-button-type="delete"]', function () {
+                    let $this = this;
+                    $.ajax({
+                        url: '{{url('tasks/notification/')}}/' + $(this).attr('data-id'),
+                        method: 'post',
+                        data: {_method: 'delete'},
+                        success: function () {
+                            $this.closest('tr').remove();
+                        },
+                    });
+                });
+            });
+        })(jQuery);
+    </script>
+@endpush
+
+@section('content')
+    <style>
+        .table td, .table th {
+            vertical-align: middle;
+        }
+
+        .table tr.unread td {
+            font-weight: 600;
+        }
+
+        .table tr ul {
+            list-style: none;
+            padding: 3px 0;
+            margin: 0;
+        }
+
+        .table tr ul li {
+            margin: 2px 0;
+        }
+
+        .table tr.unread i.unread {
+            background-color: #f00;
+            border-radius: 50%;
+            width: 8px;
+            height: 8px;
+            display: block;
+        }
+    </style>
+    {{--    <h2 style="margin-top: 50px">{{__('Tâches en cours')}}</h2>--}}
+    <h2 style="margin-top: 50px">{{__('Notifications')}}</h2>
+    <table id="crudTable"
+           class="bg-white table table-striped table-hover nowrap rounded shadow-xs border-xs mt-2 dataTable dtr-inline">
+        {{--        <thead>--}}
+        {{--        <tr role="row">--}}
+        {{--            <th></th>--}}
+        {{--            <th>{{__('Bulletin')}}</th>--}}
+        {{--            <th>{{__('Date')}}</th>--}}
+        {{--            <th></th>--}}
+        {{--        </tr>--}}
+        {{--        </thead>--}}
+        <tbody>
+
+        @if(!$notifications || !count($notifications))
+            {{__('Aucune notification')}}
+        @endif
+        @foreach($notifications as $id=>$notification)
+            <tr role="row" @if($notification->read_at===null) class="unread" @endif>
+                <td></td>
+                <td>{{$notification->data['subject']}}<br>
+                    <ul>
+                        @foreach($notification->data['actions'] as $label=>$url)
+                            <li>{{$label}} : <a href="{{$url}}" target="_blank">{{$url}}</a></li>
+                        @endforeach
+                    </ul>
+                </td>
+                <td><i class="unread"></i></td>
+                <td>{{$notification->created_at}}</td>
+                <td>
+                    <a href="#" class="btn btn-sm btn-link" data-button-type="delete" data-id="{{$notification->id}}"><i
+                            class="la la-trash"></i></a>
+                </td>
+            </tr>
+        @endforeach
+        </tbody>
+    </table>
+@endsection
+
+
index 9202dd0e749e48019ea20e6e65ede3e844a7bc09..f4e2d9edc9040a2eda079e611a88dec4c2b3f050 100644 (file)
@@ -6,6 +6,7 @@
         $state=(backpack_user()->getToolboxSetting('sidebar_'.$id,$default)=='1')?' open':'';
         return 'class="nav-item nav-dropdown'.$state.'" data-sidebar-id="'.$id.'"';
     }
+
 @endphp
 @push('after_scripts')
     <script>
                 }, 500);
                 return true;
             });
+
+            function checkUnread() {
+                $.ajax({
+                    url: '{{url('tasks/countUnread')}}',
+                    success: function (data) {
+                        if (data.unread > 0) {
+                            $('.la-bell').addClass('unread');
+                        } else {
+                            $('.la-bell').removeClass('unread');
+                        }
+                    },
+                });
+            }
+
+            setInterval(function () {
+                checkUnread();
+            }, 10000);
+            checkUnread();
         });
     </script>
 @endpush
@@ -33,7 +52,7 @@
             class='nav-icon la la-dashboard'></i>{{ trans('backpack::base.dashboard') }}
     </a></li>
 <li class="nav-item"><a class="nav-link" href="{{ backpack_url('tasks') }}"><i
-            class='nav-icon la la-bell'></i>{{ __('Tâches et notifications') }}
+            class='nav-icon la la-bell'></i>{{ __('Notifications') }}
     </a></li>
 
 @can('files:read')
index 079110f27f98ec0d949fae52b29da03b519cb147..ac7d215fb9ff18f63338169b398f9a4e12268128 100644 (file)
@@ -22,6 +22,9 @@ Route::group([
     Route::get('fluidbookthemepreview/{id}-burger.jpg', 'FluidbookThemePreviewController@previewBurger');
     Route::get('fluidbookthemepreview/{id}-menu.jpg', 'FluidbookThemePreviewController@previewMenu');
     Route::get('fluidbookthemepreview/{id}.jpg', 'FluidbookThemePreviewController@preview');
+    Route::get('tasks', 'TasksController@index');
+    Route::get('tasks/countUnread', 'TasksController@countUnread');
+    Route::delete('tasks/notification/{id}', 'TasksController@deleteNotification');
 });
 
 Route::group([