]> _ Git - fluidbook-toolbox.git/commitdiff
wip #4210 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 13 Jun 2022 17:32:35 +0000 (19:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Jun 2022 09:48:02 +0000 (11:48 +0200)
app/Fields/FluidbookTheme.php
app/Http/Controllers/API/FluidbookThemeAPIController.php
app/Jobs/UpdateWS2ThemeTable.php
app/Models/FluidbookTheme.php
resources/views/fields/fluidbook_theme_selector.blade.php
resources/views/vendor/backpack/crud/inc/form_save_buttons.blade.php

index 8ac7318aa4cfdd4650e13c1d728d8439cff4f074..6c08d8a83135accecbd84fe808b498bb13d53235 100644 (file)
@@ -4,24 +4,19 @@
 namespace App\Fields;
 
 
-use Cubist\Backpack\Magic\Fields\SelectFromArray;
+use Cubist\Backpack\Magic\Fields\SelectFromModel;
 
-class FluidbookTheme extends SelectFromArray
+class FluidbookTheme extends SelectFromModel
 {
     protected $_adminType = 'fluidbook_theme_selector';
     protected $_viewNamespace = 'fields';
 
-    public function getOptions()
+    public function __construct($attributes)
     {
-        return self::getThemeSelectorOptions();
-    }
-
-    public static function getThemeSelectorOptions()
-    {
-        $res = [];
-        foreach (\App\Models\FluidbookTheme::orderBy('id', 'DESC')->get() as $theme) {
-            $res[$theme['id']] = $theme->name . ' (#' . $theme->id . ')';
-        }
-        return $res;
+        $attributes['optionsmodel'] = \App\Models\FluidbookTheme::class;
+        $attributes['attribute'] = 'nameAndId';
+        $attributes['optionsmodel_orderby'] = 'id';
+        $attributes['optionsmodel_orderby_way'] = 'desc';
+        parent::__construct($attributes);
     }
 }
index d162af65f92bf42476a2e362761239454a47f85f..2719b691678ef1e46432a981528aafd4f5f490f8 100644 (file)
@@ -138,8 +138,6 @@ class FluidbookThemeAPIController extends Controller
         $newtheme->owner = Auth::id();
         $newtheme->push();
 
-        copy(GenerateThemePreview::getPreviewPath($id), GenerateThemePreview::getPreviewPath($newtheme->id));
-
         return $newtheme->id;
     }
 
index d0f8da06a36e42d679dc4da4b5064b1ab7a4f43f..c923da6bb2fa2ef38f01efec4bb65555ec997e46 100644 (file)
@@ -12,7 +12,7 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
 
 class UpdateWS2ThemeTable extends Base
 {
-        protected $id = 'all';
+    protected $id = 'all';
 
     protected $_fileFields = [];
     protected $_colorFields = [];
@@ -70,7 +70,6 @@ class UpdateWS2ThemeTable extends Base
             $data[] = $this->_handleTheme($theme);
             $t->where('theme_id', '=', $this->id)->delete();
         }
-//        dd($data);
         $t->insert($data);
     }
 
index c22d5867d10cd7cbf1a702b0fc472b56f8143fdc..5187e1b2cc328ae6ed2b2bbd8c6cf7263ccbc6fa 100644 (file)
@@ -665,7 +665,9 @@ class FluidbookTheme extends ToolboxModel
     {
         if (self::$updateWS2ViewOnChange) {
             if (null !== $id) {
+                start_measure('update_theme_table', 'Update ws2 theme');
                 dispatch(new UpdateWS2ThemeTable($id))->onConnection('sync');
+                stop_measure('update_theme_table');
             }
             dispatch(new UpdateWS2ThemeTable('all'))->onQueue('theme');
         }
@@ -785,4 +787,20 @@ class FluidbookTheme extends ToolboxModel
         }
         return '<img src="data:image/' . $type . ';base64,' . $b . '" width="200" height="140" alt="" />';
     }
+
+    public function getNameAndIdAttribute()
+    {
+        return $this->getAttribute('name') . ' (#' . $this->getAttribute('id') . ')';
+    }
+
+    public function replicate(array $except = null)
+    {
+        $currentId = $this->id;
+
+        $res = parent::replicate($except);
+        $newId = $res->id;
+        copy(GenerateThemePreview::getPreviewPath($currentId), GenerateThemePreview::getPreviewPath($newId));
+
+        return $res;
+    }
 }
index 916a76ecc3eb4bcbf0f196013a07678312a1b5b0..5767c9b8055449bacea14e0be9dd8e75eef367c6 100644 (file)
                 width: 40%;
                 vertical-align: top;
                 padding: 0 0 0 20px;
-                white-space: normal;
             }
 
             .themeSelector .actions a {
index 13bb34cce2ec1a017bc79820ef8a629d51447d73..51812594bb87776f66875ce0ac8add2133271d5e 100644 (file)
                         return false;
                     });
 
-                    $(document).on('click', 'button[type="submit"].btn-success', function () {
-                        $(window).on('unload', function () {
+                    $(window).on('unload', function () {
+                        try {
                             window.parent.crud.table.ajax.reload();
-                            window.parent.jQuery.featherlight.current().close();
-                            return true;
-                        });
+                        } catch (e) {
+
+                        }
+                        window.parent.jQuery.featherlight.current().close();
                         return true;
                     });
                 });