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

Merge branch '2.0' into gitee2

jqh 4 лет назад
Родитель
Сommit
59c9d5c44d

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

@@ -33,7 +33,7 @@
 
 <script require="@moment,@bootstrap-datetimepicker" init="{!! $selector['start'] !!}">
     var options = {!! admin_javascript_json($options) !!};
-    var $end = $this.parents('.row').find('{!! $selector['end'] !!}');
+    var $end = $('{!! $selector['end'] !!}');
 
     $this.datetimepicker(options);
     $end.datetimepicker($.extend(options, {useCurrent: false}));

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

@@ -33,7 +33,7 @@
 
 <script require="@moment,@bootstrap-datetimepicker" init="{!! $selector['start'] !!}">
     var options = {!! admin_javascript_json($options) !!};
-    var $end = $this.parents('.row').find('{!! $selector['end'] !!}');
+    var $end = $('{!! $selector['end'] !!}');
 
     $this.datetimepicker(options);
     $end.datetimepicker($.extend(options, {useCurrent: false}));

+ 2 - 2
resources/views/form/timerange.blade.php

@@ -33,12 +33,12 @@
 
 <script require="@moment,@bootstrap-datetimepicker" init="{!! $selector['start'] !!}">
     var options = {!! admin_javascript_json($options) !!};
-    var $end = $this.parents('.row').find('{!! $selector['end'] !!}');
+    var $end = $('{!! $selector['end'] !!}');
 
     $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);

+ 1 - 1
src/Admin.php

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

+ 36 - 0
src/Form.php

@@ -1505,6 +1505,42 @@ class Form implements Renderable
         return $this;
     }
 
+    /**
+     * default View Checked on footer.
+     *
+     * @return $this
+     */
+    public function defaultViewChecked(bool $checked = true)
+    {
+        $this->builder->footer()->defaultViewChecked($checked);
+
+        return $this;
+    }
+
+    /**
+     * default Editing Checked on footer.
+     *
+     * @return $this
+     */
+    public function defaultEditingChecked(bool $checked = true)
+    {
+        $this->builder->footer()->defaultEditingChecked($checked);
+
+        return $this;
+    }
+
+    /**
+     * default Creating Checked on footer.
+     *
+     * @return $this
+     */
+    public function defaultCreatingChecked(bool $checked = true)
+    {
+        $this->builder->footer()->defaultCreatingChecked($checked);
+
+        return $this;
+    }
+
     /**
      * Disable `view` tool.
      *

+ 63 - 1
src/Form/Footer.php

@@ -42,6 +42,13 @@ class Footer implements Renderable
      */
     protected $checkboxes = ['view' => true, 'continue_editing' => true, 'continue_creating' => true];
 
