From 0e3d1576b2bae40de145291cb5fe136e7faebc4c Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Wed, 3 May 2017 22:10:24 +0200 Subject: [PATCH] Use stars to note flats Instead of a binary "followed" / "not followed" status, use 5 stars to allow users to give a note to a flat between 0 (not followed) and 5. Any note different from zero add a "followed" status. Closes issue #36. --- flatisfy/models/flat.py | 5 +- flatisfy/web/app.py | 2 + flatisfy/web/js_src/api/index.js | 18 ++++++ flatisfy/web/js_src/components/flatstable.vue | 7 ++- flatisfy/web/js_src/store/actions.js | 6 ++ flatisfy/web/js_src/store/mutations-types.js | 1 + flatisfy/web/js_src/store/mutations.js | 7 +++ flatisfy/web/js_src/tools/index.js | 4 ++ flatisfy/web/js_src/views/details.vue | 56 +++++++++++++++---- flatisfy/web/routes/api.py | 28 ++++++++++ 10 files changed, 119 insertions(+), 15 deletions(-) diff --git a/flatisfy/models/flat.py b/flatisfy/models/flat.py index df67f7a..3111f2d 100644 --- a/flatisfy/models/flat.py +++ b/flatisfy/models/flat.py @@ -10,7 +10,9 @@ import logging import arrow import enum -from sqlalchemy import Column, DateTime, Enum, Float, String, Text +from sqlalchemy import ( + Column, DateTime, Enum, Float, SmallInteger, String, Text +) from flatisfy.database.base import BASE from flatisfy.database.types import MagicJSON @@ -77,6 +79,7 @@ class Flat(BASE): urls = Column(MagicJSON) merged_ids = Column(MagicJSON) notes = Column(Text) + notation = Column(SmallInteger, default=0) # Flatisfy data # TODO: Should be in another table with relationships diff --git a/flatisfy/web/app.py b/flatisfy/web/app.py index 2709dbd..0428d58 100644 --- a/flatisfy/web/app.py +++ b/flatisfy/web/app.py @@ -80,6 +80,8 @@ def get_app(config): api_routes.update_flat_status_v1) app.route("/api/v1/flat/:flat_id/notes", "POST", api_routes.update_flat_notes_v1) + app.route("/api/v1/flat/:flat_id/notation", "POST", + api_routes.update_flat_notation_v1) app.route("/api/v1/search", "POST", api_routes.search_v1) diff --git a/flatisfy/web/js_src/api/index.js b/flatisfy/web/js_src/api/index.js index 1c59ebb..4dfbba8 100644 --- a/flatisfy/web/js_src/api/index.js +++ b/flatisfy/web/js_src/api/index.js @@ -88,6 +88,24 @@ export const updateFlatNotes = function (flatId, newNotes, callback) { }) } +export const updateFlatNotation = function (flatId, newNotation, callback) { + fetch( + '/api/v1/flat/' + encodeURIComponent(flatId) + '/notation', + { + credentials: 'same-origin', + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + notation: newNotation + }) + } + ).then(callback).catch(function (ex) { + console.error('Unable to update flat notation: ' + ex) + }) +} + export const getTimeToPlaces = function (callback) { fetch('/api/v1/time_to/places', { credentials: 'same-origin' }) .then(function (response) { diff --git a/flatisfy/web/js_src/components/flatstable.vue b/flatisfy/web/js_src/components/flatstable.vue index 20e2556..75e837a 100644 --- a/flatisfy/web/js_src/components/flatstable.vue +++ b/flatisfy/web/js_src/components/flatstable.vue @@ -36,7 +36,7 @@ -