]> _ Git - cubist_cms-back.git/commitdiff
wip #2628 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 13 Mar 2019 13:49:13 +0000 (14:49 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 13 Mar 2019 13:49:13 +0000 (14:49 +0100)
src/CubistBackpackServiceProvider.php
src/app/Http/Controllers/TemplateCrudController.php
src/app/Models/Template.php
src/database/migrations/2019_03_11_155835_create_template_table.php [deleted file]
src/database/migrations/2019_03_13_162103_create_template_table.php [new file with mode: 0644]
src/resources/lang/en/templates.php

index 9006bca1486f274867d9e90cedaf168be647eaad..d56ac34221bf2c576f0bc039d0bacda404002c1f 100644 (file)
@@ -46,13 +46,8 @@ class CubistBackpackServiceProvider extends ServiceProvider
 //                Config::set('settings.' . $setting->key, $setting->value);
 //            }
 //        }
-        // publish the migrations and seeds
-        $this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')], 'migrations');
-
         $this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'cubist_back');
-
-        // publish translation files
-        $this->publishes([__DIR__ . '/resources/lang' => resource_path('lang/vendor/cubist_back')], 'lang');
+        $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
     }
 
     /**
index fd3cd8877ae9965146dcae1aa089288a410e3cd2..23c9f3359748013dca127767f62c403cfd12802c 100644 (file)
@@ -16,8 +16,6 @@ class TemplateCrudController extends CrudController
         $this->crud->setModel("Cubist\Backpack\app\Models\Template");
         $this->crud->setEntityNameStrings(trans('cubist_back::templates.template_singular'), trans('cubist_back::templates.template_plural'));
         $this->crud->setRoute(backpack_url('template'));
-        $this->crud->addClause('where', 'active', 1);
-        $this->crud->denyAccess(['create', 'delete']);
         $this->crud->setColumns([
             [
                 'name' => 'name',
@@ -33,18 +31,26 @@ class TemplateCrudController extends CrudController
             'label' => trans('cubist_back::templates.name'),
             'type' => 'text',
         ]);
-    }
+        $this->crud->addField([
+            'name' => 'description',
+            'label' => trans('cubist_back::templates.description'),
+            'type' => 'textarea',
+        ]);
+        $this->crud->addField([
+            'name' => 'parent',
+            'label' => trans('cubist_back::templates.parent'),
+            'type' => 'select',
+            'entity' => 'parent',
+            'attribute' => 'name',
+            'model' => 'Cubist\Backpack\app\Models\Template',
+        ]);
+        $this->crud->addField([
+            'name' => 'fields',
+            'label' => trans('cubist_back::templates.field_plural'),
+            'type' => 'textarea'
+        ]);
 
-    /**
-     * Display all rows in the database for this entity.
-     * This overwrites the default CrudController behaviour:
-     * - instead of showing all entries, only show the "active" ones.
-     *
-     * @return Response
-     */
-    public function index()
-    {
-        return parent::index();
+        $this->crud->enableAjaxTable();
     }
 
     public function store(StoreRequest $request)
