From 9657cb17f0a4b7e1370d04f66e24b36cd8ca93b0 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Thu, 26 Jan 2017 22:11:06 +0100 Subject: [PATCH] fixes #7: add notes to attendees, groups and days --- build/webpack.dev.conf.js | 6 +++ build/webpack.prod.conf.js | 6 +++ config/index.js | 3 +- docs/DEVELOPMENT.md | 2 +- ibt2.py | 39 +++++++++++++-- src/App.vue | 76 ++++++++++++++++++++++++++++- src/Group.vue | 97 +++++++++++++++++++++++++++++++++++--- src/main.js | 1 - tests/ibt2_tests.py | 29 ++++++++++++ 9 files changed, 244 insertions(+), 15 deletions(-) diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js index 3cc7a20..1f64700 100644 --- a/build/webpack.dev.conf.js +++ b/build/webpack.dev.conf.js @@ -17,6 +17,12 @@ module.exports = merge(baseWebpackConfig, { // eval-source-map is faster for development devtool: '#eval-source-map', plugins: [ + new webpack.ProvidePlugin({ + $: 'jquery', + jquery: 'jquery', + 'window.jQuery': 'jquery', + jQuery: 'jquery' + }), new webpack.DefinePlugin({ 'process.env': config.dev.env }), diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index 0ca5450..b18d3bf 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -25,6 +25,12 @@ var webpackConfig = merge(baseWebpackConfig, { }) }, plugins: [ + new webpack.ProvidePlugin({ + $: 'jquery', + jquery: 'jquery', + 'window.jQuery': 'jquery', + jQuery: 'jquery' + }), // http://vuejs.github.io/vue-loader/en/workflow/production.html new webpack.DefinePlugin({ 'process.env': env diff --git a/config/index.js b/config/index.js index a3aaddb..b094ac4 100644 --- a/config/index.js +++ b/config/index.js @@ -26,7 +26,8 @@ module.exports = { '/attendees': 'http://localhost:3000', '/login': 'http://localhost:3000', '/logout': 'http://localhost:3000', - '/user': 'http://localhost:3000' + '/user': 'http://localhost:3000', + '/groups': 'http://localhost:3000' }, // CSS Sourcemaps off by default because relative paths are "buggy" // with this option, according to the CSS-Loader README diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 96f719c..a512791 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -38,7 +38,7 @@ Example of */attendees/:id*: Example of */days/:day*: ``` json -{"day": "2017-01-20", "groups": [{"name": "Group Name", "attendees": [{"day": "2017-01-20", "name": "Attendee Name", "group": "Group Name", "updated_by": "587a7c79dff0d71c89211dc4", "created_at": "2017-01-20 13:57:26.029000", "updated_at": "2017-01-20 13:57:26.029000", "created_by": "587a7c79dff0d71c89211dc4", "_id": "58820936dff0d740dee647a4"}]}]} +{"day": "2017-01-20", "groups": [{"group": "Group Name", "attendees": [{"day": "2017-01-20", "name": "Attendee Name", "group": "Group Name", "updated_by": "587a7c79dff0d71c89211dc4", "created_at": "2017-01-20 13:57:26.029000", "updated_at": "2017-01-20 13:57:26.029000", "created_by": "587a7c79dff0d71c89211dc4", "_id": "58820936dff0d740dee647a4"}]}]} ``` diff --git a/ibt2.py b/ibt2.py index f7feccc..8bceb95 100755 --- a/ibt2.py +++ b/ibt2.py @@ -270,8 +270,12 @@ class DaysHandler(BaseHandler): end = params.get('end') if end: del params['end'] + base = {} + groupsDetails = {} if day: params['day'] = day + base = self.db.getOne('days', {'day': day}) + groupsDetails = dict([(x['group'], x) for x in self.db.query('groups', {'day': day})]) else: if start: params['day'] = {'$gte': start} @@ -299,18 +303,42 @@ class DaysHandler(BaseHandler): for group, attendees in itertools.groupby(sorted(dayItems, key=itemgetter('group')), key=itemgetter('group')): attendees = sorted(attendees, key=itemgetter('_id')) - dayData['groups'].append({'group': group, 'attendees': attendees}) + groupData = groupsDetails.get(group) or {} + groupData.update({'group': group, 'attendees': attendees}) + dayData['groups'].append(groupData) days.append(dayData) except Exception as e: - self.logger.warn('unable to parse entry; dayData: %s', dayData) + self.logger.warn('unable to parse entry; dayData: %s error: %s', dayData, e) if summary: days = self._summarize(days) if not day: self.write({'days': days}) elif days: - self.write(days[0]) + base.update(days[0]) + self.write(base) else: - self.write({}) + self.write(base) + + @gen.coroutine + def put(self, **kwargs): + data = self.clean_body + now = datetime.datetime.now() + data['updated_by'] = self.current_user_info.get('_id') + data['updated_at'] = now + merged, doc = self.db.update('days', self.arguments, data) + self.write(doc) + + +class GroupsHandler(BaseHandler): + """Handle requests for Groups.""" + @gen.coroutine + def put(self, **kwargs): + data = self.clean_body + now = datetime.datetime.now() + data['updated_by'] = self.current_user_info.get('_id') + data['updated_at'] = now + merged, doc = self.db.update('groups', self.arguments, data) + self.write(doc) class UsersHandler(BaseHandler): @@ -504,6 +532,7 @@ def run(): {'setting': 'server_cookie_secret', 'cookie_secret': cookie_secret}) _days_path = r"/days/?(?P[\d_-]+)?" + _groups_path = r"/groups/?" _attendees_path = r"/attendees/?(?P[\w\d_-]+)?" _current_user_path = r"/users/current/?" _users_path = r"/users/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?/?(?P[\w\d_-]+)?" @@ -511,6 +540,8 @@ def run(): (_attendees_path, AttendeesHandler, init_params), (r'/v%s%s' % (API_VERSION, _attendees_path), AttendeesHandler, init_params), (_days_path, DaysHandler, init_params), + (r'/v%s%s' % (API_VERSION, _groups_path), GroupsHandler, init_params), + (_groups_path, GroupsHandler, init_params), (r'/v%s%s' % (API_VERSION, _days_path), DaysHandler, init_params), (_current_user_path, CurrentUserHandler, init_params), (r'/v%s%s' % (API_VERSION, _current_user_path), CurrentUserHandler, init_params), diff --git a/src/App.vue b/src/App.vue index cbcd65b..5559112 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,6 +3,29 @@ + + + +
+ today {{ day.day }} +
+ + + more_vert + + + + edit notes + edit + + + +
+
+ +
{{ day.notes }}
+
+
@@ -12,6 +35,15 @@ + +