From c936228726e0d035bc1e61991a43d1f50802d4ac Mon Sep 17 00:00:00 2001
From: "Phyks (Lucas Verney)"
Date: Thu, 9 Nov 2017 17:33:39 +0100
Subject: [PATCH] Add an ICS feed of visits
UI is minimalist and should be improved in the future. Fixes #40.
---
.gitignore | 1 +
flatisfy/models/flat.py | 3 +
flatisfy/web/app.py | 5 ++
flatisfy/web/js_src/api/index.js | 23 ++++++-
flatisfy/web/js_src/i18n/en/index.js | 2 +
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/views/details.vue | 41 +++++++++++-
flatisfy/web/routes/api.py | 69 ++++++++++++++++++++
package.json | 1 +
requirements.txt | 1 +
12 files changed, 157 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index dc40d0c..ec36322 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ config/
node_modules
flatisfy/web/static/assets
data/
+package-lock.json
diff --git a/flatisfy/models/flat.py b/flatisfy/models/flat.py
index 209bf83..a5889ac 100644
--- a/flatisfy/models/flat.py
+++ b/flatisfy/models/flat.py
@@ -93,6 +93,9 @@ class Flat(BASE):
# Status
status = Column(Enum(FlatStatus), default=FlatStatus.new)
+ # Date for visit
+ visit_date = Column(DateTime)
+
@staticmethod
def from_dict(flat_dict):
"""
diff --git a/flatisfy/web/app.py b/flatisfy/web/app.py
index 8dfea39..2915e74 100644
--- a/flatisfy/web/app.py
+++ b/flatisfy/web/app.py
@@ -83,6 +83,11 @@ def get_app(config):
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/flat/:flat_id/visit_date", "POST",
+ api_routes.update_flat_visit_date_v1)
+
+ app.route("/api/v1/visits.ics", "GET",
+ api_routes.ics_feed_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 3818df8..e96f552 100644
--- a/flatisfy/web/js_src/api/index.js
+++ b/flatisfy/web/js_src/api/index.js
@@ -6,7 +6,10 @@ require('isomorphic-fetch')
const postProcessAPIResults = function (flat) {
/* eslint-disable camelcase */
if (flat.date) {
- flat.date = moment(flat.date)
+ flat.date = moment.utc(flat.date)
+ }
+ if (flat.visit_date) {
+ flat.visit_date = moment.utc(flat.visit_date)
}
if (flat.flatisfy_time_to) {
const momentifiedTimeTo = {}
@@ -110,6 +113,24 @@ export const updateFlatNotation = function (flatId, newNotation, callback) {
})
}
+export const updateFlatVisitDate = function (flatId, newVisitDate, callback) {
+ fetch(
+ '/api/v1/flat/' + encodeURIComponent(flatId) + '/visit_date',
+ {
+ credentials: 'same-origin',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ visit_date: newVisitDate
+ })
+ }
+ ).then(callback).catch(function (ex) {
+ console.error('Unable to update flat date of visit: ' + 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/i18n/en/index.js b/flatisfy/web/js_src/i18n/en/index.js
index fcc082f..d61d4c6 100644
--- a/flatisfy/web/js_src/i18n/en/index.js
+++ b/flatisfy/web/js_src/i18n/en/index.js
@@ -45,6 +45,8 @@ export default {
'Times_to': 'Times to',
'Location': 'Location',
'Contact': 'Contact',
+ 'Visit': 'Visit',
+ 'setDateOfVisit': 'Set date of visit',
'no_phone_found': 'No phone found',
'rooms': 'room | rooms',
'bedrooms': 'bedroom | bedrooms'
diff --git a/flatisfy/web/js_src/store/actions.js b/flatisfy/web/js_src/store/actions.js
index 7294570..4d1bc9c 100644
--- a/flatisfy/web/js_src/store/actions.js
+++ b/flatisfy/web/js_src/store/actions.js
@@ -39,6 +39,12 @@ export default {
commit(types.UPDATE_FLAT_NOTES, { flatId, newNotes })
})
},
+ updateFlatVisitDate ({ commit }, { flatId, newVisitDate }) {
+ commit(types.IS_LOADING)
+ api.updateFlatVisitDate(flatId, newVisitDate, response => {
+ commit(types.UPDATE_FLAT_VISIT_DATE, { flatId, newVisitDate })
+ })
+ },
doSearch ({ commit }, { query }) {
commit(types.IS_LOADING)
api.doSearch(query, flats => {
diff --git a/flatisfy/web/js_src/store/mutations-types.js b/flatisfy/web/js_src/store/mutations-types.js
index 5336eee..89c45fa 100644
--- a/flatisfy/web/js_src/store/mutations-types.js
+++ b/flatisfy/web/js_src/store/mutations-types.js
@@ -3,5 +3,6 @@ export const MERGE_FLATS = 'MERGE_FLATS'
export const UPDATE_FLAT_STATUS = 'UPDATE_FLAT_STATUS'
export const UPDATE_FLAT_NOTES = 'UPDATE_FLAT_NOTES'
export const UPDATE_FLAT_NOTATION = 'UPDATE_FLAT_NOTATION'
+export const UPDATE_FLAT_VISIT_DATE = 'UPDATE_FLAT_VISIT_DATE'
export const RECEIVE_TIME_TO_PLACES = 'RECEIVE_TIME_TO_PLACES'
export const IS_LOADING = 'IS_LOADING'
diff --git a/flatisfy/web/js_src/store/mutations.js b/flatisfy/web/js_src/store/mutations.js
index e7c30e5..1c9dbc5 100644
--- a/flatisfy/web/js_src/store/mutations.js
+++ b/flatisfy/web/js_src/store/mutations.js
@@ -47,6 +47,13 @@ export const mutations = {
}
state.loading -= 1
},
+ [types.UPDATE_FLAT_VISIT_DATE] (state, { flatId, newVisitDate }) {
+ const index = state.flats.findIndex(flat => flat.id === flatId)
+ if (index > -1) {
+ Vue.set(state.flats[index], 'visit-date', newVisitDate)
+ }
+ state.loading -= 1
+ },
[types.RECEIVE_TIME_TO_PLACES] (state, { timeToPlaces }) {
state.timeToPlaces = timeToPlaces
state.loading -= 1
diff --git a/flatisfy/web/js_src/views/details.vue b/flatisfy/web/js_src/views/details.vue
index ce9763f..1956cd9 100644
--- a/flatisfy/web/js_src/views/details.vue
+++ b/flatisfy/web/js_src/views/details.vue
@@ -147,6 +147,15 @@
+ {{ $t("flatsDetails.Visit") }}
+
+
+
+
{{ $t("common.Actions") }}