瀏覽代碼

Merge pull request #440 from jqhph/analysis-PxMA0A

Apply fixes from StyleCI
Jiang Qinghua 4 年之前
父節點
當前提交
15ae6494e1

+ 178 - 178
src/Form/Field/SelectTable.php

@@ -1,184 +1,184 @@
-<?php
-
-namespace Dcat\Admin\Form\Field;
-
-use Dcat\Admin\Form\Field;
-use Dcat\Admin\Support\Helper;
-use Dcat\Admin\Widgets\TableModal;
-use Dcat\Admin\Grid\LazyRenderable;
-
-class SelectTable extends Field
-{
-    use PlainInput;
-
-    protected static $js = [
-        '@select-table',
-    ];
-
-    /**
-     * @var TableModal
-     */
-    protected $modal;
-
-    protected $style = 'primary';
-
-    public function __construct($column, $arguments = [])
-    {
-        parent::__construct($column, $arguments);
-
-        $this->modal = TableModal::title($this->label);
-    }
-
-    /**
-     * 设置弹窗标题.
-     *
-     * @param string $title
-     *
-     * @return $this
-     */
-    public function title($title)
-    {
-        $this->modal->title($title);
-
-        return $this;
-    }
-
-    /**
-     * 设置尺寸为 xl.
-     *
-     * @return $this
-     */
-    public function xl()
-    {
-        $this->modal->xl();
-
-        return $this;
-    }
-
-    /**
-     * 设置表格异步渲染实例.
-     *
-     * @param LazyRenderable $renderable
-     *
-     * @return $this
-     */
-    public function from(LazyRenderable $renderable)
-    {
-        $this->modal->body($renderable);
-
-        return $this;
-    }
-
-    /**
-     * 转化为数组格式保存.
-     *
-     * @param mixed $value
-     *
-     * @return array|mixed
-     */
-    public function prepareInputValue($value)
-    {
-        return Helper::array($value, true);
-    }
-
-    protected function formatOptions()
-    {
-        $value = Helper::array(old($this->column, $this->value()));
-
-        if ($this->options instanceof \Closure) {
-            $this->options = $this->options->call($this->values(), $value, $this);
-        }
-
-        $values = [];
-
-        foreach (Helper::array($this->options) as $id => $label) {
-            foreach ($value as $v) {
-                if ($v == $id && $v !== null) {
-                    $values[] = ['id' => $v, 'label' => $label];
-                }
-            }
-        }
-
-        $this->options = json_encode($values);
-    }
-
-    protected function addScript()
-    {
-        $this->script .= <<<JS
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Form\Field;
+use Dcat\Admin\Grid\LazyRenderable;
+use Dcat\Admin\Support\Helper;
+use Dcat\Admin\Widgets\TableModal;
+
+class SelectTable extends Field
+{
+    use PlainInput;
+
+    protected static $js = [
+        '@select-table',
+    ];
+
+    /**
+     * @var TableModal
+     */
+    protected $modal;
+
+    protected $style = 'primary';
+
+    public function __construct($column, $arguments = [])
+    {
+        parent::__construct($column, $arguments);
+
+        $this->modal = TableModal::title($this->label);
+    }
+
+    /**
+     * 设置弹窗标题.
+     *
+     * @param string $title
+     *
+     * @return $this
+     */
+    public function title($title)
+    {
+        $this->modal->title($title);
+
+        return $this;
+    }
+
+    /**
+     * 设置尺寸为 xl.
+     *
+     * @return $this
+     */
+    public function xl()
+    {
+        $this->modal->xl();
+
+        return $this;
+    }
+
+    /**
+     * 设置表格异步渲染实例.
+     *
+     * @param LazyRenderable $renderable
+     *
+     * @return $this
+     */
+    public function from(LazyRenderable $renderable)
+    {
+        $this->modal->body($renderable);
+
+        return $this;
+    }
+
+    /**
+     * 转化为数组格式保存.
+     *
+     * @param mixed $value
+     *
+     * @return array|mixed
+     */
+    public function prepareInputValue($value)
+    {
+        return Helper::array($value, true);
+    }
+
+    protected function formatOptions()
+    {
+        $value = Helper::array(old($this->column, $this->value()));
+
+        if ($this->options instanceof \Closure) {
+            $this->options = $this->options->call($this->values(), $value, $this);
+        }
+
+        $values = [];
+
+        foreach (Helper::array($this->options) as $id => $label) {
+            foreach ($value as $v) {
+                if ($v == $id && $v !== null) {
+                    $values[] = ['id' => $v, 'label' => $label];
+                }
+            }
+        }
+
+        $this->options = json_encode($values);
+    }
+
+    protected function addScript()
+    {
+        $this->script .= <<<JS
 Dcat.grid.SelectTable({
     modal: replaceNestedFormIndex('#{$this->modal->getId()}'),
     container: '{$this->getElementClassSelector()}',
     input: replaceNestedFormIndex('#hidden-{$this->id}'),
     button: replaceNestedFormIndex('#{$this->getButtonId()}'),
-    values: {$this->options},
-});
-JS;
-    }
-
-    protected function setUpModal()
-    {
-        $this->modal
-            ->getTable()
-            ->getRenderable()
-            ->with('key', $this->form->getKey());
-
-        $this->modal
-            ->join()
-            ->id($this->getElementId())
-            ->runScript(false)
-            ->footer($this->renderFooter());
-    }
-
-    public function render()
-    {
-        $this->setUpModal();
-        $this->formatOptions();
-
-        $name = $this->getElementName();
-
-        $this->prepend('<i class="feather icon-arrow-up"></i>')
-            ->defaultAttribute('class', 'form-control '. $this->getElementClassString())
-            ->defaultAttribute('type', 'text')
-            ->defaultAttribute('name', $name);
-
-        $this->addVariables([
-            'prepend'     => $this->prepend,
-            'append'      => $this->append,
-            'style'       => $this->style,
-            'modal'       => $this->modal->render(),
-            'placeholder' => $this->placeholder(),
-        ]);
-
-        $this->script = $this->modal->getScript();
-
-        $this->addScript();
-
-        return parent::render();
-    }
-
-    /**
-     * 弹窗底部内容构建.
-     *
-     * @return string
-     */
-    protected function renderFooter()
-    {
-        $submit = trans('admin.submit');
-        $cancel = trans('admin.cancel');
-
-        return <<<HTML
+    values: {$this->options},
+});
+JS;
+    }
+
+    protected function setUpModal()
+    {
+        $this->modal
+            ->getTable()
+            ->getRenderable()
+            ->with('key', $this->form->getKey());
+
+        $this->modal
+            ->join()
+            ->id($this->getElementId())
+            ->runScript(false)
+            ->footer($this->renderFooter());
+    }
+
+    public function render()
+    {
+        $this->setUpModal();
+        $this->formatOptions();
+
+        $name = $this->getElementName();
+
+        $this->prepend('<i class="feather icon-arrow-up"></i>')
+            ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
+            ->defaultAttribute('type', 'text')
+            ->defaultAttribute('name', $name);
+
+        $this->addVariables([
+            'prepend'     => $this->prepend,
+            'append'      => $this->append,
+            'style'       => $this->style,
+            'modal'       => $this->modal->render(),
+            'placeholder' => $this->placeholder(),
+        ]);
+
+        $this->script = $this->modal->getScript();
+
+        $this->addScript();
+
+        return parent::render();
+    }
+
+    /**
+     * 弹窗底部内容构建.
+     *
+     * @return string
+     */
+    protected function renderFooter()
+    {
+        $submit = trans('admin.submit');
+        $cancel = trans('admin.cancel');
+
+        return <<<HTML
 <a id="{$this->getButtonId()}" class="btn btn-primary" style="color: #fff">&nbsp;{$submit}&nbsp;</a>&nbsp;
-<a onclick="$(this).parents('.modal').modal('toggle')" class="btn btn-white">&nbsp;{$cancel}&nbsp;</a>
-HTML;
-    }
-
-    /**
-     * 提交按钮ID
-     *
-     * @return string
-     */
-    protected function getButtonId()
-    {
-        return 'submit-'.$this->id;
-    }
-}
+<a onclick="$(this).parents('.modal').modal('toggle')" class="btn btn-white">&nbsp;{$cancel}&nbsp;</a>
+HTML;
+    }
+
+    /**
+     * 提交按钮ID.
+     *
+     * @return string
+     */
+    protected function getButtonId()
+    {
+        return 'submit-'.$this->id;
+    }
+}

