import with image working

This commit is contained in:
vabene1111
2022-02-21 15:59:30 +01:00
parent c06c511dc9
commit e04d672750
7 changed files with 94 additions and 38 deletions

View File

@ -34,13 +34,41 @@
<div class="row">
<div class="col col-md-12" v-if="recipe_json !== undefined">
Images
<div class="row">
<div class="col col-md-12 text-center">
<b-img rounded fluid :src="recipe_json.image"
style="max-height: 30vh"></b-img>
</div>
</div>
<div class="row mt-1">
<div class="col col-md-12 text-center">
<small class="text-muted">Click the image you want to import for this
recipe</small> <!-- TODO localize -->
</div>
<div class="col col-md-12 text-center">
<b-img v-for="i in recipe_images" rounded thumbnail fluid :src="i"
style="max-height: 10vh" v-bind:key="i"
@click="recipe_json.image = i"></b-img>
</div>
</div>
Keywords
<ul>
<li v-for="k in recipe_json.keywords" v-bind:key="k">{{k}}</li>
<li v-for="k in recipe_json.keywords" v-bind:key="k.name">{{ k.label }}</li>
</ul>
unused
<ul>
<li v-for="k in recipe_json.unused_keywords" v-bind:key="k.name">{{
k.label
}}
</li>
</ul>
Steps
<ul>
<li v-for="s in recipe_json.steps" v-bind:key="s">{{s}}</li>
<li v-for="s in recipe_json.steps" v-bind:key="s">{{ s }}</li>
</ul>
</div>
</div>
@ -119,8 +147,14 @@ export default {
importRecipe: function () {
let apiFactory = new ApiApiFactory()
apiFactory.createRecipe(this.recipe_json).then(response => {
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
window.location = resolveDjangoUrl('edit_recipe', response.data.id)
let recipe = response.data
apiFactory.imageRecipe(response.data.id, undefined, this.recipe_json.image).then(response => {
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
window.location = resolveDjangoUrl('edit_recipe', recipe.id)
}).catch(e => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE)
window.location = resolveDjangoUrl('edit_recipe', recipe.id)
})
}).catch(err => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_CREATE)
})
@ -154,6 +188,10 @@ export default {
'mode': this.mode
},).then((response) => {
this.recipe_json = response.data['recipe_json'];
this.$set(this.recipe_json, 'unused_keywords', this.recipe_json.keywords.filter(k => k.id === undefined))
this.$set(this.recipe_json, 'keywords', this.recipe_json.keywords.filter(k => k.id !== undefined))
this.recipe_tree = response.data['recipe_tree'];
this.recipe_html = response.data['recipe_html'];
this.recipe_images = response.data['recipe_images']; //todo change on backend as well after old view is deprecated

View File

@ -1856,6 +1856,12 @@ export interface RecipeImage {
* @memberof RecipeImage
*/
image?: any | null;
/**
*
* @type {string}
* @memberof RecipeImage
*/
image_url?: string | null;
}
/**
*
@ -5227,10 +5233,11 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
*
* @param {string} id A unique integer value identifying this recipe.
* @param {any} [image]
* @param {string} [imageUrl]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
imageRecipe: async (id: string, image?: any, options: any = {}): Promise<RequestArgs> => {
imageRecipe: async (id: string, image?: any, imageUrl?: string, options: any = {}): Promise<RequestArgs> => {
// verify required parameter 'id' is not null or undefined
assertParamExists('imageRecipe', 'id', id)
const localVarPath = `/api/recipe/{id}/image/`
@ -5252,6 +5259,10 @@ export const ApiApiAxiosParamCreator = function (configuration?: Configuration)
localVarFormParams.append('image', image as any);
}
if (imageUrl !== undefined) {
localVarFormParams.append('image_url', imageUrl as any);
}
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
@ -10341,11 +10352,12 @@ export const ApiApiFp = function(configuration?: Configuration) {
*
* @param {string} id A unique integer value identifying this recipe.
* @param {any} [image]
* @param {string} [imageUrl]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async imageRecipe(id: string, image?: any, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RecipeImage>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.imageRecipe(id, image, options);
async imageRecipe(id: string, image?: any, imageUrl?: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RecipeImage>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.imageRecipe(id, image, imageUrl, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
@ -12174,11 +12186,12 @@ export const ApiApiFactory = function (configuration?: Configuration, basePath?:
*
* @param {string} id A unique integer value identifying this recipe.
* @param {any} [image]
* @param {string} [imageUrl]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
imageRecipe(id: string, image?: any, options?: any): AxiosPromise<RecipeImage> {
return localVarFp.imageRecipe(id, image, options).then((request) => request(axios, basePath));
imageRecipe(id: string, image?: any, imageUrl?: string, options?: any): AxiosPromise<RecipeImage> {
return localVarFp.imageRecipe(id, image, imageUrl, options).then((request) => request(axios, basePath));
},
/**
*
@ -13992,12 +14005,13 @@ export class ApiApi extends BaseAPI {
*
* @param {string} id A unique integer value identifying this recipe.
* @param {any} [image]
* @param {string} [imageUrl]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ApiApi
*/
public imageRecipe(id: string, image?: any, options?: any) {
return ApiApiFp(this.configuration).imageRecipe(id, image, options).then((request) => request(this.axios, this.basePath));
public imageRecipe(id: string, image?: any, imageUrl?: string, options?: any) {
return ApiApiFp(this.configuration).imageRecipe(id, image, imageUrl, options).then((request) => request(this.axios, this.basePath));
}
/**