Skip to content

Commit

Permalink
fix notification views
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Oct 20, 2022
1 parent b43cd10 commit f95dc8b
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 34 deletions.
4 changes: 3 additions & 1 deletion Config/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Models\User;
use Modules\Accounts\Entities\Account;

return [
'name' => 'Notifications',
Expand Down Expand Up @@ -41,7 +42,8 @@
'provider' => "pusher",

'models' => [
User::class
"Admins" => User::class,
"Accounts" => Account::class,
],

'providers' => [
Expand Down
24 changes: 7 additions & 17 deletions Vilt/Resources/NotificationsLogsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
use Modules\Base\Services\Rows\Select;
use Modules\Base\Services\Rows\Text;
use Modules\Notifications\Entities\NotificationsLogs;
use Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits\Methods;
use Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits\Translations;
use Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits\Components;

class NotificationsLogsResource extends Resource
{

use Components, Translations, Methods;

public ?string $model = NotificationsLogs::class;
public string $icon = "bx bx-history";
public string $group = "Notifications";
public ?bool $import = false;
public ?bool $menu = false;

public function rows(): array
{
Expand All @@ -33,21 +40,4 @@ public function rows(): array
DateTime::make('created_at')->label(__('Date')),
];
}

public function afterIndex(LengthAwarePaginator $data,Request $request): void
{
$data->map(function ($item){
if ($item->model_id && $item->model_type) {
$item->model_id = $item->model_type::find($item->model_id);
} else {
$item->model_id = [
"name" => __('Public'),
"id" => "public"
];
}

return $item;
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Actions;

use Modules\Base\Services\Components\Actions;

class NotificationAction extends Actions
{
public function setup(): void
{
$this->name("notification");
$this->label(__('Back'));
$this->type("success");
$this->icon("");
$this->modal(null);
$this->action("user_notifications.index", "get");
$this->url(null);
$this->can(true);
}
}

16 changes: 16 additions & 0 deletions Vilt/Resources/NotificationsLogsResource/Traits/Components.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits;

use Modules\Base\Services\Components\Base\Action;
use Modules\Base\Services\Components\Base\Component;
use Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Actions\NotificationAction;

trait Components
{
public function components(): array {
return [
Component::make(NotificationAction::class)->action(),
];
}
}
25 changes: 25 additions & 0 deletions Vilt/Resources/NotificationsLogsResource/Traits/Methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits;

use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;

trait Methods
{
public function afterIndex(LengthAwarePaginator $data,Request $request): void
{
$data->map(function ($item){
if ($item->model_id && $item->model_type) {
$item->model_id = $item->model_type::find($item->model_id);
} else {
$item->model_id = [
"name" => __('Public'),
"id" => "public"
];
}

return $item;
});
}
}
22 changes: 22 additions & 0 deletions Vilt/Resources/NotificationsLogsResource/Traits/Translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\NotificationsLogsResource\Traits;

trait Translations
{
public function loadTranslations(): array
{
return [
"index" => __(" Notifications Log"),
"create" => __('Create ' . " Notification Log"),
"bulk" => __('Delete Selected ' . " Notification Log"),
"edit_title" => __('Edit ' . " Notification Log"),
"create_title" => __('Create New ' . " Notification Log"),
"view_title" => __('View ' . " Notification Log"),
"delete_title" => __('Delete ' . " Notification Log"),
"bulk_title" => __('Run Bulk Action To ' . " Notification Log"),
];
}
}

37 changes: 24 additions & 13 deletions Vilt/Resources/NotificationsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
use Modules\Base\Services\Rows\Date;
use Modules\Base\Services\Rows\HasOne;
use Modules\Base\Services\Rows\Option;
use Modules\Base\Services\Rows\Relation;
use Modules\Base\Services\Rows\Select;
use Modules\Base\Services\Rows\Text;
use Modules\Notifications\Entities\NotifiactionsTemplates;
use Modules\Notifications\Entities\UserNotification;
use Modules\Notifications\Services\SendNotification;
use Modules\Notifications\Vilt\Resources\NotificationsResource\Traits\Components;
use Modules\Notifications\Vilt\Resources\NotificationsResource\Traits\Methods;
use Modules\Notifications\Vilt\Resources\NotificationsResource\Traits\Translations;

class NotificationsResource extends Resource
{
use Methods, Components;
use Methods, Components, Translations;

public ?string $model = UserNotification::class;
public string $icon = "bx bxs-bell";
Expand All @@ -30,27 +32,36 @@ public function rows(): array
{
$this->canEdit = false;

$types = [];
foreach (config('notifications.models') as $key=>$type){
$types[] = Option::make(__($key))->id($type)->api('model_id', $type, __($key));
}

return [
Text::make('id')->label(__('ID'))->create(false)->edit(false),
Select::make('template_id')->label(__('Template'))->validation("required|array")->options(NotifiactionsTemplates::where('action', 'manual')->get()->toArray())->trackByName('key'),
Select::make('privacy')->label(__('Privacy'))->validation("required|array")->options([
Option::make(__('Public'))->id('public'),
Option::make(__('Private'))->id('private'),
]),

Select::make('model_type')
->label(__('Type'))
->validation("required|array")
->options([
Option::make(__('User'))->id(User::class)
]),
HasOne::make('model_id')
->label(__('User'))
->validation("nullable|array")
->options($types),

Select::make('privacy')
->reactive()
->reactiveRow('model_type')
->reactiveWhere(Option::make(__('User'))->id(User::class))
->model(User::class)
->label(__('Privacy'))->validation("required|array")->options([
Option::make(__('Public'))->id('public'),
Option::make(__('Private'))->id('private'),
]),

HasOne::make('model_id')
->reactive()
->reactiveRow('privacy')
->reactiveBy('id')
->reactiveWhere('private')
->validation("nullable|array")
->relation('model'),

Date::make('created_at')
->label(__('Date'))
->create(false)
Expand Down
22 changes: 22 additions & 0 deletions Vilt/Resources/NotificationsResource/Actions/LogAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\NotificationsResource\Actions;

use Modules\Base\Services\Components\Actions;

class LogAction extends Actions
{
public function setup(): void
{
$this->name("log");
$this->label(__('Log'));
$this->type("success");
$this->icon("");
$this->modal(null);
$this->action('notifications_logs.index', 'get');
$this->url(null);
$this->can(true);
}
}

22 changes: 22 additions & 0 deletions Vilt/Resources/NotificationsResource/Actions/TemplatesAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\NotificationsResource\Actions;

use Modules\Base\Services\Components\Actions;

class TemplatesAction extends Actions
{
public function setup(): void
{
$this->name("templates");
$this->label(__('Templates'));
$this->type("success");
$this->icon("");
$this->modal(null);
$this->action("notifiactions_templates.index", "get");
$this->url(null);
$this->can(true);
}
}

4 changes: 4 additions & 0 deletions Vilt/Resources/NotificationsResource/Traits/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use Modules\Base\Services\Components\Base\Table;
use Modules\Menu\Vilt\Resources\MenuResource\Actions\GenerateMenuAction;
use Modules\Menu\Vilt\Resources\MenuResource\Routes\GenerateRoute;
use Modules\Notifications\Vilt\Resources\NotificationsResource\Actions\LogAction;
use Modules\Notifications\Vilt\Resources\NotificationsResource\Actions\TemplatesAction;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Routes\SendRoute;

trait Components
{
public function components(): array {
return [
Component::make(LogAction::class)->action(),
Component::make(TemplatesAction::class)->action(),
];
}
}
22 changes: 22 additions & 0 deletions Vilt/Resources/NotificationsResource/Traits/Translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\NotificationsResource\Traits;

trait Translations
{
public function loadTranslations(): array
{
return [
"index" => __(" Notifications"),
"create" => __('Create ' . " Notification"),
"bulk" => __('Delete Selected ' . " Notification"),
"edit_title" => __('Edit ' . " Notification"),
"create_title" => __('Create New ' . " Notification"),
"view_title" => __('View ' . " Notification"),
"delete_title" => __('Delete ' . " Notification"),
"bulk_title" => __('Run Bulk Action To ' . " Notification"),
];
}
}

6 changes: 5 additions & 1 deletion Vilt/Resources/TemplatesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Modules\Base\Services\Resource\Resource;
use Modules\Base\Services\Rows\Icon;
use Modules\Base\Services\Rows\Media;
use Modules\Base\Services\Rows\Relation;
use Modules\Base\Services\Rows\Schema;
Expand All @@ -12,16 +13,19 @@
use Modules\Notifications\Entities\NotifiactionsTemplates;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Traits\Components;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Traits\Methods;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Traits\Translations;
use Spatie\Permission\Models\Role;

class TemplatesResource extends Resource
{
use Methods;
use Components;
use Translations;

public ?string $model = NotifiactionsTemplates::class;
public string $icon = "bx bxs-notification";
public string $group = "Notifications";
public ?bool $menu = false;

public function rows(): array
{
Expand Down Expand Up @@ -63,7 +67,7 @@ public function rows(): array
"create" => "nullable|string",
"update" => "nullable|string",
]),
Text::make('icon')->label(__('Icon'))->validation([
Icon::make('icon')->label(__('Icon'))->validation([
"create" => "nullable|string",
"update" => "nullable|string",
])->list(false),
Expand Down
22 changes: 22 additions & 0 deletions Vilt/Resources/TemplatesResource/Actions/NotificationAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace Modules\Notifications\Vilt\Resources\TemplatesResource\Actions;

use Modules\Base\Services\Components\Actions;

class NotificationAction extends Actions
{
public function setup(): void
{
$this->name("notification");
$this->label(__('Back'));
$this->type("success");
$this->icon("");
$this->modal(null);
$this->action("user_notifications.index", "get");
$this->url(null);
$this->can(true);
}
}

6 changes: 4 additions & 2 deletions Vilt/Resources/TemplatesResource/Traits/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
use Modules\Base\Services\Components\Base\Table;
use Modules\Menu\Vilt\Resources\MenuResource\Actions\GenerateMenuAction;
use Modules\Menu\Vilt\Resources\MenuResource\Routes\GenerateRoute;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Actions\NotificationAction;
use Modules\Notifications\Vilt\Resources\TemplatesResource\Routes\SendRoute;

trait Components
{
public function components(): array {
return [
Component::make(SendRoute::class)->route()
Component::make(SendRoute::class)->route(),
Component::make(NotificationAction::class)->action(),
];
}

public function table(): Table {
return Table::make('table')->actions([
Action::make('send')->label(__('Send'))->icon('bx bx-send')->type('primary')->action('notifiactions_templates.send'),
Action::make('send')->label(__('Send'))->icon('bx bx-send')->type('primary')->action('notifiactions_templates.send')->confirmed(),
]);
}
}
Loading

0 comments on commit f95dc8b

Please sign in to comment.