├── resources
├── sass
│ └── tool.scss
├── js
│ ├── MultipleDashboard.js
│ └── components
│ │ └── Dashboard.vue
└── views
│ ├── navigation.blade.php
│ └── nova-overrides
│ └── dashboard
│ └── navigation.blade.php
├── screenshots
└── example.gif
├── .prettierrc
├── webpack.mix.js
├── CHANGELOG.md
├── src
├── Dashboard.php
├── Console
│ ├── stubs
│ │ └── dashboard.stub
│ └── Commands
│ │ └── CreateDashboard.php
├── Http
│ ├── Controllers
│ │ └── MultipleDashboardController.php
│ └── Requests
│ │ ├── DashboardCardRequest.php
│ │ └── DashboardMetricRequest.php
├── ToolServiceProvider.php
└── DashboardNova.php
├── .circleci
└── config.yml
├── .eslintrc
├── routes
└── api.php
├── composer.json
├── LICENSE.md
├── package.json
├── README.md
├── dist
└── js
│ └── MultipleDashboard.js
└── CONTRIBUTING.md
/resources/sass/tool.scss:
--------------------------------------------------------------------------------
1 | // Nova Tool CSS
2 |
--------------------------------------------------------------------------------
/screenshots/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexbowers/nova-multiple-dashboard/HEAD/screenshots/example.gif
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 100,
3 | "singleQuote": true,
4 | "tabWidth": 4,
5 | "trailingComma": "es5"
6 | }
7 |
--------------------------------------------------------------------------------
/webpack.mix.js:
--------------------------------------------------------------------------------
1 | let mix = require('laravel-mix')
2 |
3 | mix.js('resources/js/MultipleDashboard.js', 'dist/js/MultipleDashboard.js');
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to `nova-multiple-dashboard` will be documented in this file
4 |
5 | ## 1.0.0 - 2018-XX-XX
6 |
7 | - initial release
8 |
--------------------------------------------------------------------------------
/src/Dashboard.php:
--------------------------------------------------------------------------------
1 | {
4 | router.beforeEach((to, from, next) => {
5 | /**
6 | * Load the dashboard using our custom route.
7 | */
8 | if (to.name == 'dashboard' && to.path == '/') {
9 | next('/dashboards/main');
10 | }
11 |
12 | next();
13 | });
14 |
15 | router.addRoutes([
16 | {
17 | name: 'dashboard.custom',
18 | path: '/dashboards/:dashboardName',
19 | component: Dashboard,
20 | props: true,
21 | },
22 | ])
23 | })
24 |
--------------------------------------------------------------------------------
/routes/api.php:
--------------------------------------------------------------------------------
1 | availableCards($dashboard);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Http/Requests/DashboardCardRequest.php:
--------------------------------------------------------------------------------
1 | unique()
20 | ->filter
21 | ->authorize($this)
22 | ->values();
23 | }
24 |
25 | return DashboardNova::availableDashboardCardsForDashboard($dashboard, $this);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/resources/views/navigation.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/src/Http/Requests/DashboardMetricRequest.php:
--------------------------------------------------------------------------------
1 | availableMetrics()->first(function ($metric) {
20 | return $this->metric === $metric->uriKey();
21 | }) ?: abort(404);
22 | }
23 |
24 | /**
25 | * Get all of the possible metrics for the request.
26 | *
27 | * @return \Illuminate\Support\Collection
28 | */
29 | public function availableMetrics()
30 | {
31 | return DashboardNova::allAvailableDashboardCards($this)->whereInstanceOf(Metric::class);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "alexbowers/nova-multiple-dashboard",
3 | "description": "Support for multiple custom dashboards in Laravel Nova",
4 | "keywords": [
5 | "laravel",
6 | "nova"
7 | ],
8 | "homepage": "https://github.com/AlexBowers/nova-multiple-dashboard",
9 | "license": "MIT",
10 | "authors": [
11 | {
12 | "name": "Alex Bowers",
13 | "email": "bowersbros@gmail.com",
14 | "role": "Developer"
15 | }
16 | ],
17 | "require": {
18 | "php": ">=7.1.0"
19 | },
20 | "require-dev": {
21 | "phpstan/phpstan": "^0.10.3"
22 | },
23 | "autoload": {
24 | "psr-4": {
25 | "AlexBowers\\MultipleDashboard\\": "src/"
26 | }
27 | },
28 | "extra": {
29 | "laravel": {
30 | "providers": [
31 | "AlexBowers\\MultipleDashboard\\ToolServiceProvider"
32 | ]
33 | }
34 | },
35 | "config": {
36 | "sort-packages": true
37 | },
38 | "minimum-stability": "dev",
39 | "prefer-stable": true
40 | }
41 |
--------------------------------------------------------------------------------
/resources/js/components/Dashboard.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
{{__('Dashboard')}}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
42 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) AlexBowers bvba
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "scripts": {
4 | "dev": "npm run development",
5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
6 | "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
7 | "watch-poll": "npm run watch -- --watch-poll",
8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
9 | "prod": "npm run production",
10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
11 | "check-format": "prettier --list-different 'resources/**/*.{css,js,vue}'",
12 | "format": "prettier --write 'resources/**/*.{css,js,vue}'",
13 | "lint": "eslint resources/js --fix --ext js,vue"
14 | },
15 | "devDependencies": {
16 | "cross-env": "^5.0.0",
17 | "eslint": "^4.19.1",
18 | "eslint-config-prettier": "^2.9.0",
19 | "eslint-plugin-vue": "^4.4.0",
20 | "laravel-mix": "^1.0",
21 | "prettier": "^1.14.0"
22 | },
23 | "dependencies": {
24 | "animated-scroll-to": "^1.2.2",
25 | "laravel-nova": "^1.0.2",
26 | "vue": "^2.5.0"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Console/Commands/CreateDashboard.php:
--------------------------------------------------------------------------------
1 | argument('name'), '-'), $stub);
40 |
41 | return str_replace('dashboard-name', ucwords(Str::snake($this->argument('name'), ' ')), $stub);
42 | }
43 |
44 | /**
45 | * Get the stub file for the generator.
46 | *
47 | * @return string
48 | */
49 | protected function getStub()
50 | {
51 | return realpath(__DIR__ . '/../stubs/dashboard.stub');
52 | }
53 |
54 | /**
55 | * Get the default namespace for the class.
56 | *
57 | * @param string $rootNamespace
58 | * @return string
59 | */
60 | protected function getDefaultNamespace($rootNamespace)
61 | {
62 | return $rootNamespace.'\Nova\Dashboards';
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/ToolServiceProvider.php:
--------------------------------------------------------------------------------
1 | loadViewsFrom(__DIR__ . '/../resources/views/nova-overrides', 'nova');
22 |
23 | Nova::serving(function (ServingNova $event) {
24 | DashboardNova::dashboardsIn(app_path('Nova/Dashboards'));
25 | Nova::script('nova-multiple-dashboard', __DIR__ . '/../dist/js/MultipleDashboard.js');
26 | });
27 |
28 | $this->app->booted(function () {
29 | $this->routes();
30 |
31 | Nova::serving(function (ServingNova $event) {
32 | DashboardNova::copyDefaultDashboardCards();
33 | DashboardNova::cardsInDashboards();
34 | });
35 | });
36 |
37 | if ($this->app->runningInConsole()) {
38 | $this->commands([
39 | CreateDashboard::class,
40 | ]);
41 | }
42 | }
43 |
44 | /**
45 | * Register the tool's routes.
46 | *
47 | * @return void
48 | */
49 | protected function routes()
50 | {
51 | if ($this->app->routesAreCached()) {
52 | return;
53 | }
54 |
55 | Route::middleware('nova')
56 | ->prefix('nova-vendor/AlexBowers/nova-multiple-dashboard')
57 | ->group(__DIR__.'/../routes/api.php');
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/resources/views/nova-overrides/dashboard/navigation.blade.php:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 | @foreach (\AlexBowers\MultipleDashboard\DashboardNova::availableDashboards(request()) as $dashboard)
13 | -
14 |
20 | {{ $dashboard->label }}
21 |
22 |
23 | @endforeach
24 |
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Support for multiple custom dashboards in Laravel Nova
3 |
4 | [](https://packagist.org/packages/alexbowers/nova-multiple-dashboard)
5 | [](https://scrutinizer-ci.com/g/alexbowers/nova-multiple-dashboard)
6 | [](https://packagist.org/packages/alexbowers/nova-multiple-dashboard)
7 |
8 |
9 | You can now add multiple custom dashboards in Laravel Nova.
10 |
11 | Whether you want to group some cards together, have different dashboards visible depending on the logged in user, or want to provide a dashboard with your tool, Multiple Dashboards allows you to do this.
12 |
13 | 
14 |
15 | # Deprecated
16 |
17 | This is now covered in Nova 2.1.0+ so does not need a package for it.
18 |
19 | See [documentation](https://nova.laravel.com/docs/2.0/customization/dashboards.html#overview)
20 |
21 | ## Installation
22 |
23 | You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:
24 |
25 | ```bash
26 | composer require alexbowers/nova-multiple-dashboard
27 | ```
28 |
29 | ## Usage
30 |
31 | There is now a `php artisan nova:dashboard ` command exposed via the CLI.
32 |
33 | If you run this, you'll get a `App/Nova/Dashboards` directory created, which will house your custom dashboards.
34 |
35 | Dashboards have a `public $order` variable you can use to set the order they appear in the navbar. See the `Dashboard` class for more.
36 |
37 | If you are another package creating a nova dashboard, you will need to register it using:
38 |
39 | ```php
40 | \AlexBowers\MultipleDashboard\DashboardNova::registerDashboards(new \Your\Dashboard\Here);
41 | ```
42 |
43 | You can register multiple at once by passing through to the `DashboardNova::registerDashboards` function.
44 |
45 |
46 | ### Security
47 |
48 | If you discover any security related issues, please email bowersbros@gmail.com instead of using the issue tracker.
49 |
50 | ## Credits
51 |
52 | - [Alex Bowers](https://github.com/alexbowers)
53 |
54 | ## License
55 |
56 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
57 |
--------------------------------------------------------------------------------
/dist/js/MultipleDashboard.js:
--------------------------------------------------------------------------------
1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2),a=r.n(n);Nova.booting(function(e,t){t.beforeEach(function(e,t,r){"dashboard"==e.name&&"/"==e.path&&r("/dashboards/main"),r()}),t.addRoutes([{name:"dashboard.custom",path:"/dashboards/:dashboardName",component:a.a,props:!0}])})},function(e,t,r){var n=r(3)(r(4),r(5),!1,null,null,null);e.exports=n.exports},function(e,t){e.exports=function(e,t,r,n,a,s){var o,d=e=e||{},i=typeof e.default;"object"!==i&&"function"!==i||(o=e,d=e.default);var c,u="function"==typeof d?d.options:d;if(t&&(u.render=t.render,u.staticRenderFns=t.staticRenderFns,u._compiled=!0),r&&(u.functional=!0),a&&(u._scopeId=a),s?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),n&&n.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},u._ssrRegister=c):n&&(c=n),c){var l=u.functional,f=l?u.render:u.beforeCreate;l?(u._injectStyles=c,u.render=function(e,t){return c.call(t),f(e,t)}):u.beforeCreate=f?[].concat(f,c):[c]}return{esModule:o,exports:d,options:u}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=["1/2","1/3","2/3","1/4","3/4","1/5","2/5","3/5","4/5","1/6","5/6"],a={props:{loadCards:{type:Boolean,default:!0}},data:()=>({cards:[]}),created(){this.fetchCards()},methods:{async fetchCards(){if(this.loadCards){const{data:e}=await Nova.request().get(this.cardsEndpoint);this.cards=e}}},computed:{shouldShowCards(){return this.cards.length>0},smallCards(){return _.filter(this.cards,e=>-1!==n.indexOf(e.width))},largeCards(){return _.filter(this.cards,e=>"full"==e.width)}}};t.default={mixins:[a],props:{dashboardName:{type:String,required:!1,default:"main"}},watch:{cardsEndpoint:function(){this.fetchCards()}},computed:{cardsEndpoint:function(){return"/nova-vendor/AlexBowers/nova-multiple-dashboard/dashboards/"+this.dashboardName}}}},function(e,t){e.exports={render:function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[e.cards.length>1?r("heading",{staticClass:"mb-6"},[e._v(e._s(e.__("Dashboard")))]):e._e(),e._v(" "),e.shouldShowCards?r("div",[e.smallCards.length>0?r("cards",{staticClass:"mb-3",attrs:{cards:e.smallCards}}):e._e(),e._v(" "),e.largeCards.length>0?r("cards",{attrs:{cards:e.largeCards,size:"large"}}):e._e()],1):e._e()],1)},staticRenderFns:[]}}]);
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are **welcome** and will be fully **credited**.
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Etiquette
8 |
9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11 | extremely unfair for them to suffer abuse or anger for their hard work.
12 |
13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14 | world that developers are civilized and selfless people.
15 |
16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18 |
19 | ## Viability
20 |
21 | When requesting or submitting new features, first consider whether it might be useful to others. Open
22 | source projects are used by many developers, who may have entirely different needs to your own. Think about
23 | whether or not your feature is likely to be used by other users of the project.
24 |
25 | ## Procedure
26 |
27 | Before filing an issue:
28 |
29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30 | - Check to make sure your feature suggestion isn't already present within the project.
31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32 | - Check the pull requests tab to ensure that the feature isn't already in progress.
33 |
34 | Before submitting a pull request:
35 |
36 | - Check the codebase to ensure that your feature doesn't already exist.
37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38 |
39 | ## Requirements
40 |
41 | If the project maintainer has any additional requirements, you will find them listed here.
42 |
43 | - **[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](http://pear.php.net/package/PHP_CodeSniffer).
44 |
45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46 |
47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48 |
49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
50 |
51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52 |
53 | - **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](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54 |
55 | **Happy coding**!
56 |
--------------------------------------------------------------------------------
/src/DashboardNova.php:
--------------------------------------------------------------------------------
1 | filter
45 | ->authorize($request)
46 | ->all();
47 | }
48 |
49 | /**
50 | * Register one or more dashboards
51 | *
52 | * @param Dashboard ...$dashboards
53 | */
54 | public static function registerDashboards(Dashboard ...$dashboards)
55 | {
56 | static::dashboards($dashboards);
57 | }
58 |
59 | /**
60 | * Register the dashboards from a specific directory
61 | */
62 | public static function dashboardsIn($directory)
63 | {
64 | $namespace = app()->getNamespace();
65 |
66 | $dashboards = [];
67 |
68 | foreach ((new Finder)->in($directory)->files() as $dashboard) {
69 | $dashboard = $namespace.str_replace(
70 | ['/', '.php'],
71 | ['\\', ''],
72 | Str::after($dashboard->getPathname(), app_path().DIRECTORY_SEPARATOR)
73 | );
74 |
75 | if (is_subclass_of($dashboard, Dashboard::class) && !(new \ReflectionClass($dashboard))->isAbstract()) {
76 | $dashboards[] = $dashboard;
77 | }
78 | }
79 |
80 | static::dashboards(
81 | collect($dashboards)->transform(function ($dashboard) {
82 | if ($dashboard instanceof Dashboard) {
83 | return $dashboard;
84 | }
85 |
86 | return app()->make($dashboard);
87 | })->sortBy('label')->sortBy('order')->all()
88 | );
89 | }
90 |
91 | /**
92 | * Load the cards in use in each dashboard
93 | */
94 | public static function cardsInDashboards()
95 | {
96 | $dashboards = static::$dashboards;
97 |
98 | foreach ($dashboards as $dashboard) {
99 | DashboardNova::cards($dashboard->cards());
100 | }
101 | }
102 |
103 | /**
104 | * Register the given dashboards.
105 | *
106 | * @param array $dashboards
107 | * @return static
108 | */
109 | public static function dashboards(array $dashboards)
110 | {
111 | static::$dashboards = array_merge(static::$dashboards, $dashboards);
112 |
113 | return new static;
114 | }
115 |
116 | /**
117 | * Get the available dashboard cards for the given request.
118 | *
119 | * @param \Laravel\Nova\Http\Requests\NovaRequest $request
120 | * @return \Illuminate\Support\Collection
121 | */
122 | public static function allAvailableDashboardCards(NovaRequest $request)
123 | {
124 | return collect(static::$dashboards)
125 | ->filter
126 | ->authorize($request)
127 | ->flatMap(function ($dashboard) {
128 | return $dashboard->cards();
129 | })->merge(static::$cards)
130 | ->unique()
131 | ->filter
132 | ->authorize($request)
133 | ->values();
134 | }
135 |
136 | /**
137 | * Get the available dashboard cards for the given request.
138 | *
139 | * @param string $dashboard
140 | * @param \Laravel\Nova\Http\Requests\NovaRequest $request
141 | * @return \Illuminate\Support\Collection
142 | */
143 | public static function availableDashboardCardsForDashboard($dashboard, NovaRequest $request)
144 | {
145 | return collect(static::$dashboards)->filter->authorize($request)->filter(function ($board) use ($dashboard) {
146 | return $board->uriKey() === $dashboard;
147 | })->flatMap(function ($dashboard) {
148 | return $dashboard->cards();
149 | })->filter->authorize($request)->values();
150 | }
151 | }
152 |
--------------------------------------------------------------------------------