+    /**
+     * Default checked.
+     *
+     * @var arrays
+     */
+    protected $defaultcheckeds = ['view' => false, 'continue_editing' => false, 'continue_creating' => false];
+
     /**
      * Footer constructor.
      *
@@ -122,6 +129,48 @@ class Footer implements Renderable
         return $this;
     }
 
+    /**
+     * default View Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultViewChecked(bool $checked = true)
+    {
+        $this->defaultcheckeds['view'] = $checked;
+
+        return $this;
+    }
+
+    /**
+     * default Editing Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultEditingChecked(bool $checked = true)
+    {
+        $this->defaultcheckeds['continue_editing'] = $checked;
+
+        return $this;
+    }
+
+    /**
+     * default Creating Checked.
+     *
+     * @param bool $checked
+     *
+     * @return $this
+     */
+    public function defaultCreatingChecked(bool $checked = true)
+    {
+        $this->defaultcheckeds['continue_creating'] = $checked;
+
+        return $this;
+    }
+
     /**
      * Build checkboxes.
      *
@@ -134,6 +183,7 @@ class Footer implements Renderable
         }
 
         $options = [];
+        $checked = [];
 
         if ($this->checkboxes['continue_editing']) {
             $options[1] = sprintf('<span class="text-80 text-bold">%s</span>', trans('admin.continue_editing'));
@@ -147,11 +197,23 @@ class Footer implements Renderable
             $options[3] = sprintf('<span class="text-80 text-bold">%s</span>', trans('admin.view'));
         }
 
+        if ($this->defaultcheckeds['continue_editing']) {
+            $checked[] = 1;
+        }
+
+        if ($this->defaultcheckeds['continue_creating']) {
+            $checked[] = 2;
+        }
+
+        if ($this->defaultcheckeds['view']) {
+            $checked[] = 3;
+        }
+
         if (! $options) {
             return;
         }
 
-        return (new Checkbox('after-save', $options))->inline()->circle(true);
+        return (new Checkbox('after-save', $options))->check($checked)->inline()->circle(true);
     }
 
     /**

+ 30 - 10
src/Grid/Displayers/Actions.php

@@ -90,6 +90,11 @@ class Actions extends AbstractDisplayer
         }
     }
 
+    public function view(bool $value = true)
+    {
+        return $this->setAction('view', $value);
+    }
+
     /**
      * Disable view action.
      *
@@ -99,7 +104,12 @@ class Actions extends AbstractDisplayer
      */
     public function disableView(bool $disable = true)
     {
-        return $this->disableDefaultAction('view', $disable);
+        return $this->setAction('view', ! $disable);
+    }
+
+    public function delete(bool $value = true)
+    {
+        return $this->setAction('delete', $value);
     }
 
     /**
@@ -111,7 +121,12 @@ class Actions extends AbstractDisplayer
      */
     public function disableDelete(bool $disable = true)
     {
-        return $this->disableDefaultAction('delete', $disable);
+        return $this->setAction('delete', ! $disable);
+    }
+
+    public function edit(bool $value = true)
+    {
+        return $this->setAction('edit', $value);
     }
 
     /**
@@ -123,7 +138,12 @@ class Actions extends AbstractDisplayer
      */
     public function disableEdit(bool $disable = true)
     {
-        return $this->disableDefaultAction('edit', $disable);
+        return $this->setAction('edit', ! $disable);
+    }
+
+    public function quickEdit(bool $value = true)
+    {
+        return $this->setAction('quickEdit', $value);
     }
 
     /**
@@ -135,7 +155,7 @@ class Actions extends AbstractDisplayer
      */
     public function disableQuickEdit(bool $disable = true)
     {
-        return $this->disableDefaultAction('quickEdit', $disable);
+        return $this->setAction('quickEdit', ! $disable);
     }
 
     /**
@@ -144,9 +164,9 @@ class Actions extends AbstractDisplayer
      *
      * @return $this
      */
-    protected function disableDefaultAction(string $key, bool $disable)
+    protected function setAction(string $key, bool $value)
     {
-        $this->actions[$key] = ! $disable;
+        $this->actions[$key] = $value;
 
         return $this;
     }
