Browse Source

:construction: wip

jqh 4 years ago
parent
commit
ff30d42434

+ 6 - 6
src/Color.php

@@ -197,7 +197,7 @@ class Color
      *
      * @param string $name
      */
-    public function __construct($name = null)
+    public function __construct(?string $name = null)
     {
         $this->name = ($name ?: config('admin.layout.color')) ?: static::DEFAULT_COLOR;
 
@@ -210,7 +210,7 @@ class Color
     /**
      * @return string
      */
-    public function name()
+    public function getName()
     {
         return $this->name;
     }
@@ -218,12 +218,12 @@ class Color
     /**
      * 获取颜色.
      *
-     * @param array  $colorName
+     * @param string $colorName
      * @param string $default
      *
      * @return string
      */
-    public function get(string $colorName, string $default = null)
+    public function get(?string $colorName, ?string $default = null)
     {
         if ($this->realColors) {
             return $this->realColors[$colorName] ?? $default;
@@ -264,7 +264,7 @@ class Color
      *
      * @return string
      */
-    public function lighten(string $color, int $amt)
+    public function lighten(?string $color, int $amt)
     {
         return Helper::colorLighten($this->get($color, $color), $amt);
     }
@@ -290,7 +290,7 @@ class Color
      *
      * @return string
      */
-    public function alpha(string $color, $alpha)
+    public function alpha(?string $color, $alpha)
     {
         return Helper::colorAlpha($this->get($color, $color), $alpha);
     }

+ 3 - 3
src/Extend/Manager.php

@@ -129,7 +129,7 @@ class Manager
      *
      * @return ServiceProvider[]|Collection
      */
-    public function extensions()
+    public function all()
     {
         return $this->extensions;
     }
@@ -139,9 +139,9 @@ class Manager
      *
      * @return ServiceProvider[]|Collection
      */
-    public function availableExtensions()
+    public function available()
     {
-        return $this->extensions()->filter->enabled();
+        return $this->all()->filter->enabled();
     }
 
     /**

+ 31 - 1
src/Extend/ServiceProvider.php

@@ -15,7 +15,7 @@ abstract class ServiceProvider extends LaravelServiceProvider
     /**
      * @var ComposerProperty
      */
-    protected $composerProperty;
+    public $composerProperty;
 
     /**
      * @var string
@@ -109,6 +109,36 @@ abstract class ServiceProvider extends LaravelServiceProvider
         return $this->name ?: ($this->name = str_replace('/', '.', $this->composerProperty->name));
     }
 
+    /**
+     * 获取当前已安装版本.
+     *
+     * @return string
+     */
+    final public function getVersion()
+    {
+        return Admin::extension()->versionManager()->getCurrentVersion($this);
+    }
+
+    /**
+     * 获取当前最新版本.
+     *
+     * @return string
+     */
+    final public function getLatestVersion()
+    {
+        return Admin::extension()->versionManager()->getFileVersions($this);
+    }
+
+    /**
+     * 获取当前本地最新版本.
+     *
+     * @return string
+     */
+    final public function getLocalLatestVersion()
+    {
+        return Admin::extension()->versionManager()->getFileVersions($this);
+    }
+
     /**
      * 获取扩展包路径.
      *

+ 5 - 1
src/Extend/VersionManager.php

@@ -182,7 +182,7 @@ class VersionManager
     protected function getLatestFileVersion($name)
     {
         $versionInfo = $this->getFileVersions($name);
-        if (!$versionInfo) {
+        if (! $versionInfo) {
             return static::NO_VERSION_VALUE;
         }
 
@@ -191,6 +191,8 @@ class VersionManager
 
     public function getNewFileVersions($name, $version = null)
     {
+        $name = $this->manager->getName($name);
+
         if ($version === null) {
             $version = static::NO_VERSION_VALUE;
         }
@@ -204,6 +206,8 @@ class VersionManager
 
     public function getFileVersions($name)
     {
+        $name = $this->manager->getName($name);
+
         if ($this->fileVersions !== null && array_key_exists($name, $this->fileVersions)) {
             return $this->fileVersions[$name];
         }

+ 0 - 8
src/Grid/Column/HasDisplayers.php

@@ -219,14 +219,6 @@ trait HasDisplayers
         });
     }
 
-    /**
-     * @return $this
-     */
-    public function emptyString()
-    {
-        return $this->display('');
-    }
-
     /**
      * Show children of current node.
      *

+ 7 - 38
src/Http/Controllers/ExtensionController.php

@@ -57,14 +57,12 @@ class ExtensionController extends Controller
             $grid->number();
             $grid->column('name');
             $grid->column('version');
-            $grid->column('alias');
-
-            $grid->description
-                ->if(function () {
-                    return mb_strlen($this->description) > 14;
+            $grid->column('description')
+                ->if(function ($column) {
+                    return mb_strlen($column->getValue(), 'UTF-8') > 14;
                 })
                 ->display(function ($v) {
-                    return mb_substr($v, 0, 14);
+                    return Helper::strLimit($v, 0, 14);
                 })
                 ->expand(function ($expand) {
                     if (! $this->description) {
@@ -74,37 +72,8 @@ class ExtensionController extends Controller
                     return "<div style='padding:10px 20px'>{$this->description}</div>";
                 });
 
-            $grid->authors;
-            $grid->enable->switch();
-            $grid->imported;
-
-            $view = trans('admin.view');
-            $grid->config
-                ->if(function () {
-                    return $this->config ? true : false;
-                })
-                ->display($view)
-                ->expand($this->getExpandHandler('config'))
-                ->else()
-                ->emptyString();
-
-            $grid->require
-                ->if(function () {
-                    return $this->require ? true : false;
-                })
-                ->display($view)
-                ->expand($this->getExpandHandler())
-                ->else()
-                ->emptyString();
-
-            $grid->require_dev
-                ->if(function () {
-                    return $this->require_dev ? true : false;
-                })
-                ->display($view)
-                ->expand($this->getExpandHandler('require_dev'))
-                ->else()
-                ->emptyString();
+            $grid->column('authors');
+            $grid->column('enable')->switch();
 
             $grid->disablePagination();
             $grid->disableCreateButton();
@@ -117,7 +86,7 @@ class ExtensionController extends Controller
             $grid->disableDeleteButton();
             $grid->disableViewButton();
 
-            $grid->actions(new ImportButton());
+            $grid->actions([new ImportButton()]);
 
             $grid->quickCreate(function (Grid\Tools\QuickCreate $create) {
                 $create->text('package_name')->required();

+ 1 - 1
src/Http/Controllers/UserController.php

@@ -47,7 +47,7 @@ class UserController extends AdminController
                         }
                     })
                     ->else()
-                    ->emptyString();
+                    ->display('');
             }
 
             $grid->column('created_at');

+ 7 - 27
src/Http/Repositories/Extension.php

@@ -3,20 +3,19 @@
 namespace Dcat\Admin\Http\Repositories;
 
 use Dcat\Admin\Admin;
-use Dcat\Admin\Extension as AbstractExtension;
+use Dcat\Admin\Extend\ServiceProvider as AbstractExtension;
 use Dcat\Admin\Form;
 use Dcat\Admin\Grid;
 use Dcat\Admin\Repositories\Repository;
 use Dcat\Admin\Show;
-use Dcat\Admin\Support\Composer;
 
 class Extension extends Repository
 {
     public function get(Grid\Model $model)
     {
         $data = [];
-        foreach (Admin::extension() as $class) {
-            $data[] = $this->each($class::make());
+        foreach (Admin::extension()->all() as $extension) {
+            $data[] = $this->each($extension);
         }
 
         return $data;
@@ -29,24 +28,17 @@ class Extension extends Repository
      */
     protected function each(AbstractExtension $extension)
     {
-        $property = Composer::parse($extension->composer());
-
-        $config = (array) config('admin-extensions.'.$extension->getName());
+        $property = $extension->composerProperty;
 
         return [
-            'id'           => $extension::NAME,
+            'id'           => $extension->getName(),
             'alias'        => $extension->getName(),
             'name'         => $property->name,
-            'version'      => Composer::getVersion($property->name),
+            'version'      => $extension->getVersion(),
             'description'  => $property->description,
             'authors'      => $property->authors,
-            'require'      => $property->require,
-            'require_dev'  => $property->require_dev,
             'homepage'     => $property->homepage,
-            'enable'       => $extension::enabled(),
-            'config'       => (array) $extension->config(),
-            'imported'     => $config['imported'] ?? false,
-            'imported_at'  => $config['imported_at'] ?? null,
+            'enable'       => $extension->enabled(),
         ];
     }
 
@@ -59,18 +51,6 @@ class Extension extends Repository
     {
         $id = $form->getKey();
 
-        $extension = Admin::extensions()[$id] ?? null;
-
-        if (! $extension) {
-            return false;
-        }
-
-        $attributes = $form->updates();
-
-        $enable = (bool) ($attributes['enable'] ?? false);
-
-        Admin::enableExtenstion($extension, $enable);
-
         return true;
     }
 

+ 1 - 1
src/Layout/Asset.php

@@ -281,7 +281,7 @@ class Asset
      */
     protected function initTheme()
     {
-        $color = Admin::color()->name();
+        $color = Admin::color()->getName();
 
         if ($color === Color::DEFAULT_COLOR) {
             return;

+ 1 - 1
src/Widgets/Box.php

@@ -51,7 +51,7 @@ class Box extends Widget
             $content->simple();
         }
 
-        $this->content = $this->lazyRenderable($content);
+        $this->content = $this->formatRenderable($content);
 
         return $this;
     }

+ 1 - 1
src/Widgets/Card.php

@@ -69,7 +69,7 @@ class Card extends Widget
             $content->simple();
         }
 
-        $this->content = $this->lazyRenderable($content);
+        $this->content = $this->formatRenderable($content);
 
         return $this;
     }

+ 1 - 1
src/Widgets/Tab.php

@@ -41,7 +41,7 @@ class Tab extends Widget
         $this->data['tabs'][] = [
             'id'      => mt_rand(),
             'title'   => $title,
-            'content' => $this->toString($this->lazyRenderable($content)),
+            'content' => $this->toString($this->formatRenderable($content)),
             'type'    => static::TYPE_CONTENT,
         ];
 

+ 1 - 1
src/Widgets/Widget.php

@@ -267,7 +267,7 @@ abstract class Widget implements Renderable
      *
      * @return Lazy|LazyTable|mixed
      */
-    protected function lazyRenderable($content)
+    protected function formatRenderable($content)
     {
         if ($content instanceof LazyGrid) {
             return LazyTable::make($content);