diff --git a/.github/workflows/monorepo-split.yml b/.github/workflows/monorepo-split.yml index f6ace486..7a780147 100644 --- a/.github/workflows/monorepo-split.yml +++ b/.github/workflows/monorepo-split.yml @@ -13,6 +13,7 @@ jobs: package: - fields - media + - announcements - core steps: - uses: actions/checkout@v3 diff --git a/packages/announcements/.editorconfig b/packages/announcements/.editorconfig new file mode 100644 index 00000000..dd9a2b51 --- /dev/null +++ b/packages/announcements/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/packages/announcements/.gitattributes b/packages/announcements/.gitattributes new file mode 100644 index 00000000..9c9472bc --- /dev/null +++ b/packages/announcements/.gitattributes @@ -0,0 +1,28 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.idea export-ignore +/.prettierrc export-ignore +/.package-lock.json export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/.vscode export-ignore +/art export-ignore +/docs export-ignore +/images export-ignore +/tests export-ignore +/package.json export-ignore +/phpstan-baseline.neon export-ignore +/phpstan.neon.dist export-ignore +/postcss.config.js export-ignore +/phpunit.xml.dist export-ignore +/pint.json export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/tailwind.config.js export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore diff --git a/packages/announcements/.github/CONTRIBUTING.md b/packages/announcements/.github/CONTRIBUTING.md new file mode 100644 index 00000000..b0ee5d8e --- /dev/null +++ b/packages/announcements/.github/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skills, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/packages/announcements/.github/FUNDING.yml b/packages/announcements/.github/FUNDING.yml new file mode 100644 index 00000000..29313eb4 --- /dev/null +++ b/packages/announcements/.github/FUNDING.yml @@ -0,0 +1 @@ +github: Backstage diff --git a/packages/announcements/.github/ISSUE_TEMPLATE/bug.yml b/packages/announcements/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 00000000..8fa85ce7 --- /dev/null +++ b/packages/announcements/.github/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,66 @@ +name: Bug Report +description: Report an Issue or Bug with the Package +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + We're sorry to hear you have a problem. Can you help us solve it by providing the following details. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: What did you expect to happen? + placeholder: I cannot currently do X thing because when I do, it breaks X thing. + validations: + required: true + - type: textarea + id: how-to-reproduce + attributes: + label: How to reproduce the bug + description: How did this occur, please add any config values used and provide a set of reliable steps if possible. + placeholder: When I do X I see Y. + validations: + required: true + - type: input + id: package-version + attributes: + label: Package Version + description: What version of our Package are you running? Please be as specific as possible + placeholder: 2.0.0 + validations: + required: true + - type: input + id: php-version + attributes: + label: PHP Version + description: What version of PHP are you running? Please be as specific as possible + placeholder: 8.2.0 + validations: + required: true + - type: input + id: laravel-version + attributes: + label: Laravel Version + description: What version of Laravel are you running? Please be as specific as possible + placeholder: 9.0.0 + validations: + required: true + - type: dropdown + id: operating-systems + attributes: + label: Which operating systems does with happen with? + description: You may select more than one. + multiple: true + options: + - macOS + - Windows + - Linux + - type: textarea + id: notes + attributes: + label: Notes + description: Use this field to provide any other notes that you feel might be relevant to the issue. + validations: + required: false diff --git a/packages/announcements/.github/ISSUE_TEMPLATE/config.yml b/packages/announcements/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..1aa7f6d6 --- /dev/null +++ b/packages/announcements/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,11 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/Backstage/backstage-announcements/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/Backstage/backstage-announcements/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/Backstage/backstage-announcements/security/policy + about: Learn how to notify us for sensitive bugs diff --git a/packages/announcements/.github/SECURITY.md b/packages/announcements/.github/SECURITY.md new file mode 100644 index 00000000..c80a0ee4 --- /dev/null +++ b/packages/announcements/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email manoj@backstagephp.com instead of using the issue tracker. diff --git a/packages/announcements/.github/dependabot.yml b/packages/announcements/.github/dependabot.yml new file mode 100644 index 00000000..30c8a493 --- /dev/null +++ b/packages/announcements/.github/dependabot.yml @@ -0,0 +1,12 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "dependencies" \ No newline at end of file diff --git a/packages/announcements/.github/workflows/dependabot-auto-merge.yml b/packages/announcements/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 00000000..d2664188 --- /dev/null +++ b/packages/announcements/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,33 @@ +name: "Dependabot Auto-Merge" + +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1.6.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Auto-merge Dependabot PRs for semver-minor updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Auto-merge Dependabot PRs for semver-patch updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/packages/announcements/.github/workflows/fix-php-code-style-issues.yml b/packages/announcements/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 00000000..1b99f85f --- /dev/null +++ b/packages/announcements/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,27 @@ +name: "Fix PHP Code Styling" + +on: + push: + paths: + - '**.php' + +permissions: + contents: write + +jobs: + php-code-styling: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@2.6 + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v6 + with: + commit_message: Fix styling diff --git a/packages/announcements/.github/workflows/phpstan.yml b/packages/announcements/.github/workflows/phpstan.yml new file mode 100644 index 00000000..c1a2fa82 --- /dev/null +++ b/packages/announcements/.github/workflows/phpstan.yml @@ -0,0 +1,26 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon.dist' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/packages/announcements/.github/workflows/run-tests.yml b/packages/announcements/.github/workflows/run-tests.yml new file mode 100644 index 00000000..1f75815b --- /dev/null +++ b/packages/announcements/.github/workflows/run-tests.yml @@ -0,0 +1,56 @@ +name: "Run Tests" + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.4, 8.3, 8.2] + laravel: [12.*, 11.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 12.* + testbench: 10.* + carbon: 3.* + collision: 8.* + - laravel: 11.* + testbench: 9.* + carbon: 3.* + collision: 8.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/pest --ci diff --git a/packages/announcements/.github/workflows/update-changelog.yml b/packages/announcements/.github/workflows/update-changelog.yml new file mode 100644 index 00000000..ec40921c --- /dev/null +++ b/packages/announcements/.github/workflows/update-changelog.yml @@ -0,0 +1,31 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/packages/announcements/.gitignore b/packages/announcements/.gitignore new file mode 100644 index 00000000..12d978a4 --- /dev/null +++ b/packages/announcements/.gitignore @@ -0,0 +1,14 @@ +**/.DS_Store +.idea +.phpunit.result.cache +.phpunit.cache +.vscode +build +composer.lock +coverage +docs +node_modules +phpunit.xml +phpstan.neon +testbench.yaml +vendor diff --git a/packages/announcements/.prettierrc b/packages/announcements/.prettierrc new file mode 100644 index 00000000..98406c6b --- /dev/null +++ b/packages/announcements/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "all" +} diff --git a/packages/announcements/CHANGELOG.md b/packages/announcements/CHANGELOG.md new file mode 100644 index 00000000..07ea178f --- /dev/null +++ b/packages/announcements/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to `backstage-announcements` will be documented in this file. + +## 1.0.0 - 202X-XX-XX + +- initial release diff --git a/packages/announcements/LICENSE.md b/packages/announcements/LICENSE.md new file mode 100644 index 00000000..cc26ee35 --- /dev/null +++ b/packages/announcements/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Backstage + +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/announcements/README.md b/packages/announcements/README.md new file mode 100644 index 00000000..1f152cf8 --- /dev/null +++ b/packages/announcements/README.md @@ -0,0 +1,135 @@ +# Backstage Announcements + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/backstage/backstage-announcements.svg?style=flat-square)](https://packagist.org/packages/backstage/backstage-announcements) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/backstage/backstage-announcements/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/backstage/backstage-announcements/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/backstage/backstage-announcements/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/backstage/backstage-announcements/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/backstage/backstage-announcements.svg?style=flat-square)](https://packagist.org/packages/backstage/backstage-announcements) + +A powerful Filament plugin for managing announcements in your Laravel application. Create, manage, and display announcements with customizable scopes, colors, and navigation controls. + +## Installation + +You can install the package via composer: + +```bash +composer require backstage/announcements +``` + +> [!IMPORTANT] +> If you have not set up a custom theme and are using Filament Panels follow the instructions in the [Filament Docs](https://filamentphp.com/docs/4.x/styling/overview#creating-a-custom-theme) first. + +After setting up a custom theme add the plugin's views to your theme css file or your app's css file if using the standalone packages. + +```css +@source '../../../../vendor/backstage/announcements/resources/**/*.blade.php'; +``` + +You can publish and run the migrations with: + +```bash +php artisan vendor:publish --tag="backstage-announcements-migrations" +php artisan migrate +``` + +Optionally, you can publish the views using + +```bash +php artisan vendor:publish --tag="backstage-announcements-views" +``` + +This is the contents of the published config file: + +```php +return [ +]; +``` + +## Usage + +Add the plugin to your Filament panel provider: + +```php +use Backstage\Announcements\AnnouncementsPlugin; + +public function panel(Panel $panel): Panel +{ + return $panel + ->plugins([ + AnnouncementsPlugin::make(), + ]); +} +``` + +### Navigation Control + +Control whether the announcements resource appears in the navigation menu: + +```php +AnnouncementsPlugin::make() + ->canRegisterNavigation(false) // Hide from navigation +``` + +```php +AnnouncementsPlugin::make() + ->canRegisterNavigation(true) // Show in navigation (default) +``` + +### Forced Scopes + +Limit which scopes (resources/pages) are available when creating announcements. You can specify the full class names of resources or pages: + +```php +AnnouncementsPlugin::make() + ->forceScopes([ + 'App\\Filament\\Resources\\Users\\UserResource', + 'App\\Filament\\Resources\\Products\\ProductResource', + 'App\\Filament\\Pages\\Dashboard', + ]) +``` + +The plugin will automatically match these class names to the formatted scope names that appear in the dropdown, so users will see friendly names like "Users (list)" instead of the full class names. The form automatically converts between class names (stored in database) and formatted names (displayed in UI) using the `formatStateUsing()` method. + +### Creating Announcements + +Once configured, you can create announcements through the Filament interface: + +1. **Title**: The announcement title +2. **Content**: The announcement content (supports HTML) +3. **Scopes**: Select which resources/pages the announcement should appear on +4. **Color**: Choose a color theme for the announcement + +### Displaying Announcements + +Announcements are automatically displayed on the selected scopes using the included Livewire component. The component handles: + +- Dismissal tracking per user +- Color theming +- Responsive design +- Accessibility features + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities. + +## Credits + +- [Manoj Hortulanus](https://github.com/arduinomaster22) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/packages/announcements/bin/build.js b/packages/announcements/bin/build.js new file mode 100644 index 00000000..4ec794ec --- /dev/null +++ b/packages/announcements/bin/build.js @@ -0,0 +1,52 @@ +import esbuild from 'esbuild' + +const isDev = process.argv.includes('--dev') + +async function compile(options) { + const context = await esbuild.context(options) + + if (isDev) { + await context.watch() + } else { + await context.rebuild() + await context.dispose() + } +} + +const defaultOptions = { + define: { + 'process.env.NODE_ENV': isDev ? `'development'` : `'production'`, + }, + bundle: true, + mainFields: ['module', 'main'], + platform: 'neutral', + sourcemap: isDev ? 'inline' : false, + sourcesContent: isDev, + treeShaking: true, + target: ['es2020'], + minify: !isDev, + plugins: [{ + name: 'watchPlugin', + setup: function (build) { + build.onStart(() => { + console.log(`Build started at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) + }) + + build.onEnd((result) => { + if (result.errors.length > 0) { + console.log(`Build failed at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`, result.errors) + } else { + console.log(`Build finished at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) + } + }) + } + }], +} + +compile({ + ...defaultOptions, + entryPoints: ['./resources/js/index.js'], + outfile: './resources/dist/backstage-announcements.js', +}).then(() => { + console.log(`Build completed for backstage-announcements.js`) +}) diff --git a/packages/announcements/composer.json b/packages/announcements/composer.json new file mode 100644 index 00000000..b31eb5d5 --- /dev/null +++ b/packages/announcements/composer.json @@ -0,0 +1,83 @@ +{ + "name": "backstage/announcements", + "description": "This is my package backstage-announcements", + "keywords": [ + "Backstage", + "laravel", + "filamentphp", + "backstage-announcements" + ], + "homepage": "https://github.com/backstagephp/announcements", + "support": { + "issues": "https://github.com/backstagephp/announcements/issues", + "source": "https://github.com/backstagephp/announcements" + }, + "license": "MIT", + "authors": [ + { + "name": "Manoj Hortulanus", + "email": "manoj@backstagephp.com", + "role": "Developer" + } + ], + "require": { + "php": "^8.2", + "filament/filament": "^4.0", + "spatie/laravel-package-tools": "^1.15.0" + }, + "require-dev": { + "larastan/larastan": "^3.0", + "laravel/pint": "^1.0", + "nunomaduro/collision": "^8.0", + "orchestra/testbench": "^9.0|^10.0", + "pestphp/pest": "^3.0", + "pestphp/pest-plugin-arch": "^3.0", + "pestphp/pest-plugin-laravel": "^3.0", + "pestphp/pest-plugin-livewire": "^3.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "rector/rector": "^2.0", + "spatie/laravel-ray": "^1.26" + }, + "autoload": { + "psr-4": { + "Backstage\\Announcements\\": "src/", + "Backstage\\Announcements\\Database\\Factories\\": "database/factories/" + } + }, + "autoload-dev": { + "psr-4": { + "Backstage\\Announcements\\Tests\\": "tests/" + } + }, + "scripts": { + "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", + "analyse": "phpstan analyse", + "lint": "pint", + "refactor": "rector", + "test": "pest", + "test:lint": "pint --test", + "test:refactor": "rector --dry-run" + }, + "extra": { + "laravel": { + "providers": [ + "Backstage\\Announcements\\AnnouncementsServiceProvider" + ], + "aliases": { + "Announcements": "Backstage\\Announcements\\Facades\\Announcements" + } + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "composer/package-versions-deprecated": true, + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/packages/announcements/config/backstage-announcements.php b/packages/announcements/config/backstage-announcements.php new file mode 100644 index 00000000..6953d2f7 --- /dev/null +++ b/packages/announcements/config/backstage-announcements.php @@ -0,0 +1,6 @@ +id(); + $table->foreignId('announcement_id') + ->constrained('announcements') + ->cascadeOnDelete(); + + $table->foreignId('user_id') + ->constrained('users') + ->cascadeOnDelete(); + + $table->timestamp('dismissed_at')->nullable(); + $table->timestamps(); + + $table->unique(['announcement_id', 'user_id']); + }); + } + + public function down(): void + { + Schema::dropIfExists('announcement_dismissals'); + } +}; diff --git a/packages/announcements/database/migrations/create_backstage_announcements_table.php.stub b/packages/announcements/database/migrations/create_backstage_announcements_table.php.stub new file mode 100644 index 00000000..9772562a --- /dev/null +++ b/packages/announcements/database/migrations/create_backstage_announcements_table.php.stub @@ -0,0 +1,32 @@ +id(); + + $table->string('title'); + + $table->text('content'); + + $table->json('scopes'); + + $table->string('color') + ->default('info'); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + public function down(): void + { + Schema::dropIfExists('announcements'); + } +}; diff --git a/packages/announcements/package-lock.json b/packages/announcements/package-lock.json new file mode 100644 index 00000000..58107ee2 --- /dev/null +++ b/packages/announcements/package-lock.json @@ -0,0 +1,709 @@ +{ + "name": "backstage-announcements", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "devDependencies": { + "esbuild": "^0.25.5", + "prettier": "^3.5.3" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.9.tgz", + "integrity": "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.9.tgz", + "integrity": "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.9.tgz", + "integrity": "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.9.tgz", + "integrity": "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.9.tgz", + "integrity": "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.9.tgz", + "integrity": "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.9.tgz", + "integrity": "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.9.tgz", + "integrity": "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.9.tgz", + "integrity": "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.9.tgz", + "integrity": "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.9.tgz", + "integrity": "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.9.tgz", + "integrity": "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.9.tgz", + "integrity": "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.9.tgz", + "integrity": "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.9.tgz", + "integrity": "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.9.tgz", + "integrity": "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.9.tgz", + "integrity": "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.9.tgz", + "integrity": "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.9.tgz", + "integrity": "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.9.tgz", + "integrity": "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.9.tgz", + "integrity": "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.9.tgz", + "integrity": "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.9.tgz", + "integrity": "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.9.tgz", + "integrity": "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.9.tgz", + "integrity": "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.9.tgz", + "integrity": "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/esbuild": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz", + "integrity": "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.9", + "@esbuild/android-arm": "0.25.9", + "@esbuild/android-arm64": "0.25.9", + "@esbuild/android-x64": "0.25.9", + "@esbuild/darwin-arm64": "0.25.9", + "@esbuild/darwin-x64": "0.25.9", + "@esbuild/freebsd-arm64": "0.25.9", + "@esbuild/freebsd-x64": "0.25.9", + "@esbuild/linux-arm": "0.25.9", + "@esbuild/linux-arm64": "0.25.9", + "@esbuild/linux-ia32": "0.25.9", + "@esbuild/linux-loong64": "0.25.9", + "@esbuild/linux-mips64el": "0.25.9", + "@esbuild/linux-ppc64": "0.25.9", + "@esbuild/linux-riscv64": "0.25.9", + "@esbuild/linux-s390x": "0.25.9", + "@esbuild/linux-x64": "0.25.9", + "@esbuild/netbsd-arm64": "0.25.9", + "@esbuild/netbsd-x64": "0.25.9", + "@esbuild/openbsd-arm64": "0.25.9", + "@esbuild/openbsd-x64": "0.25.9", + "@esbuild/openharmony-arm64": "0.25.9", + "@esbuild/sunos-x64": "0.25.9", + "@esbuild/win32-arm64": "0.25.9", + "@esbuild/win32-ia32": "0.25.9", + "@esbuild/win32-x64": "0.25.9" + } + }, + "node_modules/prettier": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + }, + "dependencies": { + "@esbuild/aix-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.9.tgz", + "integrity": "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==", + "dev": true, + "optional": true + }, + "@esbuild/android-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.9.tgz", + "integrity": "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==", + "dev": true, + "optional": true + }, + "@esbuild/android-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.9.tgz", + "integrity": "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==", + "dev": true, + "optional": true + }, + "@esbuild/android-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.9.tgz", + "integrity": "sha512-I853iMZ1hWZdNllhVZKm34f4wErd4lMyeV7BLzEExGEIZYsOzqDWDf+y082izYUE8gtJnYHdeDpN/6tUdwvfiw==", + "dev": true, + "optional": true + }, + "@esbuild/darwin-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.9.tgz", + "integrity": "sha512-XIpIDMAjOELi/9PB30vEbVMs3GV1v2zkkPnuyRRURbhqjyzIINwj+nbQATh4H9GxUgH1kFsEyQMxwiLFKUS6Rg==", + "dev": true, + "optional": true + }, + "@esbuild/darwin-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.9.tgz", + "integrity": "sha512-jhHfBzjYTA1IQu8VyrjCX4ApJDnH+ez+IYVEoJHeqJm9VhG9Dh2BYaJritkYK3vMaXrf7Ogr/0MQ8/MeIefsPQ==", + "dev": true, + "optional": true + }, + "@esbuild/freebsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.9.tgz", + "integrity": "sha512-z93DmbnY6fX9+KdD4Ue/H6sYs+bhFQJNCPZsi4XWJoYblUqT06MQUdBCpcSfuiN72AbqeBFu5LVQTjfXDE2A6Q==", + "dev": true, + "optional": true + }, + "@esbuild/freebsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.9.tgz", + "integrity": "sha512-mrKX6H/vOyo5v71YfXWJxLVxgy1kyt1MQaD8wZJgJfG4gq4DpQGpgTB74e5yBeQdyMTbgxp0YtNj7NuHN0PoZg==", + "dev": true, + "optional": true + }, + "@esbuild/linux-arm": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.9.tgz", + "integrity": "sha512-HBU2Xv78SMgaydBmdor38lg8YDnFKSARg1Q6AT0/y2ezUAKiZvc211RDFHlEZRFNRVhcMamiToo7bDx3VEOYQw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.9.tgz", + "integrity": "sha512-BlB7bIcLT3G26urh5Dmse7fiLmLXnRlopw4s8DalgZ8ef79Jj4aUcYbk90g8iCa2467HX8SAIidbL7gsqXHdRw==", + "dev": true, + "optional": true + }, + "@esbuild/linux-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.9.tgz", + "integrity": "sha512-e7S3MOJPZGp2QW6AK6+Ly81rC7oOSerQ+P8L0ta4FhVi+/j/v2yZzx5CqqDaWjtPFfYz21Vi1S0auHrap3Ma3A==", + "dev": true, + "optional": true + }, + "@esbuild/linux-loong64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.9.tgz", + "integrity": "sha512-Sbe10Bnn0oUAB2AalYztvGcK+o6YFFA/9829PhOCUS9vkJElXGdphz0A3DbMdP8gmKkqPmPcMJmJOrI3VYB1JQ==", + "dev": true, + "optional": true + }, + "@esbuild/linux-mips64el": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.9.tgz", + "integrity": "sha512-YcM5br0mVyZw2jcQeLIkhWtKPeVfAerES5PvOzaDxVtIyZ2NUBZKNLjC5z3/fUlDgT6w89VsxP2qzNipOaaDyA==", + "dev": true, + "optional": true + }, + "@esbuild/linux-ppc64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.9.tgz", + "integrity": "sha512-++0HQvasdo20JytyDpFvQtNrEsAgNG2CY1CLMwGXfFTKGBGQT3bOeLSYE2l1fYdvML5KUuwn9Z8L1EWe2tzs1w==", + "dev": true, + "optional": true + }, + "@esbuild/linux-riscv64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.9.tgz", + "integrity": "sha512-uNIBa279Y3fkjV+2cUjx36xkx7eSjb8IvnL01eXUKXez/CBHNRw5ekCGMPM0BcmqBxBcdgUWuUXmVWwm4CH9kg==", + "dev": true, + "optional": true + }, + "@esbuild/linux-s390x": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.9.tgz", + "integrity": "sha512-Mfiphvp3MjC/lctb+7D287Xw1DGzqJPb/J2aHHcHxflUo+8tmN/6d4k6I2yFR7BVo5/g7x2Monq4+Yew0EHRIA==", + "dev": true, + "optional": true + }, + "@esbuild/linux-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.9.tgz", + "integrity": "sha512-iSwByxzRe48YVkmpbgoxVzn76BXjlYFXC7NvLYq+b+kDjyyk30J0JY47DIn8z1MO3K0oSl9fZoRmZPQI4Hklzg==", + "dev": true, + "optional": true + }, + "@esbuild/netbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.9.tgz", + "integrity": "sha512-9jNJl6FqaUG+COdQMjSCGW4QiMHH88xWbvZ+kRVblZsWrkXlABuGdFJ1E9L7HK+T0Yqd4akKNa/lO0+jDxQD4Q==", + "dev": true, + "optional": true + }, + "@esbuild/netbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.9.tgz", + "integrity": "sha512-RLLdkflmqRG8KanPGOU7Rpg829ZHu8nFy5Pqdi9U01VYtG9Y0zOG6Vr2z4/S+/3zIyOxiK6cCeYNWOFR9QP87g==", + "dev": true, + "optional": true + }, + "@esbuild/openbsd-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.9.tgz", + "integrity": "sha512-YaFBlPGeDasft5IIM+CQAhJAqS3St3nJzDEgsgFixcfZeyGPCd6eJBWzke5piZuZ7CtL656eOSYKk4Ls2C0FRQ==", + "dev": true, + "optional": true + }, + "@esbuild/openbsd-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.9.tgz", + "integrity": "sha512-1MkgTCuvMGWuqVtAvkpkXFmtL8XhWy+j4jaSO2wxfJtilVCi0ZE37b8uOdMItIHz4I6z1bWWtEX4CJwcKYLcuA==", + "dev": true, + "optional": true + }, + "@esbuild/openharmony-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.9.tgz", + "integrity": "sha512-4Xd0xNiMVXKh6Fa7HEJQbrpP3m3DDn43jKxMjxLLRjWnRsfxjORYJlXPO4JNcXtOyfajXorRKY9NkOpTHptErg==", + "dev": true, + "optional": true + }, + "@esbuild/sunos-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.9.tgz", + "integrity": "sha512-WjH4s6hzo00nNezhp3wFIAfmGZ8U7KtrJNlFMRKxiI9mxEK1scOMAaa9i4crUtu+tBr+0IN6JCuAcSBJZfnphw==", + "dev": true, + "optional": true + }, + "@esbuild/win32-arm64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.9.tgz", + "integrity": "sha512-mGFrVJHmZiRqmP8xFOc6b84/7xa5y5YvR1x8djzXpJBSv/UsNK6aqec+6JDjConTgvvQefdGhFDAs2DLAds6gQ==", + "dev": true, + "optional": true + }, + "@esbuild/win32-ia32": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.9.tgz", + "integrity": "sha512-b33gLVU2k11nVx1OhX3C8QQP6UHQK4ZtN56oFWvVXvz2VkDoe6fbG8TOgHFxEvqeqohmRnIHe5A1+HADk4OQww==", + "dev": true, + "optional": true + }, + "@esbuild/win32-x64": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.9.tgz", + "integrity": "sha512-PPOl1mi6lpLNQxnGoyAfschAodRFYXJ+9fs6WHXz7CSWKbOqiMZsubC+BQsVKuul+3vKLuwTHsS2c2y9EoKwxQ==", + "dev": true, + "optional": true + }, + "esbuild": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz", + "integrity": "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==", + "dev": true, + "requires": { + "@esbuild/aix-ppc64": "0.25.9", + "@esbuild/android-arm": "0.25.9", + "@esbuild/android-arm64": "0.25.9", + "@esbuild/android-x64": "0.25.9", + "@esbuild/darwin-arm64": "0.25.9", + "@esbuild/darwin-x64": "0.25.9", + "@esbuild/freebsd-arm64": "0.25.9", + "@esbuild/freebsd-x64": "0.25.9", + "@esbuild/linux-arm": "0.25.9", + "@esbuild/linux-arm64": "0.25.9", + "@esbuild/linux-ia32": "0.25.9", + "@esbuild/linux-loong64": "0.25.9", + "@esbuild/linux-mips64el": "0.25.9", + "@esbuild/linux-ppc64": "0.25.9", + "@esbuild/linux-riscv64": "0.25.9", + "@esbuild/linux-s390x": "0.25.9", + "@esbuild/linux-x64": "0.25.9", + "@esbuild/netbsd-arm64": "0.25.9", + "@esbuild/netbsd-x64": "0.25.9", + "@esbuild/openbsd-arm64": "0.25.9", + "@esbuild/openbsd-x64": "0.25.9", + "@esbuild/openharmony-arm64": "0.25.9", + "@esbuild/sunos-x64": "0.25.9", + "@esbuild/win32-arm64": "0.25.9", + "@esbuild/win32-ia32": "0.25.9", + "@esbuild/win32-x64": "0.25.9" + } + }, + "prettier": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz", + "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", + "dev": true + } + } +} diff --git a/packages/announcements/package.json b/packages/announcements/package.json new file mode 100644 index 00000000..1f70fe1a --- /dev/null +++ b/packages/announcements/package.json @@ -0,0 +1,12 @@ +{ + "private": true, + "type": "module", + "scripts": { + "dev": "node bin/build.js --dev", + "build": "node bin/build.js" + }, + "devDependencies": { + "esbuild": "^0.25.5", + "prettier": "^3.5.3" + } +} diff --git a/packages/announcements/phpstan-baseline.neon b/packages/announcements/phpstan-baseline.neon new file mode 100644 index 00000000..e69de29b diff --git a/packages/announcements/phpstan.neon.dist b/packages/announcements/phpstan.neon.dist new file mode 100644 index 00000000..a940793a --- /dev/null +++ b/packages/announcements/phpstan.neon.dist @@ -0,0 +1,15 @@ +includes: + - vendor/larastan/larastan/extension.neon + - vendor/nesbot/carbon/extension.neon + - phpstan-baseline.neon + +parameters: + level: 4 + paths: + - src + - config + - database + tmpDir: build/phpstan + checkOctaneCompatibility: true + checkModelProperties: true + diff --git a/packages/announcements/phpunit.xml.dist b/packages/announcements/phpunit.xml.dist new file mode 100644 index 00000000..ae36eaa3 --- /dev/null +++ b/packages/announcements/phpunit.xml.dist @@ -0,0 +1,38 @@ + + + + + tests + + + + + + + + + + + + + + + ./src + + + diff --git a/packages/announcements/pint.json b/packages/announcements/pint.json new file mode 100644 index 00000000..c6ddb494 --- /dev/null +++ b/packages/announcements/pint.json @@ -0,0 +1,14 @@ +{ + "preset": "laravel", + "rules": { + "blank_line_before_statement": true, + "concat_space": { + "spacing": "one" + }, + "method_argument_space": true, + "single_trait_insert_per_statement": true, + "types_spaces": { + "space": "single" + } + } +} diff --git a/packages/announcements/rector.php b/packages/announcements/rector.php new file mode 100644 index 00000000..9a3dfc8e --- /dev/null +++ b/packages/announcements/rector.php @@ -0,0 +1,17 @@ +withPaths([ + __DIR__ . '/src', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withPhpSets(); diff --git a/packages/announcements/resources/css/index.css b/packages/announcements/resources/css/index.css new file mode 100644 index 00000000..b3949d56 --- /dev/null +++ b/packages/announcements/resources/css/index.css @@ -0,0 +1 @@ +@import '../../vendor/filament/filament/resources/css/theme.css'; diff --git a/packages/announcements/resources/dist/.gitkeep b/packages/announcements/resources/dist/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/packages/announcements/resources/dist/backstage-announcements.js b/packages/announcements/resources/dist/backstage-announcements.js new file mode 100644 index 00000000..a8141d3b --- /dev/null +++ b/packages/announcements/resources/dist/backstage-announcements.js @@ -0,0 +1 @@ +console.log("Hello, world!"); diff --git a/packages/announcements/resources/js/index.js b/packages/announcements/resources/js/index.js new file mode 100644 index 00000000..afda0785 --- /dev/null +++ b/packages/announcements/resources/js/index.js @@ -0,0 +1 @@ +console.log('Hello, world!'); \ No newline at end of file diff --git a/packages/announcements/resources/lang/en/backstage-announcements.php b/packages/announcements/resources/lang/en/backstage-announcements.php new file mode 100644 index 00000000..1054e170 --- /dev/null +++ b/packages/announcements/resources/lang/en/backstage-announcements.php @@ -0,0 +1,6 @@ + 'mb-6', + $instance instanceof \Filament\Pages\Page => 'mt-5 -mb-4', + default => null, + }; + +@endphp + +
+
+

