jqh 5 years ago
parent
commit
93bd94b727

+ 2 - 1
.gitignore

@@ -1,3 +1,4 @@
 vendor/
 composer.lock
-.idea
+.idea
+.php_cs.cache

+ 20 - 0
.php_cs

@@ -0,0 +1,20 @@
+<?php
+
+return (new MattAllan\LaravelCodeStyle\Config())
+    ->setFinder(
+        PhpCsFixer\Finder::create()
+            ->exclude('vendor')
+            ->in(__DIR__)
+    )
+    ->setRules([
+        '@Laravel' => true,
+        '@Laravel:risky' => true,
+        'array_syntax' => array('syntax' => 'short'),
+        'ordered_imports' => true,
+        'no_useless_else' => true,
+        'no_useless_return' => true,
+        'php_unit_construct' => true,
+        'php_unit_strict' => true,
+        'yoda_style' => false,
+    ])
+    ->setRiskyAllowed(true);

+ 10 - 6
README.md

@@ -16,6 +16,9 @@
 
 <p align="center">
     <a href="https://github.com/jqhph/dcat-admin/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-7389D8.svg?style=flat" ></a>
+    <a href="https://travis-ci.org/jqhph/dcat-admin">
+        <img src="https://travis-ci.org/jqhph/dcat-admin.svg?branch=master" alt="Build Status">
+    </a>
     <a href="https://styleci.io/repos/182349597">
         <img src="https://github.styleci.io/repos/182349597/shield" alt="StyleCI">
     </a>
@@ -41,9 +44,9 @@
 
 近几年,前后端分离方案已经发展成前端技术的主流,也是未来的发展趋势。那么我为什么不把Laravel Admin改造成前后端分离的模式呢?原因如下:
 
-+ 改成前后端分离会增加项目复杂度,提高了使用门槛。
-+ 保持`Laravel Admin`架构的前后端分离(类似`Laravel nova`)只是“技术角度”的前后端分离,从团队合作的角度而言并不能做到前后端分离,实际上不论是前端还是后端的工作都需要后端去做,所以这么做可能不但无法减轻开发者的工作量,反而会增加工作量。
-+ 前后端分离技术固然已经是行业的主流和趋势,但是基于`jQuery`的非前后端分离项目也有自己的优势,比如门槛低、类库非常丰富等等,所以市场占有率依然极高
++ 这个项目的设计方向是简单、高效,方便后端开发者快速搭建后台系统,而改成前后端分离无疑会增加项目复杂度,提高了使用门槛。
++ 保持`Laravel Admin`架构的前后端分离(类似`Laravel nova`)只是“技术角度”的前后端分离,从团队合作的角度而言并不能做到前后端分离,实际上不论是前端还是后端的工作都需要后端去做,所以这么做可能不但无法减轻开发者的工作量,反而可能会增加工作量。
++ 前后端分离技术固然已经是行业的主流和趋势,但是基于`jQuery`的非前后端分离项目也有自己的优势,比如门槛低、类库非常丰富等等。
 + 不是什么项目都适合采用前后端分离方案,显然对于希望控制人力成本的小公司和个人开发者而言,基于`jQuery`的非前后端分离项目显然更加的简单高效。
 
 </details>
@@ -58,13 +61,14 @@
 - [x] 按需加载静态资源,无需担心安装组件过多
 - [x] 简单清晰的数据操作接口,可随意切换数据源
 - [x] 基于`Bootstrap3`的栅格布局系统
-- [x] 数据表格构建工具,内置 20+ 种字段类型,10+ 种表格常用功能(如双表头、数据导出、快捷搜索、快捷创建、批量操作等)
+- [x] 数据表格构建工具,内置 20+ 种字段类型,10+ 种表格常用功能(如组合表头、数据导出、快捷搜索、快捷创建、批量操作等)
+- [x] 树状表格功能构建工具,支持分页和点击加载
 - [x] 数据表格搜索工具,内置 20+ 种过滤器,近 10 种表单类型
 - [x] 数据表单构建工具,内置 50+ 种表单类型,支持异步提交
 - [x] 分步表单构建工具
 - [x] 弹窗表单构建工具
 - [x] 数据详情页构建工具
