]> _ Git - cubist_cms-back.git/commitdiff
wip #3699 @7
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Jun 2020 12:39:42 +0000 (14:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 15 Jun 2020 12:39:42 +0000 (14:39 +0200)
16 files changed:
src/CubistBackpackServiceProvider.php
src/app/Magic/Fields/RolesPermissions.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicAuthenticatable.php
src/resources/config/app.php [new file with mode: 0644]
src/resources/views/fields/bunch.blade.php
src/resources/views/fields/bunch_multiple.blade.php
src/resources/views/fields/button.blade.php
src/resources/views/fields/color.blade.php
src/resources/views/fields/hidden.blade.php
src/resources/views/fields/rangeofvalues.blade.php
src/resources/views/fields/select2_from_array.blade.php
src/resources/views/fields/select_and_order.blade.php
src/resources/views/fields/simplemde.blade.php
src/resources/views/fields/tags.blade.php
src/resources/views/fields/text.blade.php

index a825f4e93469c819fa14232799ce16f81f0591f2..85a3425064ddfe2b0624ae570dce76997c80c6a9 100644 (file)
@@ -49,6 +49,7 @@ class CubistBackpackServiceProvider extends ServiceProvider
             return "<?php echo \$__env->make('" . self::NAMESPACE . "::favicon', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>";
         });
 
+
         $this->app->extend('crud', function () {
             return new CubistCrudPanel();
         });
