From: Vincent Vanwaelscappel Date: Wed, 5 Oct 2022 14:47:49 +0000 (+0200) Subject: wip #5509 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=3b0289ebd6cd7d80c05d9499f08c3f3528f25a7a;p=cubist_cms-back.git wip #5509 @1 --- diff --git a/src/app/Magic/MagicObserver.php b/src/app/Magic/MagicObserver.php new file mode 100644 index 0000000..318c62d --- /dev/null +++ b/src/app/Magic/MagicObserver.php @@ -0,0 +1,67 @@ +_trigger($model, 'creating'); + } + + function created(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'created'); + } + + function updating(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'updating'); + } + + function updated(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'updated'); + } + + function saving(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'saving'); + } + + function saved(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'saved'); + } + + function deleting(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'deleting'); + } + + function deleted(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'deleted'); + } + + function restoring(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'restoring'); + } + + function restored(CubistMagicAbstractModel $model) + { + return $this->_trigger($model, 'restored'); + } + + protected function _trigger($model, $event) + { + $event = Str::camel('on_' . $event); + if (method_exists($model, $event)) { + return $model->$event(); + } + } +} diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 20509b3..42ce65a 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -78,43 +78,39 @@ class CMSPage extends CubistMagicNestedModel ]); } - /** - * @param \Cubist\Backpack\Magic\Controllers\CubistMagicController $controller - * @throws \Exception - */ - public function onBeforeCreate($controller) - { - $this->useTemplateIfNotSet(request('template'), $controller); - parent::onBeforeCreate($controller); - } - public function onBeforeEdit($controller, $id) + public function onCreating() { - $template = request('template'); - // if the template in the GET parameter is missing, figure it out from the db - if ($template == false) { - $template = self::getTemplatesById()[$id]; - } - - $this->useTemplateIfNotSet($template); - $controller->updateFieldsFromModel($this); - parent::onBeforeEdit($controller, $id); + $this->useTemplateIfNotSet(request('template')); + return $this->onCreating(); } - public function onBeforeStore($controller, $request) +// public function onBeforeEdit($controller, $id) +// { +// $template = request('template'); +// // if the template in the GET parameter is missing, figure it out from the db +// if ($template == false) { +// $template = self::getTemplatesById()[$id]; +// } +// +// $this->useTemplateIfNotSet($template); +// $controller->updateFieldsFromModel($this); +// parent::onBeforeEdit($controller, $id); +// } + + public function onSaving() { - $this->useTemplateIfNotSet(\Request::input('template')); - $controller->updateFieldsFromModel($this); - parent::onBeforeStore($controller, $request); + $this->useTemplateIfNotSet(request('template')); + return $this->onSaving(); } - public function onBeforeUpdate($controller, $request) + public function onUpdating() { - $this->useTemplateIfNotSet(\Request::input('template')); - $controller->updateFieldsFromModel($this); - parent::onBeforeUpdate($controller, $request); + $this->useTemplateIfNotSet(request('template')); + return $this->onUpdating(); } + /** * @param $template TemplateAbstract|string|null * @param $controller CubistMagicController diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 5d2d39c..b9c78ca 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -5,14 +5,15 @@ namespace Cubist\Backpack\Magic\Models; use Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation; use Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation; use Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation; +use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; use Cubist\Backpack\Http\Controllers\Operations\CloneEditOperation; use Cubist\Backpack\Magic\Fields\Composed; use Cubist\Backpack\Magic\Fields\Files; use Cubist\Backpack\Magic\Fields\FilesOrURL; use Cubist\Backpack\Magic\Fields\HiddenDatetime; +use Cubist\Backpack\Magic\MagicObserver; use Cubist\Backpack\Magic\Operations\CreateOperation; use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; -use Cubist\Backpack\Magic\Operations\UpdateOperation; use Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation; use Cubist\Backpack\Http\Controllers\Operations\ReviseOperation; use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; @@ -24,7 +25,6 @@ use Cubist\Backpack\Magic\Fields\Field; use Cubist\Backpack\Magic\Fields\UnstoredField; use Cubist\Backpack\Magic\PageData; use Cubist\Backpack\Magic\QueryBuilder; -use Cubist\Backpack\Magic\Requests\CubistMagicUpdateRequest; use Cubist\Backpack\Magic\Util; use Cubist\Util\Json; use Doctrine\DBAL\Schema\Schema; @@ -125,6 +125,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia static::addGlobalScope('ownerclause', function (Builder $builder) { static::addOwnerClause($builder); }); + + static::observe(new MagicObserver); } public function scopeOneinstance($query) @@ -645,22 +647,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia return $res; } - /** - * @param $controller CubistMagicController - */ - public function onBeforeCreate($controller) - { - - } - - /** - * @param $controller CubistMagicController - * @param $id int - */ - public function onBeforeEdit($controller, $id) - { - $this->_createOneInstance($id); - } protected function _createOneInstance($id = 1) { @@ -671,30 +657,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia } } - public function onAfterSave() - { - - } - - /** - * @param $controller CubistMagicController - * @param $request CubistMagicUpdateRequest - */ - - public function onBeforeUpdate($controller, $request) - { - - } - - /** - * @param $controller CubistMagicController - * @param $request CubistMagicUpdateRequest - */ - public function onBeforeStore($controller, $request) - { - - } - /** * @return EntityData */ @@ -1252,4 +1214,54 @@ class CubistMagicAbstractModel extends Model implements HasMedia } return $nb; } + + public function onSaved() + { + return true; + } + + public function onSaving() + { + return true; + } + + public function onCreating() + { + return true; + } + + public function onCreated() + { + return true; + } + + public function onUpdating() + { + return true; + } + + public function onUpdated() + { + return true; + } + + public function onDeleting() + { + return true; + } + + public function onDeleted() + { + return true; + } + + public function onRestoring() + { + return true; + } + + public function onRestored() + { + return true; + } } diff --git a/src/app/Magic/Models/Translate.php b/src/app/Magic/Models/Translate.php index 7b4810f..4ad73b8 100644 --- a/src/app/Magic/Models/Translate.php +++ b/src/app/Magic/Models/Translate.php @@ -81,21 +81,18 @@ class Translate extends CubistMagicTranslatableModel } } - /** - * @param \Cubist\Backpack\Magic\Controllers\CubistMagicController $controller - * @param \Cubist\Backpack\Magic\Requests\CubistMagicUpdateRequest $request - */ - public function onBeforeUpdate($controller, $request) + + public function onSaving() { $this->saveLanguageFile(); - parent::onBeforeUpdate($controller, $request); + return parent::onSaving(); } - public function onAfterSave() + public function onSaved() { $this->saveLanguageFile(); - parent::onAfterSave(); + return parent::onSaved(); } diff --git a/src/app/Magic/Operations/CreateOperation.php b/src/app/Magic/Operations/CreateOperation.php index a4036bd..b4067a2 100644 --- a/src/app/Magic/Operations/CreateOperation.php +++ b/src/app/Magic/Operations/CreateOperation.php @@ -7,9 +7,7 @@ use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel; trait CreateOperation { use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { - store as _store; create as _create; - setupCreateDefaults as _setupCreateDefaults; } /** @@ -33,17 +31,4 @@ trait CreateOperation return $this->_create(); } - public function store() - { - $res = $this->_store(); - if ($this->crud->entry instanceof CubistMagicAbstractModel) { - $this->crud->entry->onAfterSave(); - } - return $res; - } - - protected function setupCreateDefaults() - { - $this->_setupCreateDefaults(); - } } diff --git a/src/app/Magic/Operations/UpdateOperation.php b/src/app/Magic/Operations/UpdateOperation.php deleted file mode 100644 index b79d7f2..0000000 --- a/src/app/Magic/Operations/UpdateOperation.php +++ /dev/null @@ -1,27 +0,0 @@ -_update(); - if ($this->crud->entry instanceof CubistMagicAbstractModel) { - $this->crud->entry->onAfterSave(); - } - return $res; - } - -} diff --git a/src/public/bunchmultiple/bunchmultiple.css b/src/public/bunchmultiple/bunchmultiple.css index 349789b..32584a8 100644 --- a/src/public/bunchmultiple/bunchmultiple.css +++ b/src/public/bunchmultiple/bunchmultiple.css @@ -117,7 +117,7 @@ .bunchmultiple .bunchmultiple__wrapper .item .legend > span .icon img, .bunchmultiple .bunchmultiple__wrapper .item .legend > span .icon svg { width: auto; - height: 15px; + height: 25px; } .bunchmultiple .bunchmultiple__wrapper .item .legend a.action { color: #333; diff --git a/src/public/bunchmultiple/bunchmultiple.less b/src/public/bunchmultiple/bunchmultiple.less index b271c76..21ae118 100644 --- a/src/public/bunchmultiple/bunchmultiple.less +++ b/src/public/bunchmultiple/bunchmultiple.less @@ -159,7 +159,7 @@ img, svg { width: auto; - height: 15px; + height: 25px; } } }