use App\Models\QuizTheme;
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
+use Illuminate\Support\Facades\Cache;
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)
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;
const DARK_COLOR = '#383838';
const LIGHT_COLOR = '#ffffff';
- protected $_operations = [PreviewOperation::class];
+ protected $_operations = [PreviewOperation::class, ChangeownerOperation::class];
public function setFields()
{
$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();
$theme->addMediaToField('logo', $tmp);
$theme->backgroundCustom = '1';
- $theme->backgroundSize = ThemeBackgroundSize::RATIO;
- $theme->backgroundHorizontalAlign = HorizontalAlign::CENTER;
- $theme->backgroundVerticalAlign = VerticalAlign::MIDDLE;
$theme->font = 'SourceSans';
$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;
}
// 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
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});