From: Vincent Vanwaelscappel Date: Wed, 22 May 2019 14:37:04 +0000 (+0200) Subject: wip #2783 @4 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e352acc73e23cfc813ee041ae67584275d244b7c;p=cubist_cms-back.git wip #2783 @4 --- diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php index ee72546..c33dc4e 100644 --- a/src/CubistBackpackServiceProvider.php +++ b/src/CubistBackpackServiceProvider.php @@ -22,23 +22,6 @@ class CubistBackpackServiceProvider extends ServiceProvider */ public function boot() { - // define the routes for the application - //$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'))) { -// // get all settings from the database -// $settings = Setting::all(); -// -// // bind all settings to the Laravel config, so you can call them like -// // Config::get('settings.contact_email') -// foreach ($settings as $key => $setting) { -// Config::set('settings.' . $setting->key, $setting->value); -// } -// } - - $this->publishes([__DIR__.'/database/migrations' => database_path('migrations')], 'migrations'); - $this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'cubist_back'); foreach (glob(__DIR__ . '/routes/cubist/backpack/*.php') as $filename) { $this->loadRoutesFrom($filename); @@ -46,6 +29,8 @@ class CubistBackpackServiceProvider extends ServiceProvider $this->loadViewsFrom(__FILE__ . '/resources/views','cubist_back'); } + + /** * Register any package services. * @@ -54,8 +39,6 @@ class CubistBackpackServiceProvider extends ServiceProvider public function register() { - - // $this->app->bind('templates', function ($app) { // return new Template($app); // }); diff --git a/src/app/Http/Controllers/CubistCrud.php b/src/app/Http/Controllers/CubistCrud.php deleted file mode 100644 index 6f1d427..0000000 --- a/src/app/Http/Controllers/CubistCrud.php +++ /dev/null @@ -1,30 +0,0 @@ - $field['name'], 'label' => $field['label'], 'type' => 'text']; - if (isset($field['column'])) { - unset($field['column']); - } - if (isset($field['column_label'])) { - $column_data['label'] = $field['column_label']; - unset($field['column_label']); - } - if (isset($field['column_type'])) { - $column_data['type'] = $field['column_type']; - unset($column_data['type']); - } - $this->crud->addColumn($column_data); - } - $this->crud->addField($field, $form); - } -} diff --git a/src/app/Http/Controllers/CubistModelCrudController.php b/src/app/Http/Controllers/CubistModelCrudController.php deleted file mode 100644 index d7c414b..0000000 --- a/src/app/Http/Controllers/CubistModelCrudController.php +++ /dev/null @@ -1,87 +0,0 @@ -crud->setModel('Cubist\Backpack\app\Models\CubistModel'); - $this->crud->setRoute(config('backpack.base.route_prefix') . '/model'); - $this->crud->setEntityNameStrings('model', 'models'); - - - /* - |-------------------------------------------------------------------------- - | CrudPanel Configuration - |-------------------------------------------------------------------------- - */ - - $this->addField(['type' => 'text', - 'name' => 'name', - 'label' => 'Model table name', - 'column' => true], 'create'); - $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], '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'); - $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/Http/Controllers/CubistModelFieldCrudController.php b/src/app/Http/Controllers/CubistModelFieldCrudController.php deleted file mode 100644 index d3174f1..0000000 --- a/src/app/Http/Controllers/CubistModelFieldCrudController.php +++ /dev/null @@ -1,69 +0,0 @@ -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/Http/Controllers/CubistPageCrudController.php b/src/app/Http/Controllers/CubistPageCrudController.php index 853f414..deea027 100644 --- a/src/app/Http/Controllers/CubistPageCrudController.php +++ b/src/app/Http/Controllers/CubistPageCrudController.php @@ -4,6 +4,7 @@ namespace Cubist\Backpack\app\Http\Controllers; use Backpack\PageManager\app\Http\Controllers\Admin\PageCrudController; use Cubist\Backpack\app\Template\TemplateAbstract; +use Cubist\Backpack\app\Magic\CubistCrud; use Illuminate\Support\Str; class CubistPageCrudController extends PageCrudController diff --git a/src/app/Http/Requests/ModelRequest.php b/src/app/Http/Requests/ModelRequest.php deleted file mode 100644 index 88b98b5..0000000 --- a/src/app/Http/Requests/ModelRequest.php +++ /dev/null @@ -1,55 +0,0 @@ -check(); - } - - /** - * Get the validation rules that apply to the request. - * - * @return array - */ - public function rules() - { - return [ - // 'name' => 'required|min:5|max:255' - ]; - } - - /** - * Get the validation attributes that apply to the request. - * - * @return array - */ - public function attributes() - { - return [ - // - ]; - } - - /** - * Get the validation messages that apply to the request. - * - * @return array - */ - public function messages() - { - return [ - // - ]; - } -} diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php new file mode 100644 index 0000000..d8f6b14 --- /dev/null +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -0,0 +1,85 @@ +crud->setModel($this->_modelNamespace); + $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL); + $this->crud->setEntityNameStrings($this->_singular, $this->_plural); + + + /* + |-------------------------------------------------------------------------- + | CrudPanel Configuration + |-------------------------------------------------------------------------- + */ + + $this->addField(['type' => 'text', + 'name' => 'name', + 'label' => 'Model table name', + 'column' => true], 'create'); + $this->addField(['type' => 'text', 'name' => 'label', 'label' => 'Model label', 'column' => true], 'both'); + + $this->addField([ + 'name' => 'fields', + 'type' => 'select2_from_ajax_multiple', + 'label' => 'Fields definitions', + 'view_namespace' => 'webfactor::fields', + 'model' => CubistModelField::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(CubistMagicStoreRequest::class, 'create'); + $this->crud->setRequiredFields(CubistMagicUpdateRequest::class, 'edit'); + } + + public function store(CubistMagicStoreRequest $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(CubistMagicUpdateRequest $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/Magic/CubistCrud.php b/src/app/Magic/CubistCrud.php new file mode 100644 index 0000000..6dadc1b --- /dev/null +++ b/src/app/Magic/CubistCrud.php @@ -0,0 +1,23 @@ +isDisplayColumn()) { + $this->crud->addColumn($field->getColumnData()); + } + $this->crud->addField($field, $field->getCRUDForm()); + } +} diff --git a/src/app/Magic/CubistMagicAttribute.php b/src/app/Magic/CubistMagicAttribute.php new file mode 100644 index 0000000..ae42677 --- /dev/null +++ b/src/app/Magic/CubistMagicAttribute.php @@ -0,0 +1,16 @@ +_attributes[$key])) { + return $this->_attributes[$key]; + } + return $default; + } +} diff --git a/src/app/Magic/Fields/CubistMagicField.php b/src/app/Magic/Fields/CubistMagicField.php new file mode 100644 index 0000000..2bac171 --- /dev/null +++ b/src/app/Magic/Fields/CubistMagicField.php @@ -0,0 +1,79 @@ + 'text', 'column' => false, 'form' => 'both']; + } + + public function __construct($attributes) + { + $this->_attributes = array_merge($attributes, $this->getDefaultAttributes()); + $this->init(); + } + + public function init() + { + + } + + /** + * @return bool + */ + public function isDisplayColumn() + { + return !!$this->getAttribute('column'); + } + + public function getColumnData() + { + $res = [ + 'type' => $this->getAttribute('column_type', $this->getAttribute('type')), + 'label' => $this->getAttribute('column_label', $this->getAttribute('label')) + ]; + + return $res; + } + + public function getCRUDForm() + { + return $this->getAttribute('form'); + } + + public function getDatabaseSchema() + { + + } +} diff --git a/src/app/Magic/Models/CubistMagicModelAbstract.php b/src/app/Magic/Models/CubistMagicModelAbstract.php new file mode 100644 index 0000000..5649838 --- /dev/null +++ b/src/app/Magic/Models/CubistMagicModelAbstract.php @@ -0,0 +1,69 @@ +_controller) { + $this->_controller = new CubistMagicController(); + } + + return $this->_controller; + } + + /** + * @param $attributes + */ + public function addField($attributes) + { + /** @var CubistMagicField $field */ + $field = CubistMagicField::getInstance($attributes); + $this->getController()->addField($field); + + $this->_fields[$field->getAttribute('name')] = $field; + } + + public function loadRoute() + { + Route::group([ + 'prefix' => config('backpack.base.route_prefix', 'admin'), + 'middleware' => ['web', config('backpack.base.middleware_key', 'admin')], + 'namespace' => 'Cubist\Backpack\app\Http\Controllers', + ], function () { // custom admin routes + CRUD::resource('model', 'CubistModelCrudController'); + CRUD::resource('model', 'CubistModelCrudController'); + }); // this should be the absolute last line of this file + + + } +} diff --git a/src/app/Magic/Requests/CubistMagicRequest.php b/src/app/Magic/Requests/CubistMagicRequest.php new file mode 100644 index 0000000..d5c64d4 --- /dev/null +++ b/src/app/Magic/Requests/CubistMagicRequest.php @@ -0,0 +1,58 @@ +check(); + } + + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } + +} diff --git a/src/app/Magic/Requests/CubistMagicStoreRequest.php b/src/app/Magic/Requests/CubistMagicStoreRequest.php new file mode 100644 index 0000000..adf513c --- /dev/null +++ b/src/app/Magic/Requests/CubistMagicStoreRequest.php @@ -0,0 +1,12 @@ +