From 7b8f56d737d33ca0fef6b732d710ab9a7792f3bd Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Nov 2019 16:59:24 +0300 Subject: [PATCH 001/340] JSON order by --- src/Grid/Model.php | 35 ++++++++++++++++++++++++++++------- tests/MenuTest.php | 2 +- tests/TestCase.php | 6 +++--- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/Grid/Model.php b/src/Grid/Model.php index 825f3811e3..d3fe1c0462 100644 --- a/src/Grid/Model.php +++ b/src/Grid/Model.php @@ -541,23 +541,44 @@ protected function setSort() return; } - if (empty($this->sort['column']) || empty($this->sort['type'])) { + $columnName = $this->sort['column'] ?? null; + if ($columnName === null || empty($this->sort['type'])) { return; } - if (Str::contains($this->sort['column'], '.')) { - $this->setRelationSort($this->sort['column']); + $columnNameContainsDots = Str::contains($columnName, '.'); + if ($columnNameContainsDots === true) { + $isRelation = $this->queries->contains(function ($query) use ($columnName) { + return $query['method'] === 'with' && in_array($columnName, $query['arguments'], true); + }); + if ($isRelation === true) { + $this->setRelationSort($columnName); + } else { + //json + $this->resetOrderBy(); + $explodedCols = explode('.', $this->sort['column']); + $col = array_shift($explodedCols); + $parts = implode('.', $explodedCols); + $column = "{$col}->>'$.{$parts}' {$this->sort['type']}"; + $method = 'orderByRaw'; + $arguments = [$column]; + + $this->queries->push([ + 'method' => $method, + 'arguments' => $arguments, + ]); + } } else { $this->resetOrderBy(); // get column. if contains "cast", set set column as cast if (!empty($this->sort['cast'])) { - $column = "CAST({$this->sort['column']} AS {$this->sort['cast']}) {$this->sort['type']}"; - $method = 'orderByRaw'; + $column = "CAST({$columnName} AS {$this->sort['cast']}) {$this->sort['type']}"; + $method = 'orderByRaw'; $arguments = [$column]; } else { - $column = $this->sort['column']; - $method = 'orderBy'; + $column = $columnName; + $method = 'orderBy'; $arguments = [$column, $this->sort['type']]; } diff --git a/tests/MenuTest.php b/tests/MenuTest.php index 6964e381fe..16799ad2e9 100644 --- a/tests/MenuTest.php +++ b/tests/MenuTest.php @@ -61,7 +61,7 @@ public function testEditMenu() public function testShowPage() { - $this->visit('admin/auth/menu/1') + $this->visit('admin/auth/menu/1/edit') ->seePageIs('admin/auth/menu/1/edit'); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7ef5ad6b91..d6184cd3fc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -39,9 +39,9 @@ public function setUp() $this->app['config']->set('database.default', 'mysql'); $this->app['config']->set('database.connections.mysql.host', env('MYSQL_HOST', 'localhost')); - $this->app['config']->set('database.connections.mysql.database', 'laravel_admin_test'); - $this->app['config']->set('database.connections.mysql.username', 'root'); - $this->app['config']->set('database.connections.mysql.password', ''); + $this->app['config']->set('database.connections.mysql.database', env('MYSQL_DATABASE', 'laravel_admin_test')); + $this->app['config']->set('database.connections.mysql.username', env('MYSQL_USER', 'root')); + $this->app['config']->set('database.connections.mysql.password', env('MYSQL_PASSWORD', '')); $this->app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF'); $this->app['config']->set('filesystems', require __DIR__.'/config/filesystems.php'); $this->app['config']->set('admin', $adminConfig); From d2c59320b1cc1bee984a16a1f7688dc4a798078d Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Nov 2019 17:17:02 +0300 Subject: [PATCH 002/340] styleci --- src/Grid/Model.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Grid/Model.php b/src/Grid/Model.php index d3fe1c0462..091fab8b39 100644 --- a/src/Grid/Model.php +++ b/src/Grid/Model.php @@ -557,11 +557,11 @@ protected function setSort() //json $this->resetOrderBy(); $explodedCols = explode('.', $this->sort['column']); - $col = array_shift($explodedCols); - $parts = implode('.', $explodedCols); - $column = "{$col}->>'$.{$parts}' {$this->sort['type']}"; - $method = 'orderByRaw'; - $arguments = [$column]; + $col = array_shift($explodedCols); + $parts = implode('.', $explodedCols); + $column = "{$col}->>'$.{$parts}' {$this->sort['type']}"; + $method = 'orderByRaw'; + $arguments = [$column]; $this->queries->push([ 'method' => $method, @@ -573,12 +573,12 @@ protected function setSort() // get column. if contains "cast", set set column as cast if (!empty($this->sort['cast'])) { - $column = "CAST({$columnName} AS {$this->sort['cast']}) {$this->sort['type']}"; - $method = 'orderByRaw'; + $column = "CAST({$columnName} AS {$this->sort['cast']}) {$this->sort['type']}"; + $method = 'orderByRaw'; $arguments = [$column]; } else { - $column = $columnName; - $method = 'orderBy'; + $column = $columnName; + $method = 'orderBy'; $arguments = [$column, $this->sort['type']]; } From 69225c85c2797eead4bd747f63e132504cb4e8a1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Nov 2019 18:26:01 +0300 Subject: [PATCH 003/340] Cast for integer sort && tests --- src/Grid/Model.php | 27 +++++++------------ tests/UserGridTest.php | 19 +++++++++++++ tests/controllers/UserController.php | 1 + .../2016_11_22_093148_create_test_tables.php | 1 + tests/models/User.php | 2 ++ tests/seeds/UserTableSeeder.php | 1 + 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Grid/Model.php b/src/Grid/Model.php index 091fab8b39..e8b45089b7 100644 --- a/src/Grid/Model.php +++ b/src/Grid/Model.php @@ -547,29 +547,22 @@ protected function setSort() } $columnNameContainsDots = Str::contains($columnName, '.'); - if ($columnNameContainsDots === true) { - $isRelation = $this->queries->contains(function ($query) use ($columnName) { - return $query['method'] === 'with' && in_array($columnName, $query['arguments'], true); - }); - if ($isRelation === true) { - $this->setRelationSort($columnName); - } else { + $isRelation = $this->queries->contains(function ($query) use ($columnName) { + return $query['method'] === 'with' && in_array($columnName, $query['arguments'], true); + }); + if ($columnNameContainsDots === true && $isRelation) { + $this->setRelationSort($columnName); + } else { + $this->resetOrderBy(); + + if ($columnNameContainsDots === true) { //json $this->resetOrderBy(); $explodedCols = explode('.', $this->sort['column']); $col = array_shift($explodedCols); $parts = implode('.', $explodedCols); - $column = "{$col}->>'$.{$parts}' {$this->sort['type']}"; - $method = 'orderByRaw'; - $arguments = [$column]; - - $this->queries->push([ - 'method' => $method, - 'arguments' => $arguments, - ]); + $columnName = "{$col}->>'$.{$parts}'"; } - } else { - $this->resetOrderBy(); // get column. if contains "cast", set set column as cast if (!empty($this->sort['cast'])) { diff --git a/tests/UserGridTest.php b/tests/UserGridTest.php index df02c83744..efc1b36b1e 100644 --- a/tests/UserGridTest.php +++ b/tests/UserGridTest.php @@ -56,6 +56,8 @@ protected function seedsTable($count = 100) ->each(function ($u) { $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); + $u->data = ['json' => ['field' => random_int(0,50)]]; + $u->save(); }); } @@ -90,6 +92,23 @@ public function testGridPagination() $this->assertCount(20, $this->crawler()->filter('td a i[class*=fa-edit]')); } + public function testOrderByJson() + { + $this->seedsTable(10); + $this->assertCount(10, UserModel::all()); + + $this->visit('admin/users?_sort[column]=data.json.field&_sort[type]=desc&_sort[cast]=unsigned'); + + $jsonTds = $this->crawler->filter('table.table tbody td.column-data-json-field'); + $this->assertCount(10, $jsonTds); + $prevValue = PHP_INT_MAX; + foreach ($jsonTds as $jsonTd) { + $currentValue = (int)$jsonTd->nodeValue; + $this->assertTrue($currentValue <= $prevValue); + $prevValue = $currentValue; + } + } + public function testEqualFilter() { $this->seedsTable(50); diff --git a/tests/controllers/UserController.php b/tests/controllers/UserController.php index e199d75f75..7634595f17 100644 --- a/tests/controllers/UserController.php +++ b/tests/controllers/UserController.php @@ -84,6 +84,7 @@ protected function grid() $grid->column('profile.color'); $grid->profile()->start_at('开始时间'); $grid->profile()->end_at('结束时间'); + $grid->column('data->json->field', 'Json Field'); $grid->column('column1_not_in_table')->display(function () { return 'full name:'.$this->full_name; diff --git a/tests/migrations/2016_11_22_093148_create_test_tables.php b/tests/migrations/2016_11_22_093148_create_test_tables.php index 206e35d0e9..3632bd1d87 100644 --- a/tests/migrations/2016_11_22_093148_create_test_tables.php +++ b/tests/migrations/2016_11_22_093148_create_test_tables.php @@ -47,6 +47,7 @@ public function up() $table->string('mobile')->nullable(); $table->string('avatar')->nullable(); $table->string('password'); + $table->json('data')->nullable(); $table->timestamps(); }); diff --git a/tests/models/User.php b/tests/models/User.php index 364db737bd..56fe4adc2d 100644 --- a/tests/models/User.php +++ b/tests/models/User.php @@ -10,6 +10,8 @@ class User extends Model protected $appends = ['full_name', 'position']; + protected $casts = ['data' => 'array']; + public function profile() { return $this->hasOne(Profile::class, 'user_id'); diff --git a/tests/seeds/UserTableSeeder.php b/tests/seeds/UserTableSeeder.php index 97ffeb7b46..4e118d4a97 100644 --- a/tests/seeds/UserTableSeeder.php +++ b/tests/seeds/UserTableSeeder.php @@ -13,6 +13,7 @@ public function run() ->each(function ($u) { $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); + $u->data = ['json' => ['field' => random_int(0,50)]]; }); } } From 905b1c4aba69d74febebfdb32c5ce11a05b2fc72 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Nov 2019 18:27:20 +0300 Subject: [PATCH 004/340] style ci fix --- tests/UserGridTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/UserGridTest.php b/tests/UserGridTest.php index efc1b36b1e..7d99750e2b 100644 --- a/tests/UserGridTest.php +++ b/tests/UserGridTest.php @@ -56,7 +56,7 @@ protected function seedsTable($count = 100) ->each(function ($u) { $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); - $u->data = ['json' => ['field' => random_int(0,50)]]; + $u->data = ['json' => ['field' => random_int(0, 50)]]; $u->save(); }); } @@ -103,7 +103,7 @@ public function testOrderByJson() $this->assertCount(10, $jsonTds); $prevValue = PHP_INT_MAX; foreach ($jsonTds as $jsonTd) { - $currentValue = (int)$jsonTd->nodeValue; + $currentValue = (int) $jsonTd->nodeValue; $this->assertTrue($currentValue <= $prevValue); $prevValue = $currentValue; } From d7f44d4e7d34de6c8e0a4575db880d1564afed1f Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 7 Nov 2019 18:28:23 +0300 Subject: [PATCH 005/340] style ci fix --- tests/seeds/UserTableSeeder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/seeds/UserTableSeeder.php b/tests/seeds/UserTableSeeder.php index 4e118d4a97..c5dfe4df7e 100644 --- a/tests/seeds/UserTableSeeder.php +++ b/tests/seeds/UserTableSeeder.php @@ -13,7 +13,7 @@ public function run() ->each(function ($u) { $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); - $u->data = ['json' => ['field' => random_int(0,50)]]; + $u->data = ['json' => ['field' => random_int(0, 50)]]; }); } } From d1e751c097cddcfa73e2c9a6b7710956dc459e95 Mon Sep 17 00:00:00 2001 From: xiaofu <14215060@qq.com> Date: Thu, 2 Jan 2020 15:00:51 +0800 Subject: [PATCH 006/340] fix bug --- src/Form/Field/HasMany.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Form/Field/HasMany.php b/src/Form/Field/HasMany.php index e872f06ff1..fd77297869 100644 --- a/src/Form/Field/HasMany.php +++ b/src/Form/Field/HasMany.php @@ -589,8 +589,14 @@ protected function setupScriptForTableView($templateScript) }); $('#has-many-{$this->column}').on('click', '.remove', function () { - $(this).closest('.has-many-{$this->column}-form').hide(); - $(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1); + var first_input_name = $(this).closest('.has-many-{$this->column}-form').find('input:first').attr('name'); + if (first_input_name.match('{$this->column}\\\[new_')) { + $(this).closest('.has-many-{$this->column}-form').remove(); + } else { + $(this).closest('.has-many-{$this->column}-form').hide(); + $(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1); + $(this).closest('.has-many-{$this->column}-form').find('input').removeAttr('required'); + } return false; }); From 1c285b4e0af276466afe14df3cef5f3ab58a939b Mon Sep 17 00:00:00 2001 From: jianmingLee Date: Fri, 3 Jan 2020 17:01:55 +0800 Subject: [PATCH 007/340] =?UTF-8?q?Form=20table=E5=AD=97=E6=AE=B5=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E6=95=B0=E6=8D=AE=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 创建页面无法打开抛出异常 ```php Invalid argument supplied for foreach() (View: /home/vagrant/code/order-system/vendor/encore/laravel-admin/resources/views/widgets/form.blade.php) vendor/encore/laravel-admin/src/Form/Field/Table.php:54 ... //调试发现$this->value为null foreach ($this->value as $key => $data) { if (isset($data['pivot'])) { $data = array_merge($data, $data['pivot']); } $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $key)->fill($data); } ... ``` --- src/Form/Field/Table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Field/Table.php b/src/Form/Field/Table.php index bb94b06779..1103d9e6f7 100644 --- a/src/Form/Field/Table.php +++ b/src/Form/Field/Table.php @@ -51,7 +51,7 @@ protected function buildRelatedForms() $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $key)->fill($data); } } else { - foreach ($this->value as $key => $data) { + foreach ($this->value ?? [] as $key => $data) { if (isset($data['pivot'])) { $data = array_merge($data, $data['pivot']); } From 6bdf21b78ce29877726f0aec936200741726d3ad Mon Sep 17 00:00:00 2001 From: z-song Date: Thu, 9 Jan 2020 15:28:35 +0800 Subject: [PATCH 008/340] fix #4309 --- src/Form/Field/HasMany.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Form/Field/HasMany.php b/src/Form/Field/HasMany.php index e872f06ff1..e4f07384d2 100644 --- a/src/Form/Field/HasMany.php +++ b/src/Form/Field/HasMany.php @@ -632,6 +632,10 @@ public function disableDelete() */ public function render() { + if (!$this->shouldRender()) { + return ''; + } + if ($this->viewMode == 'table') { return $this->renderTable(); } From bd7847686076ae335b55d4f236dc1c17d8681635 Mon Sep 17 00:00:00 2001 From: ichynul Date: Fri, 10 Jan 2020 23:02:25 +0800 Subject: [PATCH 009/340] @return array. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多了个点 --- src/Form/Field/MultipleFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Field/MultipleFile.php b/src/Form/Field/MultipleFile.php index 997665e46d..0c73518aa7 100644 --- a/src/Form/Field/MultipleFile.php +++ b/src/Form/Field/MultipleFile.php @@ -331,7 +331,7 @@ public function render() * * @param string $key * - * @return array. + * @return array */ public function destroy($key) { From 18a27d0e8519e42644158801d3c762c6ee8f2a6a Mon Sep 17 00:00:00 2001 From: ALMAS Date: Tue, 14 Jan 2020 18:18:17 +0800 Subject: [PATCH 010/340] Update ContainsForms.php --- src/Widgets/ContainsForms.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Widgets/ContainsForms.php b/src/Widgets/ContainsForms.php index ac89c709d1..036cdebaec 100644 --- a/src/Widgets/ContainsForms.php +++ b/src/Widgets/ContainsForms.php @@ -31,9 +31,9 @@ protected function buildTabbedForms($forms, $active = null) $form = app()->make($class); if ($name == $active) { - $this->add($form->title, $form->unbox(), true); + $this->add($form->title(), $form->unbox(), true); } else { - $this->addLink($form->title, $this->getTabUrl($name)); + $this->addLink($form->title(), $this->getTabUrl($name)); } } From 1a050caf8c2a299ca96ebd5ae229a668a0957002 Mon Sep 17 00:00:00 2001 From: "xiaohui.lam" Date: Mon, 20 Jan 2020 21:16:53 +0800 Subject: [PATCH 011/340] add asDefault method --- src/Grid/Filter/Scope.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Grid/Filter/Scope.php b/src/Grid/Filter/Scope.php index 2040e104d2..35d29a78a2 100644 --- a/src/Grid/Filter/Scope.php +++ b/src/Grid/Filter/Scope.php @@ -76,6 +76,19 @@ public function render() return "
  • {$this->label}
  • "; } + /** + * Set this scope as default. + * + * @return self + */ + public function asDefault() + { + if (!request()->input('_scope_')) { + request()->merge(['_scope_' => $this->key,]); + } + return $this; + } + /** * @param string $method * @param array $arguments From a2fafe2c0f288aa28be317bc71e2557f450d74ad Mon Sep 17 00:00:00 2001 From: "xiaohui.lam" Date: Tue, 21 Jan 2020 13:32:45 +0800 Subject: [PATCH 012/340] psr2 --- src/Grid/Filter/Scope.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grid/Filter/Scope.php b/src/Grid/Filter/Scope.php index 35d29a78a2..09398275a2 100644 --- a/src/Grid/Filter/Scope.php +++ b/src/Grid/Filter/Scope.php @@ -84,7 +84,7 @@ public function render() public function asDefault() { if (!request()->input('_scope_')) { - request()->merge(['_scope_' => $this->key,]); + request()->merge(['_scope_' => $this->key]); } return $this; } From 3682ad6e1a94a909fd33bb1ea99d9204b12e0931 Mon Sep 17 00:00:00 2001 From: "xiaohui.lam" Date: Tue, 21 Jan 2020 13:33:12 +0800 Subject: [PATCH 013/340] psr2 --- src/Grid/Filter/Scope.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Grid/Filter/Scope.php b/src/Grid/Filter/Scope.php index 09398275a2..9890acc2eb 100644 --- a/src/Grid/Filter/Scope.php +++ b/src/Grid/Filter/Scope.php @@ -86,6 +86,7 @@ public function asDefault() if (!request()->input('_scope_')) { request()->merge(['_scope_' => $this->key]); } + return $this; } From e8edc1809d12d9276ae48b190bfc685f3be61cfd Mon Sep 17 00:00:00 2001 From: motikan2010 Date: Fri, 31 Jan 2020 11:43:48 +0900 Subject: [PATCH 014/340] fix '/admin/auth/logs' page Authenticated Store XSS bug --- src/Controllers/LogController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php index 2b457eb20d..3988673dc0 100644 --- a/src/Controllers/LogController.php +++ b/src/Controllers/LogController.php @@ -41,7 +41,7 @@ protected function grid() return '{}'; } - return '
    '.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'
    '; + return '
    '.json_encode($input, JSON_PRETTY_PRINT | JSON_HEX_TAG).'
    '; }); $grid->column('created_at', trans('admin.created_at')); From c9f4d9f280662a18f4015933ea8c4204c3b3085c Mon Sep 17 00:00:00 2001 From: z-song Date: Mon, 3 Feb 2020 18:26:16 +0800 Subject: [PATCH 015/340] fix #4337 --- resources/views/partials/sidebar.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php index 5d33c3b425..1eac1bdc99 100644 --- a/resources/views/partials/sidebar.blade.php +++ b/resources/views/partials/sidebar.blade.php @@ -37,7 +37,7 @@ @endif -