logs
This commit is contained in:
parent
248700778f
commit
6f213865f0
2
Gemfile
2
Gemfile
@ -1,6 +1,6 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'rails', '5.2.0.rc2'
|
||||
gem 'rails', '5.2.0'
|
||||
gem 'pg', '~> 0.21.0'
|
||||
|
||||
gem 'webpacker', '3.4.1'
|
||||
|
@ -21,9 +21,9 @@ class LogsController < ApplicationController
|
||||
def update
|
||||
ensure_owner(@log) do
|
||||
if @log.update(log_params)
|
||||
redirect_to logs_path, notice: 'Log Entry was successfully updated.'
|
||||
render json: { success: true }
|
||||
else
|
||||
render :edit
|
||||
render json: @log.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -61,7 +61,7 @@ class LogsController < ApplicationController
|
||||
private
|
||||
|
||||
def set_log
|
||||
@log = Log.find(params[:id])
|
||||
@log = Log.includes({recipe: {recipe_ingredients: {ingredient: :ingredient_units} }}).find(params[:id])
|
||||
end
|
||||
|
||||
def set_recipe
|
||||
|
@ -10,7 +10,7 @@
|
||||
props: {
|
||||
value: {
|
||||
required: false,
|
||||
type: Date
|
||||
type: [Date, String]
|
||||
},
|
||||
|
||||
label: {
|
||||
@ -22,7 +22,8 @@
|
||||
|
||||
computed: {
|
||||
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}})
|
||||
</div>
|
||||
|
||||
<div class="level-item">
|
||||
<p>Yields</p>
|
||||
<p>{{recipe.yields}}</p>
|
||||
<div class="level-item has-text-centered">
|
||||
<p class="heading">Yields</p>
|
||||
<p class="title">{{recipe.yields}}</p>
|
||||
</div>
|
||||
|
||||
<div class="level-item">
|
||||
|
@ -1,11 +1,62 @@
|
||||
<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>
|
||||
|
||||
<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>
|
||||
|
@ -289,10 +289,6 @@ class Api {
|
||||
buildLogParams(log) {
|
||||
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 {
|
||||
log: {
|
||||
date: log.date,
|
||||
@ -305,7 +301,12 @@ class Api {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
class Log < ApplicationRecord
|
||||
|
||||
belongs_to :recipe
|
||||
belongs_to :recipe, dependent: :destroy
|
||||
belongs_to :source_recipe, class_name: 'Recipe'
|
||||
belongs_to :user
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user