akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View 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');
}
}

View 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;
}
}

View 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 = '';
}
}

View 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 = '';
}
}

View 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');
}
}

View 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 = '';
}
}