]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 May 2019 09:35:19 +0000 (11:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 May 2019 09:35:19 +0000 (11:35 +0200)
src/app/Http/Controllers/CubistCrud.php
src/app/Http/Controllers/CubistModelCrudController.php
src/app/Http/Controllers/CubistModelFieldCrudController.php [new file with mode: 0644]
src/app/Models/CubistModelField.php [new file with mode: 0644]
src/database/migrations/2019_05_20_161943_create_models_table.php
src/routes/cubist/backpack/modelfield.php [new file with mode: 0644]

index 1396beb3de0330c1aab7bc46c46c02ad291821a6..6f1d4278c71f76accb1557c8bd4cc95486988510 100644 (file)
@@ -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) {
index 8bb5001ae80fb585146eed1ee9740a35400205b6..d7c414be27efff7bd9e35432ca3403f5eecbd538 100644 (file)
@@ -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 (file)
index 0000000..d3174f1
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Http\Controllers;
+
+use Backpack\CRUD\app\Http\Controllers\CrudController;
+
+// VALIDATION: change the requests to match your own file names if you need form validation
+use Cubist\Backpack\app\Http\Requests\CubistModelRequest as StoreRequest;
+use Cubist\Backpack\app\Http\Requests\CubistModelRequest as UpdateRequest;
+use Webfactor\Laravel\Backpack\InstantFields\InstantFields;
+
+
+class CubistModelFieldCrudController extends CrudController
+{
+    use CubistCrud;
+    use InstantFields;
+
+    public function setup()
+    {
+        /*
+        |--------------------------------------------------------------------------
+        | CrudPanel Basic Information
+        |--------------------------------------------------------------------------
+        */
+        $this->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 (file)
index 0000000..b18c02c
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+
+namespace app\Models;
+
+
+use Backpack\CRUD\CrudTrait;
+
+class CubistModelField
+{
+    use CrudTrait;
+    protected $table = 'cubist_modelfields';
+    protected $fillable = ['name', 'label', 'attributes'];
+}
index 3ab4f2ca217954cc4628ac0167e200343f34d329..05794236da825103f261c653649b9c0782fd18e8 100644 (file)
@@ -19,6 +19,14 @@ class CreateModelsTable extends Migration
             $table->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 (file)
index 0000000..472a2ea
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+CRUD::resource('modelfield', 'ModelFieldCrudController')->with(function () {
+    Route::any('modelfield/ajax/{mode?}', 'ModelFieldCrudController@handleAjaxRequest');
+});