-- [x] 无限层级树状页面构建工具
+- [x] 无限层级树状页面构建工具,支持用拖拽的方式实现数据的层级、排序等操作
 - [x] 可视化代码生成器,支持生成增删改查代码、语言包、数据表等,可根据数据表生成增删改查页面
 - [x] 内置 40+ 种常用页面组件(如图表、下拉菜单、Tab卡片、提示工具、提示卡片等)
 - [x] Section功能(类似`Wordpress`的过滤器Filter)
@@ -94,7 +98,7 @@ composer require dcat/laravel-admin
 然后运行下面的命令来发布资源:
 
 ```
-php artisan vendor:publish --provider="Dcat\Admin\AdminServiceProvider"
+php artisan admin:publish
 ```
 
 在该命令会生成配置文件`config/admin.php`,可以在里面修改安装的地址、数据库连接、以及表名,建议都是用默认配置不修改。

+ 4 - 6
composer.json

@@ -26,7 +26,8 @@
         "phpunit/phpunit": "^7.5",
         "fzaninotto/faker": "^1.4",
         "mockery/mockery": "^1.0",
-        "dcat/easy-excel": "^1.0"
+        "dcat/easy-excel": "^1.0",
+        "matt-allan/laravel-code-style": "^0.5.0"
     },
     "autoload": {
         "psr-4": {
@@ -42,14 +43,11 @@
         }
     },
     "scripts": {
-        "phpcs": "vendor/bin/php-cs-fixer fix",
+        "fix-style": "vendor/bin/php-cs-fixer fix",
+        "check-style": "vendor/bin/php-cs-fixer fix --dry-run --diff",
         "phpstan": "vendor/bin/phpstan analyse",
         "test": "vendor/bin/phpunit"
     },
-    "suggest": {
-        "intervention/image": "Required to handling and manipulation upload images (~2.3).",
-        "spatie/eloquent-sortable": "Required to built orderable gird."
-    },
     "extra": {
         "laravel": {
             "providers": [

+ 1 - 1
resources/views/partials/exception.blade.php

@@ -1,5 +1,5 @@
 @if(isset($errors) && $errors->hasBag('exception'))
-    <?php $error = $errors->getBag('exception');?>
+    <?php $error = $errors->getBag('exception'); ?>
     <div class="alert alert-warning alert-dismissable">
         <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
         <h4>

+ 4 - 4
tests/Feature/CombineGridTest.php

@@ -27,15 +27,15 @@ class CombineGridTest extends TestCase
         $firstTr = $this->crawler()->filter('thead tr')->first()->filter('th');
 
         // cost
-        $this->assertEquals('2', (string) $firstTr->eq(2)->attr('rowspan'));
+        $this->assertSame('2', (string) $firstTr->eq(2)->attr('rowspan'));
 
         // avgCost
-        $this->assertEquals('3', (string) $firstTr->eq(3)->attr('colspan'));
+        $this->assertSame('3', (string) $firstTr->eq(3)->attr('colspan'));
 
         // avgVist
-        $this->assertEquals('3', (string) $firstTr->eq(4)->attr('colspan'));
+        $this->assertSame('3', (string) $firstTr->eq(4)->attr('colspan'));
 
         // top
-        $this->assertEquals('3', (string) $firstTr->eq(5)->attr('colspan'));
+        $this->assertSame('3', (string) $firstTr->eq(5)->attr('colspan'));
     }
 }

+ 1 - 1
tests/Feature/OperationLogTest.php

@@ -38,7 +38,7 @@ class OperationLogTest extends TestCase
             ->seeInDatabase($table, ['path' => 'admin/auth/permissions', 'method' => 'GET'])
             ->seeInDatabase($table, ['path' => 'admin/auth/roles', 'method' => 'GET']);
 
-        $this->assertEquals(4, OperationLog::count());
+        $this->assertSame(4, OperationLog::count());
     }
 
     public function testDeleteLogs()

+ 2 - 2
tests/Feature/PermissionsTest.php

@@ -51,7 +51,7 @@ class PermissionsTest extends TestCase
             ->submitForm('Submit', ['slug' => 'can-create', 'name' => 'Can Create', 'http_path' => ['users/create'], 'http_method' => ['GET']])
             ->seePageIs('admin/auth/permissions');
 
-        $this->assertEquals(7, Permission::count());
+        $this->assertSame(7, Permission::count());
 
         $this->visit('admin/auth/roles/1/edit')
             ->see('Edit')