+ 0 - 1
src/Grid/Column/Filter.php

@@ -167,7 +167,6 @@ abstract class Filter implements Renderable
     <a href="{$this->urlWithoutFilter()}" class="btn btn-sm btn-default"><i class="feather icon-rotate-ccw"></i></a>
 </li>
 HMLT;
-
     }
 
     /**

+ 42 - 42
src/Grid/LazyRenderable.php

@@ -1,42 +1,42 @@
-<?php
-
-namespace Dcat\Admin\Grid;
-
-use Dcat\Admin\Grid;
-use Dcat\Admin\Support\LazyRenderable as Renderable;
-
-abstract class LazyRenderable extends Renderable
-{
-    abstract public function grid(): Grid;
-
-    public function render()
-    {
-        return $this->prepare($this->grid())->render();
-    }
-
-    protected function prepare(Grid $grid)
-    {
-        if (! $grid->getName()) {
-            $grid->setName($this->getDefaultName());
-        }
-
-        $grid->disableCreateButton();
-        $grid->disableActions();
-        $grid->disablePerPages();
-        $grid->disableBatchActions();
-        $grid->disableRefreshButton();
-
-        $grid->filter()
-            ->panel()
-            ->view('admin::filter.tile-container');
-
-        $grid->rowSelector()->click();
-
-        return $grid;
-    }
-
-    protected function getDefaultName()
-    {
-        return strtolower(str_replace('\\', '-', static::class));
-    }
-}
+<?php
+
+namespace Dcat\Admin\Grid;
+
+use Dcat\Admin\Grid;
+use Dcat\Admin\Support\LazyRenderable as Renderable;
+
+abstract class LazyRenderable extends Renderable
+{
+    abstract public function grid(): Grid;
+
+    public function render()
+    {
+        return $this->prepare($this->grid())->render();
+    }
+
+    protected function prepare(Grid $grid)
+    {
+        if (! $grid->getName()) {
+            $grid->setName($this->getDefaultName());
+        }
+
+        $grid->disableCreateButton();
+        $grid->disableActions();
+        $grid->disablePerPages();
+        $grid->disableBatchActions();
+        $grid->disableRefreshButton();
+
+        $grid->filter()
+            ->panel()
+            ->view('admin::filter.tile-container');
+
+        $grid->rowSelector()->click();
+
+        return $grid;
+    }
+
+    protected function getDefaultName()
+    {
+        return strtolower(str_replace('\\', '-', static::class));
+    }
+}

+ 104 - 104
src/Widgets/AsyncTable.php

@@ -1,104 +1,104 @@
-<?php
-
-namespace Dcat\Admin\Widgets;
-
-use Dcat\Admin\Admin;
-use Dcat\Admin\Grid\LazyRenderable;
-use Dcat\Admin\Traits\AsyncRenderable;
-use Illuminate\Support\Str;
-
-class AsyncTable extends Widget
-{
-    use AsyncRenderable;
-
-    public static $js = [
-        '@grid-extension',
-    ];
-
-    protected $load = true;
-
-    public function __construct(LazyRenderable $renderable = null, bool $load = true)
-    {
-        $this->setRenderable($renderable);
-        $this->load($load);
-
-        $this->id('table-card-'.Str::random(8));
-        $this->class('table-card');
-    }
-
-    /**
-     * 设置是否自动加载.
-     *
-     * @param bool $value
-     *
-     * @return $this
-     */
-    public function load(bool $value)
-    {
-        $this->load = $value;
-
-        return $this;
-    }
-
-    /**
-     * 监听异步渲染完成事件.
-     *
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function onLoad(string $script)
-    {
-        $this->script .= "$(replaceNestedFormIndex('{$this->getElementSelector()}')).on('table:loaded', function (event) { {$script} });";
-
-        return $this;
-    }
-
-    protected function addScript()
-    {
-        Admin::script(<<<'JS'
-Dcat.grid.AsyncTable('.table-card');
-JS
-        );
-
-        if ($this->load) {
-            $this->script .= $this->getLoadScript();
-        }
-    }
-
-    /**
-     * @return string
-     */
-    public function getElementSelector()
-    {
-        return '#'.$this->getHtmlAttribute('id');
-    }
-
-    /**
-     * @return string
-     */
-    public function getLoadScript()
-    {
-        return <<<JS
-$(replaceNestedFormIndex('{$this->getElementSelector()}')).trigger('table:load');
-JS;
-    }
-
-    public function render()
-    {
-        $this->addScript();
-
-        return parent::render();
-    }
-
-    public function html()
-    {
-        $this->setHtmlAttribute([
-            'data-url' => $this->getRequestUrl(),
-        ]);
-
-        return <<<HTML
-<div {$this->formatHtmlAttributes()} style="min-height: 200px"></div>        
-HTML;
-    }
-}
+<?php
+
+namespace Dcat\Admin\Widgets;
+
+use Dcat\Admin\Admin;
+use Dcat\Admin\Grid\LazyRenderable;
+use Dcat\Admin\Traits\AsyncRenderable;
+use Illuminate\Support\Str;
+
+class AsyncTable extends Widget
+{
+    use AsyncRenderable;
+
+    public static $js = [
+        '@grid-extension',
+    ];
+
+    protected $load = true;
+
+    public function __construct(LazyRenderable $renderable = null, bool $load = true)
+    {
+        $this->setRenderable($renderable);
+        $this->load($load);
+
+        $this->id('table-card-'.Str::random(8));
+        $this->class('table-card');
+    }
+
+    /**
+     * 设置是否自动加载.
+     *
+     * @param bool $value
+     *
+     * @return $this
+     */
+    public function load(bool $value)
+    {
+        $this->load = $value;
+
+        return $this;
+    }
+
+    /**
+     * 监听异步渲染完成事件.
+     *
+     * @param string $script
+     *
+     * @return $this
+     */
+    public function onLoad(string $script)
+    {
+        $this->script .= "$(replaceNestedFormIndex('{$this->getElementSelector()}')).on('table:loaded', function (event) { {$script} });";
+
+        return $this;
+    }
+
+    protected function addScript()
+    {
+        Admin::script(<<<'JS'
+Dcat.grid.AsyncTable('.table-card');
+JS
+        );
+
+        if ($this->load) {
+            $this->script .= $this->getLoadScript();
+        }
+    }
+
+    /**
+     * @return string
+     */
+    public function getElementSelector()
+    {
+        return '#'.$this->getHtmlAttribute('id');
+    }
+
+    /**
+     * @return string
+     */
+    public function getLoadScript()
+    {
+        return <<<JS
+$(replaceNestedFormIndex('{$this->getElementSelector()}')).trigger('table:load');
+JS;
+    }
+
+    public function render()
+    {
+        $this->addScript();
+
+        return parent::render();
+    }
+
+    public function html()
+    {
+        $this->setHtmlAttribute([
+            'data-url' => $this->getRequestUrl(),
+        ]);
+
+        return <<<HTML
+<div {$this->formatHtmlAttributes()} style="min-height: 200px"></div>        
+HTML;
+    }
+}

