Selaa lähdekoodia

update

update
jqh 5 vuotta sitten
vanhempi
commit
3bd01e54a1

+ 23 - 23
resources/assets/dcat-admin/grid-extend.js

@@ -8,13 +8,13 @@
             showNextPage: '',
             pageQueryName: '',
             parentIdQueryName: '',
-            levelQueryName: '',
+            tierQueryName: '',
             showIcon: 'fa-angle-right',
             hideIcon: 'fa-angle-down',
             loadMoreText: '<svg style="fill:currentColor" t="1582877365167" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="32874" width="24" height="24"><path d="M162.8 515m-98.3 0a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32875"></path><path d="M511.9 515m-98.3 0a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32876"></path><path d="M762.8 515a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32877"></path></svg>',
         }, opts);
 
-        this.key = this.level = this.row = this.data = this._req = null;
+        this.key = this.tier = this.row = this.data = this._req = null;
 
         this._init();
     }
@@ -38,7 +38,7 @@
                     shown = _i.hasClass(opts.showIcon);
 
                 _this.key = $this.data('key');
-                _this.level = $this.data('level');
+                _this.tier = $this.data('tier');
                 _this.row = $this.closest('tr');
 
                 if ($this.data('inserted') == '0') {
@@ -51,7 +51,7 @@
                 var children = [];
 
                 getChildren(_this.row.nextAll(), _this.row).forEach(function (v) {
-                    if (! (getLevel(v) === (_this.level + 1))) {
+                    if (getTier(v) !== (_this.tier + 1)) {
                         return;
                     }
 
@@ -65,7 +65,7 @@
                         return
                     }
 
-                    var icon = $(v).find('a[data-level=' + getLevel(v) + '] i');
+                    var icon = $(v).find('a[data-tier=' + getTier(v) + '] i');
 
                     if (icon.hasClass(opts.hideIcon)) {
                         icon.parent().click();
@@ -78,7 +78,7 @@
             var _this = this,
                 row = _this.row,
                 key = _this.key,
-                level = _this.level,
+                tier = _this.tier,
                 tableSelector = _this.options.table;
 
             if (_this._req) {
@@ -92,7 +92,7 @@
             };
 
             data[_this.options.parentIdQueryName] = key;
-            data[_this.options.levelQueryName] = level + 1;
+            data[_this.options.tierQueryName] = tier + 1;
             data[_this.options.pageQueryName.replace(':key', key)] = page;
 
             $.ajax({
@@ -116,7 +116,7 @@
 
                     // 标记子节点行
                     _tbody.find('tr').each(function (_, v) {
-                        $(v).attr('data-level', level + 1)
+                        $(v).attr('data-tier', tier + 1)
                     });
 
                     if (
@@ -125,7 +125,7 @@
                         && lastPage >= page
                     ) {
                         // 加载更多
-                        var loadMore = $("<tr data-level='" + (level + 1) + "' data-page='" + nextPage
+                        var loadMore = $("<tr data-tier='" + (tier + 1) + "' data-page='" + nextPage
                             + "'><td colspan='"+(row.find('td').length)
                             + "' align='center' style='cursor: pointer'> <a>" + _this.options.loadMoreText + "</a> </td></tr>");
 
@@ -167,7 +167,7 @@
             url: '',
         }, opts);
 
-        this.direction = this.key = this.level = this.row = this._req = null;
+        this.direction = this.key = this.tier = this.row = this._req = null;
 
         this._init();
     }
@@ -193,7 +193,7 @@
                 _this.key = $this.data('id');
                 _this.direction = $this.data('direction');
                 _this.row = $this.closest('tr');
-                _this.level = getLevel(_this.row);
+                _this.tier = getTier(_this.row);
 
                 _this._request();
             })
@@ -203,7 +203,7 @@
             var _this = this,
                 key = _this.key,
                 row = _this.row,
-                level = _this.level,
+                tier = _this.tier,
                 direction = _this.direction,
                 prevAll = row.prevAll(),
                 nextAll = row.nextAll(),
@@ -224,8 +224,8 @@
                     LA.success(data.message);
 
                     if (direction) {
-                        var prevRow = sibling(prevAll, level);
-                        if (swapable(prevRow, level) && prev.length && getLevel(prev) >= level) {
+                        var prevRow = sibling(prevAll, tier);
+                        if (swapable(prevRow, tier) && prev.length && getTier(prev) >= tier) {
                             prevRow.before(row);
 
                             // 把所有子节点上移
@@ -234,10 +234,10 @@
                             });
                         }
                     } else {
-                        var nextRow = sibling(nextAll, level),
+                        var nextRow = sibling(nextAll, tier),
                             nextRowChildren = nextRow ? getChildren(nextRow.nextAll(), nextRow) : [];
 
-                        if (swapable(nextRow, level) && next.length && getLevel(next) >= level) {
+                        if (swapable(nextRow, tier) && next.length && getTier(next) >= tier) {
                             nextAll = row.nextAll();
 
                             if (nextRowChildren.length) {
@@ -271,12 +271,12 @@
         return $(v).prop('tagName').toLocaleLowerCase() === 'tr'
     }
 
-    function getLevel(v) {
-        return parseInt($(v).data('level') || 0);
+    function getTier(v) {
+        return parseInt($(v).data('tier') || 0);
     }
 
     function isChildren(parent, child) {
-        return getLevel(child) > getLevel(parent);
+        return getTier(child) > getTier(parent);
     }
 
     function getChildren(all, parent) {
@@ -302,21 +302,21 @@
         return arr;
     }
 
-    function swapable(_o, level) {
+    function swapable(_o, tier) {
         if (
             _o
             && _o.length
-            && level === getLevel(_o)
+            && tier === getTier(_o)
         ) {
             return true
         }
     }
 
-    function sibling(all, level) {
+    function sibling(all, tier) {
         var next;
 
         all.each(function (_, v) {
-            if (getLevel(v) === level && ! next && isTr(v)) {
+            if (getTier(v) === tier && ! next && isTr(v)) {
                 next = $(v);
             }
         });

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
resources/assets/dcat-admin/grid-extend.min.js


+ 2 - 4
src/Grid/BatchAction.php

@@ -17,7 +17,7 @@ abstract class BatchAction extends GridAction
         $warning = __('No data selected!');
 
         return <<<JS
-    var key = LA.grid.selected('{$this->parent->getName()}');
+    var key = {$this->getSelectedKeysScript()}
     
     if (key.length === 0) {
         LA.warning('{$warning}');
@@ -32,8 +32,6 @@ JS;
      */
     public function getSelectedKeysScript()
     {
-        return <<<JS
-LA.grid.selected('{$this->parent->getName()}');
-JS;
+        return "LA.grid.selected('{$this->parent->getName()}');";
     }
 }

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

@@ -11,12 +11,12 @@ trait HasTree
     /**
      * @var string
      */
-    protected $parentIdQueryName = '__parent_id__';
+    protected $parentIdQueryName = '_parent_id_';
 
     /**
      * @var string
      */
-    protected $levelQueryName = '__level__';
+    protected $tierQueryName = '_tier_';
 
     /**
      * @var bool
@@ -169,7 +169,7 @@ HTML
      */
     public function getChildrenPageName($parentId)
     {
-        return $this->getChildrenQueryNamePrefix().'children_page_'.$parentId;
+        return $this->getChildrenQueryNamePrefix().'_children_page_'.$parentId;
     }
 
     /**
@@ -205,18 +205,18 @@ HTML
     /**
      * @return string
      */
-    public function getLevelQueryName()
+    public function getTierQueryName()
     {
-        return $this->getChildrenQueryNamePrefix().$this->levelQueryName;
+        return $this->getChildrenQueryNamePrefix().$this->tierQueryName;
     }
 
     /**
      * @return int
      */
-    public function getLevelFromRequest()
+    public function getTierFromRequest()
     {
         return $this->request->get(
-            $this->getLevelQueryName()
+            $this->getTierQueryName()
         ) ?: 0;
     }
 

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

@@ -29,7 +29,7 @@ LA.grid.tree({
     showNextPage: {$showNextPage},
     pageQueryName: '{$pageName}',
     parentIdQueryName: '{$model->getParentIdQueryName()}',
-    levelQueryName: '{$model->getLevelQueryName()}',
+    tierQueryName: '{$model->getTierQueryName()}',
 });
 JS;
         Admin::script($script);
@@ -42,11 +42,11 @@ JS;
         $key = $this->key();
         $tableId = $this->grid->tableId();
 
-        $level = $this->grid->model()->getLevelFromRequest();
-        $indents = str_repeat(' &nbsp; &nbsp; &nbsp; &nbsp; ', $level);
+        $tier = $this->grid->model()->getTierFromRequest();
+        $indents = str_repeat(' &nbsp; &nbsp; &nbsp; &nbsp; ', $tier);
 
         return <<<EOT
-<a href="javascript:void(0)" class="{$tableId}-grid-load-children" data-level="{$level}" data-inserted="0" data-key="{$key}">
+<a href="javascript:void(0)" class="{$tableId}-grid-load-children" data-tier="{$tier}" data-inserted="0" data-key="{$key}">
    {$indents}<i class="fa fa-angle-right"></i> &nbsp; {$this->value}
 </a>
 EOT;

+ 32 - 12
src/Grid/Filter.php

@@ -390,11 +390,17 @@ class Filter implements Renderable
         return $this->name;
     }
 
+    /**
+     * @return $this
+     */
     public function withoutBorder()
     {
         return $this->withBorder('');
     }
 
+    /**
+     * @return $this
+     */
     public function withBorder($border = null)
     {
         $this->border = is_null($border) ? 'border-top:1px solid #f4f4f4;' : $border;
@@ -443,7 +449,7 @@ class Filter implements Renderable
      *
      * @return array
      */
-    public function conditions()
+    public function getConditions()
     {
         $inputs = $this->inputs();
 
@@ -538,13 +544,21 @@ class Filter implements Renderable
      */
     public function scope($key, $label = '')
     {
-        $scope = new Scope($key, $label);
+        $scope = new Scope($this, $key, $label);
 
         $this->scopes->push($scope);
 
         return $scope;
     }
 
+    /**
+     * @return string
+     */
+    public function getScopeQueryName()
+    {
+        return $this->grid()->getName().'_scope_';
+    }
+
     /**
      * Get all filter scopes.
      *
@@ -560,9 +574,9 @@ class Filter implements Renderable
      *
      * @return Scope|null
      */
-    public function currentScope()
+    public function getCurrentScope()
     {
-        $key = request(Scope::QUERY_NAME);
+        $key = $this->getCurrentScopeName();
 
         return $this->scopes->first(function ($scope) use ($key) {
             return $scope->key == $key;
@@ -574,9 +588,9 @@ class Filter implements Renderable
      *
      * @return string
      */
-    public function currentScopeName()
+    public function getCurrentScopeName()
     {
-        return request(Scope::QUERY_NAME);
+        return request($this->getScopeQueryName());
     }
 
     /**
@@ -584,9 +598,9 @@ class Filter implements Renderable
      *
      * @return array
      */
-    protected function scopeConditions()
+    protected function getScopeConditions()
     {
-        if ($scope = $this->currentScope()) {
+        if ($scope = $this->getCurrentScope()) {
             return $scope->condition();
         }
 
@@ -617,8 +631,8 @@ class Filter implements Renderable
     public function execute(bool $toArray = true)
     {
         $conditions = array_merge(
-            $this->conditions(),
-            $this->scopeConditions()
+            $this->getConditions(),
+            $this->getScopeConditions()
         );
 
         return $this->model->addConditions($conditions)->buildData($toArray);
@@ -649,11 +663,17 @@ class Filter implements Renderable
         return $this;
     }
 
-    public function resetPosition()
+    /**
+     * @return $this
+     */
+    public function noPadding()
     {
         return $this->style('padding:0;left:-4px;');
     }
 
+    /**
+     * @return $this
+     */
     public function hiddenResetButtonText()
     {
         Admin::style(".{$this->containerClass} a.reset .hidden-xs{display:none}");
@@ -722,7 +742,7 @@ class Filter implements Renderable
      */
     public function urlWithoutScopes()
     {
-        return Helper::fullUrlWithoutQuery(Scope::QUERY_NAME);
+        return Helper::fullUrlWithoutQuery($this->getScopeQueryName());
     }
 
     /**

+ 13 - 5
src/Grid/Filter/Scope.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Grid\Filter;
 
+use Dcat\Admin\Grid\Filter;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Database\Query\Builder;
 use Illuminate\Support\Collection;
@@ -11,7 +12,10 @@ use Illuminate\Support\Collection;
  */
 class Scope implements Renderable
 {
-    const QUERY_NAME = '_scope_';
+    /**
+     * @var Filter
+     */
+    protected $filter;
 
     /**
      * @var string
@@ -31,13 +35,15 @@ class Scope implements Renderable
     /**
      * Scope constructor.
      *
-     * @param $key
+     * @param Filter $filter
+     * @param string $key
      * @param string $label
      */
-    public function __construct($key, $label = '')
+    public function __construct(Filter $filter, $key, $label = '')
     {
+        $this->filter = $filter;
         $this->key = $key;
-        $this->label = $label ? $label : admin_trans_field($key);
+        $this->label = $label ?: admin_trans_field($key);
 
         $this->queries = new Collection();
     }
@@ -69,7 +75,9 @@ class Scope implements Renderable
      */
     public function render()
     {
-        $url = request()->fullUrlWithQuery([static::QUERY_NAME => $this->key]);
+        $url = request()->fullUrlWithQuery(
+            [$this->filter->getScopeQueryName() => $this->key]
+        );
 
         return "<li><a href=\"{$url}\">{$this->label}</a></li>";
     }

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

@@ -114,7 +114,7 @@ JS;
      */
     protected function currentScopeLabel()
     {
-        if ($scope = $this->filter()->currentScope()) {
+        if ($scope = $this->filter()->getCurrentScope()) {
             return "&nbsp;{$scope->getLabel()}&nbsp;";
         }
 

+ 6 - 0
src/Models/AdminTablesSeeder.php

@@ -45,6 +45,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '',
                 'parent_id'   => 0,
+                'order'       => 1,
                 'created_at'  => $createdAt,
             ],
             [
@@ -54,6 +55,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '/auth/users*',
                 'parent_id'   => 1,
+                'order'       => 2,
                 'created_at'  => $createdAt,
             ],
             [
@@ -63,6 +65,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '/auth/roles*',
                 'parent_id'   => 1,
+                'order'       => 3,
                 'created_at'  => $createdAt,
             ],
             [
@@ -72,6 +75,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '/auth/permissions*',
                 'parent_id'   => 1,
+                'order'       => 4,
                 'created_at'  => $createdAt,
             ],
             [
@@ -81,6 +85,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '/auth/menu*',
                 'parent_id'   => 1,
+                'order'       => 5,
                 'created_at'  => $createdAt,
             ],
             [
@@ -90,6 +95,7 @@ class AdminTablesSeeder extends Seeder
                 'http_method' => '',
                 'http_path'   => '/auth/logs*',
                 'parent_id'   => 1,
+                'order'       => 6,
                 'created_at'  => $createdAt,
             ],
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä