akaunting 3.0 (the last dance)
This commit is contained in:
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Exports extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
protected $listeners = [
|
||||
'refreshParent' => '$notifications',
|
||||
];
|
||||
|
||||
public function markRead($notification_id)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
$type = isset($data['file_name']) ?: trans('general.export');
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'export',
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $type]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'export',
|
||||
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('general.export')]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$limit = 5;
|
||||
|
||||
$notifications = $this->getNotifications($limit);
|
||||
|
||||
return view('livewire.common.notifications.exports', compact('notifications'));
|
||||
}
|
||||
|
||||
protected function getNotifications($limit = false)
|
||||
{
|
||||
$query = user()->notifications()->unread()
|
||||
->where(function ($query) {
|
||||
$query->where('type', 'App\Notifications\Common\ExportCompleted')
|
||||
->orWhere('type', 'App\Notifications\Common\ExportFailed');
|
||||
});
|
||||
|
||||
if ($limit) {
|
||||
$notifications = $query->paginate($limit);
|
||||
} else {
|
||||
$notifications = $query->get();
|
||||
}
|
||||
|
||||
if ($notifications) {
|
||||
$items = [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$data = (object) $notification->getAttribute('data');
|
||||
$data->notification_id = $notification->getAttribute('id');
|
||||
|
||||
$items[] = $data;
|
||||
}
|
||||
|
||||
$notifications->setCollection(Collection::make($items));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function paginationView()
|
||||
{
|
||||
return 'vendor.livewire.default';
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Imports extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
protected $listeners = [
|
||||
'refreshParent' => '$notifications',
|
||||
];
|
||||
|
||||
public function markRead($notification_id)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
$type = isset($data['translation']) ?: trans('import.import');
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'import',
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $type]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'import',
|
||||
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('import.import')]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$limit = 5;
|
||||
|
||||
$notifications = $this->getNotifications($limit);
|
||||
|
||||
return view('livewire.common.notifications.imports', compact('notifications'));
|
||||
}
|
||||
|
||||
protected function getNotifications($limit = false)
|
||||
{
|
||||
$query = user()->notifications()->unread()
|
||||
->where(function ($query) {
|
||||
$query->where('type', 'App\Notifications\Common\ImportCompleted')
|
||||
->orWhere('type', 'App\Notifications\Common\ImportFailed');
|
||||
});
|
||||
|
||||
if ($limit) {
|
||||
$notifications = $query->paginate($limit);
|
||||
} else {
|
||||
$notifications = $query->get();
|
||||
}
|
||||
|
||||
if ($notifications) {
|
||||
$items = [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$data = (object) $notification->getAttribute('data');
|
||||
$data->notification_id = $notification->getAttribute('id');
|
||||
|
||||
$items[] = $data;
|
||||
}
|
||||
|
||||
$notifications->setCollection(Collection::make($items));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function paginationView()
|
||||
{
|
||||
return 'vendor.livewire.default';
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use App\Traits\Modules;
|
||||
use App\Utilities\Date;
|
||||
use Livewire\Component;
|
||||
|
||||
class NewApps extends Component
|
||||
{
|
||||
use Modules;
|
||||
|
||||
public function markRead($alias)
|
||||
{
|
||||
$notifications = $this->getNotifications('new-apps');
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
if ($notification->alias != $alias) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$read = $notification;
|
||||
}
|
||||
|
||||
$prefix = 'notifications.' . user()->id . '.' . $alias;
|
||||
|
||||
setting()->set([
|
||||
$prefix . '.name' => $read->name,
|
||||
$prefix . '.message' => $read->alias,
|
||||
$prefix . '.date' => Date::now(),
|
||||
$prefix . '.status' => '0',
|
||||
]);
|
||||
|
||||
setting()->save();
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'new-apps',
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $read->name]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = $this->getNotifications('new-apps');
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$prefix = 'notifications.' . user()->id . '.' . $notification->alias;
|
||||
|
||||
setting()->set([
|
||||
$prefix . '.name' => $notification->name,
|
||||
$prefix . '.message' => $notification->alias,
|
||||
$prefix . '.date' => Date::now(),
|
||||
$prefix . '.status' => '0',
|
||||
]);
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'new-apps',
|
||||
'message' => trans('notifications.messages.mark_read_all', ['type' => trans_choice('notifications.new_apps', 2)]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$notifications = $this->getNotifications('new-apps');
|
||||
|
||||
$this->clearReadNotifications($notifications);
|
||||
|
||||
return view('livewire.common.notifications.new-apps', compact('notifications'));
|
||||
}
|
||||
|
||||
protected function clearReadNotifications(&$notifications)
|
||||
{
|
||||
$hide_notifications = setting('notifications.' . user()->id);
|
||||
|
||||
if (!$hide_notifications) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$notifications) {
|
||||
return;
|
||||
}
|
||||
|
||||
$aliases = [];
|
||||
|
||||
// MarkRead app notification
|
||||
foreach ($notifications as $index => $notification) {
|
||||
$aliases[] = $notification->alias;
|
||||
|
||||
if (setting('notifications.' . user()->id . '.' . $notification->alias)) {
|
||||
unset($notifications[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear setting table missing notification
|
||||
foreach ($hide_notifications as $alias => $hide_notification) {
|
||||
if (in_array($alias, $aliases)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
setting()->forget('notifications.' . user()->id . '.' . $alias);
|
||||
setting()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use App\Abstracts\Livewire\Document as Component;
|
||||
use App\Models\Document\Document;
|
||||
use Livewire\WithPagination;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Recurring extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public function markRead($notification_id)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'recurring-' . $this->type,
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'recurring-' . $this->type,
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$limit = 5;
|
||||
|
||||
$notifications = $this->getNotifications($limit);
|
||||
|
||||
return view('livewire.common.notifications.recurring', compact('notifications'));
|
||||
}
|
||||
|
||||
protected function getNotifications($limit = false)
|
||||
{
|
||||
$type = config('type.' . $this->type . '.notification.class');
|
||||
|
||||
$query = user()->notifications()->unread()
|
||||
->where('type', $type)
|
||||
->where('data', 'like', '%template_alias:{$this->type}_recurring_admin%');
|
||||
|
||||
if ($limit) {
|
||||
$notifications = $query->paginate($limit);
|
||||
} else {
|
||||
$notifications = $query->get();
|
||||
}
|
||||
|
||||
if ($notifications) {
|
||||
$items = [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$data = (object) $notification->getAttribute('data');
|
||||
|
||||
$item = Document::{$this->type}()->where('id', $data[$this->type . '_id'])->first();
|
||||
$item->notification_id = $notification->getAttribute('id');
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
$notifications->setCollection(Collection::make($items));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function paginationView()
|
||||
{
|
||||
return 'vendor.livewire.default';
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Common\Notifications;
|
||||
|
||||
use App\Abstracts\Livewire\Document as Component;
|
||||
use App\Models\Document\Document;
|
||||
use Livewire\WithPagination;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Reminder extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public function markRead($notification_id)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'reminder-' . $this->type,
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = $this->getNotifications();
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'reminder-' . $this->type,
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$limit = 5;
|
||||
|
||||
$notifications = $this->getNotifications($limit);
|
||||
|
||||
return view('livewire.common.notifications.reminder', compact('notifications'));
|
||||
}
|
||||
|
||||
protected function getNotifications($limit = false)
|
||||
{
|
||||
$type = config('type.' . $this->type . '.notification.class');
|
||||
|
||||
$query = user()->notifications()->unread()
|
||||
->where('type', $type)
|
||||
->where('data', 'like', '%template_alias:{$this->type}_remind_admin%');
|
||||
|
||||
if ($limit) {
|
||||
$notifications = $query->paginate($limit);
|
||||
} else {
|
||||
$notifications = $query->get();
|
||||
}
|
||||
|
||||
if ($notifications) {
|
||||
$items = [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$data = (object) $notification->getAttribute('data');
|
||||
|
||||
$item = Document::{$this->type}()->where('id', $data[$this->type . '_id'])->first();
|
||||
$item->notification_id = $notification->getAttribute('id');
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
|
||||
$notifications->setCollection(Collection::make($items));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function paginationView()
|
||||
{
|
||||
return 'vendor.livewire.default';
|
||||
}
|
||||
}
|
||||
99
app/Http/Livewire/Menu/Favorite.php
Normal file
99
app/Http/Livewire/Menu/Favorite.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Favorite extends Component
|
||||
{
|
||||
public $title = null;
|
||||
|
||||
public $icon = null;
|
||||
|
||||
public $route = null;
|
||||
|
||||
public $url = null;
|
||||
|
||||
public $favorited = false;
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$favorites = setting('favorites.menu.' . user()->id, []);
|
||||
|
||||
if (!empty($favorites)) {
|
||||
$favorites = json_decode($favorites, true);
|
||||
|
||||
foreach ($favorites as $favorite) {
|
||||
if ($this->title == $favorite['title']) {
|
||||
$this->favorited = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('livewire.menu.favorite');
|
||||
}
|
||||
|
||||
public function changeStatus()
|
||||
{
|
||||
if ($this->favorited) {
|
||||
$this->removeFavorite();
|
||||
} else {
|
||||
$this->addFavorite();
|
||||
}
|
||||
}
|
||||
|
||||
public function addFavorite()
|
||||
{
|
||||
$favorites = setting('favorites.menu.' . user()->id, []);
|
||||
|
||||
if (!empty($favorites)) {
|
||||
$favorites = json_decode($favorites, true);
|
||||
}
|
||||
|
||||
/*
|
||||
if (in_array($this->title, $favorites)) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
$favorites[] = [
|
||||
'title' => $this->title,
|
||||
'icon' => $this->icon,
|
||||
'route' => $this->route,
|
||||
'url' => $this->url,
|
||||
];
|
||||
|
||||
$this->favorited = true;
|
||||
|
||||
setting(['favorites.menu.' . user()->id => json_encode($favorites)])->save();
|
||||
|
||||
$this->emit('addedFavorite');
|
||||
}
|
||||
|
||||
public function removeFavorite()
|
||||
{
|
||||
$favorites = setting('favorites.menu.' . user()->id, []);
|
||||
|
||||
if (!empty($favorites)) {
|
||||
$favorites = json_decode($favorites, true);
|
||||
}
|
||||
|
||||
foreach ($favorites as $key => $favorited) {
|
||||
if ($favorited['title'] != $this->title) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($favorites[$key]);
|
||||
$this->favorited = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
setting(['favorites.menu.' . user()->id => json_encode($favorites)])->save();
|
||||
|
||||
$this->emit('removedFavorite');
|
||||
}
|
||||
}
|
||||
95
app/Http/Livewire/Menu/Favorites.php
Normal file
95
app/Http/Livewire/Menu/Favorites.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Favorites extends Component
|
||||
{
|
||||
public $favorites = [];
|
||||
|
||||
protected $listeners = [
|
||||
'addedFavorite' => 'render',
|
||||
'removedFavorite' => 'render',
|
||||
];
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->favorites = collect();
|
||||
|
||||
$favorites = setting('favorites.menu.' . user()->id, []);
|
||||
|
||||
if (!empty($favorites)) {
|
||||
$favorites = json_decode($favorites, true);
|
||||
|
||||
foreach ($favorites as $favorite) {
|
||||
$favorite['active'] = false;
|
||||
$favorite['url'] = $this->getUrl($favorite);
|
||||
$favorite['id'] = $this->getId($favorite);
|
||||
|
||||
if ($this->isActive($favorite['url'])) {
|
||||
$favorite['active'] = true;
|
||||
}
|
||||
|
||||
$this->favorites->push($favorite);
|
||||
}
|
||||
}
|
||||
|
||||
return view('livewire.menu.favorites');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl($favorite)
|
||||
{
|
||||
if (! empty($favorite['route'])) {
|
||||
$route = $favorite['route'];
|
||||
|
||||
if (is_array($route)) {
|
||||
$url = route($route[0], $route[1]);
|
||||
} else {
|
||||
$url = route($route);
|
||||
}
|
||||
|
||||
return str_replace(url('/') . '/', '', $url);
|
||||
}
|
||||
|
||||
if (empty($favorite['url'])) {
|
||||
return '/#';
|
||||
}
|
||||
|
||||
return str_replace(url('/') . '/', '', url($favorite['url']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active state for current item.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isActive($url)
|
||||
{
|
||||
if (empty($url) || in_array($url, ['/'])) {
|
||||
return Request::is($url);
|
||||
} else {
|
||||
return Request::is($url, $url . '/*');
|
||||
}
|
||||
}
|
||||
|
||||
public function getId($favorite)
|
||||
{
|
||||
$id = Str::of($favorite['url'])
|
||||
->replace(url('/'), '-')
|
||||
->replace(company_id(), '')
|
||||
->replace(['/', '?', '='], '-')
|
||||
->trim('-')
|
||||
->squish();
|
||||
|
||||
return 'menu-favorites-' . $id;
|
||||
}
|
||||
}
|
||||
80
app/Http/Livewire/Menu/Neww.php
Normal file
80
app/Http/Livewire/Menu/Neww.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use App\Events\Menu\NewwCreated;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class Neww extends Component
|
||||
{
|
||||
public $user = null;
|
||||
|
||||
public $keyword = '';
|
||||
|
||||
public $neww = [];
|
||||
|
||||
protected $listeners = ['resetKeyword'];
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->user = user();
|
||||
|
||||
menu()->create('neww', function ($menu) {
|
||||
$menu->style('tailwind');
|
||||
|
||||
event(new NewwCreated($menu));
|
||||
|
||||
foreach($menu->getItems() as $item) {
|
||||
if ($this->availableInSearch($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$menu->removeByTitle($item->title);
|
||||
}
|
||||
});
|
||||
|
||||
return view('livewire.menu.neww');
|
||||
}
|
||||
|
||||
public function availableInSearch($item): bool
|
||||
{
|
||||
if (empty($this->keyword)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->search($item);
|
||||
}
|
||||
|
||||
public function search($item): bool
|
||||
{
|
||||
$status = false;
|
||||
|
||||
$keywords = explode(' ', $this->keyword);
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
if (Str::contains(Str::lower($item->title), Str::lower($keyword))) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
!empty($item->attributes['search_keywords'])
|
||||
&& Str::contains(Str::lower($item->attributes['search_keywords']), Str::lower($keyword))
|
||||
) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function resetKeyword(): void
|
||||
{
|
||||
$this->keyword = '';
|
||||
}
|
||||
}
|
||||
119
app/Http/Livewire/Menu/Notifications.php
Normal file
119
app/Http/Livewire/Menu/Notifications.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use App\Events\Menu\NotificationsCreated;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class Notifications extends Component
|
||||
{
|
||||
public $user = null;
|
||||
|
||||
public $keyword = '';
|
||||
|
||||
public $notifications = [];
|
||||
|
||||
protected $listeners = ['resetKeyword'];
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->user = user();
|
||||
|
||||
$this->notifications = $this->getNotifications();
|
||||
|
||||
return view('livewire.menu.notifications');
|
||||
}
|
||||
|
||||
public function markRead($notification_id)
|
||||
{
|
||||
$notification = DatabaseNotification::find($notification_id);
|
||||
$data = $notification->getAttribute('data');
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
$type = isset($data['file_name']) ?: trans('general.export');
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read', [
|
||||
'type' => 'notification',
|
||||
'message' => trans('notifications.messages.mark_read', ['type' => $type]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function markReadAll()
|
||||
{
|
||||
$notifications = user()->unreadNotifications;
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
$this->dispatchBrowserEvent('mark-read-all', [
|
||||
'type' => 'notification',
|
||||
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('general.export')]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getNotifications(): array
|
||||
{
|
||||
$notifications = new \stdClass();
|
||||
$notifications->notifications = [];
|
||||
$notifications->keyword = $this->keyword;
|
||||
|
||||
event(new NotificationsCreated($notifications));
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($notifications->notifications as $notification) {
|
||||
if (! $this->availableInSearch($notification)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows[] = $notification;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function availableInSearch($notification): bool
|
||||
{
|
||||
if (empty($this->keyword)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->search($notification);
|
||||
}
|
||||
|
||||
public function search($notification): bool
|
||||
{
|
||||
$status = false;
|
||||
|
||||
$keywords = explode(' ', $this->keyword);
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
if (Str::contains(Str::lower($notification->data['title']), Str::lower($keyword))) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
!empty($notification->data['description'])
|
||||
&& Str::contains(Str::lower($notification->data['description']), Str::lower($keyword))
|
||||
) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function resetKeyword(): void
|
||||
{
|
||||
$this->keyword = '';
|
||||
}
|
||||
}
|
||||
29
app/Http/Livewire/Menu/Profile.php
Normal file
29
app/Http/Livewire/Menu/Profile.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use App\Events\Menu\ProfileCreated;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Profile extends Component
|
||||
{
|
||||
public $active_menu = 0;
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
menu()->create('profile', function ($menu) {
|
||||
$menu->style('tailwind');
|
||||
|
||||
event(new ProfileCreated($menu));
|
||||
|
||||
foreach($menu->getItems() as $item) {
|
||||
if ($item->isActive()) {
|
||||
$this->active_menu = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return view('livewire.menu.profile');
|
||||
}
|
||||
}
|
||||
117
app/Http/Livewire/Menu/Settings.php
Normal file
117
app/Http/Livewire/Menu/Settings.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Menu;
|
||||
|
||||
use App\Events\Menu\SettingsCreated;
|
||||
use App\Models\Module\Module;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class Settings extends Component
|
||||
{
|
||||
public $user = null;
|
||||
|
||||
public $keyword = '';
|
||||
|
||||
public $settings = [];
|
||||
|
||||
public $active_menu = 0;
|
||||
|
||||
protected $listeners = ['resetKeyword'];
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->user = user();
|
||||
|
||||
menu()->create('settings', function ($menu) {
|
||||
$menu->style('tailwind');
|
||||
|
||||
event(new SettingsCreated($menu));
|
||||
|
||||
$this->addSettingsOfModulesFromJsonFile($menu);
|
||||
|
||||
foreach($menu->getItems() as $item) {
|
||||
if ($item->isActive()) {
|
||||
$this->active_menu = 1;
|
||||
}
|
||||
|
||||
if ($this->availableInSearch($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$menu->removeByTitle($item->title);
|
||||
}
|
||||
});
|
||||
|
||||
return view('livewire.menu.settings');
|
||||
}
|
||||
|
||||
public function addSettingsOfModulesFromJsonFile($menu): void
|
||||
{
|
||||
// Get enabled modules
|
||||
$enabled_modules = Module::enabled()->get();
|
||||
|
||||
$order = 110;
|
||||
|
||||
foreach ($enabled_modules as $module) {
|
||||
$m = module($module->alias);
|
||||
|
||||
// Check if the module exists and has settings
|
||||
if (!$m || empty($m->get('settings'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->user->cannot('read-' . $m->getAlias() . '-settings')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$menu->route('settings.module.edit', $m->getName(), ['alias' => $m->getAlias()], $m->get('setting_order', $order), [
|
||||
'icon' => $m->get('icon', 'custom-akaunting'),
|
||||
'search_keywords' => $m->getDescription(),
|
||||
]);
|
||||
|
||||
$order += 10;
|
||||
}
|
||||
}
|
||||
|
||||
public function availableInSearch($item): bool
|
||||
{
|
||||
if (empty($this->keyword)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->search($item);
|
||||
}
|
||||
|
||||
public function search($item): bool
|
||||
{
|
||||
$status = false;
|
||||
|
||||
$keywords = explode(' ', $this->keyword);
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
if (Str::contains(Str::lower($item->title), Str::lower($keyword))) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
!empty($item->attributes['search_keywords'])
|
||||
&& Str::contains(Str::lower($item->attributes['search_keywords']), Str::lower($keyword))
|
||||
) {
|
||||
$status = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function resetKeyword(): void
|
||||
{
|
||||
$this->keyword = '';
|
||||
}
|
||||
}
|
||||
110
app/Http/Livewire/Report/Pin.php
Normal file
110
app/Http/Livewire/Report/Pin.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Report;
|
||||
|
||||
use App\Models\Common\Report;
|
||||
use App\Utilities\Reports as Utility;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class Pin extends Component
|
||||
{
|
||||
public $categories;
|
||||
|
||||
public $pinned = false;
|
||||
|
||||
public $reportId = null;
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$pins = setting('favorites.report.' . user()->id, []);
|
||||
|
||||
if (!empty($pins)) {
|
||||
$pins = json_decode($pins, true);
|
||||
|
||||
foreach ($this->categories as $category) {
|
||||
foreach($category['reports'] as $report) {
|
||||
if (is_array($report)) {
|
||||
$report = Report::find($report['id']);
|
||||
}
|
||||
|
||||
if (! Utility::canShow($report->class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = Utility::getClassInstance($report, false);
|
||||
|
||||
if (empty($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($this->reportId, $pins)) {
|
||||
$this->pinned = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('livewire.report.pin');
|
||||
}
|
||||
|
||||
public function changeStatus($report_id)
|
||||
{
|
||||
if ($this->pinned) {
|
||||
$this->removePin($report_id);
|
||||
} else {
|
||||
$this->addPin($report_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function addPin($report_id)
|
||||
{
|
||||
$pins = setting('favorites.report.' . user()->id, []);
|
||||
|
||||
if (!empty($pins)) {
|
||||
$pins = json_decode($pins, true);
|
||||
}
|
||||
|
||||
if (in_array($report_id, $pins)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (count($pins) >= 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pins[] = $report_id;
|
||||
|
||||
$this->pinned = true;
|
||||
|
||||
setting(['favorites.report.' . user()->id => json_encode($pins)])->save();
|
||||
|
||||
$this->emit('addedPin');
|
||||
}
|
||||
|
||||
public function removePin($report_id)
|
||||
{
|
||||
$pins = setting('favorites.report.' . user()->id, []);
|
||||
|
||||
if (!empty($pins)) {
|
||||
$pins = json_decode($pins, true);
|
||||
}
|
||||
|
||||
foreach ($pins as $key => $pinned_id) {
|
||||
if ($pinned_id != $report_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($pins[$key]);
|
||||
$this->pinned = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
setting(['favorites.report.' . user()->id => json_encode($pins)])->save();
|
||||
|
||||
$this->emit('removedPin');
|
||||
}
|
||||
}
|
||||
64
app/Http/Livewire/Report/Pins.php
Normal file
64
app/Http/Livewire/Report/Pins.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Report;
|
||||
|
||||
use App\Models\Common\Report;
|
||||
use App\Utilities\Reports as Utility;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class Pins extends Component
|
||||
{
|
||||
public $pins = [];
|
||||
|
||||
public $categories;
|
||||
|
||||
public $reports = [];
|
||||
|
||||
public $icons = [];
|
||||
|
||||
public $report_id = null;
|
||||
|
||||
protected $listeners = [
|
||||
'addedPin' => 'render',
|
||||
'removedPin' => 'render',
|
||||
];
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$this->reports = collect();
|
||||
|
||||
$pins = setting('favorites.report.' . user()->id, []);
|
||||
|
||||
if (!empty($pins)) {
|
||||
$pins = json_decode($pins, true);
|
||||
|
||||
foreach ($this->categories as $category) {
|
||||
foreach($category['reports'] as $report) {
|
||||
if (is_array($report)) {
|
||||
$report = Report::find($report['id']);
|
||||
}
|
||||
|
||||
if (! Utility::canShow($report->class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = Utility::getClassInstance($report, false);
|
||||
|
||||
if (empty($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($report->id, $pins)) {
|
||||
$this->reports->push($report);
|
||||
|
||||
$this->icons[$report->id] = $class->getIcon();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('livewire.report.pins');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user