@@ -103,7 +103,7 @@ class PermissionsTest extends TestCase
             ->submitForm('Submit', ['slug' => 'can-remove', 'name' => 'Can Remove', 'http_path' => ['users/*'], 'http_method' => ['DELETE']])
             ->seePageIs('admin/auth/permissions');
 
-        $this->assertEquals(7, Permission::count());
+        $this->assertSame(7, Permission::count());
 
         $this->assertTrue(Administrator::find(2)->cannot('can-remove'));
 

+ 3 - 3
tests/Feature/RolesTest.php

@@ -44,7 +44,7 @@ class RolesTest extends TestCase
             ->seePageIs('admin/auth/users')
             ->seeInDatabase(config('admin.database.users_table'), ['username' => 'Test']);
 
-        $this->assertEquals(1, Role::count());
+        $this->assertSame(1, Role::count());
 
         $this->visit('admin/auth/roles/create')
             ->see('Roles')
@@ -69,7 +69,7 @@ class RolesTest extends TestCase
 
     public function testDeleteRole()
     {
-        $this->assertEquals(1, Role::count());
+        $this->assertSame(1, Role::count());
 
         $this->visit('admin/auth/roles/create')
             ->see('Roles')
@@ -79,7 +79,7 @@ class RolesTest extends TestCase
 //            ->assertEquals(2, Role::count());
 
         $this->delete('admin/auth/roles/2');
-        $this->assertEquals(1, Role::count());
+        $this->assertSame(1, Role::count());
 
 //        $this->delete('admin/auth/roles/1');
 //        $this->assertEquals(0, Role::count());

+ 12 - 12
tests/Feature/SectionTest.php

@@ -13,19 +13,19 @@ class SectionTest extends TestCase
         // view
         admin_inject_section('key1', view('admin-tests::test'));
 
-        $this->assertEquals(admin_section('key1'), '<h1>Hello world</h1>');
+        $this->assertSame(admin_section('key1'), '<h1>Hello world</h1>');
 
         // string
         admin_inject_section('key2', 'test');
 
-        $this->assertEquals(admin_section('key2'), 'test');
+        $this->assertSame(admin_section('key2'), 'test');
 
         // callable
         admin_inject_section('key3', function () {
             return view('admin-tests::test');
         });
 
-        $this->assertEquals(admin_section('key3'), '<h1>Hello world</h1>');
+        $this->assertSame(admin_section('key3'), '<h1>Hello world</h1>');
     }
 
     public function testOptions()
@@ -36,7 +36,7 @@ class SectionTest extends TestCase
             return "previous:{$options->previous},name:{$options->name},age:{$options->age}";
         }, false);
 
-        $this->assertEquals(
+        $this->assertSame(
             admin_section('key1', null, ['name' => 'Mike', 'age' => 18]),
             'previous:value1,name:Mike,age:18'
         );
@@ -49,17 +49,17 @@ class SectionTest extends TestCase
         admin_inject_section('key1', 'test2,');
         admin_inject_section('key1', 'test3,');
 
-        $this->assertEquals(admin_section('key1'), 'test1,test2,test3,');
+        $this->assertSame(admin_section('key1'), 'test1,test2,test3,');
 
         // 2 overwrite
         admin_inject_section('key2', 'test1,');
         admin_inject_section('key2', 'test2,', false);
 
-        $this->assertEquals(admin_section('key2'), 'test2,');
+        $this->assertSame(admin_section('key2'), 'test2,');
 
         admin_inject_section('key2', 'test3,', false);
 
-        $this->assertEquals(admin_section('key2'), 'test3,');
+        $this->assertSame(admin_section('key2'), 'test3,');
 
         // 3 overwrite
         admin_inject_section('key3', 'test1,');
@@ -71,7 +71,7 @@ class SectionTest extends TestCase
             return $options->previous.'test4,';
         }, false);
 
-        $this->assertEquals(admin_section('key3'), 'test2,test3,test4,');
+        $this->assertSame(admin_section('key3'), 'test2,test3,test4,');
     }
 
     public function testSort()
@@ -82,7 +82,7 @@ class SectionTest extends TestCase
         admin_inject_section('key1', '1,', true, 3);
         admin_inject_section('key1', '3,', true, 1);
 
-        $this->assertEquals(admin_section('key1'), '1,2,3,4,');
+        $this->assertSame(admin_section('key1'), '1,2,3,4,');
     }
 
     public function testInjectDefaultSection()
