From: Vincent Vanwaelscappel Date: Mon, 15 Jun 2020 12:39:42 +0000 (+0200) Subject: wip #3699 @7 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ff3564d81a80daeca6b669f44c5e8ba9374c2301;p=cubist_cms-back.git wip #3699 @7 --- diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php index a825f4e..85a3425 100644 --- a/src/CubistBackpackServiceProvider.php +++ b/src/CubistBackpackServiceProvider.php @@ -49,6 +49,7 @@ class CubistBackpackServiceProvider extends ServiceProvider return "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, diff --git a/src/app/Magic/Fields/RolesPermissions.php b/src/app/Magic/Fields/RolesPermissions.php index a1ffc0d..20b2535 100644 --- a/src/app/Magic/Fields/RolesPermissions.php +++ b/src/app/Magic/Fields/RolesPermissions.php @@ -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 { diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 79b7964..a42e854 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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 diff --git a/src/app/Magic/Models/CubistMagicAuthenticatable.php b/src/app/Magic/Models/CubistMagicAuthenticatable.php index f88db8c..2ddbcdf 100644 --- a/src/app/Magic/Models/CubistMagicAuthenticatable.php +++ b/src/app/Magic/Models/CubistMagicAuthenticatable.php @@ -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 index 0000000..08b2395 --- /dev/null +++ b/src/resources/config/app.php @@ -0,0 +1,8 @@ + [ + 'App' => Cubist\Backpack\app\Facades\App::class, + 'Arr' => Illuminate\Support\Arr::class, + 'Str' => Illuminate\Support\Str::class, + ], +]; diff --git a/src/resources/views/fields/bunch.blade.php b/src/resources/views/fields/bunch.blade.php index 57bf734..933752d 100644 --- a/src/resources/views/fields/bunch.blade.php +++ b/src/resources/views/fields/bunch.blade.php @@ -22,20 +22,20 @@ foreach ($value as $k => $v) { ?>
-
- - @include('crud::inc.field_translatable_icon') -
+ @include('crud::fields.inc.wrapper_start') + + @include('crud::fields.inc.translatable_icon') +
- @include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields'])) + @include('cubist_back::inc.show_bunch_fields', array('bunchfields'=>$field['bunchfields'])) -
+
- {{-- HINT --}} - @if (isset($field['hint'])) -

{!! $field['hint'] !!}

- @endif -
+ {{-- HINT --}} + @if (isset($field['hint'])) +

{!! $field['hint'] !!}

