]> _ Git - cubist_cms-back.git/commitdiff
wip #2628 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Mar 2019 17:13:28 +0000 (18:13 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 14 Mar 2019 17:13:28 +0000 (18:13 +0100)
src/CubistBackpackServiceProvider.php
src/app/Http/Controllers/TemplateCrudController.php [deleted file]
src/app/Http/Requests/TemplateRequest.php [deleted file]
src/app/Models/Field.php [deleted file]
src/app/Models/Template.php [deleted file]
src/app/Template/Abstract.php [new file with mode: 0644]
src/database/migrations/2019_03_13_162103_create_template_table.php [deleted file]
src/database/migrations/2019_03_13_180800_create_fields_table.php [deleted file]
src/resources/views/fields/relation_table.blade.php [new file with mode: 0644]
src/routes/cubist/backpack/template.php

index d56ac34221bf2c576f0bc039d0bacda404002c1f..0dcd42cd852b4269478febad3f7202a536aa79c4 100644 (file)
@@ -18,12 +18,6 @@ class CubistBackpackServiceProvider extends ServiceProvider
      */
     protected $defer = false;
 
-    /**
-     * Where the route file lives, both inside the package and in the app (if overwritten).
-     *
-     * @var string
-     */
-    public $routeFilePath = '/routes/cubist/backpack/template.php';
 
     /**
      * Perform post-registration booting of services.
@@ -33,7 +27,7 @@ class CubistBackpackServiceProvider extends ServiceProvider
     public function boot()
     {
         // define the routes for the application
-        $this->setupRoutes($this->app->router);
+        //$this->setupRoutes($this->app->router);
 
 //        // only use the Settings package if the Settings table is present in the database
 //        if (!\App::runningInConsole() && count(Schema::getColumnListing('settings'))) {
@@ -48,26 +42,10 @@ class CubistBackpackServiceProvider extends ServiceProvider
 //        }
         $this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'cubist_back');
         $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
-    }
-
-    /**
-     * Define the routes for the application.
-     *
-     * @param \Illuminate\Routing\Router $router
-     *
-     * @return void
-     */
-    public function setupRoutes(Router $router)
-    {
-        // by default, use the routes file provided in vendor
-        $routeFilePathInUse = __DIR__ . $this->routeFilePath;
-
-        // but if there's a file with the same name in routes/backpack, use that one
-        if (file_exists(base_path() . $this->routeFilePath)) {
-            $routeFilePathInUse = base_path() . $this->routeFilePath;
+        foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) {
+            $this->loadRoutesFrom($filename);
         }
-
-        $this->loadRoutesFrom($routeFilePathInUse);
+        $this->loadViewsFrom(__FILE__ . '/resources/views','crud');
     }
 
     /**
@@ -77,12 +55,12 @@ class CubistBackpackServiceProvider extends ServiceProvider
      */
     public function register()
     {
-        $this->app->bind('templates', function ($app) {
-            return new Template($app);
-        });
-
-        // register their aliases
-        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
-        $loader->alias('Template', \Backpack\Settings\app\Models\Template::class);
+//        $this->app->bind('templates', function ($app) {
+//            return new Template($app);
+//        });
+//
+//        // register their aliases
+//        $loader = \Illuminate\Foundation\AliasLoader::getInstance();
+//        $loader->alias('Template', \Backpack\Settings\app\Models\Template::class);
     }
 }
