From: Vincent Vanwaelscappel Date: Wed, 22 May 2019 09:35:19 +0000 (+0200) Subject: #2783 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=4d232aa2ca656a08391ddbb433bc102fce06ad01;p=cubist_cms-back.git #2783 --- diff --git a/src/app/Http/Controllers/CubistCrud.php b/src/app/Http/Controllers/CubistCrud.php index 1396beb..6f1d427 100644 --- a/src/app/Http/Controllers/CubistCrud.php +++ b/src/app/Http/Controllers/CubistCrud.php @@ -2,9 +2,12 @@ namespace Cubist\Backpack\app\Http\Controllers; +use Backpack\CRUD\CrudTrait; trait CubistCrud { + use CrudTrait; + public function addField($field, $form = 'both') { if (isset($field['column_label']) || isset($field['column']) && $field['column'] == true) { diff --git a/src/app/Http/Controllers/CubistModelCrudController.php b/src/app/Http/Controllers/CubistModelCrudController.php index 8bb5001..d7c414b 100644 --- a/src/app/Http/Controllers/CubistModelCrudController.php +++ b/src/app/Http/Controllers/CubistModelCrudController.php @@ -31,6 +31,7 @@ class CubistModelCrudController extends CrudController $this->crud->setRoute(config('backpack.base.route_prefix') . '/model'); $this->crud->setEntityNameStrings('model', 'models'); + /* |-------------------------------------------------------------------------- | CrudPanel Configuration @@ -42,7 +43,24 @@ class CubistModelCrudController extends CrudController 'label' => 'Model table name', 'column' => true], 'create'); $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], 'both'); - $this->addField(['type' => 'select2_from_ajax_multiple', 'name' => 'fields', 'label' => 'Fields definitions'], 'both'); + + $this->addField([ + 'name' => 'fields', + 'type' => 'select2_from_ajax_multiple', + 'label' => 'Fields definitions', + 'view_namespace' => 'webfactor::fields', + 'model' => Entity::class, + 'entity' => 'modelfield', + 'attribute' => 'name', + 'placeholder' => 'Choose', + 'pagination' => 20, // optional, default: 10 + 'minimum_input_length' => 0, + 'on_the_fly' => [ + 'entity' => 'modelfield', // e. g. user, contact, company etc... + 'create' => true, + 'edit' => true, + 'delete' => true, + ]], 'both'); // add asterisk for fields that are required in ModelRequest $this->crud->setRequiredFields(StoreRequest::class, 'create'); diff --git a/src/app/Http/Controllers/CubistModelFieldCrudController.php b/src/app/Http/Controllers/CubistModelFieldCrudController.php new file mode 100644 index 0000000..d3174f1 --- /dev/null +++ b/src/app/Http/Controllers/CubistModelFieldCrudController.php @@ -0,0 +1,69 @@ +crud->setModel('Cubist\Backpack\app\Models\CubistModelField'); + $this->crud->setRoute(config('backpack.base.route_prefix') . '/modelfield'); + $this->crud->setEntityNameStrings('modelfield', 'modelfieldss'); + + + $this->setAjaxEntity('modelfield'); + + /* + |-------------------------------------------------------------------------- + | CrudPanel Configuration + |-------------------------------------------------------------------------- + */ + + $this->addField(['type' => 'text', + 'name' => 'name', + 'label' => 'Field column name', + 'column' => true], 'create'); + $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Field label', 'column' => true], 'both'); + $this->addField(['type' => 'table', 'name' => 'attributes', 'label' => 'Attributes'], 'both'); + + // add asterisk for fields that are required in ModelRequest + $this->crud->setRequiredFields(StoreRequest::class, 'create'); + $this->crud->setRequiredFields(UpdateRequest::class, 'edit'); + } + + public function store(StoreRequest $request) + { + // your additional operations before save here + $redirect_location = parent::storeCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } + + public function update(UpdateRequest $request) + { + // your additional operations before save here + $redirect_location = parent::updateCrud($request); + // your additional operations after save here + // use $this->data['entry'] or $this->crud->entry + return $redirect_location; + } +} + diff --git a/src/app/Models/CubistModelField.php b/src/app/Models/CubistModelField.php new file mode 100644 index 0000000..b18c02c --- /dev/null +++ b/src/app/Models/CubistModelField.php @@ -0,0 +1,14 @@ +longText('fields'); $table->timestamps(); }); + + Schema::create('cubist_modelfields', function (Blueprint $table) { + $table->increments('id'); + $table->string('name')->unique(); + $table->string('label'); + $table->longText('attributes'); + $table->timestamps(); + }); } /** @@ -28,6 +36,8 @@ class CreateModelsTable extends Migration */ public function down() { - Schema::drop('models'); + Schema::drop('cubist_models'); + Schema::drop('cubist_modelfields'); + } } diff --git a/src/routes/cubist/backpack/modelfield.php b/src/routes/cubist/backpack/modelfield.php new file mode 100644 index 0000000..472a2ea --- /dev/null +++ b/src/routes/cubist/backpack/modelfield.php @@ -0,0 +1,5 @@ +with(function () { + Route::any('modelfield/ajax/{mode?}', 'ModelFieldCrudController@handleAjaxRequest'); +});