logs
This commit is contained in:
parent
248700778f
commit
6f213865f0
2
Gemfile
2
Gemfile
@ -1,6 +1,6 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
gem 'rails', '5.2.0.rc2'
|
gem 'rails', '5.2.0'
|
||||||
gem 'pg', '~> 0.21.0'
|
gem 'pg', '~> 0.21.0'
|
||||||
|
|
||||||
gem 'webpacker', '3.4.1'
|
gem 'webpacker', '3.4.1'
|
||||||
|
|||||||
@ -21,9 +21,9 @@ class LogsController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
ensure_owner(@log) do
|
ensure_owner(@log) do
|
||||||
if @log.update(log_params)
|
if @log.update(log_params)
|
||||||
redirect_to logs_path, notice: 'Log Entry was successfully updated.'
|
render json: { success: true }
|
||||||
else
|
else
|
||||||
render :edit
|
render json: @log.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -61,7 +61,7 @@ class LogsController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_log
|
def set_log
|
||||||
@log = Log.find(params[:id])
|
@log = Log.includes({recipe: {recipe_ingredients: {ingredient: :ingredient_units} }}).find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_recipe
|
def set_recipe
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
required: false,
|
required: false,
|
||||||
type: Date
|
type: [Date, String]
|
||||||
},
|
},
|
||||||
|
|
||||||
label: {
|
label: {
|
||||||
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
stringValue() {
|
stringValue() {
|
||||||
return DateTimeUtils.formatDateForEdit(this.value);
|
const d = DateTimeUtils.toDate(this.value);
|
||||||
|
return DateTimeUtils.formatDateForEdit(d);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,9 @@
|
|||||||
{{ recipe.total_time}} ({{recipe.active_time}})
|
{{ recipe.total_time}} ({{recipe.active_time}})
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="level-item">
|
<div class="level-item has-text-centered">
|
||||||
<p>Yields</p>
|
<p class="heading">Yields</p>
|
||||||
<p>{{recipe.yields}}</p>
|
<p class="title">{{recipe.yields}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="level-item">
|
<div class="level-item">
|
||||||
|
|||||||
@ -1,11 +1,62 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<log-edit v-if="log !== null" :log="log">
|
||||||
|
<div class="buttons">
|
||||||
|
<button type="button" class="button is-primary" @click="save">Save Log</button>
|
||||||
|
<router-link class="button is-secondary" to="/">Cancel</router-link>
|
||||||
|
</div>
|
||||||
|
</log-edit>
|
||||||
|
|
||||||
|
<div class="buttons">
|
||||||
|
<button type="button" class="button is-primary" @click="save">Save Log</button>
|
||||||
|
<router-link class="button is-secondary" to="/">Cancel</router-link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
import { mapState } from "vuex";
|
||||||
|
import api from "../lib/Api";
|
||||||
|
import * as Errors from "../lib/Errors";
|
||||||
|
import LogEdit from "./LogEdit";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
validationErrors: [],
|
||||||
|
log: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
...mapState({
|
||||||
|
logId: state => state.route.params.id,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
save() {
|
||||||
|
this.loadResource(
|
||||||
|
api.patchLog(this.log)
|
||||||
|
.then(() => this.$router.push('/'))
|
||||||
|
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.loadResource(
|
||||||
|
api.getLog(this.logId)
|
||||||
|
.then(data => { this.log = data; return data; })
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
LogEdit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -289,10 +289,6 @@ class Api {
|
|||||||
buildLogParams(log) {
|
buildLogParams(log) {
|
||||||
const recParams = this.buildRecipeParams(log.recipe);
|
const recParams = this.buildRecipeParams(log.recipe);
|
||||||
|
|
||||||
if (recParams.recipe && recParams.recipe.recipe_ingredients_attributes) {
|
|
||||||
recParams.recipe.recipe_ingredients_attributes.forEach(ri => ri.id = null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
log: {
|
log: {
|
||||||
date: log.date,
|
date: log.date,
|
||||||
@ -305,7 +301,12 @@ class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postLog(log) {
|
postLog(log) {
|
||||||
return this.post("/recipes/" + log.original_recipe_id + "/logs/", this.buildLogParams(log));
|
const params = this.buildLogParams(log);
|
||||||
|
const rec = params.log.recipe_attributes;
|
||||||
|
if (rec && rec.recipe_ingredients_attributes) {
|
||||||
|
rec.recipe_ingredients_attributes.forEach(ri => ri.id = null);
|
||||||
|
}
|
||||||
|
return this.post("/recipes/" + log.original_recipe_id + "/logs/", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
patchLog(log) {
|
patchLog(log) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
class Log < ApplicationRecord
|
class Log < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :recipe
|
belongs_to :recipe, dependent: :destroy
|
||||||
belongs_to :source_recipe, class_name: 'Recipe'
|
belongs_to :source_recipe, class_name: 'Recipe'
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user