jqh пре 5 година
родитељ
комит
1564044338

+ 12 - 6
src/Console/ImportCommand.php

@@ -50,15 +50,10 @@ class ImportCommand extends VendorPublishCommand
         $extension = $className::make();
 
         $this->setServiceProvider($extension);
+        $this->publish($extension);
 
         $extension->import($this);
 
-        $extensionName = $extension->getName();
-
-        if ($assets = $extension->assets()) {
-            $this->publishItem($assets, public_path('vendor/dcat-admin-extensions/'.$extensionName));
-        }
-
         $this->publishTag(null);
         $this->call('view:clear');
         $this->call('admin:ide-helper');
@@ -68,9 +63,20 @@ class ImportCommand extends VendorPublishCommand
         $this->info("Extension [$className] imported");
     }
 
+    protected function publish(Extension $extension)
+    {
+        if (
+            ($assets = $extension->assets())
+            && file_exists($assets)
+        ) {
+            $this->publishItem($assets, public_path('vendor/dcat-admin-extensions/'.$extension::NAME));
+        }
+    }
+
     protected function setServiceProvider(Extension $extension)
     {
         $this->provider = $extension->serviceProvider();
+
         $this->laravel->register($this->provider);
     }
 

+ 1 - 1
src/Console/stubs/extension/composer.json.stub

@@ -13,7 +13,7 @@
     ],
     "require": {
         "php": ">=7.1.0",
-        "dcat/laravel-admin": "~1.0"
+        "dcat/laravel-admin": "*"
     },
     "require-dev": {
         "phpunit/phpunit": "~6.0"

+ 5 - 4
src/Console/stubs/extension/extension.stub

@@ -10,18 +10,19 @@ class :class_name extends Extension
 
     protected $serviceProvider = :class_nameServiceProvider::class;
 
-//    protected $views = __DIR__.'/../resources/views';
+    protected $composer = __DIR__.'/../composer.json';
+
+    protected $configs = __DIR__.'/../config';
 
     protected $assets = __DIR__.'/../resources/assets';
 
-//    protected $lang = __DIR__.'/../resources/lang';
+    protected $views = __DIR__.'/../resources/views';
 
-    protected $composerJson = __DIR__.'/../composer.json';
+//    protected $lang = __DIR__.'/../resources/lang';
 
     protected $menu = [
         'title' => ':title',
         'path'  => ':path',
         'icon'  => 'fa-gears',
     ];
-
 }

+ 0 - 5
src/Console/stubs/extension/service-provider.stub

@@ -28,11 +28,6 @@ class :class_nameServiceProvider extends ServiceProvider
         $this->app->booted(function () use ($extension) {
             $extension->routes(__DIR__.'/../routes/web.php');
         });
-
-//        if ($this->app->runningInConsole() || request()->getMethod() == 'POST') {
-//            $this->publishes([__DIR__.'/../config' => config_path()]);
-//        }
-
     }
 
     /**

+ 23 - 26
src/Controllers/ExtensionController.php

@@ -2,7 +2,7 @@
 
 namespace Dcat\Admin\Controllers;
 
-use Dcat\Admin\Extension\Grid\BuildExtensionButton;
+use Dcat\Admin\Extension\Grid\CreateExtensionButton;
 use Dcat\Admin\Extension\Grid\ImportButton;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
@@ -61,9 +61,14 @@ class ExtensionController extends Controller
     {
         $name = request('name');
         $namespace = trim(request('namespace'), '\\');
-
-        $box = Box::make("<span>admin:extend <small>$name --namespace=$namespace</small></span>")
-            ->content(Terminal::call('admin:extend', ['extension' => $name, '--namespace' => $namespace]))
+        $contents = "<span>admin:extend <small>$name --namespace=$namespace</small></span>";
+        $terminal = Terminal::call('admin:extend', [
+            'extension' => $name,
+            '--namespace' => $namespace,
+        ]);
+
+        $box = Box::make($contents)
+            ->content($terminal)
             ->style('default')
             ->collapsable()
             ->removable();
@@ -80,25 +85,6 @@ class ExtensionController extends Controller
     {
         $grid = new Grid(new Extension());
 
-        $grid->disablePagination();
-        $grid->disableCreateButton();
-        $grid->disableDeleteButton();
-        $grid->disableBatchDelete();
-        $grid->disableFilterButton();
-        $grid->disableFilter();
-        $grid->disableQuickEditButton();
-        $grid->disableEditButton();
-        $grid->disableDeleteButton();
-        $grid->disableViewButton();
-
-        $grid->actions(function (Grid\Displayers\Actions $actions) {
-            $actions->append(new ImportButton($this));
-        });
-
-        $grid->tools(function (Grid\Tools $tools) {
-            $tools->append(new BuildExtensionButton());
-        });
-
         $grid->number();
         $grid->name;
         $grid->version;
@@ -118,13 +104,10 @@ class ExtensionController extends Controller
             });
 
         $grid->authors;
-
         $grid->enable->switch();
-
         $grid->imported;
 
         $view = ucfirst(trans('admin.view'));
-
         $grid->config
             ->if(function () {
                 return $this->config ? true : false;
@@ -142,6 +125,20 @@ class ExtensionController extends Controller
             ->display($view)
             ->expand($this->getExpandHandler('require_dev'));
 
+        $grid->disablePagination();
+        $grid->disableCreateButton();
+        $grid->disableDeleteButton();
+        $grid->disableBatchDelete();
+        $grid->disableFilterButton();
+        $grid->disableFilter();
+        $grid->disableQuickEditButton();
+        $grid->disableEditButton();
+        $grid->disableDeleteButton();
+        $grid->disableViewButton();
+
+        $grid->actions(new ImportButton());
+        $grid->tools(new CreateExtensionButton());
+
         return $grid;
     }
 

+ 4 - 34
src/Extension.php

@@ -16,16 +16,6 @@ abstract class Extension
      */
     protected $serviceProvider;
 