+ @endif + @include('crud::fields.inc.wrapper_end')
diff --git a/src/resources/views/fields/bunch_multiple.blade.php b/src/resources/views/fields/bunch_multiple.blade.php index 4c383e0..291064f 100644 --- a/src/resources/views/fields/bunch_multiple.blade.php +++ b/src/resources/views/fields/bunch_multiple.blade.php @@ -15,9 +15,9 @@ if (!is_string($value)) {
-
+ @include('crud::fields.inc.wrapper_start') - @include('crud::inc.field_translatable_icon') + @include('crud::fields.inc.translatable_icon')
@@ -52,7 +52,7 @@ if (!is_string($value)) { @if (isset($field['hint']))

{!! $field['hint'] !!}

@endif -
+ @include('crud::fields.inc.wrapper_end')
diff --git a/src/resources/views/fields/button.blade.php b/src/resources/views/fields/button.blade.php index 2f069e7..8cf274a 100644 --- a/src/resources/views/fields/button.blade.php +++ b/src/resources/views/fields/button.blade.php @@ -18,9 +18,9 @@ $value = array_merge($empty, \Cubist\Util\ArrayUtil::asArray($value)); ?> -
+@include('crud::fields.inc.wrapper_start') - @include('crud::inc.field_translatable_icon') + @include('crud::fields.inc.translatable_icon')
@@ -104,7 +104,7 @@ $value = array_merge($empty, \Cubist\Util\ArrayUtil::asArray($value));

{!! $field['hint'] !!}

@endif -
+@include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} diff --git a/src/resources/views/fields/color.blade.php b/src/resources/views/fields/color.blade.php index aba9891..615e152 100644 --- a/src/resources/views/fields/color.blade.php +++ b/src/resources/views/fields/color.blade.php @@ -1,20 +1,20 @@ -
+@include('crud::fields.inc.wrapper_start') - @include('crud::inc.field_translatable_icon') + @include('crud::fields.inc.translatable_icon') {{-- HINT --}} @if (isset($field['hint']))

{!! $field['hint'] !!}

@endif -
+@include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} {{-- Extra CSS and JS for this particular field --}} diff --git a/src/resources/views/fields/hidden.blade.php b/src/resources/views/fields/hidden.blade.php index b1834db..f80c9d6 100644 --- a/src/resources/views/fields/hidden.blade.php +++ b/src/resources/views/fields/hidden.blade.php @@ -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 -
- -
\ No newline at end of file + @include('crud::fields.inc.attributes') +> +@include('crud::fields.inc.wrapper_end') diff --git a/src/resources/views/fields/rangeofvalues.blade.php b/src/resources/views/fields/rangeofvalues.blade.php index b92e887..e27f992 100644 --- a/src/resources/views/fields/rangeofvalues.blade.php +++ b/src/resources/views/fields/rangeofvalues.blade.php @@ -21,7 +21,7 @@ if (!isset($value['second'])) { } ?> -
+@include('crud::fields.inc.wrapper_start')
@@ -30,7 +30,7 @@ if (!isset($value['second'])) {
@endif @if(isset($field['prefix']))
{!! $field['prefix'] !!}
@endif - {!! $field['prefix'] !!}
@endif - {!! $field['hint'] !!}

@endif -
+@include('crud::fields.inc.wrapper_end') @if ($crud->checkIfFieldIsFirstOfItsType($field)) {{-- FIELD EXTRA CSS --}} diff --git a/src/resources/views/fields/select2_from_array.blade.php b/src/resources/views/fields/select2_from_array.blade.php index 59af16c..a0dcdaf 100644 --- a/src/resources/views/fields/select2_from_array.blade.php +++ b/src/resources/views/fields/select2_from_array.blade.php @@ -19,12 +19,12 @@ @endphp -
+@include('crud::fields.inc.wrapper_start') {{-- HINT --}} @if (isset($field['hint']))

{!! $field['hint'] !!}

@endif -
+@include('crud::fields.inc.wrapper_end') {{-- ########################################## --}} diff --git a/src/resources/views/fields/tags.blade.php b/src/resources/views/fields/tags.blade.php index 4a96d78..a4bfa44 100644 --- a/src/resources/views/fields/tags.blade.php +++ b/src/resources/views/fields/tags.blade.php @@ -24,9 +24,9 @@ foreach ($values as $value) { $values = $normalizedValues; ?> -
+@include('crud::fields.inc.wrapper_start') - @include('crud::inc.field_translatable_icon') +@include('crud::fields.inc.translatable_icon') @if(isset($field['prefix']) || isset($field['suffix']))
@endif @@ -35,7 +35,7 @@ $values = $normalizedValues; - @if(isset($field['suffix']))
{!! $field['suffix'] !!}
@endif + @if(isset($field['suffix']))
{!! $field['suffix'] !!}
@endif @if(isset($field['prefix']) || isset($field['suffix']))
@endif {{-- HINT --}} @@ -19,22 +19,3 @@

{!! $field['hint'] !!}

@endif
- - -{{-- FIELD EXTRA CSS --}} -{{-- push things in the after_styles section --}} - -{{-- @push('crud_fields_styles') - -@endpush --}} - - -{{-- FIELD EXTRA JS --}} -{{-- push things in the after_scripts section --}} - -{{-- @push('crud_fields_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 --}}