From: Vincent Vanwaelscappel Date: Thu, 28 Sep 2023 08:28:06 +0000 (+0200) Subject: wip #6170 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=01806e229fcc519bd375bf86320e9242df31c014;p=fluidbook-toolbox.git wip #6170 @0.75 --- diff --git a/app/Http/Controllers/Admin/Operations/QuizTheme/PreviewOperation.php b/app/Http/Controllers/Admin/Operations/QuizTheme/PreviewOperation.php new file mode 100644 index 000000000..16352a5bc --- /dev/null +++ b/app/Http/Controllers/Admin/Operations/QuizTheme/PreviewOperation.php @@ -0,0 +1,42 @@ +whereIn('type', ['intro', 'outro', 'standard', 'draganddrop']) + ->whereNumber('id'); + } + + protected function previewImage($id, $type) + { + if (!QuizTheme::hasPermission($id, 'read')) { + abort(401); + } + + /** @var QuizTheme $theme */ + $theme = QuizTheme::withoutGlobalScopes()->find($id); + $path = $theme->getPreviewImagePath($type); + if (!file_exists($path)) { + $job = new GenerateQuizThemePreview($theme); + $job->handle(); + } + if (!file_exists($path)) { + abort(404, 'Unable to generate theme ' . $theme->id . ' preview :' . $path); + } + return XSendFileController::sendfileNoCache($path); + } +} diff --git a/app/Jobs/GenerateQuizThemePreview.php b/app/Jobs/GenerateQuizThemePreview.php index ef40c18b6..0735655e6 100644 --- a/app/Jobs/GenerateQuizThemePreview.php +++ b/app/Jobs/GenerateQuizThemePreview.php @@ -42,18 +42,18 @@ class GenerateQuizThemePreview extends Base $cl->setArg('height', 680); $cl->setArg('delay', 2); $cl->setArg('scale', 1); - $cl->setArg('intro', self::getPreviewPath($this->theme->getIdValue(), 'intro')); - $cl->setArg('standard', self::getPreviewPath($this->theme->getIdValue(), 'standard')); - $cl->setArg('draganddrop', self::getPreviewPath($this->theme->getIdValue(), 'draganddrop')); - $cl->setArg('outro', self::getPreviewPath($this->theme->getIdValue(), 'outro')); + $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(); $cl->debug(); } - public static function getPreviewPath($themeId, $variant = '') + public function getPreviewPath($type) { - return Files::mkdir(storage_path('quizthemes') . '/' . $themeId) . $variant . '.jpg'; + return $this->theme->getPreviewImagePath($type); } } diff --git a/app/Models/FluidbookTheme.php b/app/Models/FluidbookTheme.php index 74ca20064..4db0b6473 100644 --- a/app/Models/FluidbookTheme.php +++ b/app/Models/FluidbookTheme.php @@ -9,7 +9,7 @@ use App\Fields\HorizontalAlign; use App\Fields\ThemeBackgroundSize; use App\Fields\VerticalAlign; use App\Http\Controllers\Admin\Operations\ChangeownerOperation; -use App\Jobs\GenerateSecondPagePreview; +use App\Http\Controllers\Admin\Operations\QuizTheme\PreviewOperation; use App\Jobs\GenerateThemePreview; use App\Jobs\UpdateWS2ThemeTable; use App\Models\Base\ToolboxSettingsModel; @@ -56,7 +56,7 @@ class FluidbookTheme extends ToolboxSettingsModel public static $updateWS2ViewOnChange = true; public static $updateWS2SyncViewOnChange = false; - protected $_operations = [ChangeownerOperation::class]; + protected $_operations = [ChangeownerOperation::class, PreviewOperation::class]; public function setFields() { @@ -86,7 +86,7 @@ class FluidbookTheme extends ToolboxSettingsModel ]); $this->addField(['name' => 'interfaceFont', - 'type'=>FluidbookFont::class, + 'type' => FluidbookFont::class, 'default' => 'OpenSans', 'label' => __('Police de caractères'), 'translatable' => false, diff --git a/app/Models/QuizTheme.php b/app/Models/QuizTheme.php index 0a1e932d0..ce5b935c8 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\Jobs\GenerateQuizThemePreview; use App\Models\Base\ToolboxModel; use Cubist\Backpack\Magic\Fields\Checkbox; use Cubist\Backpack\Magic\Fields\Color; @@ -15,7 +16,6 @@ use Cubist\Backpack\Magic\Fields\FormSectionDescription; use Cubist\Backpack\Magic\Fields\FormSeparator; use Cubist\Backpack\Magic\Fields\Hidden; use Cubist\Backpack\Magic\Fields\SelectFromArray; -use Cubist\Backpack\Magic\Fields\Text; use Cubist\Util\CommandLine\Imagemagick; use Cubist\Util\Files\Files; use Cubist\Util\Graphics\Resizer; @@ -190,7 +190,6 @@ class QuizTheme extends ToolboxModel return $theme->id; } - $theme = new QuizTheme(); $theme->hash = $hash; $theme->name = $quiz->client . ' - ' . $quiz->title; @@ -256,9 +255,9 @@ class QuizTheme extends ToolboxModel return $blur; } - public function getPreviewURL($params = [], $page = 2) + public function getPreviewURL($params = []) { - return self::getThemePreviewURL($this->getIdValue(), $params, $page); + return self::getThemePreviewURL($this->getIdValue(), $params); } public static function getThemePreviewURL($id, $params = []) @@ -268,10 +267,24 @@ class QuizTheme extends ToolboxModel } - public function getPreviewImage() + public function getPreviewImage($type = 'intro') + { + return clean(''); + } + + public function getPreviewImagePath($type) { - return clean(''); + return \Cubist\Util\Files\Files::mkdir(storage_path('quizthemes') . '/' . $this->id) . $type . '.jpg'; } + public function postSave() + { + parent::postSave(); + $this->_generateThemePreview(); + } + protected function _generateThemePreview($sync = false) + { + dispatch(new GenerateQuizThemePreview($this))->onQueue('theme'); + } } diff --git a/resources/quiztheme/theme_preview/theme_preview.js b/resources/quiztheme/theme_preview/theme_preview.js index fd540133d..1720ea5bb 100644 --- a/resources/quiztheme/theme_preview/theme_preview.js +++ b/resources/quiztheme/theme_preview/theme_preview.js @@ -14,7 +14,6 @@ const optionDefinitions = [ ]; (async () => { - const {installMouseHelper} = require('./install-mouse-helper'); const options = commandLineArgs(optionDefinitions); const browser = await puppeteer.launch({ headless: 'new',