]> _ Git - cubist_cms-back.git/commitdiff
wip #5509 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Oct 2022 14:47:49 +0000 (16:47 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Oct 2022 14:47:49 +0000 (16:47 +0200)
src/app/Magic/MagicObserver.php [new file with mode: 0644]
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/Translate.php
src/app/Magic/Operations/CreateOperation.php
src/app/Magic/Operations/UpdateOperation.php [deleted file]
src/public/bunchmultiple/bunchmultiple.css
src/public/bunchmultiple/bunchmultiple.less

diff --git a/src/app/Magic/MagicObserver.php b/src/app/Magic/MagicObserver.php
new file mode 100644 (file)
index 0000000..318c62d
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+namespace Cubist\Backpack\Magic;
+
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+use Cubist\Util\Str;
+
+class MagicObserver
+{
+    function creating(CubistMagicAbstractModel $model)
+    {
+        return $this->_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();
+        }
+    }
+}
index 20509b3ad52591df9c688df960321d697a4f41c1..42ce65a1d610b58711106bd9f18289bbc4495e1e 100644 (file)
@@ -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
index 5d2d39c6d1ce997f75ff6d1b45589bd0ef5946ea..b9c78cac05bcfb84d82f7b9f3ee16e468a21d485 100644 (file)
@@ -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;
+    }
 }
index 7b4810fc579968d82c690aaec63b7326355b8b98..4ad73b8473f53cc228958985d8393964db9a0b0a 100644 (file)
@@ -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();
     }
 
 
index a4036bd608ee8bbaeb98e04197c1b3587b40f8c4..b4067a27376afd6786d8bc74a198b9a1f95d226d 100644 (file)
@@ -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 (file)
index b79d7f2..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\Magic\Operations;
-
-use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
-
-trait UpdateOperation
-{
-    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation {
-        update as _update;
-    }
-
-    /**
-     * Update the specified resource in the database.
-     *
-     * @return Response
-     */
-    public function update()
-    {
-        $res = $this->_update();
-        if ($this->crud->entry instanceof CubistMagicAbstractModel) {
-            $this->crud->entry->onAfterSave();
-        }
-        return $res;
-    }
-
-}
index 349789b9e3e3ab080d723cfa4389c50b9b274cdb..32584a8fb43f952a8ec944999177fa44d4895498 100644 (file)
 .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;
index b271c763da83bc22a5d13452c8649966923f8f6b..21ae118bbb16c03f4af0eeb04139bff3031fd269 100644 (file)
 
                         img, svg {
                             width: auto;
-                            height: 15px;
+                            height: 25px;
                         }
                     }
                 }