Jelajahi Sumber

Merge pull request #9 from jqhph/master

拉取最新
yxx 5 tahun lalu
induk
melakukan
e4e62c636d

+ 2 - 1
resources/views/form/container.blade.php

@@ -4,13 +4,14 @@
         <div class="pull-right">{!! $form->renderTools() !!}</div>
     </div>
 @endif
-<div class="box-body">
+<div class="box-body" {!! $tabObj->isEmpty() ? 'style="margin-top: 10px"' : '' !!} >
     @if(!$tabObj->isEmpty())
         @include('admin::form.tab', compact('tabObj', 'form'))
     @else
         <div class="fields-group">
             @if($form->hasRows())
                 <div class="ml-2 mb-2">
+                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                     @foreach($form->rows() as $row)
                         {!! $row->render() !!}
                     @endforeach

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

@@ -1,5 +1,5 @@
 <div>
-    <ul class="nav nav-tabs pl-1">
+    <ul class="nav nav-tabs pl-1" style="margin-top: -1rem">
         @foreach($tabObj->getTabs() as $tab)
             <li class="nav-item">
                 <a class="nav-link {{ $tab['active'] ? 'active' : '' }}" href="#{{ $tab['id'] }}" data-toggle="tab">

+ 1 - 1
resources/views/layouts/full-page.blade.php

@@ -37,7 +37,7 @@
 {!! admin_section(\AdminSection::BODY_INNER_BEFORE) !!}
 
 <div class="app-content content">
-    <div class="wrapper">
+    <div class="wrapper" id="{{ $pjaxContainerId }}">
         @yield('app')
     </div>
 </div>

+ 3 - 0
resources/views/pages/login.blade.php

@@ -16,6 +16,9 @@
     .content {
         overflow-x: hidden;
     }
+    .form-group .control-label {
+        text-align: left;
+    }
 </style>
 
 <div class="login-page bg-40">

+ 11 - 3
resources/views/show/panel.blade.php

@@ -6,9 +6,17 @@
 @endif
 <div class="box-body">
     <div class="form-horizontal mt-1">
-        @foreach($fields as $field)
-            {!! $field->render() !!}
-        @endforeach
+        @if($rows->isEmpty())
+            @foreach($fields as $field)
+                {!! $field->render() !!}
+            @endforeach
+        @else
+            <div>
+                @foreach($rows as $row)
+                    {!! $row->render() !!}
+                @endforeach
+            </div>
+        @endif
         <div class="clearfix"></div>
     </div>
 </div>

+ 7 - 0
resources/views/show/row.blade.php

@@ -0,0 +1,7 @@
+<div class="row">
+    @foreach($fields as $field)
+        <div class="col-md-{{ $field['width'] }}">
+            {!! $field['element']->render() !!}
+        </div>
+    @endforeach
+</div>

+ 1 - 1
src/Admin.php

@@ -35,7 +35,7 @@ class Admin
      *
      * @var string
      */