+ + {{ $announcement->title }} + + + {{ $announcement->content }} +

+ @if ($this->canMarkAsRead()) + + @endif +
+
diff --git a/packages/announcements/src/Announcements.php b/packages/announcements/src/Announcements.php new file mode 100644 index 00000000..91303cd7 --- /dev/null +++ b/packages/announcements/src/Announcements.php @@ -0,0 +1,47 @@ +getTable())) { + return; + } + + Announcement::all()->each(function ($announcement) { + collect($announcement->scopes)->each(function ($scope) use ($announcement) { + $instance = new $scope; + + $hook = match (true) { + $instance instanceof SimplePage => PanelsRenderHook::SIMPLE_PAGE_START, + $instance instanceof Page => PanelsRenderHook::CONTENT_START, + default => null, + }; + + if ($hook) { + FilamentView::registerRenderHook( + name: $hook, + hook: function () use ($announcement, $scope) { + if ($announcement->isDismissedBy(Filament::auth()->user()?->id)) { + return ''; + } + + return $announcement->render($scope); + }, + scopes: $scope + ); + } + }); + }); + } +} diff --git a/packages/announcements/src/AnnouncementsPlugin.php b/packages/announcements/src/AnnouncementsPlugin.php new file mode 100644 index 00000000..05d745af --- /dev/null +++ b/packages/announcements/src/AnnouncementsPlugin.php @@ -0,0 +1,69 @@ +shouldRegisterNavigation); + AnnouncementResource::scopeToTenant(false); + + $panel->resources([ + AnnouncementResource::class, + ]); + + \Backstage\Announcements\Facades\Announcements::register(); + } + + public function boot(Panel $panel): void {} + + public static function make(): static + { + return app(static::class); + } + + public static function get(): static + { + /** @var static $plugin */ + $plugin = filament(app(static::class)->getId()); + + return $plugin; + } + + public function canRegisterNavigation(bool $canRegister = true): static + { + $this->shouldRegisterNavigation = $canRegister; + + return $this; + } + + public function forceScopes(array | \Closure $scopes): static + { + $this->forcedScopes = $scopes; + + return $this; + } + + public function getForcedScopes(): ?array + { + return $this->evaluate($this->forcedScopes); + } +} diff --git a/packages/announcements/src/AnnouncementsServiceProvider.php b/packages/announcements/src/AnnouncementsServiceProvider.php new file mode 100644 index 00000000..39cf8b27 --- /dev/null +++ b/packages/announcements/src/AnnouncementsServiceProvider.php @@ -0,0 +1,159 @@ +name(static::$name) + ->hasCommands($this->getCommands()) + ->hasInstallCommand(function (InstallCommand $command) { + $command + ->setName('backstage:announcements:install') + ->publishConfigFile() + ->publishMigrations() + ->askToRunMigrations() + ->askToStarRepoOnGitHub('backstage/backstage-announcements'); + }); + + $configFileName = $package->shortName(); + + if (file_exists($package->basePath("/../config/{$configFileName}.php"))) { + $package->hasConfigFile(); + } + + if (file_exists($package->basePath('/../database/migrations'))) { + $package->hasMigrations($this->getMigrations()); + } + + if (file_exists($package->basePath('/../resources/lang'))) { + $package->hasTranslations(); + } + + if (file_exists($package->basePath('/../resources/views'))) { + $package->hasViews(static::$viewNamespace); + } + } + + public function packageRegistered(): void {} + + public function packageBooted(): void + { + // Asset Registration + FilamentAsset::register( + $this->getAssets(), + $this->getAssetPackageName() + ); + + FilamentAsset::registerScriptData( + $this->getScriptData(), + $this->getAssetPackageName() + ); + + // Icon Registration + FilamentIcon::register($this->getIcons()); + + Livewire::component('backstage.announcements.livewire.announcement', Announcement::class); + + // Handle Stubs + if (app()->runningInConsole()) { + foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) { + $this->publishes([ + $file->getRealPath() => base_path("stubs/backstage-announcements/{$file->getFilename()}"), + ], 'backstage-announcements-stubs'); + } + } + + // Testing + Testable::mixin(new TestsAnnouncements); + } + + protected function getAssetPackageName(): ?string + { + return 'backstage/announcements'; + } + + /** + * @return array + */ + protected function getAssets(): array + { + return [ + // AlpineComponent::make('backstage-announcements', __DIR__ . '/../resources/dist/components/backstage-announcements.js'), + // Css::make('backstage-announcements-styles', __DIR__ . '/../resources/dist/backstage-announcements.css'), + Js::make('backstage-announcements-scripts', __DIR__ . '/../resources/dist/backstage-announcements.js'), + ]; + } + + /** + * @return array + */ + protected function getCommands(): array + { + return [ + AnnouncementsCommand::class, + ]; + } + + /** + * @return array + */ + protected function getIcons(): array + { + return []; + } + + /** + * @return array + */ + protected function getRoutes(): array + { + return []; + } + + /** + * @return array + */ + protected function getScriptData(): array + { + return []; + } + + /** + * @return array + */ + protected function getMigrations(): array + { + return [ + 'create_backstage_announcements_table', + 'create_announcement_dismissals_table', + ]; + } +} diff --git a/packages/announcements/src/Collections/ScopeCollection.php b/packages/announcements/src/Collections/ScopeCollection.php new file mode 100644 index 00000000..fe4720a0 --- /dev/null +++ b/packages/announcements/src/Collections/ScopeCollection.php @@ -0,0 +1,115 @@ +getResources(); + + $mutatedResources = static::mutateResources($resources); + + $extraActions = [ + $panel->getLoginRouteAction(), + ]; + + if ($panel->hasRegistration()) { + $extraActions[] = $panel->getRegistrationRouteAction(); + } + + $pages = array_merge($panel->getPages(), $extraActions); + + $mutatedPages = static::mutatePages($pages); + + $scopes = array_merge($mutatedResources, $mutatedPages); + + // If forced scopes are provided, filter the scopes to only include those + if ($forcedScopes !== null) { + $filteredScopes = []; + + // If it's a closure, call it to get the array of scopes + if ($forcedScopes instanceof \Closure) { + $forcedScopes = $forcedScopes($scopes); + } + + foreach ($scopes as $key => $value) { + // Check if the key (page class) matches any of the forced scopes + foreach ($forcedScopes as $forcedScope) { + if ($key === $forcedScope || is_subclass_of($key, $forcedScope)) { + $filteredScopes[$key] = $value; + + break; + } + } + } + + $scopes = $filteredScopes; + } + + $cached = parent::make($scopes); + + return $cached; + } + + public static function mutateResources($resources) + { + $resources = new static($resources); + + $resources = $resources->values()->map(function ($resource, $x) { + $modelLabel = $resource::getPluralModelLabel() ?? $resource::getNavigationLabel(); + + $pages = $resource::getPages(); + + $labels = []; + + foreach ($pages as $page) { + $labels[$page->getPage()] = str($modelLabel) + ->append(' ') + ->append('(') + ->append(strtolower($page->getPage()::getNavigationLabel())) + ->append(')') + ->append(' ') + ->when( + $page->getPage()::getResource()::getNavigationGroup(), + fn ($group) => $group->append('(')->append(strtolower($page->getPage()::getResource()::getNavigationGroup())) + ->append(')') + ) + + ->toString(); + } + + return $labels; + }) + ->pipe(fn ($c) => Arr::collapse($c->toArray())); + + return $resources; + } + + public static function mutatePages($pages) + { + $pages = new static($pages); + + $pages = $pages->values()->mapWithKeys(function ($page) { + if ($page === null) { + return []; + } + + $value = str(method_exists($page, 'getNavigationLabel') ? $page::getNavigationLabel() : (method_exists($page, 'getLabel') ? $page::getLabel() : app($page)->getTitle())) + ->when( + method_exists($page, 'getNavigationGroup') ? $page::getNavigationGroup() : null, + fn ($group) => $group->append(' (')->append(strtolower($page::getNavigationGroup()))->append(')') + ) + ->toString(); + + return [$page => $value]; + }) + ->toArray(); + + return $pages; + } +} diff --git a/packages/announcements/src/Commands/AnnouncementsCommand.php b/packages/announcements/src/Commands/AnnouncementsCommand.php new file mode 100644 index 00000000..745b7ebe --- /dev/null +++ b/packages/announcements/src/Commands/AnnouncementsCommand.php @@ -0,0 +1,25 @@ +comment('All done'); + + $newAnnouncement = Announcement::create([ + 'title' => 'New Announcement', + 'content' => 'This is a new announcement.', + ]); + + return self::SUCCESS; + } +} diff --git a/packages/announcements/src/Facades/Announcements.php b/packages/announcements/src/Facades/Announcements.php new file mode 100644 index 00000000..4c7f058c --- /dev/null +++ b/packages/announcements/src/Facades/Announcements.php @@ -0,0 +1,18 @@ +announcement = $announcement; + + $this->scope = $scope; + + $this->getColor(); + } + + public function render() + { + if ($this->announcement->isDismissedBy()) { + return '
'; + } + + return view('backstage/announcements::livewire.announcement'); + } + + public function getColor() + { + $styles = \Illuminate\Support\Arr::toCssStyles([ + \Filament\Support\get_color_css_variables($this->announcement->color, shades: [600]), + ]); + + return $styles; + } + + public function canMarkAsRead(): bool + { + return Filament::auth()->check(); + } + + public function markAsRead() + { + if (! $this->announcement->isDismissedBy()) { + $this->announcement->dismissals()->create([ + ]); + } + } +} diff --git a/packages/announcements/src/Models/Announcement.php b/packages/announcements/src/Models/Announcement.php new file mode 100644 index 00000000..cdde2838 --- /dev/null +++ b/packages/announcements/src/Models/Announcement.php @@ -0,0 +1,64 @@ + 'array', + ]; + + protected static function boot() + { + parent::boot(); + + static::saving(function (self $announcement) { + $announcement->scopes = ! empty($announcement->scopes) ? $announcement->scopes : ['*']; + }); + } + + public function render(string $scope): Htmlable + { + $livewire = Livewire::mount(LivewireAnnouncement::class, ['announcement' => $this, 'scope' => $scope]); + + return new HtmlString($livewire); + } + + public function dismissals(): HasMany + { + return $this->hasMany(AnnouncementDismissal::class); + } + + public function isDismissedBy(?int $userId = null): bool + { + if (! Filament::auth()->check()) { + return false; + } + + if (is_null($userId)) { + $userId = Filament::auth()->user()->id; + } + + return $this->dismissals() + ->where('user_id', $userId) + ->exists(); + } +} diff --git a/packages/announcements/src/Models/AnnouncementDismissal.php b/packages/announcements/src/Models/AnnouncementDismissal.php new file mode 100644 index 00000000..fb0f790b --- /dev/null +++ b/packages/announcements/src/Models/AnnouncementDismissal.php @@ -0,0 +1,45 @@ + 'datetime', + ]; + + protected static function boot() + { + parent::boot(); + + static::creating(function (self $dismissal) { + if (is_null($dismissal->dismissed_at)) { + $dismissal->dismissed_at = now(); + } + + if (is_null($dismissal->user_id) && Filament::auth()->check()) { + $dismissal->user_id = Filament::auth()->id(); + } + }); + } + + public function announcement(): BelongsTo + { + return $this->belongsTo(Announcement::class); + } + + public function user(): BelongsTo + { + return $this->belongsTo(config('auth.providers.users.model', \App\Models\User::class)); + } +} diff --git a/packages/announcements/src/Resources/Announcements/AnnouncementResource.php b/packages/announcements/src/Resources/Announcements/AnnouncementResource.php new file mode 100644 index 00000000..4bb5f8d8 --- /dev/null +++ b/packages/announcements/src/Resources/Announcements/AnnouncementResource.php @@ -0,0 +1,93 @@ + ListAnnouncements::route('/'), + 'create' => CreateAnnouncement::route('/create'), + 'view' => ViewAnnouncement::route('/{record}'), + 'edit' => EditAnnouncement::route('/{record}/edit'), + ]; + } + + public static function getRecordRouteBindingEloquentQuery(): Builder + { + return parent::getRecordRouteBindingEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/packages/announcements/src/Resources/Announcements/Pages/CreateAnnouncement.php b/packages/announcements/src/Resources/Announcements/Pages/CreateAnnouncement.php new file mode 100644 index 00000000..c4261b02 --- /dev/null +++ b/packages/announcements/src/Resources/Announcements/Pages/CreateAnnouncement.php @@ -0,0 +1,11 @@ +components([ + TextInput::make('title') + ->required(), + + Textarea::make('content') + ->required() + ->columnSpanFull(), + + Select::make('scopes') + ->searchable() + ->multiple() + ->options(function () { + $plugin = AnnouncementsPlugin::get(); + $forcedScopes = $plugin->getForcedScopes(); + + return ScopeCollection::create(Filament::getCurrentPanel(), $forcedScopes)->toArray(); + }) + ->formatStateUsing(function ($state) { + if (empty($state)) { + return $state; + } + + // Convert class names to formatted names for display + $plugin = AnnouncementsPlugin::get(); + $forcedScopes = $plugin->getForcedScopes(); + $allScopes = ScopeCollection::create(Filament::getCurrentPanel(), $forcedScopes)->toArray(); + + return array_map(fn ($value) => $allScopes[$value] ?? $value, (array) $state); + }) + ->required(), + + Select::make('color') + ->live() + ->prefixIcon(Heroicon::OutlinedCube, true) + ->prefixIconColor(fn (?string $state) => $state ?? 'gray') + ->options(function () { + $colors = ColorManager::DEFAULT_COLORS; + + return collect($colors) + ->keys() + ->mapWithKeys(function ($key) { + return [ + $key => $key, + ]; + }); + }), + ]); + } +} diff --git a/packages/announcements/src/Resources/Announcements/Schemas/AnnouncementInfolist.php b/packages/announcements/src/Resources/Announcements/Schemas/AnnouncementInfolist.php new file mode 100644 index 00000000..f2dff3cd --- /dev/null +++ b/packages/announcements/src/Resources/Announcements/Schemas/AnnouncementInfolist.php @@ -0,0 +1,23 @@ +components([ + TextEntry::make('title'), + TextEntry::make('created_at') + ->dateTime(), + TextEntry::make('updated_at') + ->dateTime(), + TextEntry::make('deleted_at') + ->dateTime(), + ]); + } +} diff --git a/packages/announcements/src/Resources/Announcements/Tables/AnnouncementsTable.php b/packages/announcements/src/Resources/Announcements/Tables/AnnouncementsTable.php new file mode 100644 index 00000000..ab063c40 --- /dev/null +++ b/packages/announcements/src/Resources/Announcements/Tables/AnnouncementsTable.php @@ -0,0 +1,51 @@ +columns([ + TextColumn::make('title') + ->searchable(), + TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + TextColumn::make('deleted_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + TrashedFilter::make(), + ]) + ->recordActions([ + ViewAction::make(), + EditAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ForceDeleteBulkAction::make(), + RestoreBulkAction::make(), + ]), + ]); + } +} diff --git a/packages/announcements/src/Testing/TestsAnnouncements.php b/packages/announcements/src/Testing/TestsAnnouncements.php new file mode 100644 index 00000000..ca0402cd --- /dev/null +++ b/packages/announcements/src/Testing/TestsAnnouncements.php @@ -0,0 +1,13 @@ +expect(['dd', 'dump', 'ray']) + ->each->not->toBeUsed(); diff --git a/packages/announcements/tests/ExampleTest.php b/packages/announcements/tests/ExampleTest.php new file mode 100644 index 00000000..5d363218 --- /dev/null +++ b/packages/announcements/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/packages/announcements/tests/Pest.php b/packages/announcements/tests/Pest.php new file mode 100644 index 00000000..a2720b11 --- /dev/null +++ b/packages/announcements/tests/Pest.php @@ -0,0 +1,5 @@ +in(__DIR__); diff --git a/packages/announcements/tests/TestCase.php b/packages/announcements/tests/TestCase.php new file mode 100644 index 00000000..d489b03d --- /dev/null +++ b/packages/announcements/tests/TestCase.php @@ -0,0 +1,71 @@ + 'Backstage\\Announcements\\Database\\Factories\\' . class_basename($modelName) . 'Factory' + ); + } + + protected function getPackageProviders($app) + { + $providers = [ + ActionsServiceProvider::class, + BladeCaptureDirectiveServiceProvider::class, + BladeHeroiconsServiceProvider::class, + BladeIconsServiceProvider::class, + FilamentServiceProvider::class, + FormsServiceProvider::class, + InfolistsServiceProvider::class, + LivewireServiceProvider::class, + NotificationsServiceProvider::class, + SchemasServiceProvider::class, + SupportServiceProvider::class, + TablesServiceProvider::class, + WidgetsServiceProvider::class, + AnnouncementsServiceProvider::class, + ]; + + sort($providers); + + return $providers; + } + + public function getEnvironmentSetUp($app): void + { + $app['config']->set('database.default', 'testing'); + } + + protected function defineDatabaseMigrations(): void + { + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + } +} diff --git a/packages/core/src/Resources/ContentResource.php b/packages/core/src/Resources/ContentResource.php index db49d655..1637e31d 100644 --- a/packages/core/src/Resources/ContentResource.php +++ b/packages/core/src/Resources/ContentResource.php @@ -363,7 +363,6 @@ public static function form(Schema $schema): Schema }) ->disabledOptions(fn ($record) => [$record?->getKey()]), - Toggle::make('public') ->label(__('Public')) ->default(fn () => self::$type->public ?? true)