move REST logic into services

This commit is contained in:
Davide Alberani 2015-03-21 11:34:55 +01:00
parent 7fa4855d22
commit b6b870fc06
4 changed files with 18 additions and 25 deletions

View file

@ -6,7 +6,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/js/angular.min.js"></script>
<script src="/static/js/angular-route.js"></script>
<script src="/static/js/angular-resource.js"></script>
<script src="/js/app.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
<title>Event Man(ager)</title>
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
@ -17,6 +19,7 @@
<div class="main-header" ng-controller="navigation as n">
<input type="button" id="events-button" ng-click="n.go('/events')" class="btn btn-link" value="Events" />
<input type="button" id="new-event-button" ng-click="n.go('/new-event')" class="btn btn-link" value="Add Event" />
<input type="button" id="persons-button" ng-click="n.go('/persons')" class="btn btn-link" value="Persons" />
<input type="button" id="persons-button" ng-click="n.go('/new-person')" class="btn btn-link" value="Add Persons" />
</div>

View file

@ -1,5 +1,6 @@
var eventManApp = angular.module('eventManApp', [
'ngRoute',
'eventManServices',
'eventManControllers'
]);

View file

@ -12,41 +12,32 @@ eventManControllers.controller('navigation', ['$location',
);
eventManControllers.controller('EventsListCtrl', ['$scope', '$http',
function ($scope, $http) {
$http.get('/events').success(function(data) {
$scope.events = data.events;
});
eventManControllers.controller('EventsListCtrl', ['$scope', 'Event',
function ($scope, Event) {
$scope.events = Event.all();
$scope.orderProp = 'begin-datetime';
}]
);
eventManControllers.controller('EventDetailsCtrl', ['$scope', '$http', '$routeParams',
function ($scope, $http, $routeParams) {
$http.get("/events/" + $routeParams.eventID).success(function(data) {
$scope.event = data.event;
});
eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', '$routeParams',
function ($scope, Event, $routeParams) {
$scope.event = Event.get($routeParams);
}]
);
eventManControllers.controller('PersonsListCtrl', ['$scope', '$http',
function ($scope, $http) {
$http.get('/persons').success(function(data) {
$scope.persons = data.persons;
});
eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person',
function ($scope, Person) {
$scope.persons = Person.all();
$scope.orderProp = 'name';
}]
);
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$http', '$routeParams',
function ($scope, $http, $routeParams) {
$http.get("/persons/" + $routeParams.personID).success(function(data) {
$scope.person = data.person;
});
eventManControllers.controller('PersonDetailsCtrl', ['$scope', 'Person', '$routeParams',
function ($scope, Person, $routeParams) {
$scope.person = Person.get($routeParams);
}]
);

View file

@ -66,7 +66,7 @@ class PersonsHandler(BaseHandler):
@gen.coroutine
def get(self, id_=None):
if id_ is not None:
self.write({'person': MOCKUP_PERSONS[int(id_)]})
self.write(MOCKUP_PERSONS[int(id_)])
return
self.write({'persons': MOCKUP_PERSONS.values()})
@ -75,13 +75,11 @@ class EventsHandler(BaseHandler):
@gen.coroutine
def get(self, id_=None):
if id_ is not None:
self.write({'event': MOCKUP_EVENTS[int(id_)]})
self.write(MOCKUP_EVENTS[int(id_)])
return
self.write({'events': MOCKUP_EVENTS.values()})
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"),