@@ -52,29 +58,6 @@ class TemplateCrudController extends CrudController
         return parent::storeCrud();
     }
 
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param int $id
-     *
-     * @return Response
-     */
-    public function edit($id)
-    {
-        $this->crud->hasAccessOrFail('update');
-
-        $this->data['entry'] = $this->crud->getEntry($id);
-        $this->crud->addField(json_decode($this->data['entry']->field, true)); // <---- this is where it's different
-        $this->data['crud'] = $this->crud;
-        $this->data['saveAction'] = $this->getSaveAction();
-        $this->data['fields'] = $this->crud->getUpdateFields($id);
-        $this->data['title'] = trans('backpack::crud.edit') . ' ' . $this->crud->entity_name;
-
-        $this->data['id'] = $id;
-
-        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
-        return view($this->crud->getEditView(), $this->data);
-    }
 
     public function update(UpdateRequest $request)
     {
index f392bdaae12e5eee58cde27dfccc52777f3a2f4b..f058270b54510cd7ee623e22ca4b84ea535e12e4 100644 (file)
@@ -3,7 +3,6 @@
 namespace Cubist\Backpack\app\Models;
 
 use Backpack\CRUD\CrudTrait;
-use Config;
 use Illuminate\Database\Eloquent\Model;
 
 class Template extends Model
@@ -11,50 +10,10 @@ class Template extends Model
     use CrudTrait;
 
     protected $table = 'cubist_templates';
-    protected $fillable = ['name','description','parent',''];
+    protected $fillable = ['name', 'description', 'parent', 'fields'];
 
-    /**
-     * Grab a setting value from the database.
-     *
-     * @param string $key The setting key, as defined in the key db column
-     *
-     * @return string The setting value.
-     */
-    public static function get($key)
+    function parent()
     {
-        $setting = new self();
-        $entry = $setting->where('key', $key)->first();
-
-        if (!$entry) {
-            return;
-        }
-
-        return $entry->value;
-    }
-
-    /**
-     * Update a setting's value.
-     *
-     * @param string $key   The setting key, as defined in the key db column
-     * @param string $value The new value.
-     */
-    public static function set($key, $value = null)
-    {
-        $prefixed_key = 'template.'.$key;
-        $setting = new self();
-        $entry = $setting->where('key', $key)->firstOrFail();
-
-        // update the value in the database
-        $entry->value = $value;
-        $entry->saveOrFail();
-
-        // update the value in the session
-        Config::set($prefixed_key, $value);
-
-        if (Config::get($prefixed_key) == $value) {
-            return true;
-        }
-
-        return false;
+        return $this->belongsTo('Cubist\Backpack\app\Models\Template', 'parent');
     }
 }
diff --git a/src/database/migrations/2019_03_11_155835_create_template_table.php b/src/database/migrations/2019_03_11_155835_create_template_table.php
deleted file mode 100644 (file)
index 0148969..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-
-class CreateTemplateTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('cubist_templates', function (Blueprint $table) {
-            $table->increments('id');
-            $table->string('key')->unique();
-            $table->string('name');
-            $table->string('description')->nullable();
-            $table->string('parent')->nullable();
-            $table->json('tabs')->default('[]');
-            $table->json('fields')->default('[]');
-            $table->tinyInteger('active');
-            $table->timestamps();
-        });
-
-        Schema::create('cubist_subforms', function (Blueprint $table) {
-            $table->increments('id');
-            $table->string('key')->unique();
-            $table->string('name');
-            $table->string('description')->nullable();
-            $table->string('parent')->nullable();
-            $table->json('fields')->default('[]');
-            $table->tinyInteger('active');
-            $table->timestamps();
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::drop('cubist_templates');
-        Schema::drop('cubist_subforms');
-    }
-}
diff --git a/src/database/migrations/2019_03_13_162103_create_template_table.php b/src/database/migrations/2019_03_13_162103_create_template_table.php
new file mode 100644 (file)
index 0000000..e49ea3e
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+
+class CreateTemplateTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cubist_templates', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name');
+            $table->string('description')->nullable();
+            $table->string('parent')->nullable();
+            $table->json('fields');
+            $table->timestamps();
+        });
+
+        Schema::create('cubist_subforms', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name');
+            $table->string('description')->nullable();
+            $table->string('parent')->nullable();
+            $table->json('fields');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('cubist_templates');
+        Schema::drop('cubist_subforms');
+    }
+}
index f7982d3716be656d0c324f1a3ce309d90986086e..5a8c78e603f6260fd6fe39759e777a77211f8099 100644 (file)
@@ -9,10 +9,13 @@ return [
     | The following language lines are used for Cubist backpack
     |
     */
-    'name'             => 'Name',
-    'value'            => 'Value',
-    'description'      => 'Description',
+    'name' => 'Name',
+    'value' => 'Value',
+    'description' => 'Description',
     'template_singular' => 'template',
-    'template_plural'   => 'templates',
+    'template_plural' => 'templates',
+    'parent' => 'Parent',
+    'field_singular' => 'Field',
+    'field_plural' => 'Fields'
 
 ];