From 3aa2e057b67f40fb3c58184014af63e0793ee01e Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 15 Mar 2015 18:00:08 +0100 Subject: [PATCH] introduce events list page --- angular_app/events-list.html | 25 +++++++++++++++ angular_app/index.html | 21 ++++++++----- angular_app/js/app.js | 29 +++++++++++++++++ angular_app/js/controllers.js | 20 +++++++++--- .../{persons.html => persons-list.html} | 18 ----------- eventman_server.py | 31 ++++++++++++++++++- 6 files changed, 112 insertions(+), 32 deletions(-) create mode 100644 angular_app/events-list.html create mode 100644 angular_app/js/app.js rename angular_app/{persons.html => persons-list.html} (51%) diff --git a/angular_app/events-list.html b/angular_app/events-list.html new file mode 100644 index 0000000..8ef63e4 --- /dev/null +++ b/angular_app/events-list.html @@ -0,0 +1,25 @@ +
+
+
+ + Search: + Sort by: + + +
+
+ +
    +
  • + {{event.title}} +

    {{event['begin-datetime']}}

    +
  • +
+ +
+
+
+ diff --git a/angular_app/index.html b/angular_app/index.html index 32f0231..6c4cff1 100644 --- a/angular_app/index.html +++ b/angular_app/index.html @@ -1,16 +1,21 @@ - + + + + + + + Event Man(ager) + + -
-

1 + 2 = {{ 1 + 2 }}

- - -
-

Hello {{yourName}}!

-
+
+ + + diff --git a/angular_app/js/app.js b/angular_app/js/app.js new file mode 100644 index 0000000..4fba70e --- /dev/null +++ b/angular_app/js/app.js @@ -0,0 +1,29 @@ +var eventManApp = angular.module('eventManApp', [ + 'ngRoute', + 'eventManControllers' +]); + +eventManApp.config(['$routeProvider', + function($routeProvider) { + $routeProvider. + when('/persons', { + templateUrl: 'persons-list.html', + controller: 'PersonsListCtrl' + }). + when('/persons/:personId', { + templateUrl: 'person-detail.html', + controller: 'PersonDetailCtrl' + }). + when('/events', { + templateUrl: 'events-list.html', + controller: 'EventsListCtrl' + }). + when('/events/:eventId', { + templateUrl: 'event-detail.html', + controller: 'EventDetailCtrl' + }). + otherwise({ + redirectTo: '/events' + }); +}]); + diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 7575bc0..c619677 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -1,15 +1,25 @@ 'use strict'; /* Controllers */ +var eventManControllers = angular.module('eventManControllers', []); -var eventManApp = angular.module('eventManApp', []); -eventManApp.controller('PersonsListCtrl', ['$scope', '$http', +eventManControllers.controller('EventsListCtrl', ['$scope', '$http', function ($scope, $http) { - $http.get('/persons').success(function(data) { - $scope.persons = data.persons; - $scope.orderProp = 'name'; + $http.get('/events').success(function(data) { + $scope.events = data.events; }); + $scope.orderProp = 'begin-datetime'; + }] +); + + +eventManControllers.controller('PersonsListCtrl', ['$scope', '$http', + function ($scope, $http) { + $http.get('/persons').success(function(data) { + $scope.persons = data.persons; + }); + $scope.orderProp = 'name'; }] ); diff --git a/angular_app/persons.html b/angular_app/persons-list.html similarity index 51% rename from angular_app/persons.html rename to angular_app/persons-list.html index fac5924..725a180 100644 --- a/angular_app/persons.html +++ b/angular_app/persons-list.html @@ -1,17 +1,3 @@ - - - - - - - - - Event Man(ager) - - - - -
@@ -37,7 +23,3 @@
- - - - diff --git a/eventman_server.py b/eventman_server.py index ee8b981..f920adb 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -11,7 +11,7 @@ import tornado.ioloop import tornado.options from tornado.options import define, options import tornado.web -from tornado import gen +from tornado import gen, escape class RootHandler(tornado.web.RequestHandler): angular_app_path = os.path.join(os.path.dirname(__file__), "angular_app") @@ -31,12 +31,40 @@ MOCKUP_PERSONS = [ 'email': 'hackinbo.it@gmail.com', 'id': 3}] +import datetime +MOCKUP_EVENTS = [ + {'title': 'HackInBo 2015', 'begin-datetime': datetime.datetime(2015, 5, 23, 9, 0), + 'end-datetime': datetime.datetime(2015, 5, 24, 17, 0), + 'location': 'Bologna', 'id': 1}, + {'title': 'La fiera del carciofo', 'begin-datetime': datetime.datetime(2015, 6, 23, 9, 0), + 'end-datetime': datetime.datetime(2015, 6, 24, 17, 0), + 'location': 'Gatteo a mare', 'id': 2}, +] + +import json + +class ImprovedEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, datetime.datetime): + return str(o) + return json.JSONEncoder.default(self, o) + +json._default_encoder = ImprovedEncoder() + class PersonsHandler(tornado.web.RequestHandler): @gen.coroutine def get(self, id_=None): self.write({'persons': MOCKUP_PERSONS}) + +class EventsHandler(tornado.web.RequestHandler): + @gen.coroutine + def get(self, id_=None): + self.write({'events': MOCKUP_EVENTS}) + + + def main(): define("port", default=5242, help="run on the given port", type=int) define("data", default=os.path.join(os.path.dirname(__file__), "data"), @@ -48,6 +76,7 @@ def main(): application = tornado.web.Application([ (r"/persons/?(?P\d+)?", PersonsHandler), + (r"/events/?(?P\d+)?", EventsHandler), (r"/(?:index.html)?", RootHandler), (r'/(.*)', tornado.web.StaticFileHandler, {"path": "angular_app"}) ],