-    const VERSION = '1.3.2';
+    const VERSION = '1.3.4';
 
     /**
      * @var array

+ 3 - 0
src/Color.php

@@ -3,6 +3,7 @@
 namespace Dcat\Admin;
 
 use Dcat\Admin\Support\Helper;
+use Illuminate\Support\Traits\Macroable;
 
 /**
  * Class Color.
@@ -57,6 +58,8 @@ use Dcat\Admin\Support\Helper;
  */
 class Color
 {
+    use Macroable;
+
     const DEFAULT_COLOR = 'indigo';
 
     /**

+ 3 - 3
src/Form.php

@@ -781,14 +781,14 @@ class Form implements Renderable
         $this->builder->setResourceId($id);
         $this->builder->mode(Builder::MODE_EDIT);
 
+        $this->inputs = $data;
+
         $this->model(new Fluent($this->repository->getDataWhenUpdating($this)));
 
         $this->build();
 
         $this->setFieldOriginalValue();
 
-        $this->inputs = $data;
-
         if ($response = $this->callSubmitted()) {
             return $response;
         }
@@ -835,7 +835,7 @@ class Form implements Renderable
                 $keyName = $field->getKeyName();
 
                 foreach ($input as $k => &$v) {
-                    if (empty($v[$keyName])) {
+                    if (! array_key_exists($keyName, $v)) {
                         $v[$keyName] = $k;
                     }
 

+ 7 - 0
src/Form/Field/HasMany.php

@@ -6,6 +6,7 @@ use Dcat\Admin\Admin;
 use Dcat\Admin\Form;
 use Dcat\Admin\Form\Field;
 use Dcat\Admin\Form\NestedForm;
+use Dcat\Admin\Support\Helper;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Str;
@@ -120,6 +121,12 @@ class HasMany extends Field
                 continue;
             }
 
+            if ($field instanceof File) {
+                $fieldRules = is_string($fieldRules) ? explode('|', $fieldRules) : $fieldRules;
+
+                Helper::deleteByValue($fieldRules, ['image', 'file']);
+            }
+
             $column = $field->column();
 
             if (is_array($column)) {

+ 1 - 1
src/Form/Field/ImageField.php

@@ -76,7 +76,7 @@ trait ImageField
     public function __call($method, $arguments)
     {
         if (static::hasMacro($method)) {
-            return $this;
+            return parent::__call($method, $arguments);
         }
 
         if (! class_exists(ImageManagerStatic::class)) {

+ 0 - 9
src/Form/Field/Table.php

@@ -88,15 +88,6 @@ class Table extends HasMany
         return parent::value($value);
     }
 
-    protected function getKeyName()
-    {
-        if (is_null($this->form)) {
-            return;
-        }
-
-        return 'id';
-    }
-
     public function buildNestedForm($key = null)
     {
         $form = new NestedForm($this->column);

+ 1 - 1
src/Form/Row.php

@@ -109,7 +109,7 @@ class Row implements Renderable
      *
      * @return array
      */
-    public function getFields()
+    public function fields()
     {
         return $this->fields;
     }

+ 1 - 1
src/Form/Tab.php

@@ -72,7 +72,7 @@ class Tab
         foreach ($this->form->rows() as $row) {
             $rowFields = array_map(function ($field) {
                 return $field['element'];
-            }, $row->getFields());
+            }, $row->fields());
 
             $match = false;
 

+ 1 - 1
src/Grid/Displayers/Modal.php

@@ -16,7 +16,7 @@ class Modal extends AbstractDisplayer
 
     protected function generateElementId()
     {
-        $key = $this->getKey() ?: Str::random(8);
+        $key = Str::random(8);
 
         return 'grid-modal-'.$this->grid->getName().$key;
     }

+ 2 - 1
src/Layout/Content.php