@@ -62,6 +63,15 @@ class CubistBackpackServiceProvider extends ServiceProvider
      */
     public function register()
     {
+        $resourcesDir = __DIR__ . '/resources';
+
+        $configs = ['app', 'cubist'];
+
+        foreach ($configs as $config) {
+            $this->mergeConfigFrom($resourcesDir . '/config/' . $config . '.php', $config);
+        }
+
+
         $this->commands([
             InstallCommand::class,
             UpdateCommand::class,
index a1ffc0db96a47e774eb15a2b851c45f9afbbb374..20b25353f3a00eb15c8caef6f8da2b92f75a281e 100644 (file)
@@ -3,7 +3,7 @@
 
 namespace Cubist\Backpack\app\Magic\Fields;
 
-use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+use Illuminate\Support\Str;
 
 class RolesPermissions extends Field
 {
index 79b796491b770b258db35257dc02cd072d465757..a42e854d6ad0e93187343aefc13d8b6a5eef0bbd 100644 (file)
@@ -62,12 +62,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     protected $fakeColumns = [];
 
 
-    /**
-     * @var Field[]
-     */
-    protected $_relationships = [];
-
-
     /**
      * @var array
      */
@@ -232,10 +226,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     {
         $field = $this->bunchAddField($attributes);
         $field->setModelInstance($this);
-        if (is_callable([$field, 'getRelationship']) && null !== $field->getRelationship()) {
-            $this->_addRelationship($field);
-        }
-
         $name = $field->getAttribute('name');
 
         if ($field->getAttribute('fake', false) === true) {
@@ -350,26 +340,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         }
 
         $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
-
-        foreach ($this->_relationships as $relationship) {
-            if ($relationship->getRelationship() === 'belongsToMany') {
-
-                $model = self::_toModel($relationship->getAttribute('model'));
-
-                $reltable = $schema->createTable($this->getRelationShipTable($relationship));
-                $reltable->addColumn('id', 'integer', ['autoincrement' => true, 'unsigned' => true]);
-                $reltable->setPrimaryKey(['id']);
-                $reltable->addColumn($this->getForeignKey(), 'integer', ['unsigned' => true]);
-                $reltable->addColumn($model->getForeignKey(), 'integer', ['unsigned' => true]);
-                $this->_addTimestampsDatabaseColumns($reltable);
-            }
-        }
-
         foreach ($this->_fields as $field) {
-            if ($field->getRelationship() === 'belongsToMany') {
-                continue;
-            }
-            if ($field->getAttribute('fake', false) !== false) {
+           if ($field->getAttribute('fake', false) !== false) {
                 continue;
             }
             $field->defineDbColumn($table);
@@ -399,68 +371,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         $table->addColumn('deleted_at', 'datetime', $options);
     }
 
-//    public function __call($method, $parameters)
-//    {
-//
-//        // Set mutators
-//        if (preg_match('/^set([a-zA-Z0-9]+)Attribute$/', $method, $matches)) {
-//            $attr = Str::snake($matches[1]);
-//
-//            if (isset($this->_fields[$attr])) {
-//                $callback = [$this->_fields[$attr], 'setMutator'];
-//                if (is_callable($callback)) {
-//                    return call_user_func_array($callback, $parameters);
-//                }
-//            }
-//        }
-//
-//        // magic call of relationships
-//        foreach ($this->_relationships as $relationship) {
-//            /** @var $relationship Field */
-//            if ($method == $relationship->getAttribute('entity')) {
-//                return $this->relationship($relationship);
-//            }
-//        }
-//
-//        return parent::__call($method, $parameters);
-//    }
-//
-//    /**
-//     * @param $field Field|string
-//     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\BelongsToMany
-//     */
-//    public function relationship($field)
-//    {
-//        if (is_string($field)) {
-//            foreach ($this->_fields as $f) {
-//                if ($f->getAttribute('entity') == $field) {
-//                    $field = $f;
-//                    break;
-//                }
-//            }
-//        }
-//        switch ($field->getRelationship()) {
-//            case 'belongsTo':
-//                return $this->belongsTo($field->getAttribute('model'), $field->getAttribute('name'));
-//            case 'belongsToMany':
-//                return $this->belongsToMany($field->getAttribute('model'), $this->getRelationShipTable($field));
-//        }
-//    }
-//
-//    /**
-//     * @param $field Field
-//     * @return string
-//     */
-//    public function getRelationShipTable($field)
-//    {
-//        /** @var Model $foreignEntity */
-//        $foreignEntity = self::_toModel($field->getAttribute('model'));
-//
-//        if ($field->getRelationship() == 'belongsToMany') {
-//            return $this->getTable() . '_' . $field->getAttribute('name') . '_rel_btm';
-//        }
-//    }
-
     /**
      * @param $class Model|string
      * @return Model
index f88db8c69be55045aa06990bac46e71392141e03..2ddbcdf697df4e372de640b9ffc33291fd019a7a 100644 (file)
@@ -55,10 +55,10 @@ class CubistMagicAuthenticatable extends CubistMagicAbstractModel
             'type' => 'checkbox',
             'tab' => 'Login']);
 
-        $this->addField(['name' => 'permissions',
-            'label' => '',
-            'type' => 'RolesPermissions',
-            'tab' => 'Roles & Permissions']);
+//        $this->addField(['name' => 'permissions',
+//            'label' => '',
+//            'type' => 'RolesPermissions',
+//            'tab' => 'Roles & Permissions']);
 
         $this->addField(['name' => 'remember_token',
             'type' => 'Text',
diff --git a/src/resources/config/app.php b/src/resources/config/app.php
new file mode 100644 (file)
index 0000000..08b2395
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+return [
+    'aliases' => [
+        'App' => Cubist\Backpack\app\Facades\App::class,
+        'Arr' => Illuminate\Support\Arr::class,
+        'Str' => Illuminate\Support\Str::class,
+    ],
+];
index 57bf7347d609490013aec5b024e709ccb316456d..933752d881efcf7a028e6b164916cd8ea8cb874f 100644 (file)
@@ -22,20 +22,20 @@ foreach ($value as $k => $v) {
 ?>
 <div class="bunch__margin col-xs-12">
     <div class="bunch__wrapper col-xs-12">
-        <div @include('crud::inc.field_wrapper_attributes') >
-            <label>{!! $field['label'] !!}</label>
-            @include('crud::inc.field_translatable_icon')
-            <div class="clearfix"></div>
+        @include('crud::fields.inc.wrapper_start')
+        <label>{!! $field['label'] !!}</label>
+        @include('crud::fields.inc.translatable_icon')
+        <div class="clearfix"></div>
 
-            @include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields']))
+        @include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields']))
 
-            <div class="clearfix"></div>
+        <div class="clearfix"></div>
 
-            {{-- HINT --}}
-            @if (isset($field['hint']))
-                <p class="help-block">{!! $field['hint'] !!}</p>
-            @endif
-        </div>
+        {{-- HINT --}}
+        @if (isset($field['hint']))
+            <p class="help-block">{!! $field['hint'] !!}</p>
+        @endif
+        @include('crud::fields.inc.wrapper_end')
     </div>
 </div>
 
index 4c383e04f8b25fd9c7934e772afebe85f4c1a628..291064fcf123534179591ebe8291cddbd1433c27 100644 (file)
@@ -15,9 +15,9 @@ if (!is_string($value)) {
 <div class="bunchmultiple" id="{!! $field['rand'] !!}" data-values="{{ $value }}">
     <input type="hidden" class="hiddenfield" name="{{$field['name']}}" value="{{ $value }}" data-bmid="{!! $field['rand'] !!}"/>
     <div class="bunchmultiple__wrapper" data-bmid="{!! $field['rand'] !!}">
-        <div @include('crud::inc.field_wrapper_attributes') >
+        @include('crud::fields.inc.wrapper_start')
             <label>{!! $field['label'] !!}</label>
-            @include('crud::inc.field_translatable_icon')
+        @include('crud::fields.inc.translatable_icon')
             <div class="clearfix"></div>
 
             <div class="bunchmultiple__items" data-bmid="{!! $field['rand'] !!}">
@@ -52,7 +52,7 @@ if (!is_string($value)) {
             @if (isset($field['hint']))
                 <p class="help-block">{!! $field['hint'] !!}</p>
             @endif
-        </div>
+        @include('crud::fields.inc.wrapper_end')
     </div>
 </div>
 
index 2f069e706bfdd97a3c7647e859e0c8cc6213f879..8cf274a1f2b4c1756a5489d3dd964913132d8a7e 100644 (file)
@@ -18,9 +18,9 @@ $value = array_merge($empty, \Cubist\Util\ArrayUtil::asArray($value));
 
 ?>
 
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+    @include('crud::fields.inc.translatable_icon')
     <div class="clearfix"></div>
     <div class="button__wrapper">
         <div class="col-sm-3 button__field hideifdisabled">
@@ -104,7 +104,7 @@ $value = array_merge($empty, \Cubist\Util\ArrayUtil::asArray($value));
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
 
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 
 {{-- ########################################## --}}
index aba9891e441eda82cd38a4d96d77f612ff1f3235..615e15208d9459562d50024e391fab125283e069 100644 (file)
@@ -1,20 +1,20 @@
 <!-- html5 color input -->
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+    @include('crud::fields.inc.translatable_icon')
     <input
         type="text"
         class="spectrum"
         name="{{ $field['name'] }}"
         value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
-        @include('crud::inc.field_attributes')
+        @include('crud::fields.inc.attributes')
     >
 
     {{-- HINT --}}
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 {{-- ########################################## --}}
 {{-- Extra CSS and JS for this particular field --}}
index b1834db2758c286fe67917ec83235ef27812f236..f80c9d6c6a8e5924246c86628d8e8d90f90fea4f 100644 (file)
@@ -1,17 +1,14 @@
 @php
-       // if not otherwise specified, the hidden input should take up no space in the form
-    if (!isset($field['wrapperAttributes']) || !isset($field['wrapperAttributes']['class']))
-    {
-        $field['wrapperAttributes']['class'] = "hidden";
-    }
+    // if not otherwise specified, the hidden input should take up no space in the form
+  $field['wrapper']['class'] = $field['wrapper']['class'] ?? $field['wrapperAttributes']['class'] ?? "hidden";
 @endphp
 
 <!-- hidden input -->
-<div @include('crud::inc.field_wrapper_attributes') >
-  <input
-       type="hidden"
+@include('crud::fields.inc.wrapper_start')
+<input
+    type="hidden"
     name="{{ $field['name'] }}"
     value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
-    @include('crud::inc.field_attributes')
-       >
-</div>
\ No newline at end of file
+    @include('crud::fields.inc.attributes')
+>
+@include('crud::fields.inc.wrapper_end')
index b92e8877cca671cf8f3c3c8a0f9a4aeb5a4634e7..e27f9924305f40a36f53a3a14087c6827681b8e7 100644 (file)
@@ -21,7 +21,7 @@ if (!isset($value['second'])) {
 }
 
 ?>
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
     <div class="rangeofvalues__wrapper">
         <div class="rangeofvalues__field">
@@ -30,7 +30,7 @@ if (!isset($value['second'])) {
                 <div class="input-group"> @endif
                     @if(isset($field['prefix']))
                         <div class="input-group-addon">{!! $field['prefix'] !!}</div> @endif
-                    <input @include('crud::inc.field_attributes')
+                    <input @include('crud::fields.inc.attributes')
                            value="{{ $value['first'] }}"
                            type="number"
                            name="{{ $field['name'] }}[first]"
@@ -47,7 +47,7 @@ if (!isset($value['second'])) {
                     @if(isset($field['prefix']))
                         <div class="input-group-addon">{!! $field['prefix'] !!}</div> @endif
 
-                    <input @include('crud::inc.field_attributes')
+                    <input @include('crud::fields.inc.attributes')
                            value="{{ $value['second'] }}"
                            type="number"
                            name="{{ $field['name'] }}[second]"
@@ -63,7 +63,7 @@ if (!isset($value['second'])) {
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 @if ($crud->checkIfFieldIsFirstOfItsType($field))
     {{-- FIELD EXTRA CSS  --}}
index 59af16c0613fa867a79363a4d4207b71d5a6f58a..a0dcdaf9c06517731518b40198a49ef9a3b97ff3 100644 (file)
 @endphp
 
 <!-- select2 from array -->
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
     <select
         name="{{ $field['name'] }}@if (isset($field['allows_multiple']) && $field['allows_multiple']==true)[]@endif"
         style="width: 100%"
-        @include('crud::inc.field_attributes', ['default_class' =>  'form-control select2_from_array'])
+        @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_from_array'])
         @if (isset($field['allows_multiple']) && $field['allows_multiple']==true)multiple @endif
     >
 
@@ -54,7 +54,7 @@
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 {{-- ########################################## --}}
 {{-- Extra CSS and JS for this particular field --}}
index 898d09f2e4bddab6673617ec779f2478a7d2e506..73519c67ee9bc565e67cfd4b05cfdb236fc916dc 100644 (file)
@@ -3,9 +3,9 @@
     $values = isset($field['value']) ? (array)$field['value'] : [];
 @endphp
 
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+    @include('crud::fields.inc.translatable_icon')
     <div>
         <ul id="{{ $field['name'] }}_selected" class="{{ $field['name'] }}_connectedSortable select_and_order_selected pull-left">
             @if(old($field["name"]))
@@ -50,7 +50,7 @@
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 
 {{-- ########################################## --}}
index ed74111f422911e6ff802fc87334c9a5d8311f51..60840053eca6314f54170692835d59fcc2358eae 100644 (file)
@@ -1,18 +1,18 @@
 <!-- Simple MDE - Markdown Editor -->
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+    @include('crud::fields.inc.translatable_icon')
     <textarea
         class="simplemde_area" name="{{ $field['name'] }}"
         data-simplemdeattrs="{{json_encode($field['simplemdeAttributes'])}}"
-        @include('crud::inc.field_attributes', ['default_class' => 'form-control'])
+        @include('crud::fields.inc.attributes', ['default_class' => 'form-control'])
        >{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}</textarea>
 
     {{-- HINT --}}
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 
 {{-- ########################################## --}}
index 4a96d78bdb6352247dfdf91cd43238fcae83408d..a4bfa449d5d9477c576ff8a12861db0e9d457518 100644 (file)
@@ -24,9 +24,9 @@ foreach ($values as $value) {
 $values = $normalizedValues;
 
 ?><!-- select2 tags -->
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+@include('crud::fields.inc.translatable_icon')
 
     @if(isset($field['prefix']) || isset($field['suffix']))
         <div class="input-group"> @endif
@@ -35,7 +35,7 @@ $values = $normalizedValues;
             <select
                 name="{{ $field['name'] }}[]"
                 style="width: 100%"
-                @include('crud::inc.field_attributes', ['default_class' =>  'form-control select2_tags'])
+                @include('crud::fields.inc.attributes', ['default_class' =>  'form-control select2_tags'])
                 multiple>
                 @foreach($values as $value)
                     <option name="{{$value}}" selected>{{$value}}</option>
@@ -56,7 +56,7 @@ $values = $normalizedValues;
     @if (isset($field['hint']))
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
-</div>
+@include('crud::fields.inc.wrapper_end')
 
 
 {{-- ########################################## --}}
index b1a1642f1fd97f6882bd0fd70d60fdd27b9eb269..cbc13341aff380274e34b13edcc598c395395296 100644 (file)
@@ -1,17 +1,17 @@
 <!-- text input -->
-<div @include('crud::inc.field_wrapper_attributes') >
+@include('crud::fields.inc.wrapper_start')
     <label>{!! $field['label'] !!}</label>
-    @include('crud::inc.field_translatable_icon')
+    @include('crud::fields.inc.translatable_icon')
 
     @if(isset($field['prefix']) || isset($field['suffix'])) <div class="input-group"> @endif
-        @if(isset($field['prefix'])) <div class="input-group-addon">{!! $field['prefix'] !!}</div> @endif
+        @if(isset($field['prefix'])) <div class="input-group-prepend"><span class="input-group-text">{!! $field['prefix'] !!}</span></div> @endif
         <input
             type="text"
             name="{{ $field['name'] }}"
             value="{{ old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '' }}"
-            @include('crud::inc.field_attributes')
+            @include('crud::fields.inc.attributes')
         >
-        @if(isset($field['suffix'])) <div class="input-group-addon">{!! $field['suffix'] !!}</div> @endif
+        @if(isset($field['suffix'])) <div class="input-group-append"><span class="input-group-text">{!! $field['suffix'] !!}</span></div> @endif
         @if(isset($field['prefix']) || isset($field['suffix'])) </div> @endif
 
     {{-- HINT --}}
         <p class="help-block">{!! $field['hint'] !!}</p>
     @endif
 </div>
-
-
-{{-- FIELD EXTRA CSS  --}}
-{{-- push things in the after_styles section --}}
-
-{{-- @push('crud_fields_styles')
-    <!-- no styles -->
-@endpush --}}
-
-
-{{-- FIELD EXTRA JS --}}
-{{-- push things in the after_scripts section --}}
-
-{{-- @push('crud_fields_scripts')
-    <!-- no scripts -->
-@endpush --}}
-
-
-{{-- Note: you can use @if ($crud->checkIfFieldIsFirstOfItsType($field, $fields)) to only load some CSS/JS once, even though there are multiple instances of it --}}