From 2da16e334e0e089eb8ec9d01315f527579f106a4 Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Sat, 7 Apr 2018 10:54:56 -0500 Subject: [PATCH] notes work --- app/controllers/notes_controller.rb | 2 +- app/javascript/components/NoteEdit.vue | 57 ++++++++++++ .../components/TheIngredientList.vue | 10 ++- app/javascript/components/TheNotesList.vue | 86 ++++++++++++++++++- app/javascript/lib/Api.js | 30 ++++++- app/javascript/store/index.js | 1 + app/javascript/styles/_variables.scss | 3 + app/javascript/styles/index.scss | 10 ++- 8 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 app/javascript/components/NoteEdit.vue diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index cc90341..a417743 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -77,6 +77,6 @@ class NotesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def note_params - params.require(:note).permit(:user_id, :content) + params.require(:note).permit(:content) end end diff --git a/app/javascript/components/NoteEdit.vue b/app/javascript/components/NoteEdit.vue new file mode 100644 index 0000000..722ed70 --- /dev/null +++ b/app/javascript/components/NoteEdit.vue @@ -0,0 +1,57 @@ + + + + + \ No newline at end of file diff --git a/app/javascript/components/TheIngredientList.vue b/app/javascript/components/TheIngredientList.vue index 7cad5cb..fe9e3d0 100644 --- a/app/javascript/components/TheIngredientList.vue +++ b/app/javascript/components/TheIngredientList.vue @@ -2,11 +2,13 @@

Ingredients

- Create Ingredient +
+ Create Ingredient +
- +
@@ -46,6 +48,10 @@ +
+ Create Ingredient +
+ diff --git a/app/javascript/components/TheNotesList.vue b/app/javascript/components/TheNotesList.vue index b49d99e..75ed5ee 100644 --- a/app/javascript/components/TheNotesList.vue +++ b/app/javascript/components/TheNotesList.vue @@ -1,11 +1,95 @@ diff --git a/app/javascript/lib/Api.js b/app/javascript/lib/Api.js index 63591b8..fb8763b 100644 --- a/app/javascript/lib/Api.js +++ b/app/javascript/lib/Api.js @@ -12,8 +12,10 @@ class Api { } checkStatus(response) { - if (response.status >= 200 && response.status < 300) { - return response; + if (response.status == 204) { + return null; + } else if (response.ok) { + return response.json(); } else if (response.status === 404) { throw new Errors.ApiNotFoundError(response.statusText, response); } else if (response.status === 422) { @@ -32,6 +34,7 @@ class Api { const headers = new Headers(); headers.append('Accept', 'application/json'); + headers.append('Content-Type', 'application/json'); const opts = { headers, @@ -40,11 +43,10 @@ class Api { }; if (hasBody) { - headers.append('Content-Type', 'application/json'); opts.body = JSON.stringify(params); } - return fetch(url, opts).then(this.checkStatus).then(this.parseJSON); + return fetch(url, opts).then(this.checkStatus); } objectToUrlParams(obj, queryParams = [], prefixes = []) { @@ -84,6 +86,10 @@ class Api { return this.performRequest(url, "PATCH", params); } + del(url, params = {}) { + return this.performRequest(url, "DELETE", params); + } + getRecipeList(page, per, sortColumn, sortDirection, name, tags) { const params = { criteria: { @@ -251,6 +257,22 @@ class Api { return this.get("/ingredients/usda_food_search", {query: query}); } + getNoteList() { + return this.get("/notes/"); + } + + postNote(note) { + const params = { + content: note.content + }; + + return this.post("/notes/", params); + } + + deleteNote(note) { + return this.del("/notes/" + note.id); + } + postLogin(username, password) { const params = { username: username, diff --git a/app/javascript/store/index.js b/app/javascript/store/index.js index 70d24d1..df165ce 100644 --- a/app/javascript/store/index.js +++ b/app/javascript/store/index.js @@ -43,6 +43,7 @@ export default new Vuex.Store({ }, setError(state, value) { + console.log(value); state.error = value; }, diff --git a/app/javascript/styles/_variables.scss b/app/javascript/styles/_variables.scss index c6d0e26..a17308d 100644 --- a/app/javascript/styles/_variables.scss +++ b/app/javascript/styles/_variables.scss @@ -7,6 +7,8 @@ $coolors-green: rgba(121, 167, 54, 1); $coolors-red: #ab4c34; $coolors-yellow: rgba(240, 162, 2, 1); +$family-serif: Georgia, "Times New Roman", Times, serif; + // Bluma default overrides //$green: #79A736; //$red: #d4424e; @@ -19,6 +21,7 @@ $yellow: $coolors-yellow; $dark: $coolors-dark; $primary: $green; +$family-primary: $family-serif; $modal-content-width: 750px; diff --git a/app/javascript/styles/index.scss b/app/javascript/styles/index.scss index 2100e65..b584b49 100644 --- a/app/javascript/styles/index.scss +++ b/app/javascript/styles/index.scss @@ -33,4 +33,12 @@ body { padding: 1rem; background-color: $white; } -} \ No newline at end of file +} + +.title, .subtitle, .navbar, .button, .pagination, .modal-card-title, th { + font-family: $family-sans-serif; +} + +.pagination:not(:last-child) { + margin-bottom: 1em; +}
Name