diff --git a/src/app/Http/Controllers/TemplateCrudController.php b/src/app/Http/Controllers/TemplateCrudController.php
deleted file mode 100644 (file)
index 23c9f33..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Http\Controllers;
-
-use Backpack\CRUD\app\Http\Controllers\CrudController;
-// VALIDATION
-use Cubist\Backpack\app\Http\Requests\TemplateRequest as StoreRequest;
-use Cubist\Backpack\app\Http\Requests\TemplateRequest as UpdateRequest;
-
-class TemplateCrudController extends CrudController
-{
-    public function setup()
-    {
-        parent::setup();
-
-        $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->setColumns([
-            [
-                'name' => 'name',
-                'label' => trans('cubist_back::templates.name'),
-            ],
-            [
-                'name' => 'description',
-                'label' => trans('cubist_back::templates.description'),
-            ],
-        ]);
-        $this->crud->addField([
-            'name' => 'name',
-            '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'
-        ]);
-
-        $this->crud->enableAjaxTable();
-    }
-
-    public function store(StoreRequest $request)
-    {
-        return parent::storeCrud();
-    }
-
-
-    public function update(UpdateRequest $request)
-    {
-        return parent::updateCrud();
-    }
-}
diff --git a/src/app/Http/Requests/TemplateRequest.php b/src/app/Http/Requests/TemplateRequest.php
deleted file mode 100644 (file)
index 0762303..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Http\Requests;
-
-use Illuminate\Foundation\Http\FormRequest;
-
-class TemplateRequest extends FormRequest
-{
-    /**
-     * Determine if the user is authorized to make this request.
-     *
-     * @return bool
-     */
-    public function authorize()
-    {
-        // only allow updates if the user is logged in
-        return backpack_auth()->check();
-    }
-
-    /**
-     * Get the validation rules that apply to the request.
-     *
-     * @return array
-     */
-    public function rules()
-    {
-        return [
-            // 'key' => 'required|min:3|max:255',
-            // 'name' => 'required|min:3|max:255',
-            // 'field' => 'required'
-        ];
-    }
-}
diff --git a/src/app/Models/Field.php b/src/app/Models/Field.php
deleted file mode 100644 (file)
index 747292a..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Models;
-
-use Backpack\CRUD\CrudTrait;
-use Illuminate\Database\Eloquent\Model;
-
-class Field extends Model
-{
-    use CrudTrait;
-
-    protected $table = 'cubist_fields';
-    protected $fillable = ['name', 'type','options'];
-}
diff --git a/src/app/Models/Template.php b/src/app/Models/Template.php
deleted file mode 100644 (file)
index f058270..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Models;
-
-use Backpack\CRUD\CrudTrait;
-use Illuminate\Database\Eloquent\Model;
-
-class Template extends Model
-{
-    use CrudTrait;
-
-    protected $table = 'cubist_templates';
-    protected $fillable = ['name', 'description', 'parent', 'fields'];
-
-    function parent()
-    {
-        return $this->belongsTo('Cubist\Backpack\app\Models\Template', 'parent');
-    }
-}
diff --git a/src/app/Template/Abstract.php b/src/app/Template/Abstract.php
new file mode 100644 (file)
index 0000000..a5f3712
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+namespace Cubist\Backpack\app\Templates;
+class TemplateAbstract
+{
+    public function __construct()
+    {
+    }
+
+    public function addField($field){
+    }
+}
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
deleted file mode 100644 (file)
index e49ea3e..0000000
+++ /dev/null
@@ -1,44 +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('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/database/migrations/2019_03_13_180800_create_fields_table.php b/src/database/migrations/2019_03_13_180800_create_fields_table.php
deleted file mode 100644 (file)
index 9fcc33c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-
-class CreateFieldsTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('cubist_fields', function (Blueprint $table) {
-            $table->increments('id');
-            $table->string('name');
-            $table->string('type');
-            $table->json('options');
-            $table->timestamps();
-        });
-
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::drop('cubist_fields');
-    }
-}
diff --git a/src/resources/views/fields/relation_table.blade.php b/src/resources/views/fields/relation_table.blade.php
new file mode 100644 (file)
index 0000000..69d61ff
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+if ($field['value'] == "")
+    return;
+$crud->route = $field['route'];
+?>
+
+<div @include('crud::inc.field_wrapper_attributes') >
+    <h3 style="margin-top:0">{!! $field['label'] !!}</h3>
+
+    <div class="array-container form-group">
+
+        <table class="table table-bordered table-striped m-b-0">
+            <thead>
+            <tr>
+                @foreach( $field['columns'] as $column )
+                    <th>
+                        {{ __($column['label']) }}
+                    </th>
+                @endforeach
+                <th data-orderable="false">{{ trans('backpack::crud.actions') }}</th>
+            </tr>
+            </thead>
+            <tbody class="table-striped">
+            @foreach( $field['value'] as $item)
+                <tr class="array-row">
+                    @foreach( $field['columns'] as $key => $column)
+                        <td>
+                            {!! $item->{$column['name']} !!}
+                        </td>
+                    @endforeach
+                    <td>
+                        @include('crud::buttons.update', ['entry' => $item])
+                        @include('crud::buttons.delete', ['entry' => $item])
+                    </td>
+                </tr>
+            @endforeach
+            </tbody>
+        </table>
+
+        @php
+            // Add relation entity
+            $reflection = new ReflectionClass(get_class($crud->getModel()));
+            $classname = strtolower($reflection->getShortName());
+
+            $url = "{$crud->route}/create?$classname={$crud->entry->id}";
+        @endphp
+
+        <div class="array-controls btn-group m-t-10">
+            <a href="{{ $url }}">
+                <button class="btn btn-sm btn-default" type="button"><i
+                        class="fa fa-plus"></i> {{trans('backpack::crud.add')}}</button>
+            </a>
+        </div>
+
+    </div>
+</div>
index f167c4f3eee68ac534785fab1fa224a7f81bdad3..c8ce76b260d83a047fde388074e8fbd4d1addb7e 100644 (file)
@@ -1,19 +1,14 @@
 <?php
 
-/*
-|--------------------------------------------------------------------------
-| Backpack\Settings Routes
-|--------------------------------------------------------------------------
-|
-| This file is where you may define all of the routes that are
-| handled by the Backpack\Settings package.
-|
-*/
-
-Route::group([
-    'namespace'  => 'Cubist\Backpack\app\Http\Controllers',
-    'prefix'     => config('backpack.base.route_prefix', 'admin'),
-    'middleware' => ['web', backpack_middleware()],
-], function () {
-    CRUD::resource('template', 'TemplateCrudController');
-});
+//
+//Route::group([
+//    'namespace' => 'Cubist\Backpack\app\Http\Controllers',
+//    'prefix' => config('backpack.base.route_prefix', 'admin'),
+//    'middleware' => ['web', backpack_middleware()],
+//], function () {
+//    CRUD::resource('template', 'TemplateCrudController');
+//    CRUD::resource('field', 'FieldCrudController')->with(function () {
+//        Route::any('field/ajax/{mode?}', 'FieldCrudController@handleAjaxRequest');
+//    });
+//
+//});