recipe editing

This commit is contained in:
Dan Elbert 2018-04-01 22:32:13 -05:00
parent 1c4fa37778
commit 3b1a9246fd
10 changed files with 63 additions and 7 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016 Dan Elbert
Copyright (c) 2018 Dan Elbert
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -11,6 +11,7 @@
:value="rawValue"
:class="finalInputClass"
@click="clickHandler"
@blur="blurHandler"
@input="inputHandler"
@keydown="keydownHandler"
@ -129,6 +130,10 @@
this.activeListIndex = idx;
},
clickHandler(evt) {
this.$emit("inputClick", evt);
},
blurHandler(evt) {
// blur fires before click. If the blur was fired because the user clicked a list item, immediately hiding the list here
// would prevent the click event from firing

View File

@ -22,6 +22,7 @@
valueAttribute="name"
labelAttribute="name"
placeholder=""
@inputClick="nameClick"
@optionSelected="searchItemSelected"
:onGetOptions="updateSearchItems"
>
@ -72,6 +73,12 @@
this.ingredient.ingredient_id = ingredient.id;
this.ingredient.ingredient = ingredient;
this.ingredient.name = ingredient.name;
},
nameClick() {
if (this.ingredient.ingredient_id === null && this.ingredient.name !== null && this.ingredient.name.length > 2) {
this.$refs.autocomplete.updateOptions(this.ingredient.name);
}
}
},

View File

@ -1,5 +1,22 @@
<template>
<div class="content">
<h1 class="title">About</h1>
<p>
A Recipe manager. Source available from my Git repository at <a href="https://source.elbert.us/dan/parsley">https://source.elbert.us</a>.
</p>
<p>
Parsley is released under the MIT License. All code &copy; Dan Elbert 2018.
</p>
<p>
Food data provided by:<br/>
<cite>
US Department of Agriculture, Agricultural Research Service, Nutrient Data Laboratory. USDA National Nutrient Database for Standard Reference, Release 28. Version Current: September 2015. Internet: <a href="http://www.ars.usda.gov/nea/bhnrc/ndl">http://www.ars.usda.gov/nea/bhnrc/ndl</a>
</cite>
</p>
</div>
</template>
<script>

View File

@ -7,8 +7,8 @@
<recipe-show :recipe="recipe"></recipe-show>
</div>
<router-link :to="{name: 'edit_recipe', params: { id: recipeId }}">Edit</router-link>
<router-link to="/">Back</router-link>
<router-link class="button" :to="{name: 'edit_recipe', params: { id: recipeId }}">Edit</router-link>
<router-link class="button" to="/">Back</router-link>
</div>
</template>

View File

@ -3,6 +3,9 @@
<recipe-edit :recipe="recipe" action="Creating"></recipe-edit>
<button type="button" class="button is-primary" @click="save">Save</button>
<router-link class="button is-secondary" to="/">Cancel</router-link>
</div>
</template>
@ -11,6 +14,7 @@
import RecipeEdit from "./RecipeEdit";
import { mapState } from "vuex";
import api from "../lib/Api";
import * as Errors from '../lib/Errors';
export default {
data() {
@ -35,6 +39,16 @@
})
},
methods: {
save() {
this.loadResource(
api.postRecipe(this.recipe)
.then(() => this.$router.push('/'))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
components: {
RecipeEdit
}

View File

@ -103,7 +103,7 @@ class Api {
return this.get("/recipes/" + id);
}
patchRecipe(recipe) {
buildRecipeParams(recipe) {
const params = {
recipe: {
name: recipe.name,
@ -124,7 +124,7 @@ class Api {
return {
id: i.id,
name: i.name,
ingredient_id: null,
ingredient_id: i.ingredient_id,
quantity: i.quantity,
units: i.units,
preparation: i.preparation,
@ -134,8 +134,15 @@ class Api {
})
}
};
return params;
}
return this.patch("/recipes/" + recipe.id, params);
patchRecipe(recipe) {
return this.patch("/recipes/" + recipe.id, this.buildRecipeParams(recipe));
}
postRecipe(recipe) {
return this.post("/recipes/", this.buildRecipeParams(recipe));
}
postPreviewSteps(step_text) {

View File

@ -12,8 +12,13 @@
@import "./responsive_controls";
html, body {
min-height: 100%;
}
body {
background-color: $grey-dark;
padding-bottom: 2rem;
}
#app {

View File

@ -103,7 +103,7 @@ class Recipe < ApplicationRecord
query = active.order(criteria.sort_column => criteria.sort_direction).page(criteria.page).per(criteria.per)
if criteria.name.present?
query = query.matches_token(:name, criteria.name)
query = query.matches_tokens(:name, criteria.name.split(' '))
end
if criteria.tags.present?

View File

@ -17,6 +17,7 @@ module UnitConversion
end
def parse_value(str)
str = str.to_s.strip
if str =~ /^#{INTEGER_REGEX}$/
str.to_i
elsif str =~ /^#{RATIONAL_REGEX}$/