+ 0 - 1
src/Widgets/Modal.php

@@ -355,7 +355,6 @@ modal.on('modal:load', function () {
 });
 JS;
 
-
         $this->on('show.bs.modal', <<<JS
 body = modal.find('.modal-body');
 

+ 0 - 1
src/Widgets/Sparkline/Sparkline.php

@@ -2,7 +2,6 @@
 
 namespace Dcat\Admin\Widgets\Sparkline;
 
-use Dcat\Admin\Admin;
 use Dcat\Admin\Support\Helper;
 use Dcat\Admin\Traits\InteractsWithApi;
 use Dcat\Admin\Widgets\Widget;

+ 174 - 174
src/Widgets/TableModal.php

@@ -1,174 +1,174 @@
-<?php
-
-namespace Dcat\Admin\Widgets;
-
-use Dcat\Admin\Grid\LazyRenderable;
-use Illuminate\Contracts\Support\Renderable;
-
-/**
- * Class TableModal
- *
- * @method $this title(string $title)
- * @method $this button(string|\Closure $title)
- * @method $this join(bool $value = true)
- * @method $this xl()
- * @method $this on(string $script)
- * @method $this onShown(string $script)
- * @method $this onShow(string $script)
- * @method $this onHidden(string $script)
- * @method $this onHide(string $script)
- * @method $this footer(string|\Closure|Renderable $footer)
- * @method $this getId()
- * @method $this getElementSelector()
- */
-class TableModal extends Widget
-{
-    /**
-     * @var Modal
-     */
-    protected $modal;
-
-    /**
-     * @var AsyncTable
-     */
-    protected $table;
-
-    /**
-     * @var array
-     */
-    protected $allowMethods = [
-        'id',
-        'title',
-        'button',
-        'join',
-        'xl',
-        'on',
-        'onShown',
-        'onShow',
-        'onHidden',
-        'onHide',
-        'getId',
-        'getElementSelector',
-        'footer',
-    ];
-
-    /**
-     * @var string
-     */
-    protected $loadScript;
-
-    /**
-     * TableModal constructor.
-     *
-     * @param null $title
-     * @param \Dcat\Admin\Grid\LazyRenderable|null $renderable
-     */
-    public function __construct($title = null, LazyRenderable $renderable = null)
-    {
-        $this->modal = Modal::make()
-            ->lg()
-            ->title($title)
-            ->class('grid-modal', true);
-
-        $this->body($renderable);
-    }
-
-    /**
-     * 设置异步表格实例.
-     *
-     * @param LazyRenderable|null $renderable
-     *
-     * @return $this
-     */
-    public function body(?LazyRenderable $renderable)
-    {
-        if (! $renderable) {
-            return $this;
-        }
-
-        $this->table = AsyncTable::make($renderable, false);
-
-        $this->modal
-            ->body($this->table)
-            ->onShow($this->table->getLoadScript());
-
-        return $this;
-    }
-
-    /**
-     * 监听弹窗异步渲染完成事件.
-     *
-     * @param string $script
-     *
-     * @return $this
-     */
-    public function onLoad(string $script)
-    {
-        $this->loadScript .= $script.';';
-
-        return $this;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public function html()
-    {
-        if ($this->loadScript) {
-            $this->table->onLoad($this->loadScript);
-        }
-
-        $this->table->runScript($this->runScript);
-        $this->modal->runScript($this->runScript);
-
-        return $this->modal->render();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public function getScript()
-    {
-        return parent::getScript()
-            .$this->modal->getScript()
-            .$this->table->getScript();
-    }
-
-    /**
-     * @return Modal
-     */
-    public function getModal()
-    {
-        return $this->modal;
-    }
-
-    /**
-     * @return AsyncTable
-     */
-    public function getTable()
-    {
-        return $this->table;
-    }
-
-    public static function __callStatic($method, $arguments)
-    {
-        return static::make()->$method(...$arguments);
-    }
-
-    public function __call($method, $parameters)
-    {
-        if (in_array($method, $this->allowMethods, true)) {
-            $result = $this->modal->$method(...$parameters);
-
-            if (in_array($method, ['getElementSelector', 'getId'], true)) {
-                return $result;
-            }
-
-            return $this;
-        }
-
-        throw new \Exception(
-            sprintf('Call to undefined method "%s::%s"', static::class, $method)
-        );
-    }
-}
+<?php
+
+namespace Dcat\Admin\Widgets;
+
+use Dcat\Admin\Grid\LazyRenderable;
+use Illuminate\Contracts\Support\Renderable;
+
+/**
+ * Class TableModal.
+ *
+ * @method $this title(string $title)
+ * @method $this button(string|\Closure $title)
+ * @method $this join(bool $value = true)
+ * @method $this xl()
+ * @method $this on(string $script)
+ * @method $this onShown(string $script)
+ * @method $this onShow(string $script)
+ * @method $this onHidden(string $script)
+ * @method $this onHide(string $script)
+ * @method $this footer(string|\Closure|Renderable $footer)
+ * @method $this getId()
+ * @method $this getElementSelector()
+ */
+class TableModal extends Widget
+{
+    /**
+     * @var Modal
+     */
+    protected $modal;
+
+    /**
+     * @var AsyncTable
+     */
+    protected $table;
+
+    /**
+     * @var array
+     */
+    protected $allowMethods = [
+        'id',
+        'title',
+        'button',
+        'join',
+        'xl',
+        'on',
+        'onShown',
+        'onShow',
+        'onHidden',
+        'onHide',
+        'getId',
+        'getElementSelector',
+        'footer',
+    ];
+
+    /**
+     * @var string
+     */
+    protected $loadScript;
+
+    /**
+     * TableModal constructor.
+     *
+     * @param null $title
+     * @param \Dcat\Admin\Grid\LazyRenderable|null $renderable
+     */
+    public function __construct($title = null, LazyRenderable $renderable = null)
+    {
+        $this->modal = Modal::make()
+            ->lg()
+            ->title($title)
+            ->class('grid-modal', true);
+
+        $this->body($renderable);
+    }
+
+    /**
+     * 设置异步表格实例.
+     *
+     * @param LazyRenderable|null $renderable
+     *
+     * @return $this
+     */
+    public function body(?LazyRenderable $renderable)
+    {
+        if (! $renderable) {
+            return $this;
+        }
+
+        $this->table = AsyncTable::make($renderable, false);
+
+        $this->modal
+            ->body($this->table)
+            ->onShow($this->table->getLoadScript());
+
+        return $this;
+    }
+
+    /**
+     * 监听弹窗异步渲染完成事件.
+     *
+     * @param string $script
+     *
+     * @return $this
+     */
+    public function onLoad(string $script)
+    {
+        $this->loadScript .= $script.';';
+
+        return $this;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function html()
+    {
+        if ($this->loadScript) {
+            $this->table->onLoad($this->loadScript);
+        }
+
+        $this->table->runScript($this->runScript);
+        $this->modal->runScript($this->runScript);
+
+        return $this->modal->render();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getScript()
+    {
+        return parent::getScript()
+            .$this->modal->getScript()
+            .$this->table->getScript();
+    }
+
+    /**
+     * @return Modal
+     */
+    public function getModal()
+    {
+        return $this->modal;
+    }
+
+    /**
+     * @return AsyncTable
+     */
+    public function getTable()
+    {
+        return $this->table;
+    }
+
+    public static function __callStatic($method, $arguments)
+    {
+        return static::make()->$method(...$arguments);
+    }
+
+    public function __call($method, $parameters)
+    {
+        if (in_array($method, $this->allowMethods, true)) {
+            $result = $this->modal->$method(...$parameters);
+
+            if (in_array($method, ['getElementSelector', 'getId'], true)) {
+                return $result;
+            }
+
+            return $this;
+        }
+
+        throw new \Exception(
+            sprintf('Call to undefined method "%s::%s"', static::class, $method)
+        );
+    }
+}