From: Vincent Vanwaelscappel Date: Mon, 11 Mar 2019 16:15:51 +0000 (+0100) Subject: wip #2628 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=39c5e9a69233ceb9ed91d2b27daa10940a2ee0bd;p=cubist_cms-back.git wip #2628 @0.5 --- diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6f313c6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/composer.json b/composer.json index 5dcad91..44ce851 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,16 @@ "require-dev": { "backpack/generators": "^1.2" }, + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Cubeist\\Backpack\\ServiceProvider" + ] + } + }, "repositories": [ { "type": "composer", diff --git a/src/CubistBackpackServiceProvider.php b/src/CubistBackpackServiceProvider.php new file mode 100644 index 0000000..8c0f71a --- /dev/null +++ b/src/CubistBackpackServiceProvider.php @@ -0,0 +1,91 @@ +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); +// } +// } + // publish the migrations and seeds + $this->publishes([__DIR__ . '/database/migrations/' => database_path('migrations')], 'migrations'); + + // publish translation files + //$this->publishes([__DIR__ . '/resources/lang' => resource_path('lang/vendor/backpack')], 'lang'); + } + + /** + * 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; + } + + $this->loadRoutesFrom($routeFilePathInUse); + } + + /** + * Register any package services. + * + * @return void + */ + public function register() + { + $this->app->bind('settings', function ($app) { + return new Settings($app); + }); + + // register their aliases + $loader = \Illuminate\Foundation\AliasLoader::getInstance(); + $loader->alias('Setting', \Backpack\Settings\app\Models\Template::class); + } +} diff --git a/src/app/Http/Controllers/TemplateCrudController.php b/src/app/Http/Controllers/TemplateCrudController.php new file mode 100644 index 0000000..ce97aac --- /dev/null +++ b/src/app/Http/Controllers/TemplateCrudController.php @@ -0,0 +1,90 @@ +crud->setModel("Cubist\Backpack\app\Models\Setting"); + $this->crud->setEntityNameStrings(trans('backpack::settings.setting_singular'), trans('backpack::settings.setting_plural')); + $this->crud->setRoute(backpack_url('setting')); + $this->crud->addClause('where', 'active', 1); + $this->crud->denyAccess(['create', 'delete']); + $this->crud->setColumns([ + [ + 'name' => 'name', + 'label' => trans('backpack::settings.name'), + ], + [ + 'name' => 'value', + 'label' => trans('backpack::settings.value'), + ], + [ + 'name' => 'description', + 'label' => trans('backpack::settings.description'), + ], + ]); + $this->crud->addField([ + 'name' => 'name', + 'label' => trans('backpack::settings.name'), + 'type' => 'text', + 'attributes' => [ + 'disabled' => 'disabled', + ], + ]); + } + + /** + * 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(); + } + + public function store(StoreRequest $request) + { + 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) + { + return parent::updateCrud(); + } +} diff --git a/src/app/Http/Requests/TemplateRequest.php b/src/app/Http/Requests/TemplateRequest.php new file mode 100644 index 0000000..0762303 --- /dev/null +++ b/src/app/Http/Requests/TemplateRequest.php @@ -0,0 +1,33 @@ +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/Template.php b/src/app/Models/Template.php new file mode 100644 index 0000000..fc5a7a0 --- /dev/null +++ b/src/app/Models/Template.php @@ -0,0 +1,60 @@ +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 = 'settings.'.$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; + } +} diff --git a/src/routes/cubist/backpack/template.php b/src/routes/cubist/backpack/template.php new file mode 100644 index 0000000..f167c4f --- /dev/null +++ b/src/routes/cubist/backpack/template.php @@ -0,0 +1,19 @@ + 'Cubist\Backpack\app\Http\Controllers', + 'prefix' => config('backpack.base.route_prefix', 'admin'), + 'middleware' => ['web', backpack_middleware()], +], function () { + CRUD::resource('template', 'TemplateCrudController'); +});