From: Vincent Vanwaelscappel Date: Fri, 1 Dec 2023 15:43:10 +0000 (+0100) Subject: wip #6542 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=faa33949bf64ed4843c9243bccb9ddfeb6fec646;p=fluidbook-toolbox.git wip #6542 @2 --- diff --git a/app/Jobs/GenerateQuizThemePreview.php b/app/Jobs/GenerateQuizThemePreview.php index a738883f5..448370869 100644 --- a/app/Jobs/GenerateQuizThemePreview.php +++ b/app/Jobs/GenerateQuizThemePreview.php @@ -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) diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index 163443ac2..3bdc8cd2f 100644 --- a/app/Models/QuizTheme.php +++ b/app/Models/QuizTheme.php @@ -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; } diff --git a/resources/quiztheme/theme_preview/theme_preview.js b/resources/quiztheme/theme_preview/theme_preview.js index 9c1f13c48..87e9a6d40 100644 --- a/resources/quiztheme/theme_preview/theme_preview.js +++ b/resources/quiztheme/theme_preview/theme_preview.js @@ -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});