Added printReady selector

This commit is contained in:
Tiago Rascazzi
2022-01-08 14:44:28 -05:00
parent 7c48c13dce
commit 16b357e11e
4 changed files with 20 additions and 7 deletions

View File

@ -51,7 +51,7 @@ class PDFexport(Integration):
await page.setCookie(cookies) await page.setCookie(cookies)
await page.goto('http://'+cmd.default_addr+':'+cmd.default_port+'/view/recipe/'+str(recipe.id), {'waitUntil': 'domcontentloaded'}) await page.goto('http://'+cmd.default_addr+':'+cmd.default_port+'/view/recipe/'+str(recipe.id), {'waitUntil': 'domcontentloaded'})
await page.waitForSelector('h3'); await page.waitForSelector('#printReady');
files.append([recipe.name + '.pdf', await page.pdf(options)]) files.append([recipe.name + '.pdf', await page.pdf(options)])
await page.close(); await page.close();

View File

@ -143,12 +143,13 @@ def export_recipe(request):
) )
else: else:
pk = ''
recipe = request.GET.get('r') recipe = request.GET.get('r')
if recipe: if recipe:
if re.match(r'^([0-9])+$', recipe): if re.match(r'^([0-9])+$', recipe):
recipe = Recipe.objects.filter(pk=int(recipe), space=request.space).first() pk = Recipe.objects.filter(pk=int(recipe), space=request.space).first().pk
return render(request, 'export.html', {'pk': recipe.pk}) return render(request, 'export.html', {'pk': pk})
@group_required('user') @group_required('user')

View File

@ -105,9 +105,10 @@ export default {
} }
}, },
mounted() { mounted() {
if(this.export_id)
this.insertRequested() this.insertRequested()
else
this.searchRecipes('')
}, },
methods: { methods: {

View File

@ -107,7 +107,7 @@
<div class="col-12 order-1 col-sm-12 order-sm-1 col-md-6 order-md-2"> <div class="col-12 order-1 col-sm-12 order-sm-1 col-md-6 order-md-2">
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">
<img class="img img-fluid rounded" :src="recipe.image" style="max-height: 30vh" :alt="$t('Recipe_Image')" v-if="recipe.image !== null" /> <img class="img img-fluid rounded" :src="recipe.image" style="max-height: 30vh" :alt="$t('Recipe_Image')" v-if="recipe.image !== null" @load="onImgLoad" />
</div> </div>
</div> </div>
@ -246,6 +246,9 @@ export default {
this.start_time = moment().format("yyyy-MM-DDTHH:mm") this.start_time = moment().format("yyyy-MM-DDTHH:mm")
} }
if(recipe.image === null) this.printReady()
this.recipe = this.rootrecipe = recipe this.recipe = this.rootrecipe = recipe
this.servings = this.servings_cache[this.rootrecipe.id] = recipe.servings this.servings = this.servings_cache[this.rootrecipe.id] = recipe.servings
this.loading = false this.loading = false
@ -272,6 +275,14 @@ export default {
this.servings = this.servings_cache?.[e.id] ?? e.servings this.servings = this.servings_cache?.[e.id] ?? e.servings
} }
}, },
printReady: function(){
const template = document.createElement("template");
template.id = "printReady";
document.body.appendChild(template);
},
onImgLoad: function(){
this.printReady()
},
}, },
} }
</script> </script>