-    /**
-     * @var array
-     */
-    protected $css = [];
-
-    /**
-     * @var array
-     */
-    protected $js = [];
-
     /**
      * @var string
      */
@@ -49,7 +39,7 @@ abstract class Extension
     /**
      * @var string
      */
-    protected $composerJson = '';
+    protected $composer = '';
 
     /**
      * @var array
@@ -86,7 +76,7 @@ abstract class Extension
     /**
      * @return string
      */
-    public function getName()
+    final public function getName()
     {
         return static::NAME;
     }
@@ -94,9 +84,9 @@ abstract class Extension
     /**
      * @return string
      */
-    public function composerJson()
+    public function composer()
     {
-        return $this->composerJson;
+        return $this->composer;
     }
 
     /**
@@ -117,26 +107,6 @@ abstract class Extension
         return $this->assets;
     }
 
-    /**
-     * Get the paths of css files.
-     *
-     * @return array
-     */
-    public function css()
-    {
-        return $this->css;
-    }
-
-    /**
-     * Get the paths of js files.
-     *
-     * @return array
-     */
-    public function js()
-    {
-        return $this->js;
-    }
-
     /**
      * Get the path of view files.
      *

+ 1 - 4
src/Extension/Grid/BuildExtensionButton.php → src/Extension/Grid/CreateExtensionButton.php

@@ -5,7 +5,7 @@ namespace Dcat\Admin\Extension\Grid;
 use Dcat\Admin\Admin;
 use Illuminate\Contracts\Support\Renderable;
 
-class BuildExtensionButton implements Renderable
+class CreateExtensionButton implements Renderable
 {
     public function render()
     {
@@ -30,7 +30,6 @@ CSS
 
         Admin::script(
             <<<JS
-            
 $('#create-extension').popover({
     html: true,
     title: false,
@@ -98,9 +97,7 @@ $('#create-extension').on('shown.bs.popover', function () {
     function isValid(str) { 
         return /^[\w-\/\\\\]+$/.test(str); 
     }
-    
 });
-
 JS
         );
     }

+ 3 - 14
src/Extension/Grid/ImportButton.php

@@ -3,21 +3,10 @@
 namespace Dcat\Admin\Extension\Grid;
 
 use Dcat\Admin\Admin;
-use Illuminate\Contracts\Support\Renderable;
-use Illuminate\Support\Fluent;
+use Dcat\Admin\Grid\RowAction;
 
-class ImportButton implements Renderable
+class ImportButton extends RowAction
 {
-    /**
-     * @var Fluent
-     */
-    protected $row;
-
-    public function __construct($row)
-    {
-        $this->row = $row;
-    }
-
     /**
      * @return string
      */
@@ -28,7 +17,7 @@ class ImportButton implements Renderable
         $this->setupScript();
 
         return <<<HTML
-<a href="javascript:void(0)" class="import-extension" data-id="{$this->row->id}">$button</a>
+<a href="javascript:void(0)" class="import-extension" data-id="{$this->key()}">$button</a>
 HTML;
     }
 

+ 1 - 1
src/Models/Repositories/Extension.php

@@ -29,7 +29,7 @@ class Extension extends Repository
      */
     protected function each(AbstractExtension $extension)
     {
-        $property = Composer::parse($extension->composerJson());
+        $property = Composer::parse($extension->composer());
 
         $config = (array) config('admin-extensions.'.$extension->getName());