@@ -90,18 +90,18 @@ class SectionTest extends TestCase
         // step1
         admin_inject_default_section('key', 'Hello');
 
-        $this->assertEquals(admin_section('key'), 'Hello');
+        $this->assertSame(admin_section('key'), 'Hello');
 
         // step2
         admin_inject_default_section('key', function ($options) {
             return 'Hello '.$options->var1;
         });
 
-        $this->assertEquals(admin_section('key', null, ['var1' => 'world']), 'Hello world');
+        $this->assertSame(admin_section('key', null, ['var1' => 'world']), 'Hello world');
 
         // step3
         admin_inject_section('key', '');
 
-        $this->assertEquals(admin_section('key'), '');
+        $this->assertSame(admin_section('key'), '');
     }
 }

+ 12 - 12
tests/Feature/TranslationTest.php

@@ -18,13 +18,13 @@ class TranslationTest extends TestCase
 
         $this->registerTranslator();
 
-        $this->assertEquals('user', admin_controller_slug());
+        $this->assertSame('user', admin_controller_slug());
 
-        $this->assertEquals(admin_trans_field('username'), '用户名');
-        $this->assertEquals(admin_trans_field('profile.postcode'), '邮政编码');
+        $this->assertSame(admin_trans_field('username'), '用户名');
+        $this->assertSame(admin_trans_field('profile.postcode'), '邮政编码');
 
-        $this->assertEquals(admin_trans_field('value'), 'value');
-        $this->assertEquals(admin_trans_field('profile.value'), 'value');
+        $this->assertSame(admin_trans_field('value'), 'value');
+        $this->assertSame(admin_trans_field('profile.value'), 'value');
     }
 
     public function testTransLabel()
@@ -33,9 +33,9 @@ class TranslationTest extends TestCase
 
         $this->registerTranslator();
 
-        $this->assertEquals('user', admin_controller_slug());
+        $this->assertSame('user', admin_controller_slug());
 
-        $this->assertEquals(admin_trans_label('user'), '用户');
+        $this->assertSame(admin_trans_label('user'), '用户');
     }
 
     public function testTransGlobal()
@@ -44,14 +44,14 @@ class TranslationTest extends TestCase
 
         $this->registerTranslator();
 
-        $this->assertEquals('user', admin_controller_slug());
+        $this->assertSame('user', admin_controller_slug());
 
-        $this->assertEquals(admin_trans_field('id'), 'ID');
-        $this->assertEquals(admin_trans_field('profile.address'), '地址');
+        $this->assertSame(admin_trans_field('id'), 'ID');
+        $this->assertSame(admin_trans_field('profile.address'), '地址');
 
-        $this->assertEquals(admin_trans_label('List'), '列表');
+        $this->assertSame(admin_trans_label('List'), '列表');
 
-        $this->assertEquals(admin_trans_label('Create'), 'Create');
+        $this->assertSame(admin_trans_label('Create'), 'Create');
     }
 
     protected function registerTranslator()

+ 1 - 1
tests/Feature/UserFormTest.php

@@ -153,7 +153,7 @@ class UserFormTest extends TestCase
 
         $user = UserModel::with('profile')->find($id);
 
-        $this->assertEquals($user->username, 'hello world');
+        $this->assertSame($user->username, 'hello world');
     }
 
     public function testUpdateFormWithRule()

+ 2 - 2
tests/Feature/UserGridTest.php

@@ -128,7 +128,7 @@ class UserGridTest extends TestCase
 
         $this->visit('admin/tests/users?username=mi');
 
-        $this->assertEquals($this->crawler()->filter('td a i[class*=fa-ellipsis-v]')->count(), count($users->toArray()));
+        $this->assertSame($this->crawler()->filter('td a i[class*=fa-ellipsis-v]')->count(), count($users->toArray()));
 
         foreach ($users as $user) {
             $this->seeInElement('td', $user->username);
@@ -214,7 +214,7 @@ class UserGridTest extends TestCase
             ->seeInElement('select option', 50)
             ->seeInElement('select option', 100);
 
-        $this->assertEquals('http://localhost:8000/admin/tests/users?per_page=20', $this->crawler()->filter('select option[selected]')->attr('value'));
+        $this->assertSame('http://localhost:8000/admin/tests/users?per_page=20', $this->crawler()->filter('select option[selected]')->attr('value'));
 
         $perPage = mt_rand(1, 98);