Quellcode durchsuchen

Merge branch '2.0' into gitee2

jqh vor 5 Jahren
Ursprung
Commit
75626debd3

+ 4 - 8
README.md

@@ -27,17 +27,13 @@
 - [Demo源码 (码云)](https://gitee.com/jqhph/dcat-admin-demo)
 - [扩展](#)
 
-### 关于官网备案暂停访问的公告
 
-大家好,[Dcat Admin官网](http://www.dcatadmin.com)正在进行备案中,在备案期间会关闭网站访问,直至备案完成。在此期间大家可以通过[Learnku中文文档](https://learnku.com/docs/dcat-admin/2.x)查看文档,给大家带来的不便之处敬请谅解,谢谢支持!
+![](https://cdn.learnku.com/uploads/images/202101/28/38389/YLmL7PLqH7.png!large)
 
-### 截图
 
-![](https://cdn.learnku.com/uploads/images/202008/23/38389/Oam6CYOobf.jpeg!large)
-![](https://cdn.learnku.com/uploads/images/202007/24/38389/35KJXfVXib.png!large)
-![](https://cdn.learnku.com/uploads/images/202008/23/38389/Lu7LZDSX0M.jpg!large)
-![](https://cdn.learnku.com/uploads/images/202004/24/38389/GBkt9jYnW0.png!large)
-![](https://cdn.learnku.com/uploads/images/202008/08/38389/lGYIdhifb5.jpg!large)
+### 关于官网备案暂停访问的公告
+
+大家好,[Dcat Admin官网](http://www.dcatadmin.com)正在进行备案中,在备案期间会关闭网站访问,直至备案完成。在此期间大家可以通过[Learnku中文文档](https://learnku.com/docs/dcat-admin/2.x)查看文档,给大家带来的不便之处敬请谅解,谢谢支持!
 
 
 ### 功能特性

+ 5 - 4
resources/assets/dcat/js/bootstrappers/DataActions.js

@@ -27,8 +27,8 @@ let defaultActions = {
 
                         response.data.detail = msg;
 
-                        if (! response.then) {
-                            response.then = {action: 'redirect', value: redirect}
+                        if (redirect && ! response.data.then) {
+                            response.data.then = {action: 'redirect', value: redirect}
                         }
 
                         Dcat.handleJsonResponse(response);
@@ -42,6 +42,7 @@ let defaultActions = {
         $document.on('click', action, function() {
             let url = $(this).data('url'),
                 name = $(this).data('name'),
+                redirect = $(this).data('redirect'),
                 keys = Dcat.grid.selected(name),
                 lang = Dcat.lang;
 
@@ -57,8 +58,8 @@ let defaultActions = {
                     success: function (response) {
                         Dcat.NP.done();
 
-                        if (! response.then) {
-                            response.then = {action: 'refresh', value: true}
+                        if (redirect && ! response.data.then) {
+                            response.data.then = {action: 'redirect', value: redirect}
                         }
 
                         Dcat.handleJsonResponse(response);

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 16 - 6
resources/dist/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()) - 1);
+                setText(getVal() - 1);
             });
             var up = $("<button type='button'>+</button>").attr('class', 'btn btn-' + settings.upClass).click(function () {
-                setText(parseInt(clone.val()) + 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

@@ -26,6 +26,7 @@ return [
         'nullable'          => 'nullable',
         'key'               => 'key',
         'translate_title'   => 'Translate Title',
+        'sync_translation_with_comment' => 'Sync translation and comment',
     ],
     'client' => [
         'delete_confirm'    => 'Are you sure to delete this item ?',

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

@@ -26,6 +26,7 @@ return [
         'nullable'          => '允许空值',
         'key'               => '索引',
         'translate_title'   => '翻译标题',
+        'sync_translation_with_comment' => '同步翻译与注释',
     ],
     'client' => [
         'delete_confirm'    => '确认删除?',

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

@@ -26,6 +26,7 @@ return [
         'nullable'          => '允許null',
         'key'               => '索引',
         'translate_title'   => '翻譯標題',
+        'sync_translation_with_comment' => '同步翻譯與註釋',
     ],
     'client' => [
         'delete_confirm'    => '確認刪除?',

+ 1 - 1
resources/views/form/daterange.blade.php

@@ -38,7 +38,7 @@
     $this.datetimepicker(options);
     $end.datetimepicker($.extend(options, {useCurrent: false}));
     $this.on("dp.change", function (e) {
-        $('{{ $selector['end'] }}').data("DateTimePicker").minDate(e.date);
+        $end.data("DateTimePicker").minDate(e.date);
     });
     $end.on("dp.change", function (e) {
         $this.data("DateTimePicker").maxDate(e.date);

+ 17 - 0
resources/views/helpers/scaffold.blade.php

@@ -204,6 +204,7 @@
 
                 <div class='form-group'>
                     <button type="button" class="btn btn-sm btn-primary btn-outline text-capitalize" id="add-table-field"><i class="feather icon-plus"></i>&nbsp;&nbsp;{{(trans('admin.scaffold.add_field'))}}</button>
+                    <button type="button" class="btn btn-sm btn-primary btn-outline text-capitalize ml-1" id="sync-translation-with-comment"><i class="feather icon-repeat"></i>&nbsp;&nbsp;{{(trans('admin.scaffold.sync_translation_with_comment'))}}</button>
                 </div>
 
                 <div class="row">
@@ -334,6 +335,22 @@
             addField();
         });
 
+        $('#sync-translation-with-comment').click(function (event) {
+            var element = $('#table-fields-sortable tr');
+            if (element.length > 0) {
+                element.each(function (i, v) {
+                    var translation = $(v).find('input[name="fields[' + i + '][translation]"]');
+                    var comment = $(v).find('input[name="fields[' + i + '][comment]"]');
+                    if (translation.val() !== "" && comment.val() === "") {
+                        comment.val(translation.val());
+                    }
+                    if (translation.val() === "" && comment.val() !== "") {
+                        translation.val(comment.val());
+                    }
+                });
+            }
+        });
+
         $('#table-fields').on('click', '.table-field-remove', function(event) {
             $(event.target).closest('tr').remove();
         });

+ 12 - 1
src/Form.php

@@ -590,7 +590,6 @@ class Form implements Renderable
                 ->alert()
                 ->status($status)
                 ->message($message)
-                ->redirectIf($status, $this->resource(-1))
         );
     }
 
@@ -1370,6 +1369,18 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * @param array $vars
+     *
+     * @return $this
+     */
+    public function addVariables(array $vars)
+    {
+        $this->builder->addVariables($vars);
+
+        return $this;
+    }
+
     /**
      * Get or set title for form.
      *

+ 8 - 3
src/Grid/Actions/Delete.php

@@ -11,15 +11,20 @@ class Delete extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-trash"></i> '.__('admin.delete');
     }
 
     public function render()
     {
         $this->setHtmlAttribute([
-            'data-url'     => $this->url(),
-            'data-message' => "ID - {$this->getKey()}",
-            'data-action'  => 'delete',
+            'data-url'      => $this->url(),
+            'data-message'  => "ID - {$this->getKey()}",
+            'data-action'   => 'delete',
+            'data-redirect' => request()->fullUrl(),
         ]);
 
         return parent::render();

+ 4 - 0
src/Grid/Actions/Edit.php

@@ -11,6 +11,10 @@ class Edit extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-edit-1"></i> '.__('admin.edit');
     }
 

+ 4 - 0
src/Grid/Actions/QuickEdit.php

@@ -14,6 +14,10 @@ class QuickEdit extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-edit"></i> '.__('admin.quick_edit');
     }
 

+ 4 - 0
src/Grid/Actions/Show.php

@@ -11,6 +11,10 @@ class Show extends RowAction
      */
     public function title()
     {
+        if ($this->title) {
+            return $this->title;
+        }
+
         return '<i class="feather icon-eye"></i> '.__('admin.show');
     }
 

+ 1 - 1
src/Grid/BatchAction.php

@@ -31,6 +31,6 @@ JS;
      */
     public function getSelectedKeysScript()
     {
-        return "Dcat.grid.selected('{$this->parent->getName()}');";
+        return "Dcat.grid.selected('{$this->parent->getName()}')";
     }
 }

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

@@ -158,8 +158,8 @@ HTML
     {
         if (
             $sortable
-            && ! $this->findQueryByMethod('orderBy')
-            && ! $this->findQueryByMethod('orderByDesc')
+            && $this->findQueryByMethod('orderBy')->isEmpty()
+            && $this->findQueryByMethod('orderByDesc')->isEmpty()
             && ($orderColumn = $this->repository->getOrderColumn())
         ) {
             $this->orderBy($orderColumn)

+ 28 - 20
src/Grid/Displayers/Actions.php

@@ -4,6 +4,10 @@ namespace Dcat\Admin\Grid\Displayers;
 
 use Dcat\Admin\Actions\Action;
 use Dcat\Admin\Form;
+use Dcat\Admin\Grid\Actions\Delete;
+use Dcat\Admin\Grid\Actions\Edit;
+use Dcat\Admin\Grid\Actions\QuickEdit;
+use Dcat\Admin\Grid\Actions\Show;
 use Dcat\Admin\Grid\RowAction;
 use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Htmlable;
@@ -229,11 +233,12 @@ class Actions extends AbstractDisplayer
     {
         $label = trans('admin.show');
 
-        return <<<EOT
-<a href="{$this->resource()}/{$this->getKey()}" title="{$label}">
-    <i class="feather icon-eye grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Show::make(
+            "<i title='{$label}' class=\"feather icon-eye grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -245,11 +250,12 @@ EOT;
     {
         $label = trans('admin.edit');
 
-        return <<<EOT
-<a href="{$this->grid->getEditUrl($this->getKey())}" title="{$label}">
-    <i class="feather icon-edit-1 grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Edit::make(
+            "<i title='{$label}' class=\"feather icon-edit-1 grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -270,11 +276,12 @@ EOT;
 
         $label = trans('admin.quick_edit');
 
-        return <<<EOF
-<a title="{$label}" class="{$this->grid->getRowName()}-edit" data-url="{$this->resource()}/{$this->getKey()}/edit" href="javascript:void(0);">
-    <i class="feather icon-edit grid-action-icon"></i>
-</a>&nbsp;
-EOF;
+        return QuickEdit::make(
+            "<i title='{$label}' class=\"feather icon-edit grid-action-icon\"></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 
     /**
@@ -286,10 +293,11 @@ EOF;
     {
         $label = trans('admin.delete');
 
-        return <<<EOT
-<a title="{$label}" href="javascript:void(0);" data-message="ID - {$this->getKey()}" data-url="{$this->resource()}/{$this->getKey()}" data-action="delete">
-    <i class="feather icon-trash grid-action-icon"></i>
-</a>&nbsp;
-EOT;
+        return Delete::make(
+            "<i class=\"feather icon-trash grid-action-icon\" title='{$label}'></i> &nbsp;"
+        )
+            ->setGrid($this->grid)
+            ->setRow($this->row)
+            ->render();
     }
 }

+ 2 - 4
src/Grid/Model.php

@@ -510,13 +510,11 @@ class Model
      *
      * @param $method
      *
-     * @return static
+     * @return Collection
      */
     public function findQueryByMethod($method)
     {
-        return $this->queries->first(function ($query) use ($method) {
-            return $query['method'] == $method;
-        });
+        return $this->queries->where('method', $method);
     }
 
     /**

+ 6 - 1
src/Grid/Tools/BatchDelete.php

@@ -13,8 +13,13 @@ class BatchDelete extends BatchAction
 
     public function render()
     {
+        $redirect = request()->fullUrl();
+
         return <<<HTML
-<a href="#" data-name="{$this->parent->getName()}" data-action="batch-delete" data-url="{$this->resource()}"><i class="feather icon-trash"></i> {$this->title}</a>
+<a  data-name="{$this->parent->getName()}" 
+    data-action="batch-delete" 
+    data-redirect="{$redirect}"
+    data-url="{$this->resource()}"><i class="feather icon-trash"></i> {$this->title}</a>
 HTML;
     }
 }

+ 4 - 4
src/Http/JsonResponse.php

@@ -20,7 +20,7 @@ use Illuminate\Validation\ValidationException;
  * @method $this detailIf($condition, ?string $message)
  * @method $this statusCodeIf($condition, int $code)
  * @method $this redirectIf($condition, ?string $url)
- * @method $this locationIf($condition, ?string $url)
+ * @method $this locationIf($condition, ?string $url = null)
  * @method $this refreshIf($condition)
  * @method $this downloadIf($condition, ?string $url)
  * @method $this scriptIf($condition, ?string $script)
@@ -216,13 +216,13 @@ class JsonResponse implements Arrayable
     /**
      * Location 跳转.
      *
-     * @param string $location
+     * @param string $location 不传则刷新当前页面
      *
      * @return $this
      */
-    public function location(?string $location)
+    public function location(?string $location = null)
     {
-        return $this->then(['action' => 'location', 'value' => admin_url($location)]);
+        return $this->then(['action' => 'location', 'value' => $location ? admin_url($location) : null]);
     }
 
     /**

+ 1 - 1
src/Layout/Column.php

@@ -112,7 +112,7 @@ class Column implements Renderable
     {
         // get class name using width array
         $classnName = collect($this->width)->map(function ($value, $key) {
-            return "col-$key-$value";
+            return $value == 0 ? "col-$key" : "col-$key-$value";
         })->implode(' ');
 
         return "<div class=\"{$classnName}\">";

+ 26 - 1
src/Repositories/EloquentRepository.php

@@ -188,11 +188,36 @@ class EloquentRepository extends Repository implements TreeRepository
         [$column, $type, $cast] = $model->getSort();
 
         if (empty($column) || empty($type)) {
+            $orders = $model->findQueryByMethod('orderBy')->merge($model->findQueryByMethod('orderByDesc'));
+
+            $model->resetOrderBy();
+
+            $orders->each(function ($orderBy) use ($model) {
+                $column = $orderBy['arguments'][0];
+                $type = $orderBy['method'] === 'orderByDesc' ? 'desc' : ($orderBy['arguments'][1] ?? 'asc');
+                $cast = null;
+
+                $this->addOrderBy($model, $column, $type, $cast);
+            });
+
             return;
         }
 
         $model->resetOrderBy();
 
+        $this->addOrderBy($model, $column, $type, $cast);
+    }
+
+    /**
+     * @param Grid\Model $model
+     * @param string $column
+     * @param string $type
+     * @param string $cast
+     *
+     * @throws \Exception
+     */
+    protected function addOrderBy(Grid\Model $model, $column, $type, $cast)
+    {
         $explodedCols = explode('.', $column);
         $isRelation = empty($explodedCols[1]) ? false : method_exists($this->model(), $explodedCols[0]);
 
@@ -345,7 +370,7 @@ class EloquentRepository extends Repository implements TreeRepository
      */
     protected function setPaginate(Grid\Model $model)
     {
-        $paginate = $model->findQueryByMethod('paginate');
+        $paginate = $model->findQueryByMethod('paginate')->first();
 
         $model->rejectQuery(['paginate']);
 

+ 1 - 1
src/Repositories/QueryBuilderRepository.php

@@ -198,7 +198,7 @@ class QueryBuilderRepository extends Repository implements TreeRepository
      */
     protected function setPaginate(Grid\Model $model)
     {
-        $paginate = $model->findQueryByMethod('paginate');
+        $paginate = $model->findQueryByMethod('paginate')->first();
 
         $model->rejectQuery(['paginate']);
 

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.