@@ -6,11 +6,12 @@ use Closure;
 use Dcat\Admin\Admin;
 use Dcat\Admin\Traits\HasBuilderEvents;
 use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Support\Traits\Macroable;
 use Illuminate\Support\ViewErrorBag;
 
 class Content implements Renderable
 {
-    use HasBuilderEvents;
+    use HasBuilderEvents, Macroable;
 
     /**
      * @var string

+ 29 - 1
src/Show.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin;
 
+use Closure;
 use Dcat\Admin\Contracts\Repository;
 use Dcat\Admin\Show\AbstractTool;
 use Dcat\Admin\Show\Divider;
@@ -9,6 +10,7 @@ use Dcat\Admin\Show\Field;
 use Dcat\Admin\Show\Newline;
 use Dcat\Admin\Show\Panel;
 use Dcat\Admin\Show\Relation;
+use Dcat\Admin\Show\Row;
 use Dcat\Admin\Show\Tools;
 use Dcat\Admin\Traits\HasBuilderEvents;
 use Illuminate\Contracts\Support\Arrayable;
@@ -85,6 +87,10 @@ class Show implements Renderable
      * @var Panel
      */
     protected $panel;
+    /**
+     * @var \Illuminate\Support\Collection
+     */
+    protected $rows;
 
     /**
      * Show constructor.
@@ -108,7 +114,7 @@ class Show implements Renderable
             default:
                 $this->setKey($id);
         }
-
+        $this->rows = new Collection();
         $this->builder = $builder;
 
         $this->initModel($model);
@@ -693,6 +699,28 @@ class Show implements Renderable
         }
     }
 
+    /**
+     * Add a row in Show.
+     *
+     * @param Closure $callback
+     *
+     * @return $this
+     */
+    public function row(Closure $callback)
+    {
+        $this->rows->push(new Row($callback, $this));
+
+        return $this;
+    }
+
+    /**
+     * @return \Illuminate\Support\Collection
+     */
+    public function rows()
+    {
+        return $this->rows;
+    }
+
     /**
      * Add a model field to show.
      *

+ 1 - 0
src/Show/Panel.php

@@ -59,6 +59,7 @@ class Panel implements Renderable
         $this->data = [
             'fields' => new Collection(),
             'tools'  => new Tools($this),
+            'rows'   => $this->parent->rows(),
             'style'  => 'default',
             'title'  => trans('admin.detail'),
         ];

+ 146 - 0
src/Show/Row.php

@@ -0,0 +1,146 @@
+<?php
+
+namespace Dcat\Admin\Show;
+
+use Dcat\Admin\Show;
+use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Support\Collection;
+
+class Row implements Renderable
+{
+    /**
+     * Callback for add field to current row.s.
+     *
+     * @var \Closure
+     */
+    protected $callback;
+
+    /**
+     * Parent show.
+     *
+     * @var Show
+     */
+    protected $show;
+
+    /**
+     * @var Collection
+     */
+    protected $fields;
+
+    /**
+     * Default field width for appended field.
+     *
+     * @var int
+     */
+    protected $defaultFieldWidth = 12;
+
+    /**
+     * Row constructor.
+     *
+     * @param \Closure $callback
+     * @param Show $show
+     */
+    public function __construct(\Closure $callback, Show $show)
+    {
+        $this->callback = $callback;
+
+        $this->show = $show;
+
+        $this->fields = new Collection();
+
+        call_user_func($this->callback, $this);
+    }
+
+    /**
+     * Render the row.
+     *
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+     */
+    public function render()
+    {
+        return view('admin::show.row', ['fields' => $this->fields]);
+    }
+
+    /**
+     * @return Collection|\Dcat\Admin\Show\Field[]
+     */
+    public function fields()
+    {
+        return $this->fields;
+    }
+
+    /**
+     * Set width for a incomming field.
+     *
+     * @param int $width
+     *
+     * @return $this
+     */
+    public function width($width = 12)
+    {
+        $this->defaultFieldWidth = $width;
+
+        return $this;
+    }
+
+    /**
+     * Add field.
+     *
+     * @param string $name
+     * @param string $label
+     *
+     * @return \Dcat\Admin\Show\Field
+     */
+    public function field($name, $label = '')
+    {
+        $field = $this->show->field($name, $label);
+
+        $this->pushField($field);
+
+        return $field;
+    }
+
+    /**
+     * Add field.
+     *
+     * @param $name
+     *
+     * @return \Dcat\Admin\Show\Field|Collection
+     */
+    public function __get($name)
+    {
+        $field = $this->show->field($name);
+
+        $this->pushField($field);
+
+        return $field;
+    }
+
+    /**
+     * @param $method
+     * @param $arguments
+     *
+     * @return \Dcat\Admin\Show\Field
+     */
+    public function __call($method, $arguments)
+    {
+        $field = $this->show->__call($method, $arguments);
+
+        $this->pushField($field);
+
+        return $field;
+    }
+
+    /**
+     * @param \Dcat\Admin\Show\Field $field
+     *
+     * @return void
+     */
+    protected function pushField($field)
+    {
+        $this->fields->push([
+            'width'   => $this->defaultFieldWidth,
+            'element' => $field,
+        ]);
+    }
+}

+ 1 - 0
src/Widgets/DialogForm.php

@@ -305,6 +305,7 @@ JS
         Admin::baseCss([]);
         Admin::baseJs([]);
         Admin::fonts(false);
+        Admin::style('.form-content{ padding-top: 7px }');
 
         $form->wrap(function ($v) {
             return $v;

TEMPAT SAMPAH
tests/resources/drivers/chromedriver-win.exe