From: Vincent Vanwaelscappel Date: Wed, 13 Mar 2019 13:49:13 +0000 (+0100) Subject: wip #2628 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=028f5f6b24ec62e86bef3b0dc1935e0b8ad0a5dc;p=cubist_cms-back.git wip #2628 @1 --- diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php index 9006bca..d56ac34 100644 --- a/src/CubistBackpackServiceProvider.php +++ b/src/CubistBackpackServiceProvider.php @@ -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'); } /** diff --git a/src/app/Http/Controllers/TemplateCrudController.php b/src/app/Http/Controllers/TemplateCrudController.php index fd3cd88..23c9f33 100644 --- a/src/app/Http/Controllers/TemplateCrudController.php +++ b/src/app/Http/Controllers/TemplateCrudController.php @@ -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) { diff --git a/src/app/Models/Template.php b/src/app/Models/Template.php index f392bda..f058270 100644 --- a/src/app/Models/Template.php +++ b/src/app/Models/Template.php @@ -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 index 0148969..0000000 --- a/src/database/migrations/2019_03_11_155835_create_template_table.php +++ /dev/null @@ -1,49 +0,0 @@ -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 index 0000000..e49ea3e --- /dev/null +++ b/src/database/migrations/2019_03_13_162103_create_template_table.php @@ -0,0 +1,44 @@ +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'); + } +} diff --git a/src/resources/lang/en/templates.php b/src/resources/lang/en/templates.php index f7982d3..5a8c78e 100644 --- a/src/resources/lang/en/templates.php +++ b/src/resources/lang/en/templates.php @@ -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' ];