From e8487483850a2134d04c431f257265d994de8778 Mon Sep 17 00:00:00 2001 From: mikagrich <161597019+mikagrich@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:17:56 +0200 Subject: [PATCH] Feature/notifications (#555) * initial commit * Fix styling --------- Co-authored-by: mikagrich --- .github/workflows/monorepo-split-packages.yml | 1 + app/Providers/Filament/AdminPanelProvider.php | 1 + composer.json | 3 +- ...6_26_135736_create_notifications_table.php | 31 ++++ packages/notifications/.github/FUNDING.yml | 13 ++ packages/notifications/.gitignore | 49 ++++++ packages/notifications/CHANGELOG.md | 1 + packages/notifications/FUNDING.yml | 13 ++ packages/notifications/LICENSE.md | 21 +++ packages/notifications/README.md | 53 ++++++ packages/notifications/SECURITY.md | 13 ++ packages/notifications/composer.json | 36 ++++ .../notifications/config/notifications.php | 5 + .../create_notifications_table.php.stub | 32 ++++ .../resources/lang/de/translations.php | 16 ++ .../resources/lang/en/translations.php | 16 ++ .../resources/lang/es/translations.php | 16 ++ .../resources/lang/hr/translations.php | 16 ++ .../resources/lang/nb_NO/translations.php | 16 ++ .../resources/lang/ru/translations.php | 16 ++ .../src/Commands/InstallCommand.php | 163 ++++++++++++++++++ .../notifications/src/Models/Notification.php | 37 ++++ .../notifications/src/NotificationPlugin.php | 35 ++++ .../src/NotificationServiceProvider.php | 23 +++ .../src/Resources/NotificationResource.php | 122 +++++++++++++ .../Pages/CreateNotification.php | 11 ++ .../Pages/EditNotification.php | 17 ++ .../Pages/ListNotifications.php | 17 ++ .../Pages/ViewNotification.php | 18 ++ .../Widgets/NotificationWidgets.php | 30 ++++ 30 files changed, 840 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2024_06_26_135736_create_notifications_table.php create mode 100644 packages/notifications/.github/FUNDING.yml create mode 100644 packages/notifications/.gitignore create mode 100644 packages/notifications/CHANGELOG.md create mode 100644 packages/notifications/FUNDING.yml create mode 100644 packages/notifications/LICENSE.md create mode 100644 packages/notifications/README.md create mode 100644 packages/notifications/SECURITY.md create mode 100644 packages/notifications/composer.json create mode 100644 packages/notifications/config/notifications.php create mode 100644 packages/notifications/database/migrations/create_notifications_table.php.stub create mode 100644 packages/notifications/resources/lang/de/translations.php create mode 100644 packages/notifications/resources/lang/en/translations.php create mode 100644 packages/notifications/resources/lang/es/translations.php create mode 100644 packages/notifications/resources/lang/hr/translations.php create mode 100644 packages/notifications/resources/lang/nb_NO/translations.php create mode 100644 packages/notifications/resources/lang/ru/translations.php create mode 100644 packages/notifications/src/Commands/InstallCommand.php create mode 100644 packages/notifications/src/Models/Notification.php create mode 100644 packages/notifications/src/NotificationPlugin.php create mode 100644 packages/notifications/src/NotificationServiceProvider.php create mode 100644 packages/notifications/src/Resources/NotificationResource.php create mode 100644 packages/notifications/src/Resources/NotificationResource/Pages/CreateNotification.php create mode 100644 packages/notifications/src/Resources/NotificationResource/Pages/EditNotification.php create mode 100644 packages/notifications/src/Resources/NotificationResource/Pages/ListNotifications.php create mode 100644 packages/notifications/src/Resources/NotificationResource/Pages/ViewNotification.php create mode 100644 packages/notifications/src/Resources/NotificationResource/Widgets/NotificationWidgets.php diff --git a/.github/workflows/monorepo-split-packages.yml b/.github/workflows/monorepo-split-packages.yml index 8bbe73c5e..073baa588 100644 --- a/.github/workflows/monorepo-split-packages.yml +++ b/.github/workflows/monorepo-split-packages.yml @@ -26,6 +26,7 @@ jobs: - sync - audit - passkey + - notifications steps: - uses: actions/checkout@v4 diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index a36127bf6..bc30786fc 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -87,6 +87,7 @@ public function panel(Panel $panel): Panel \Moox\UserSession\UserSessionPlugin::make(), \Moox\Passkey\PasskeyPlugin::make(), + \Moox\Notification\NotificationPlugin::make(), ]); } diff --git a/composer.json b/composer.json index 9362d8927..c9f43ebd1 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "moox/login-link": "*", "moox/user-session": "*", "moox/passkey": "*", + "moox/notifications": "*", "wikimedia/composer-merge-plugin": "^2.1" }, "require-dev": { @@ -116,4 +117,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/database/migrations/2024_06_26_135736_create_notifications_table.php b/database/migrations/2024_06_26_135736_create_notifications_table.php new file mode 100644 index 000000000..d73803223 --- /dev/null +++ b/database/migrations/2024_06_26_135736_create_notifications_table.php @@ -0,0 +1,31 @@ +uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('notifications'); + } +}; diff --git a/packages/notifications/.github/FUNDING.yml b/packages/notifications/.github/FUNDING.yml new file mode 100644 index 000000000..0446fa42d --- /dev/null +++ b/packages/notifications/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: [mooxphp] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/packages/notifications/.gitignore b/packages/notifications/.gitignore new file mode 100644 index 000000000..6a81cbb00 --- /dev/null +++ b/packages/notifications/.gitignore @@ -0,0 +1,49 @@ +# Environment +.env +.env.backup + +# Composer +/vendor +composer.lock +auth.json + +# NPM / Node +/node_modules +npm-debug.log +package-lock.json + +# Laravel +/public/hot +/public/storage +/storage/*.key + +# PHPUnit +.phpunit.result.cache +phpunit.xml + +# Yarn +yarn-error.log + +# PHPStan +/build +phpstan.neon + +# Testbench +testbench.yaml + +# PHP CS Fixer +.php-cs-fixer.cache + +# Homestead +Homestead.json +Homestead.yaml + +# IDEs +/.idea +/.vscode + +# MacOS +.DS_Store + +# Windows +Thumbs.db diff --git a/packages/notifications/CHANGELOG.md b/packages/notifications/CHANGELOG.md new file mode 100644 index 000000000..825c32f0d --- /dev/null +++ b/packages/notifications/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/packages/notifications/FUNDING.yml b/packages/notifications/FUNDING.yml new file mode 100644 index 000000000..0446fa42d --- /dev/null +++ b/packages/notifications/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: [mooxphp] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/packages/notifications/LICENSE.md b/packages/notifications/LICENSE.md new file mode 100644 index 000000000..7dfc5ad0b --- /dev/null +++ b/packages/notifications/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Moox + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/notifications/README.md b/packages/notifications/README.md new file mode 100644 index 000000000..bca87af3c --- /dev/null +++ b/packages/notifications/README.md @@ -0,0 +1,53 @@ +![Moox Notification](https://github.com/mooxphp/moox/raw/main/art/banner/notifications.jpg) + +# Moox Notification + +This is my package notifications + +## Quick Installation + +These two commmands are all you need to install the package: + +```bash +composer require moox/notifications +php artisan mooxnotifications:install +``` + +Curious what the install command does? See manual installation below. + +## What it does + + + +Here are some things missing, like an overview with screenshots about this package, or simply a link to the package's docs. + + + +## Manual Installation + +Instead of using the install-command `php artisan mooxnotifications:install` you are able to install this package manually step by step: + +```bash +// Publish and run the migrations: +php artisan vendor:publish --tag="notifications-migrations" +php artisan migrate + +// Publish the config file with: +php artisan vendor:publish --tag="notifications-config" +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Security Vulnerabilities + +Please review [our security policy](https://github.com/mooxphp/moox/security/policy) on how to report security vulnerabilities. + +## Credits + +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/packages/notifications/SECURITY.md b/packages/notifications/SECURITY.md new file mode 100644 index 000000000..afb063ef9 --- /dev/null +++ b/packages/notifications/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +We maintain the current version of `Moox Notification` actively. + +Do not expect security fixes for older versions. + +## Reporting a Vulnerability + +If you find any security-related bug, please report it to security@moox.org. + +Please do not use Github issues, to give us enough time to review and fix the issue, before others can use it, to do stupid things. diff --git a/packages/notifications/composer.json b/packages/notifications/composer.json new file mode 100644 index 000000000..f47e637af --- /dev/null +++ b/packages/notifications/composer.json @@ -0,0 +1,36 @@ +{ + "name": "moox/notifications", + "description": "This is my package notifications", + "keywords": [ + "Laravel", + "Filament", + "Filament plugin", + "Laravel package" + ], + "homepage": "https://moox.org/", + "license": "MIT", + "authors": [ + { + "name": "Moox Developer", + "email": "dev@moox.org", + "role": "Developer" + } + ], + "require": { + "moox/core": "*" + }, + "autoload": { + "psr-4": { + "Moox\\Notification\\": "src" + } + }, + "extra": { + "laravel": { + "providers": [ + "Moox\\Notification\\NotificationServiceProvider" + ] + } + }, + "minimum-stability": "stable", + "prefer-stable": true +} diff --git a/packages/notifications/config/notifications.php b/packages/notifications/config/notifications.php new file mode 100644 index 000000000..350b60a51 --- /dev/null +++ b/packages/notifications/config/notifications.php @@ -0,0 +1,5 @@ + 2001, +]; diff --git a/packages/notifications/database/migrations/create_notifications_table.php.stub b/packages/notifications/database/migrations/create_notifications_table.php.stub new file mode 100644 index 000000000..be44b3e8e --- /dev/null +++ b/packages/notifications/database/migrations/create_notifications_table.php.stub @@ -0,0 +1,32 @@ +id(); + $table->string('name')->nullable(); + $table->timestamp('started_at')->nullable()->index(); + $table->timestamp('finished_at')->nullable(); + $table->boolean('failed')->default(false)->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + + { + Schema::dropIfExists('notifications'); + } +}; diff --git a/packages/notifications/resources/lang/de/translations.php b/packages/notifications/resources/lang/de/translations.php new file mode 100644 index 000000000..0599c0ac3 --- /dev/null +++ b/packages/notifications/resources/lang/de/translations.php @@ -0,0 +1,16 @@ + 'Notification', + 'plural' => 'Notifications', + 'breadcrumb' => 'Notification', + 'title' => 'Notification', + 'navigation_label' => 'Notification', + 'navigation_group' => 'Moox Notification', + 'totalone' => 'Notification Eins', + 'totaltwo' => 'Notification Zwei', + 'totalthree' => 'Notification Drei', + 'name' => 'Name', + 'started_at' => 'Gestartet am', + 'failed' => 'failed', +]; diff --git a/packages/notifications/resources/lang/en/translations.php b/packages/notifications/resources/lang/en/translations.php new file mode 100644 index 000000000..e1487c51e --- /dev/null +++ b/packages/notifications/resources/lang/en/translations.php @@ -0,0 +1,16 @@ + 'Notification', + 'plural' => 'Notifications', + 'breadcrumb' => 'Notification', + 'title' => 'Notification', + 'navigation_label' => 'Notification', + 'navigation_group' => 'Moox Notification', + 'totalone' => 'Notification One', + 'totaltwo' => 'Notification Two', + 'totalthree' => 'Notification Three', + 'name' => 'Name', + 'started_at' => 'Started at', + 'failed' => 'failed', +]; diff --git a/packages/notifications/resources/lang/es/translations.php b/packages/notifications/resources/lang/es/translations.php new file mode 100644 index 000000000..e7e6673f7 --- /dev/null +++ b/packages/notifications/resources/lang/es/translations.php @@ -0,0 +1,16 @@ + 'Desarrollador', + 'plural' => 'Desarrolladores', + 'breadcrumb' => 'Desarrollador', + 'title' => 'Desarrollador', + 'navigation_label' => 'Desarrollador', + 'navigation_group' => 'Desarrollador de Moox', + 'totalone' => 'Desarrollador uno', + 'totaltwo' => 'Desarrollador dos', + 'totalthree' => 'Desarrollador tres', + 'name' => 'Nombre', + 'started_at' => 'Empezó a las', + 'failed' => 'failed', +]; diff --git a/packages/notifications/resources/lang/hr/translations.php b/packages/notifications/resources/lang/hr/translations.php new file mode 100644 index 000000000..a145e7504 --- /dev/null +++ b/packages/notifications/resources/lang/hr/translations.php @@ -0,0 +1,16 @@ + '', + 'plural' => '', + 'breadcrumb' => '', + 'title' => '', + 'navigation_label' => '', + 'navigation_group' => '', + 'totalone' => '', + 'totaltwo' => '', + 'totalthree' => '', + 'name' => 'Ime', + 'started_at' => 'Pokrenuto', + 'failed' => 'neuspjelo', +]; diff --git a/packages/notifications/resources/lang/nb_NO/translations.php b/packages/notifications/resources/lang/nb_NO/translations.php new file mode 100644 index 000000000..078960419 --- /dev/null +++ b/packages/notifications/resources/lang/nb_NO/translations.php @@ -0,0 +1,16 @@ + 'Bygger', + 'plural' => 'Byggers', + 'breadcrumb' => 'Bygger', + 'title' => 'Bygger', + 'navigation_label' => 'Bygger', + 'navigation_group' => 'Moox Notification', + 'totalone' => 'Bygger én', + 'totaltwo' => 'Bygger to', + 'totalthree' => 'Bygger tre', + 'name' => 'Navn', + 'started_at' => 'Startet', + 'failed' => 'mislyktes', +]; diff --git a/packages/notifications/resources/lang/ru/translations.php b/packages/notifications/resources/lang/ru/translations.php new file mode 100644 index 000000000..38cdbd13b --- /dev/null +++ b/packages/notifications/resources/lang/ru/translations.php @@ -0,0 +1,16 @@ + 'Сборщик', + 'plural' => 'Сборщики', + 'breadcrumb' => 'Сборщик', + 'title' => 'Сборщик', + 'navigation_label' => 'Сборщик', + 'navigation_group' => 'Сборщик Moox', + 'totalone' => 'Первый сборщик', + 'totaltwo' => 'Второй Сборщик', + 'totalthree' => 'Третий Сборщик', + 'name' => 'Имя', + 'started_at' => 'Начато в', + 'failed' => 'Неудача', +]; diff --git a/packages/notifications/src/Commands/InstallCommand.php b/packages/notifications/src/Commands/InstallCommand.php new file mode 100644 index 000000000..4da4f437d --- /dev/null +++ b/packages/notifications/src/Commands/InstallCommand.php @@ -0,0 +1,163 @@ +art(); + $this->welcome(); + $this->publishConfiguration(); + $this->publishMigrations(); + $this->runMigrations(); + $this->registerPlugins(); + $this->finish(); + } + + public function art(): void + { + info(' + + ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ + ▓▓▒░░▒▓▓▒▒░░░░░░▒▒▓▓▓▒░░░░░░░▒▓▓ ▓▓▓▓▒░░░░░░░▒▓▓▓▓ ▓▓▓▓▓▒░░░░░░░▒▒▓▓▓▓▓▒▒▒▒▓▓ ▓▓▓▒▒▒▒▓▓ + ▓▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓░░░░░▒▓▓ ▓▓▒░░░░░▓▓ + ▓▒░░░░░░▒▓▓▓▓▒░░░░░░░▒▓▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓▓▓▒░░░░░░░▓▓▓▓░░░░░░▒▓▓▓▓▓░░░░░░▒▓▓░░░░░▒▓▓▓▓▓░░░░░▒▓▓ + ▓▒░░░░▓▓▓▓ ▓▓░░░░░▓▓▓ ▓▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▓░░░░░▓░░░░░░▓▓▓▓ ▓▓▓▒░░░░▓▓▓▒░░░░░▓▓▓░░░░░▓▓▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▓░░▒░░░░░▓▓▓ ▓▓░░░░▒▓▓▓▓░░░░░░░░░░░▓▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓ ▓▓▓░░░░░▒▓▓ ▓▓▒░░░░▓ ▓▓▓░░░░░░░░░▓▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓░░░░▒▓▓ ▓▓▒░░░░░▒░░▒▓▓ ▓▓░░░░▒▓▓▓▒░░░░░▒░░░░░▒▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓░░░░▒▓▓▓ ▓▓▓▒░░░░░▒▒░░░░░▒▓▓▓ ▓▓▓░░░░░▓▓▓░░░░░▒▓▓▓░░░░░▒▓▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓░░░░░░▒▒▓▓▒░░░░░░▒▓▓▓▓░░░░░░░▒▒▓▓▒░░░░░░▓▓▓░░░░░▒▓▓▓▓▓▒░░░░░▓▓ + ▓▒░░░░▒▓ ▓▓░░░░░▓▓ ▓▓░░░░▒▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓ ▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▒░░░░░▓▓▓ ▓▓▒░░░░░▒▓ + ▓▓░░░▒▓▓ ▓▓▒░░░▒▓▓ ▓▓░░░░▓▓ ▓▓▓▓▒░░░░░░▒▒▓▓▓▓ ▓▓▓▓▓▒▒░░░░░▒▒▓▓▓▓▓░░░░▒▓▓ ▓▓▓░░░░▒▓ + ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓ + + '); + } + + public function welcome(): void + { + info('Welcome to Moox Notification Installer'); + } + + public function publishConfiguration(): void + { + if (confirm('Do you wish to publish the configuration?', true)) { + if (! File::exists('config/notifications.php')) { + info('Publishing Notification Configuration...'); + $this->callSilent('vendor:publish', ['--tag' => 'notifications-config']); + + return; + } + warning('The Notification config already exist. The config will not be published.'); + } + } + + // public function publishMigrations(): void + // { + // if (confirm('Do you wish to publish the migrations?', true)) { + // if (Schema::hasTable('notifications')) { + // warning('The notifications table already exists. The migrations will not be published.'); + + // return; + // } + // info('Publishing Notifications Migrations...'); + // $this->callSilent('vendor:publish', ['--tag' => 'notifications-migrations']); + // } + // } + + // public function runMigrations(): void + // { + // if (confirm('Do you wish to run the migrations?', true)) { + // info('Running Notification Migrations...'); + // $this->callSilent('migrate'); + // } + // } + + public function registerPlugins(): void + { + $providerPath = app_path('Providers/Filament/AdminPanelProvider.php'); + + if (File::exists($providerPath)) { + $content = File::get($providerPath); + + $intend = ' '; + + $namespace = "\Moox\Notification"; + + $pluginsToAdd = multiselect( + label: 'These plugins will be installed:', + options: ['NotificationPlugin'], + default: ['NotificationPlugin'], + ); + + $function = '::make(),'; + + $pattern = '/->plugins\(\[([\s\S]*?)\]\);/'; + $newPlugins = ''; + + foreach ($pluginsToAdd as $plugin) { + $searchPlugin = '/'.$plugin.'/'; + if (preg_match($searchPlugin, $content)) { + warning("$plugin already registered."); + } else { + $newPlugins .= $intend.$namespace.'\\'.$plugin.$function."\n"; + } + } + + if ($newPlugins) { + if (preg_match($pattern, $content)) { + info('Plugins section found. Adding new plugins...'); + + $replacement = "->plugins([$1\n$newPlugins\n ]);"; + $newContent = preg_replace($pattern, $replacement, $content); + } else { + info('Plugins section created. Adding new plugins...'); + + $pluginsSection = " ->plugins([\n$newPlugins\n ]);"; + $placeholderPattern = '/(\->authMiddleware\(\[.*?\]\))\s*\;/s'; + $replacement = "$1\n".$pluginsSection; + $newContent = preg_replace($placeholderPattern, $replacement, $content, 1); + } + + File::put($providerPath, $newContent); + } + } else { + alert('AdminPanelProvider not found. You need to add the plugins manually.'); + } + } + + public function finish(): void + { + note('Moox Notification installed successfully. Enjoy!'); + } +} diff --git a/packages/notifications/src/Models/Notification.php b/packages/notifications/src/Models/Notification.php new file mode 100644 index 000000000..f4da26aad --- /dev/null +++ b/packages/notifications/src/Models/Notification.php @@ -0,0 +1,37 @@ +id)) { + $model->id = (string) Str::uuid(); + } + }); + } + + protected $table = 'notifications'; + + protected $fillable = [ + 'type', + 'notifiable_type', + 'notifiable_id', + 'data', + 'read_at', + ]; +} diff --git a/packages/notifications/src/NotificationPlugin.php b/packages/notifications/src/NotificationPlugin.php new file mode 100644 index 000000000..d77875584 --- /dev/null +++ b/packages/notifications/src/NotificationPlugin.php @@ -0,0 +1,35 @@ +resources([ + NotificationResource::class, + ]); + } + + public function boot(Panel $panel): void + { + // + } + + public static function make(): static + { + return app(static::class); + } +} diff --git a/packages/notifications/src/NotificationServiceProvider.php b/packages/notifications/src/NotificationServiceProvider.php new file mode 100644 index 000000000..2e590ec8f --- /dev/null +++ b/packages/notifications/src/NotificationServiceProvider.php @@ -0,0 +1,23 @@ +name('notifications') + ->hasConfigFile() + ->hasViews() + ->hasTranslations() + // ->hasMigrations(['create_notifications_table']) only for testing purposes + ->hasCommand(InstallCommand::class); + } +} diff --git a/packages/notifications/src/Resources/NotificationResource.php b/packages/notifications/src/Resources/NotificationResource.php new file mode 100644 index 000000000..f95481526 --- /dev/null +++ b/packages/notifications/src/Resources/NotificationResource.php @@ -0,0 +1,122 @@ +schema([ + TextInput::make('type'), + TextInput::make('notifiable_type'), + TextInput::make('notifiable_id'), + TextInput::make('data'), + DatePicker::make('read_at'), + + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('type'), + TextColumn::make('notifiable_type'), + TextColumn::make('notifiable_id'), + TextColumn::make('data'), + TextColumn::make('read_at'), + + ]) + ->defaultSort('type', 'desc') + ->actions([ + EditAction::make(), + ]) + ->bulkActions([ + DeleteBulkAction::make(), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => ListNotifications::route('/'), + 'create' => CreateNotification::route('/create'), + 'view' => ViewNotification::route('/{record}'), + 'edit' => EditNotification::route('/{record}/edit'), + ]; + } + + public static function getWidgets(): array + { + return [ + NotificationWidgets::class, + ]; + } + + public static function getModelLabel(): string + { + return __('notifications::translations.single'); + } + + public static function getPluralModelLabel(): string + { + return __('notifications::translations.plural'); + } + + public static function getNavigationLabel(): string + { + return __('notifications::translations.navigation_label'); + } + + public static function getBreadcrumb(): string + { + return __('notifications::translations.breadcrumb'); + } + + public static function shouldRegisterNavigation(): bool + { + return true; + } + + public static function getNavigationBadge(): ?string + { + return number_format(static::getModel()::count()); + } + + public static function getNavigationGroup(): ?string + { + return __('notifications::translations.navigation_group'); + } + + public static function getNavigationSort(): ?int + { + return config('notifications.navigation_sort'); + } +} diff --git a/packages/notifications/src/Resources/NotificationResource/Pages/CreateNotification.php b/packages/notifications/src/Resources/NotificationResource/Pages/CreateNotification.php new file mode 100644 index 000000000..a53d0aad3 --- /dev/null +++ b/packages/notifications/src/Resources/NotificationResource/Pages/CreateNotification.php @@ -0,0 +1,11 @@ +select($aggregationColumns) + ->first(); + + return [ + Stat::make(__('notifications::translations.totalone'), $aggregatedInfo->count ?? 0), + Stat::make(__('notifications::translations.totaltwo'), $aggregatedInfo->count ?? 0), + Stat::make(__('notifications::translations.totalthree'), $aggregatedInfo->count ?? 0), + ]; + } +}