@@ -180,10 +200,10 @@ class Actions extends AbstractDisplayer
      */
     protected function resetDefaultActions()
     {
-        $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'));
+        $this->view($this->grid->option('view_button'));
+        $this->edit($this->grid->option('edit_button'));
+        $this->quickEdit($this->grid->option('quick_edit_button'));
+        $this->delete($this->grid->option('delete_button'));
     }
 
     /**

+ 6 - 0
src/Grid/Exporters/AbstractExporter.php

@@ -230,6 +230,12 @@ abstract class AbstractExporter implements ExporterInterface
     {
         foreach ($data as &$row) {
             $row = Arr::dot($row);
+
+            foreach ($row as &$v) {
+                if (is_array($v) || is_object($v)) {
+                    $v = json_encode($v, JSON_UNESCAPED_UNICODE);
+                }
+            }
         }
 
         return $data;

+ 1 - 1
src/Http/Middleware/Permission.php

@@ -85,7 +85,7 @@ class Permission
      */
     protected function isApiRoute($request)
     {
-        return $request->routeIs('dcat.api.*');
+        return $request->routeIs(admin_api_route_name('*'));
     }
 
     /**

+ 9 - 13
src/Repositories/EloquentRepository.php

@@ -307,22 +307,18 @@ class EloquentRepository extends Repository implements TreeRepository
     {
         [$relationName, $relationColumn] = explode('.', $column, 2);
 
-        if ($model->getQueries()->contains(function ($query) use ($relationName) {
-            return $query['method'] == 'with' && in_array($relationName, $query['arguments']);
-        })) {
-            $relation = $this->model()->$relationName();
+        $relation = $this->model()->$relationName();
 
-            $model->addQuery('select', [$this->model()->getTable().'.*']);
+        $model->addQuery('select', [$this->model()->getTable().'.*']);
 
-            $model->addQuery('join', $this->joinParameters($relation));
+        $model->addQuery('join', $this->joinParameters($relation));
 
-            $this->setOrderBy(
-                $model,
-                $relation->getRelated()->getTable().'.'.str_replace('.', '->', $relationColumn),
-                $type,
-                $cast
-            );
-        }
+        $this->setOrderBy(
+            $model,
+            $relation->getRelated()->getTable().'.'.str_replace('.', '->', $relationColumn),
+            $type,
+            $cast
+        );
     }
 
     /**

+ 26 - 0
src/Support/Helper.php

@@ -34,6 +34,8 @@ class Helper
         'video'      => 'mkv|rmvb|flv|mp4|avi|wmv|rm|asf|mpeg',
     ];
 
+    protected static $controllerNames = [];
+
     /**
      * 把给定的值转化为数组.
      *
@@ -111,6 +113,30 @@ class Helper
         return (string) $value;
     }
 
+    /**
+     * 获取当前控制器名称.
+     *
+     * @return mixed|string
+     */
+    public static function getControllerName()
+    {
+        $router = app('router');
+
+        if (! $router->current()) {
+            return 'undefined';
+        }
+
+        $actionName = $router->current()->getActionName();
+
+        if (! isset(static::$controllerNames[$actionName])) {
+            $controller = class_basename(explode('@', $actionName)[0]);
+
+            static::$controllerNames[$actionName] = str_replace('Controller', '', $controller);
+        }
+
+        return static::$controllerNames[$actionName];
+    }
+
     /**
      * @param array $attributes
      *

+ 1 - 1
src/Support/Setting.php

@@ -26,7 +26,7 @@ class Setting extends Fluent
             return [];
         }
 
-        return json_decode($value, true) ?: [];
+        return is_array($value) ? $value : (json_decode($value, true) ?: []);
     }
 
     /**

+ 22 - 23
src/Support/helpers.php

@@ -9,6 +9,8 @@ use Symfony\Component\HttpFoundation\Response;
 
 if (! function_exists('admin_setting')) {
     /**
+     * 获取或保存配置参数.
+     *
      * @param string|array $key
      * @param mixed         $default
      *
@@ -32,6 +34,8 @@ if (! function_exists('admin_setting')) {
 
 if (! function_exists('admin_setting_array')) {
     /**
+     * 获取配置参数并转化为数组格式.
+     *
      * @param string $key
      * @param mixed  $default
      *
@@ -45,6 +49,8 @@ if (! function_exists('admin_setting_array')) {
 
 if (! function_exists('admin_extension_setting')) {
     /**
+     * 获取扩展配置参数.
+     *
      * @param string       $extension
      * @param string|array $key
      * @param mixed        $default
@@ -269,28 +275,11 @@ if (! function_exists('admin_controller_name')) {
      */
     function admin_controller_name()
     {
-        static $name = [];
-
-        $router = app('router');
-
-        if (! $router->current()) {
-            return 'undefined';
-        }
-
-        $actionName = $router->current()->getActionName();
-
-        if (! isset($name[$actionName])) {
-            $controller = class_basename(explode('@', $actionName)[0]);
-
-            $name[$actionName] = str_replace('Controller', '', $controller);
-        }
-
-        return $name[$actionName];
+        return Helper::getControllerName();
     }
 }
 
 if (! function_exists('admin_path')) {
-
     /**
      * Get admin path.
      *
@@ -367,7 +356,6 @@ if (! function_exists('admin_toastr')) {
 }
 
 if (! function_exists('admin_success')) {
-
     /**
      * Flash a success message bag to session.
      *
@@ -381,7 +369,6 @@ if (! function_exists('admin_success')) {
 }
 
 if (! function_exists('admin_error')) {
-
     /**
      * Flash a error message bag to session.
      *
@@ -395,7 +382,6 @@ if (! function_exists('admin_error')) {
 }
 
 if (! function_exists('admin_warning')) {
-
     /**
      * Flash a warning message bag to session.
      *
@@ -409,7 +395,6 @@ if (! function_exists('admin_warning')) {
 }
 
 if (! function_exists('admin_info')) {
-
     /**
      * Flash a message bag to session.
      *
@@ -589,6 +574,20 @@ if (! function_exists('admin_require_assets')) {
     }
 }
 
+if (! function_exists('admin_javascript')) {
+    /**
+     * 暂存JS代码,并使用唯一字符串代替.
+     *
+     * @param string $scripts
+     *
+     * @return string
+     */
+    function admin_javascript(string $scripts)
+    {
+        return Dcat\Admin\Support\JavaScript::make($scripts);
+    }
+}
+
 if (! function_exists('admin_javascript_json')) {
     /**
      * @param array|object $data
@@ -603,7 +602,7 @@ if (! function_exists('admin_javascript_json')) {
 
 if (! function_exists('admin_exit')) {
     /**
-     * 响应并中断后续逻辑.
+     * 响应数据并中断后续逻辑.
      *
      * @param Response|string|array $response
      *

+ 34 - 0
src/Tree.php

@@ -273,11 +273,21 @@ class Tree implements Renderable
         $this->useCreate = ! $value;
     }
 
+    public function showCreateButton(bool $value = true)
+    {
+        return $this->disableCreateButton(! $value);
+    }
+
     public function disableQuickCreateButton(bool $value = true)
     {
         $this->useQuickCreate = ! $value;
     }
 
+    public function showQuickCreateButton(bool $value = true)
+    {
+        return $this->disableQuickCreateButton(! $value);
+    }
+
     /**
      * @param string $width
      * @param string $height
@@ -303,6 +313,10 @@ class Tree implements Renderable
         $this->useSave = ! $value;
     }
 
+    public function showSaveButton(bool $value = true)
+    {
+        return $this->disableSaveButton(! $value);
+    }
     /**
      * Disable refresh.
      *
@@ -315,6 +329,11 @@ class Tree implements Renderable
         $this->useRefresh = ! $value;
     }
 
+    public function showRefreshButton(bool $value = true)
+    {
+        return $this->disableRefreshButton(! $value);
+    }
+
     public function disableQuickEditButton(bool $value = true)
     {
         $this->actions(function (Actions $actions) use ($value) {
@@ -322,6 +341,11 @@ class Tree implements Renderable
         });
     }
 
+    public function showQuickEditButton(bool $value = true)
+    {
+        return $this->disableQuickEditButton(! $value);
+    }
+
     public function disableEditButton(bool $value = true)
     {
         $this->actions(function (Actions $actions) use ($value) {
@@ -329,6 +353,11 @@ class Tree implements Renderable
         });
     }
 
+    public function showEditButton(bool $value = true)
+    {
+        return $this->disableEditButton(! $value);
+    }
+
     public function disableDeleteButton(bool $value = true)
     {
         $this->actions(function (Actions $actions) use ($value) {
@@ -336,6 +365,11 @@ class Tree implements Renderable
         });
     }
 
+    public function showDeleteButton(bool $value = true)
+    {
+        return $this->disableDeleteButton(! $value);
+    }
+
     /**
      * @param Closure $closure
      *

+ 20 - 5
src/Tree/Actions.php

@@ -79,25 +79,40 @@ class Actions implements Renderable
         return $this->row->{$this->parent()->getKeyName()};
     }
 
+    public function quickEdit(bool $value = true)
+    {
+        $this->actions['quickEdit'] = $value;
+
+        return $this;
+    }
+
     public function disableQuickEdit(bool $value = true)
     {
-        $this->actions['quickEdit'] = ! $value;
+        return $this->quickEdit(! $value);
+    }
+
+    public function edit(bool $value = true)
+    {
+        $this->actions['edit'] = $value;
 
         return $this;
     }
 
     public function disableEdit(bool $value = true)
     {
-        $this->actions['edit'] = ! $value;
+        return $this->edit(! $value);
+    }
+
+    public function delete(bool $value = true)
+    {
+        $this->actions['delete'] = $value;
 
         return $this;
     }
 
     public function disableDelete(bool $value = true)
     {
-        $this->actions['delete'] = ! $value;
-
-        return $this;
+        return $this->delete(! $value);
     }
 
     public function render()