]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6542 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 1 Dec 2023 15:43:10 +0000 (16:43 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 1 Dec 2023 15:43:10 +0000 (16:43 +0100)
app/Jobs/GenerateQuizThemePreview.php
app/Models/QuizTheme.php
resources/quiztheme/theme_preview/theme_preview.js

index a738883f5a224e1d36deae0077bff84746305314..4483708691d3d995476151396b63a13f456df2e3 100644 (file)
@@ -5,6 +5,7 @@ namespace App\Jobs;
 use App\Models\QuizTheme;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Cache;
 
 class GenerateQuizThemePreview extends Base
 {
@@ -36,19 +37,21 @@ class GenerateQuizThemePreview extends Base
      */
     public function handle()
     {
-        $cl = new CommandLine('node');
-        $cl->setArg(null, resource_path('quiztheme/theme_preview/theme_preview.js'));
-        $cl->setArg('width', 1200);
-        $cl->setArg('height', 680);
-        $cl->setArg('delay', 2);
-        $cl->setArg('scale', 1);
-        $cl->setArg('intro', $this->getPreviewPath('intro'));
-        $cl->setArg('standard', $this->getPreviewPath('standard'));
-        $cl->setArg('draganddrop', $this->getPreviewPath('draganddrop'));
-        $cl->setArg('outro', $this->getPreviewPath('outro'));
-        $url = $this->theme->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]);
-        $cl->setArg('url', $url);
-        $cl->execute();
+        Cache::lock('quiz_theme_preview_' . $this->theme->id, 120)->get(function () {
+            $cl = new CommandLine('node');
+            $cl->setArg(null, resource_path('quiztheme/theme_preview/theme_preview.js'));
+            $cl->setArg('width', 1200);
+            $cl->setArg('height', 680);
+            $cl->setArg('delay', 2);
+            $cl->setArg('scale', 1);
+            $cl->setArg('intro', $this->getPreviewPath('intro'));
+            $cl->setArg('standard', $this->getPreviewPath('standard'));
+            $cl->setArg('draganddrop', $this->getPreviewPath('draganddrop'));
+            $cl->setArg('outro', $this->getPreviewPath('outro'));
+            $url = $this->theme->getPreviewURL(['shortLoading' => 1, 'transition' => 1, 'puppeteer' => 1]);
+            $cl->setArg('url', $url);
+            $cl->execute();
+        });
     }
 
     public function getPreviewPath($type)
index 163443ac2207d5b7d2e2677f9d1427f5e19258af..3bdc8cd2f82bf45392404d576c81be1da75c5ba6 100644 (file)
@@ -7,6 +7,7 @@ use App\Fields\FluidbookThemeImage;
 use App\Fields\HorizontalAlign;
 use App\Fields\ThemeBackgroundSize;
 use App\Fields\VerticalAlign;
+use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
 use App\Http\Controllers\Admin\Operations\QuizTheme\PreviewOperation;
 use App\Jobs\GenerateQuizThemePreview;
 use App\Models\Base\ToolboxModel;
@@ -42,7 +43,7 @@ class QuizTheme extends ToolboxModel
     const DARK_COLOR = '#383838';
     const LIGHT_COLOR = '#ffffff';
 
-    protected $_operations = [PreviewOperation::class];
+    protected $_operations = [PreviewOperation::class, ChangeownerOperation::class];
 
     public function setFields()
     {
@@ -239,11 +240,11 @@ class QuizTheme extends ToolboxModel
         $theme->okColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->okColor);
         $theme->nokColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->nokColor);
         $theme->introColor = 'transparent';
-        $theme->outroColor = $theme->standardColor = $theme->draganddropArea1Color = $theme->draganddropArea2Color = \Cubist\Util\Graphics\Color::colorToCSS($quiz->overlay);
+        $theme->standardColor = $theme->draganddropColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->overlay);
         $theme->neutralColor = \Cubist\Util\Graphics\Color::colorToCSS($quiz->overlay);
         $theme->backgroundColor = '#ffffff';
 
-        $theme->owner = 5;
+        $theme->owner = $quiz->owner;
 
         $logo = new \SplFileInfo($logo);
         $tmp = Files::tempnam() . '.' . $logo->getExtension();
@@ -251,9 +252,6 @@ class QuizTheme extends ToolboxModel
         $theme->addMediaToField('logo', $tmp);
 
         $theme->backgroundCustom = '1';
-        $theme->backgroundSize = ThemeBackgroundSize::RATIO;
-        $theme->backgroundHorizontalAlign = HorizontalAlign::CENTER;
-        $theme->backgroundVerticalAlign = VerticalAlign::MIDDLE;
 
         $theme->font = 'SourceSans';
 
@@ -270,11 +268,6 @@ class QuizTheme extends ToolboxModel
         $theme->addMediaToField('backgroundImage', self::resizeAndBlur($banner, 1200, 680));
         $theme->addMediaToField('backgroundImageMobile', self::resizeAndBlur($banner, 390, 844));
 
-        $theme->backgroundCustomMobile = '1';
-        $theme->backgroundSizeMobile = ThemeBackgroundSize::RATIO;
-        $theme->backgroundHorizontalAlignMobile = HorizontalAlign::CENTER;
-        $theme->backgroundVerticalAlignMobile = VerticalAlign::MIDDLE;
-
         $theme->save();
         return $theme->id;
     }
index 9c1f13c4860548ebfea36427862e9fd77abe9085..87e9a6d4093c47628c717d897db03475d80ef59c 100644 (file)
@@ -37,7 +37,7 @@ const optionDefinitions = [
 
     // Intro screen
     await page.goto(options.url, {waitUntil: 'networkidle2'});
-    await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
+    await new Promise(r => setTimeout(r, 1000 * (options.delay + 5)));
     await page.screenshot({path: options.intro, type: 'jpeg', quality: 95});
 
     // Question 1
@@ -47,13 +47,13 @@ const optionDefinitions = [
     await page.evaluate(() => window.quiz.score.setAnswer(0, [0]));
 
     // Question 2
-    await  page.evaluate(() => window.quiz.screens.showScreen('q-1'));
+    await page.evaluate(() => window.quiz.screens.showScreen('q-1'));
     await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
     await page.screenshot({path: options.draganddrop, type: 'jpeg', quality: 95});
-    await  page.evaluate(() => window.quiz.score.setAnswer(1, [1, 1, 2, 1, 2]));
+    await page.evaluate(() => window.quiz.score.setAnswer(1, [1, 1, 2, 1, 2]));
 
     // Outro
-    await  page.evaluate(() => window.quiz.screens.showScreen('outro'));
+    await page.evaluate(() => window.quiz.screens.showScreen('outro'));
     await new Promise(r => setTimeout(r, 1000 * (options.delay + 3)));
     await page.screenshot({path: options.outro, type: 'jpeg', quality: 95});