From 01bcc557f0dadf2ee9749514e3d4e389885675c8 Mon Sep 17 00:00:00 2001 From: milewski Date: Sat, 28 Sep 2019 16:23:43 +0800 Subject: [PATCH] create custom resource manager --- .gitignore | 10 ++ composer.json | 29 ++++ dist/js/tool.js | 1 + dist/mix-manifest.json | 3 + package.json | 20 +++ .../components/CollapsibleResourceManager.vue | 87 ++++++++++++ resources/js/tool.js | 3 + resources/views/navigation.blade.php | 2 + src/CollapsibleResourceManager.php | 134 ++++++++++++++++++ src/ToolServiceProvider.php | 18 +++ webpack.mix.js | 4 + 11 files changed, 311 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 dist/js/tool.js create mode 100644 dist/mix-manifest.json create mode 100644 package.json create mode 100644 resources/js/components/CollapsibleResourceManager.vue create mode 100644 resources/js/tool.js create mode 100644 resources/views/navigation.blade.php create mode 100644 src/CollapsibleResourceManager.php create mode 100644 src/ToolServiceProvider.php create mode 100644 webpack.mix.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b817577 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/.idea +/vendor +/node_modules +package-lock.json +composer.phar +composer.lock +phpunit.xml +.phpunit.result.cache +.DS_Store +Thumbs.db diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ab0e8c9 --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "digital-creative/collapsible-resource-manager", + "description": "A Laravel Nova tool.", + "keywords": [ + "laravel", + "nova" + ], + "license": "MIT", + "require": { + "php": ">=7.1.0" + }, + "autoload": { + "psr-4": { + "DigitalCreative\\CollapsibleResourceManager\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "DigitalCreative\\CollapsibleResourceManager\\ToolServiceProvider" + ] + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/dist/js/tool.js b/dist/js/tool.js new file mode 100644 index 0000000..4dda859 --- /dev/null +++ b/dist/js/tool.js @@ -0,0 +1 @@ +!function(t){var e={};function n(a){if(e[a])return e[a].exports;var o=e[a]={i:a,l:!1,exports:{}};return t[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,a){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:a})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){Nova.booting(function(t,e,a){t.component("collapsible-resource-manager",n(2))})},function(t,e,n){var a=n(8)(n(9),n(10),!1,function(t){n(3)},"data-v-318664a2",null);t.exports=a.exports},function(t,e,n){var a=n(4);"string"==typeof a&&(a=[[t.i,a,""]]),a.locals&&(t.exports=a.locals);n(6)("74aa7e2a",a,!0,{})},function(t,e,n){(t.exports=n(5)(!1)).push([t.i,".collapsible-indicator[data-v-318664a2]{left:-20px;width:12px;height:12px;display:flex;justify-content:center;align-content:center}",""])},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var n=function(t,e){var n=t[1]||"",a=t[3];if(!a)return n;if(e&&"function"==typeof btoa){var o=(i=a,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),s=a.sources.map(function(t){return"/*# sourceURL="+a.sourceRoot+t+" */"});return[n].concat(s).concat([o]).join("\n")}var i;return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n}).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var a={},o=0;on.parts.length&&(a.parts.length=n.parts.length)}else{var i=[];for(o=0;o + +
+ +

+ +

+ + + +
+ + + + + + diff --git a/resources/js/tool.js b/resources/js/tool.js new file mode 100644 index 0000000..a5daddd --- /dev/null +++ b/resources/js/tool.js @@ -0,0 +1,3 @@ +Nova.booting((Vue, router, store) => { + Vue.component('collapsible-resource-manager', require('./components/CollapsibleResourceManager')) +}) diff --git a/resources/views/navigation.blade.php b/resources/views/navigation.blade.php new file mode 100644 index 0000000..c3da758 --- /dev/null +++ b/resources/views/navigation.blade.php @@ -0,0 +1,2 @@ + + diff --git a/src/CollapsibleResourceManager.php b/src/CollapsibleResourceManager.php new file mode 100644 index 0000000..cfc689a --- /dev/null +++ b/src/CollapsibleResourceManager.php @@ -0,0 +1,134 @@ +title = $title; + $this->groups = collect(); + } + + /** + * Perform any tasks that need to happen when the tool is booted. + * + * @return void + */ + public function boot() + { + + Nova::script('collapsible-resource-manager', __DIR__ . '/../dist/js/tool.js'); + + /** + * Remove the default resource manager + */ + foreach (Nova::$tools as $index => $tool) { + + if ($tool instanceof ResourceManager) { + + unset(Nova::$tools[ $index ]); + + } + + } + + } + + /** + * Build the view that renders the navigation links for the tool. + * + * @return View + */ + public function renderNavigation() + { + return view('collapsible-resource-manager::navigation', [ + 'groups' => $this->serializeGroups($this->groups), + 'title' => $this->title, + 'icon' => $this->icon, + ]); + } + + /** + * @param string $icon + * + * @return $this + */ + public function icon(string $icon): self + { + $this->icon = $icon; + + return $this; + } + + /** + * @param string $title + * + * @return $this + */ + public function title(string $title): self + { + $this->title = $title; + + return $this; + } + + /** + * @param array $group + * + * @return $this + */ + public function addGroup(array $group): self + { + $this->groups->push($group); + + return $this; + } + + /** + * @param Collection $groups + * + * @return Collection + */ + private function serializeGroups(Collection $groups): Collection + { + return $groups->map(function (array $group) { + + $group[ 'resources' ] = collect($group[ 'resources' ])->map(function ($resource) { + return [ + 'label' => $resource::label(), + 'route' => $resource::uriKey() + ]; + }); + + return $group; + + }); + } +} diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php new file mode 100644 index 0000000..24d3588 --- /dev/null +++ b/src/ToolServiceProvider.php @@ -0,0 +1,18 @@ +loadViewsFrom(__DIR__ . '/../resources/views', 'collapsible-resource-manager'); + } +} diff --git a/webpack.mix.js b/webpack.mix.js new file mode 100644 index 0000000..eff399b --- /dev/null +++ b/webpack.mix.js @@ -0,0 +1,4 @@ +let mix = require('laravel-mix') + +mix.setPublicPath('dist') + .js('resources/js/tool.js', 'js')