Просмотр исходного кода

Merge pull request #1 from jqhph/2.0

同步代码
Ving 5 лет назад
Родитель
Сommit
dd9b3765f5

+ 1 - 1
resources/assets/dcat/js/extensions/Helpers.js

@@ -241,7 +241,7 @@ export default class Helpers {
         };
         img.onerror = function () {
             Dcat.loading(false);
-            Dcat.warning('预览失败');
+            Dcat.error(Dcat.lang.trans('no_preview'))
         };
     }
 

+ 16 - 6
resources/assets/dcat/plugins/number-input/bootstrap-number-input.js

@@ -36,6 +36,16 @@
             var min = self.attr('min');
             var max = self.attr('max');
 
+            function getVal() {
+                var val = clone.val();
+
+                if (! val || val === "NaN") {
+                    return 0;
+                }
+
+                return parseInt(val);
+            }
+
             function setText(n) {
                 if ((min && n < min) || (max && n > max)) {
                     return false;
@@ -47,10 +57,10 @@
 
             var group = $("<div class='input-group'></div>");
             var down = $("<button type='button'>-</button>").attr('class', 'btn btn-' + settings.downClass).click(function () {
-                setText(parseInt(clone.val() || clone.attr('value')) - 1);
+                setText(getVal() - 1);
             });
             var up = $("<button type='button'>+</button>").attr('class', 'btn btn-' + settings.upClass).click(function () {
-                setText(parseInt(clone.val() || clone.attr('value')) + 1);
+                setText(getVal() + 1);
             });
             $("<span class='input-group-btn'></span>").append(down).appendTo(group);
             clone.appendTo(group);
@@ -62,8 +72,8 @@
             // remove spins from original
             clone.prop('type', 'text').keydown(function (e) {
                 if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
-					(e.keyCode == 65 && e.ctrlKey === true) ||
-					(e.keyCode >= 35 && e.keyCode <= 39)) {
+                    (e.keyCode == 65 && e.ctrlKey === true) ||
+                    (e.keyCode >= 35 && e.keyCode <= 39)) {
                     return;
                 }
                 if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
@@ -71,7 +81,7 @@
                 }
 
                 var c = String.fromCharCode(e.which);
-                var n = parseInt(clone.val() + c);
+                var n = (getVal() + c);
 
                 //if ((min && n < min) || (max && n > max)) {
                 //    e.preventDefault();
@@ -80,7 +90,7 @@
 
             clone.prop('type', 'text').blur(function (e) {
                 var c = String.fromCharCode(e.which);
-                var n = parseInt(clone.val() + c);
+                var n = getVal() + c;
                 if ((min && n < min)) {
                     setText(min);
                 }

+ 1 - 0
resources/lang/en/admin.php

@@ -35,6 +35,7 @@ return [
         'close'             => 'Close',
         'selected_options'  => ':num options selected',
         'exceed_max_item'   => 'Maximum items exceeded.',
+        'no_preview'        => 'No preview available.',
 
         '500' => 'Internal server error !',
         '403' => 'Permission deny !',

+ 1 - 0
resources/lang/zh_CN/admin.php

@@ -36,6 +36,7 @@ return [
         'close'             => '关闭',
         'selected_options'  => '已选中:num个选项',
         'exceed_max_item'   => '已超出最大可选数量',
+        'no_preview'        => '预览失败',
 
         '500' => '系统繁忙,请稍后再试!',
         '403' => '对不起,您没有权限访问,请与管理员联系。',

+ 1 - 0
resources/lang/zh_TW/admin.php

@@ -36,6 +36,7 @@ return [
         'submit'            => '提交',
         'selected_options'  => '已選中:num個選項',
         'exceed_max_item'   => '已超出最大可選數量',
+        'no_preview'        => '預覽失敗',
 
         '500' => '系統繁忙,請稍後再試!',
         '403' => '對不起,您無訪問權限,請聯繫管理員。',

+ 1 - 1
resources/views/filter/button.blade.php

@@ -4,7 +4,7 @@
             @if($only_scopes)data-toggle="dropdown"@endif
             @if($scopes->isNotEmpty()) style="border-right: 0" @endif
     >
-        <i class="feather icon-filter"></i>@if($show_filter_text)<span class="d-none d-sm-inline">&nbsp;&nbsp;{{ trans('admin.filter') }}</span>@endif
+        <i class="feather icon-filter"></i>@if($filter_text)<span class="d-none d-sm-inline">&nbsp;&nbsp;{{ trans('admin.filter') }}</span>@endif
 
         @if($valueCount) &nbsp;({!! $valueCount !!}) @endif
     </button>

+ 1 - 1
resources/views/grid/column-selector.blade.php

@@ -46,7 +46,7 @@
         }
 
         Dcat.reload(url.toString());
-    }, 1400);
+    }, 200);
 
     $('.column-selector .column-select-item').on('change', function () {
         submit($(this));

+ 1 - 1
resources/views/grid/fixed-table.blade.php

@@ -142,5 +142,5 @@
 
     {!! $grid->renderFooter() !!}
 
-    @include('admin::grid.table-pagination')
+    {!! $grid->renderPagination() !!}
 </div>

+ 2 - 2
resources/views/grid/table-pagination.blade.php

@@ -1,6 +1,6 @@
-@if ($paginator = $grid->paginator())
+@if ($grid->allowPagination())
     <div class="box-footer d-block clearfix ">
-        {!! $paginator->render() !!}
+        {!! $grid->paginator()->render() !!}
     </div>
 @else
     <div class="box-footer d-block clearfix text-80 " style="height:48px;line-height:25px;">

+ 1 - 1
resources/views/grid/table.blade.php

@@ -53,7 +53,7 @@
 
     {!! $grid->renderFooter() !!}
 
-    @include('admin::grid.table-pagination')
+    {!! $grid->renderPagination() !!}
 
 </div>
 

+ 1 - 1
src/Admin.php

@@ -31,7 +31,7 @@ class Admin
     use HasAssets;
     use HasHtml;
 
-    const VERSION = '2.0.16-beta';
+    const VERSION = '2.0.17-beta';
 
     const SECTION = [
         // 往 <head> 标签内输入内容

+ 23 - 23
src/Grid.php

@@ -154,21 +154,21 @@ class Grid
      * @var array
      */
     protected $options = [
-        'show_pagination'        => true,
-        'show_filter'            => true,
-        'show_actions'           => true,
-        'show_quick_edit_button' => false,
-        'show_edit_button'       => true,
-        'show_view_button'       => true,
-        'show_delete_button'     => true,
-        'show_row_selector'      => true,
-        'show_create_button'     => true,
-        'show_bordered'          => false,
-        'table_collapse'         => true,
-        'show_toolbar'           => true,
-        'create_mode'            => self::CREATE_MODE_DEFAULT,
-        'dialog_form_area'       => ['700px', '670px'],
-        'table_class'            => ['table', 'custom-data-table', 'data-table'],
+        'pagination'        => true,
+        'filter'            => true,
+        'actions'           => true,
+        'quick_edit_button' => false,
+        'edit_button'       => true,
+        'view_button'       => true,
+        'delete_button'     => true,
+        'row_selector'      => true,
+        'create_button'     => true,
+        'bordered'          => false,
+        'table_collapse'    => true,
+        'toolbar'           => true,
+        'create_mode'       => self::CREATE_MODE_DEFAULT,
+        'dialog_form_area'  => ['700px', '670px'],
+        'table_class'       => ['table', 'custom-data-table', 'data-table'],
     ];
 
     /**
@@ -396,7 +396,7 @@ class Grid
 
     public function formatTableClass()
     {
-        if ($this->options['show_bordered']) {
+        if ($this->options['bordered']) {
             $this->addTableClass(['table-bordered', 'complex-headers', 'data-table']);
         }
 
@@ -533,7 +533,7 @@ class Grid
      */
     protected function prependRowSelectorColumn()
     {
-        if (! $this->options['show_row_selector']) {
+        if (! $this->options['row_selector']) {
             return;
         }
 
@@ -567,7 +567,7 @@ class Grid
      */
     public function renderCreateButton()
     {
-        if (! $this->options['show_create_button']) {
+        if (! $this->options['create_button']) {
             return '';
         }
 
@@ -581,7 +581,7 @@ class Grid
      */
     public function withBorder(bool $value = true)
     {
-        $this->options['show_bordered'] = $value;
+        $this->options['bordered'] = $value;
 
         return $this;
     }
@@ -699,7 +699,7 @@ HTML;
 
     protected function setUpOptions()
     {
-        if ($this->options['show_bordered']) {
+        if ($this->options['bordered']) {
             $this->tableCollapse(false);
         }
     }
@@ -713,7 +713,7 @@ HTML;
     {
         $this->tools->disableBatchActions($disable);
 
-        return $this->option('show_row_selector', ! $disable);
+        return $this->option('row_selector', ! $disable);
     }
 
     /**
@@ -733,7 +733,7 @@ HTML;
      */
     public function disableCreateButton(bool $disable = true)
     {
-        return $this->option('show_create_button', ! $disable);
+        return $this->option('create_button', ! $disable);
     }
 
     /**
@@ -753,7 +753,7 @@ HTML;
      */
     public function allowCreateButton()
     {
-        return $this->options['show_create_button'];
+        return $this->options['create_button'];
     }
 
     /**

+ 1 - 1
src/Grid/Concerns/CanFixColumns.php

@@ -41,7 +41,7 @@ trait CanFixColumns
     protected function applyFixColumns()
     {
         if ($this->fixColumns) {
-            if (! $this->options['show_bordered'] && ! $this->options['table_collapse']) {
+            if (! $this->options['bordered'] && ! $this->options['table_collapse']) {
                 $this->tableCollapse();
             }
 

+ 6 - 6
src/Grid/Concerns/HasActions.php

@@ -87,7 +87,7 @@ trait HasActions
      */
     protected function appendActionsColumn()
     {
-        if (! $this->options['show_actions']) {
+        if (! $this->options['actions']) {
             return;
         }
 
@@ -106,7 +106,7 @@ trait HasActions
      */
     public function disableActions(bool $disable = true)
     {
-        return $this->option('show_actions', ! $disable);
+        return $this->option('actions', ! $disable);
     }
 
     /**
@@ -128,7 +128,7 @@ trait HasActions
      */
     public function disableEditButton(bool $disable = true)
     {
-        $this->options['show_edit_button'] = ! $disable;
+        $this->options['edit_button'] = ! $disable;
 
         return $this;
     }
@@ -152,7 +152,7 @@ trait HasActions
      */
     public function disableQuickEditButton(bool $disable = true)
     {
-        $this->options['show_quick_edit_button'] = ! $disable;
+        $this->options['quick_edit_button'] = ! $disable;
 
         return $this;
     }
@@ -176,7 +176,7 @@ trait HasActions
      */
     public function disableViewButton(bool $disable = true)
     {
-        $this->options['show_view_button'] = ! $disable;
+        $this->options['view_button'] = ! $disable;
 
         return $this;
     }
@@ -202,7 +202,7 @@ trait HasActions
      */
     public function disableDeleteButton(bool $disable = true)
     {
-        $this->options['show_delete_button'] = ! $disable;
+        $this->options['delete_button'] = ! $disable;
 
         return $this;
     }

+ 2 - 2
src/Grid/Concerns/HasFilter.php

@@ -69,7 +69,7 @@ trait HasFilter
      */
     public function renderFilter()
     {
-        if (! $this->options['show_filter']) {
+        if (! $this->options['filter']) {
             return '';
         }
 
@@ -97,7 +97,7 @@ trait HasFilter
     {
         $this->filter->disableCollapse($disable);
 
-        return $this->option('show_filter', ! $disable);
+        return $this->option('filter', ! $disable);
     }
 
     /**

+ 54 - 7
src/Grid/Concerns/HasPaginator.php

@@ -6,6 +6,11 @@ use Dcat\Admin\Grid\Tools;
 
 trait HasPaginator
 {
+    /**
+     * @var Tools\Paginator
+     */
+    protected $paginator;
+
     /**
      * Per-page options.
      *
@@ -20,6 +25,16 @@ trait HasPaginator
      */
     protected $perPage = 20;
 
+    /**
+     * @var string
+     */
+    protected $paginatorClass = Tools\Paginator::class;
+
+    /**
+     * @var \Closure
+     */
+    protected $paginationCallback;
+
     /**
      * Paginate the grid.
      *
@@ -42,6 +57,30 @@ trait HasPaginator
         return $this->perPage;
     }
 
+    /**
+     * @param string $paginator
+     *
+     * @return $this
+     */
+    public function setPaginatorClass(string $paginator)
+    {
+        $this->paginatorClass = $paginator;
+
+        return $this;
+    }
+
+    /**
+     * @param \Closure
+     *
+     * @return $this
+     */
+    public function pagination(\Closure $callback)
+    {
+        $this->paginationCallback = $callback;
+
+        return $this;
+    }
+
     /**
      * Get the grid paginator.
      *
@@ -49,11 +88,7 @@ trait HasPaginator
      */
     public function paginator()
     {
-        if (! $this->options['show_pagination']) {
-            return;
-        }
-
-        return new Tools\Paginator($this);
+        return $this->paginator ?: ($this->paginator = new $this->paginatorClass($this));
     }
 
     /**
@@ -63,7 +98,7 @@ trait HasPaginator
      */
     public function allowPagination()
     {
-        return $this->options['show_pagination'];
+        return $this->options['pagination'];
     }
 
     /**
@@ -105,7 +140,7 @@ trait HasPaginator
     {
         $this->model->usePaginate(! $disable);
 
-        return $this->option('show_pagination', ! $disable);
+        return $this->option('pagination', ! $disable);
     }
 
     /**
@@ -119,4 +154,16 @@ trait HasPaginator
     {
         return $this->disablePagination(! $val);
     }
+
+    /**
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\View\View|string
+     */
+    public function renderPagination()
+    {
+        if ($callback = $this->paginationCallback) {
+            return $callback($this);
+        }
+
+        return view('admin::grid.table-pagination', ['grid' => $this]);
+    }
 }

+ 2 - 2
src/Grid/Concerns/HasTools.php

@@ -101,7 +101,7 @@ trait HasTools
      */
     public function disableToolbar(bool $val = true)
     {
-        return $this->option('show_toolbar', ! $val);
+        return $this->option('toolbar', ! $val);
     }
 
     /**
@@ -202,7 +202,7 @@ trait HasTools
     public function allowToolbar()
     {
         if (
-            $this->option('show_toolbar')
+            $this->option('toolbar')
             && (
                 $this->tools()->has()
                 || $this->allowExporter()

+ 4 - 4
src/Grid/Displayers/Actions.php

@@ -176,10 +176,10 @@ class Actions extends AbstractDisplayer
      */
     protected function resetDefaultActions()
     {
-        $this->disableView(! $this->grid->option('show_view_button'));
-        $this->disableEdit(! $this->grid->option('show_edit_button'));
-        $this->disableQuickEdit(! $this->grid->option('show_quick_edit_button'));
-        $this->disableDelete(! $this->grid->option('show_delete_button'));
+        $this->disableView(! $this->grid->option('view_button'));
+        $this->disableEdit(! $this->grid->option('edit_button'));
+        $this->disableQuickEdit(! $this->grid->option('quick_edit_button'));
+        $this->disableDelete(! $this->grid->option('delete_button'));
     }
 
     /**

+ 1 - 1
src/Grid/Model.php

@@ -173,7 +173,7 @@ class Model
     /**
      * @return AbstractPaginator|LengthAwarePaginator
      */
-    public function paginator(): AbstractPaginator
+    public function paginator(): ?AbstractPaginator
     {
         $this->buildData();
 

+ 1 - 1
src/Grid/Tools/ExportButton.php

@@ -79,7 +79,7 @@ JS;
     protected function renderExportSelectedRows()
     {
         if (
-            ! $this->grid->option('show_row_selector')
+            ! $this->grid->option('row_selector')
             || ! $this->grid->exporter()->option('show_export_selected_rows')
         ) {
             return;

+ 9 - 9
src/Grid/Tools/FilterButton.php

@@ -150,17 +150,17 @@ JS;
 
         $this->addScript();
 
-        $onlyScopes = ((! $filters || $this->parent->option('show_filter') === false) && ! $scopres->isEmpty()) ? true : false;
+        $onlyScopes = ((! $filters || $this->parent->option('filter') === false) && ! $scopres->isEmpty()) ? true : false;
 
         $variables = [
-            'scopes'           => $scopres,
-            'current_label'    => $this->currentScopeLabel(),
-            'url_no_scopes'    => $filter->urlWithoutScopes(),
-            'btn_class'        => $this->getElementClassName(),
-            'expand'           => $filter->expand,
-            'show_filter_text' => true,
-            'only_scopes'      => $onlyScopes,
-            'valueCount'       => $valueCount,
+            'scopes'        => $scopres,
+            'current_label' => $this->currentScopeLabel(),
+            'url_no_scopes' => $filter->urlWithoutScopes(),
+            'btn_class'     => $this->getElementClassName(),
+            'expand'        => $filter->expand,
+            'filter_text'   => true,
+            'only_scopes'   => $onlyScopes,
+            'valueCount'    => $valueCount,
         ];
 
         return view($this->view, $variables)->render();

+ 1 - 1
src/Grid/Tools/Paginator.php

@@ -17,7 +17,7 @@ class Paginator implements Renderable
     /**
      * @var \Illuminate\Pagination\LengthAwarePaginator
      */
-    protected $paginator = null;
+    public $paginator = null;
 
     /**
      * Create a new Paginator instance.

+ 4 - 2
src/Layout/Asset.php

@@ -368,7 +368,9 @@ class Asset
 
         foreach ($files as &$file) {
             foreach ($params as $k => $v) {
-                $file = str_replace("{{$k}}", $v, $file);
+                if ($v !== '' && $v !== null) {
+                    $file = str_replace("{{$k}}", $v, $file);
+                }
             }
         }
 
@@ -409,7 +411,7 @@ class Asset
     {
         if (is_array($alias)) {
             foreach ($alias as $v) {
-                $this->require($v);
+                $this->require($v, $params);
             }
 
             return;