From a8e364981f132836a30cc2514aeac3b8dc4e1716 Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Tue, 17 Sep 2024 12:13:36 -0300 Subject: [PATCH] introducing envbar:show command --- config/envbar.php | 8 +++---- dist/app.js | 2 +- docs/index.md | 18 ++++++++++----- resources/js/modules/envbar.js | 10 +++++++-- resources/views/components/envbar.blade.php | 4 ++-- ...ClearCacheCommand.php => FlushCommand.php} | 4 ++-- src/Console/ShowCommand.php | 22 +++++++++++++++++++ src/EnvBarServiceProvider.php | 5 ++++- src/Response/Render.php | 2 ++ 9 files changed, 57 insertions(+), 18 deletions(-) rename src/Console/{ClearCacheCommand.php => FlushCommand.php} (83%) create mode 100644 src/Console/ShowCommand.php diff --git a/config/envbar.php b/config/envbar.php index 1eda4fd..50dabec 100644 --- a/config/envbar.php +++ b/config/envbar.php @@ -89,7 +89,7 @@ | When set, the EnvBar will wait the set minutes to appear again. | */ - 'timeout' => env('ENVBAR_CLOSABLE_TIMEOUT'), + 'timeout' => env('ENVBAR_CLOSABLE_TIMEOUT', 10), ], /* @@ -188,19 +188,19 @@ 'github' => [ 'token' => env('ENVBAR_GITHUB_TOKEN'), 'repository' => env('ENVBAR_GITHUB_REPOSITORY'), - 'cached_for' => env('ENVBAR_GITHUB_CACHED_FOR', 1), + 'cached_for' => env('ENVBAR_GITHUB_DAYS_FOR_CACHE', 1), ], 'bitbucket' => [ 'token' => env('ENVBAR_BITBUCKET_TOKEN'), 'repository' => env('ENVBAR_BITBUCKET_REPOSITORY'), - 'cached_for' => env('ENVBAR_BITBUCKET_CACHED_FOR', 1), + 'cached_for' => env('ENVBAR_BITBUCKET_DAYS_FOR_CACHE', 1), ], 'envoyer' => [ 'token' => env('ENVBAR_ENVOYER_TOKEN', null), 'project_id' => env('ENVBAR_ENVOYER_PROJECT_ID', null), - 'cached_for' => env('ENVBAR_BITBUCKET_CACHED_FOR', 1), + 'cached_for' => env('ENVBAR_BITBUCKET_DAYS_FOR_CACHE', 1), ], ], ]; diff --git a/dist/app.js b/dist/app.js index ab5b369..5e05ce4 100644 --- a/dist/app.js +++ b/dist/app.js @@ -1 +1 @@ -const r=n=>({init(){const e=localStorage.getItem("envbar::closed");e&&Date.now()parseInt(e)&&localStorage.removeItem("envbar::closed"),n.tailwind_breaking_points&&(this.breakpoint(),window.addEventListener("resize",()=>this.breakpoint()))},close(){const e=n.closable.timeout??null;this.element().style.display="none",localStorage.removeItem("envbar::closed"),e&&localStorage.setItem("envbar::closed",String(Date.now()+parseInt(e)*6e4))},breakpoint(){const e=window.innerWidth,t=this.element("resolution");return e<640?t.innerText="SM":e>=640&&e<768?t.innerText="MD":e>=768&&e<1024?t.innerText="LG":e>=1024&&e<1280?t.innerText="XL":e>=1280&&e<1536?t.innerText="2XL":t.innerText="> 2XL"},element(e=""){let t="envbar";return e&&(t+=`-${e}`),document.getElementById(t)}});window.$envbar=r; +const i=(n,r)=>({init(){let e=localStorage.getItem("envbar::closed");r===!0&&(e=null,localStorage.removeItem("envbar::closed")),e&&Date.now()parseInt(e)&&localStorage.removeItem("envbar::closed"),n.tailwind_breaking_points&&(this.breakpoint(),window.addEventListener("resize",()=>this.breakpoint()))},close(){const e=n.closable.timeout??null;this.element().style.display="none",localStorage.removeItem("envbar::closed"),e&&localStorage.setItem("envbar::closed",String(Date.now()+parseInt(e)*6e4))},breakpoint(){const e=window.innerWidth,t=this.element("resolution");return e<640?t.innerText="SM":e>=640&&e<768?t.innerText="MD":e>=768&&e<1024?t.innerText="LG":e>=1024&&e<1280?t.innerText="XL":e>=1280&&e<1536?t.innerText="2XL":t.innerText="> 2XL"},element(e=""){let t="envbar";return e&&(t+=`-${e}`),document.getElementById(t)}});window.$envbar=i; diff --git a/docs/index.md b/docs/index.md index f907c4b..40c9ae1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,13 +36,13 @@ Almost all the configuration is done through environment variables. Here are the 12. `ENVBAR_PROVIDER` - The provider to be used for fetching the last release. Allowed: github, bitbucket, envoyer. Default is `null`. 13. `ENVBAR_GITHUB_TOKEN` - GitHub token to be used for fetching the last release. 14. `ENVBAR_GITHUB_REPOSITORY` - GitHub repository to be used for fetching the last release. -15. `ENVBAR_GITHUB_CACHED_FOR` - The time in days to cache the last release. Default is `1`. +15. `ENVBAR_GITHUB_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`. 16. `ENVBAR_BITBUCKET_TOKEN` - BitBucket token to be used for fetching the last release. 17. `ENVBAR_BITBUCKET_REPOSITORY` - BitBucket repository to be used for fetching the last release. -18. `ENVBAR_BITBUCKET_CACHED_FOR` - The time in days to cache the last release. Default is `1`. +18. `ENVBAR_BITBUCKET_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`. 19. `ENVBAR_ENVOYER_TOKEN` - Envoyer token to be used for fetching the last release. 20. `ENVBAR_ENVOYER_PROJECT_ID` - Envoyer project id to be used for fetching the last release. -21. `ENVBAR_BITBUCKET_CACHED_FOR` - The time in days to cache the last release. Default is `1`. +21. `ENVBAR_ENVOYER_DAYS_FOR_CACHE` - The time in days to cache the last release. Default is `1`. ### Other Configurations: @@ -72,10 +72,16 @@ You can ignore the EnvBar for specific pages: ``` Behind the scenes, this feature uses `Request::is` to check the current route. -### Clear Release Cache: +### Commands: -To avoid multiple requests to the git provider, the latest release is cached. If you want to clear the release cache, you can clear the entire application cache or run the following command to clear the release cache only: +To avoid multiple requests to the git provider, the latest release is cached for `ENVBAR_*_CACHED_FOR` day(s). If you want to clear the release cache, you can clear the entire application cache or run the following command to clear the release cache only, without affecting the other cache: ```bash -php artisan envbar:flush-release-cache +php artisan envbar:flush +``` + +If you are using `ENVBAR_CLOSABLE_TIMEOUT` and you closed the EnvBar, you can use the command below to show the EnvBar again without waiting for the final minutes timeout to run out: + +```bash +php artisan envbar:show ``` diff --git a/resources/js/modules/envbar.js b/resources/js/modules/envbar.js index bb5b52a..6cc1964 100644 --- a/resources/js/modules/envbar.js +++ b/resources/js/modules/envbar.js @@ -1,6 +1,12 @@ -export default (configuration) => ({ +export default (configuration, show) => ({ init() { - const closedAt = localStorage.getItem('envbar::closed'); + let closedAt = localStorage.getItem('envbar::closed'); + + if (show === true) { + closedAt = null; + + localStorage.removeItem('envbar::closed'); + } if (closedAt && Date.now() < parseInt(closedAt)) { this.element().style.display = 'none'; diff --git a/resources/views/components/envbar.blade.php b/resources/views/components/envbar.blade.php index 44b092b..1fbdd75 100644 --- a/resources/views/components/envbar.blade.php +++ b/resources/views/components/envbar.blade.php @@ -56,8 +56,8 @@