diff --git a/Config/config.php b/Config/config.php index 06ddf3a..0b1837c 100644 --- a/Config/config.php +++ b/Config/config.php @@ -1,6 +1,7 @@ 'Notifications', @@ -41,7 +42,8 @@ 'provider' => "pusher", 'models' => [ - User::class + "Admins" => User::class, + "Accounts" => Account::class, ], 'providers' => [ diff --git a/Vilt/Resources/NotificationsLogsResource.php b/Vilt/Resources/NotificationsLogsResource.php index fa7da2b..7c1eafb 100644 --- a/Vilt/Resources/NotificationsLogsResource.php +++ b/Vilt/Resources/NotificationsLogsResource.php @@ -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 { @@ -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; - }); - } - } diff --git a/Vilt/Resources/NotificationsLogsResource/Actions/NotificationAction.php b/Vilt/Resources/NotificationsLogsResource/Actions/NotificationAction.php new file mode 100644 index 0000000..ad3fc70 --- /dev/null +++ b/Vilt/Resources/NotificationsLogsResource/Actions/NotificationAction.php @@ -0,0 +1,22 @@ +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); + } +} + diff --git a/Vilt/Resources/NotificationsLogsResource/Traits/Components.php b/Vilt/Resources/NotificationsLogsResource/Traits/Components.php new file mode 100644 index 0000000..99a5a5e --- /dev/null +++ b/Vilt/Resources/NotificationsLogsResource/Traits/Components.php @@ -0,0 +1,16 @@ +action(), + ]; + } +} diff --git a/Vilt/Resources/NotificationsLogsResource/Traits/Methods.php b/Vilt/Resources/NotificationsLogsResource/Traits/Methods.php new file mode 100644 index 0000000..d37e337 --- /dev/null +++ b/Vilt/Resources/NotificationsLogsResource/Traits/Methods.php @@ -0,0 +1,25 @@ +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; + }); + } +} diff --git a/Vilt/Resources/NotificationsLogsResource/Traits/Translations.php b/Vilt/Resources/NotificationsLogsResource/Traits/Translations.php new file mode 100644 index 0000000..6dcc73d --- /dev/null +++ b/Vilt/Resources/NotificationsLogsResource/Traits/Translations.php @@ -0,0 +1,22 @@ + __(" 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"), + ]; + } +} + diff --git a/Vilt/Resources/NotificationsResource.php b/Vilt/Resources/NotificationsResource.php index 0eaf19a..8c09c9b 100644 --- a/Vilt/Resources/NotificationsResource.php +++ b/Vilt/Resources/NotificationsResource.php @@ -9,6 +9,7 @@ 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; @@ -16,10 +17,11 @@ 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"; @@ -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) diff --git a/Vilt/Resources/NotificationsResource/Actions/LogAction.php b/Vilt/Resources/NotificationsResource/Actions/LogAction.php new file mode 100644 index 0000000..0471058 --- /dev/null +++ b/Vilt/Resources/NotificationsResource/Actions/LogAction.php @@ -0,0 +1,22 @@ +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); + } +} + diff --git a/Vilt/Resources/NotificationsResource/Actions/TemplatesAction.php b/Vilt/Resources/NotificationsResource/Actions/TemplatesAction.php new file mode 100644 index 0000000..e8953c1 --- /dev/null +++ b/Vilt/Resources/NotificationsResource/Actions/TemplatesAction.php @@ -0,0 +1,22 @@ +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); + } +} + diff --git a/Vilt/Resources/NotificationsResource/Traits/Components.php b/Vilt/Resources/NotificationsResource/Traits/Components.php index 8d9631e..e8126fc 100644 --- a/Vilt/Resources/NotificationsResource/Traits/Components.php +++ b/Vilt/Resources/NotificationsResource/Traits/Components.php @@ -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(), ]; } } diff --git a/Vilt/Resources/NotificationsResource/Traits/Translations.php b/Vilt/Resources/NotificationsResource/Traits/Translations.php new file mode 100644 index 0000000..9d4008e --- /dev/null +++ b/Vilt/Resources/NotificationsResource/Traits/Translations.php @@ -0,0 +1,22 @@ + __(" 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"), + ]; + } +} + diff --git a/Vilt/Resources/TemplatesResource.php b/Vilt/Resources/TemplatesResource.php index 037fcd6..61f35e2 100644 --- a/Vilt/Resources/TemplatesResource.php +++ b/Vilt/Resources/TemplatesResource.php @@ -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; @@ -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 { @@ -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), diff --git a/Vilt/Resources/TemplatesResource/Actions/NotificationAction.php b/Vilt/Resources/TemplatesResource/Actions/NotificationAction.php new file mode 100644 index 0000000..de56111 --- /dev/null +++ b/Vilt/Resources/TemplatesResource/Actions/NotificationAction.php @@ -0,0 +1,22 @@ +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); + } +} + diff --git a/Vilt/Resources/TemplatesResource/Traits/Components.php b/Vilt/Resources/TemplatesResource/Traits/Components.php index b8f3414..c96c4ea 100644 --- a/Vilt/Resources/TemplatesResource/Traits/Components.php +++ b/Vilt/Resources/TemplatesResource/Traits/Components.php @@ -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(), ]); } } diff --git a/Vilt/Resources/TemplatesResource/Traits/Translations.php b/Vilt/Resources/TemplatesResource/Traits/Translations.php new file mode 100644 index 0000000..29323b1 --- /dev/null +++ b/Vilt/Resources/TemplatesResource/Traits/Translations.php @@ -0,0 +1,22 @@ + __(" Notifications Templates"), + "create" => __('Create ' . " Template"), + "bulk" => __('Delete Selected ' . " Template"), + "edit_title" => __('Edit ' . " Template"), + "create_title" => __('Create New ' . " Template"), + "view_title" => __('View ' . " Template"), + "delete_title" => __('Delete ' . " Template"), + "bulk_title" => __('Run Bulk Action To ' . " Template"), + ]; + } +} +