--- a/app.py Fri Jan 11 15:19:57 2013 +0900
+++ b/app.py Fri Jan 11 17:22:25 2013 +0900
from CodernityDB.database_thread_safe import ThreadSafeDatabase
from fruitbar.indexes import ProjectIndex, TaskIndex
-from fruitbar.crud import ResourceList, CRUDResource
+from fruitbar.crud import ResourceList, ResourceCombiner, CRUDResource
safe_fields = ('name', 'note', 'done')
+class ProjectsAndTasks(ResourceCombiner):
+ 'projects': ProjectList,
api.add_resource(ProjectList, '/<workspace>/projects/')
api.add_resource(Project, '/<workspace>/projects/<resource_id>/')
api.add_resource(TaskList, '/<workspace>/tasks/')
api.add_resource(Task, '/<workspace>/tasks/<resource_id>/')
+api.add_resource(ProjectsAndTasks, '/<workspace>/all/')
if __name__ == '__main__':
--- a/fruitbar/crud.py Fri Jan 11 15:19:57 2013 +0900
+++ b/fruitbar/crud.py Fri Jan 11 17:22:25 2013 +0900
return g.db.get('id', response['_id'], with_doc=True)
+class ResourceCombiner(Resource):
+ def get(self, workspace):
+ for key, resource_class in self.combine.items():
+ resource = resource_class()
+ result[key] = resource.get(workspace)
class CRUDResource(Resource):
--- a/static/js/ui.js Fri Jan 11 15:19:57 2013 +0900
+++ b/static/js/ui.js Fri Jan 11 17:22:25 2013 +0900
+ fruitbar.fetchAll = function(url) {
+ }).done(function(data) {
+ fruitbar.projects.update(data['projects']);
+ fruitbar.tasks.update(data['tasks']);
fruitbar.on('workspace', function(workspace) {
$('body').stop().animate({opacity: 0});
+ this.workspace = workspace;
this.tasks.url = '/' + encodeURIComponent(workspace) + '/tasks/';
this.projects.url = '/' + encodeURIComponent(workspace) + '/projects/';
- this.xhrs.push(this.tasks.fetch(), this.projects.fetch());
+ this.xhrs.push(this.fetchAll('/' + encodeURIComponent(workspace) + '/all/'));
_(this.xhrs).each(function(fetch, index, xhrs) {
fruitbar.once('workspace', function() {
window.setInterval(function() {
- fruitbar.xhrs.push(fruitbar.tasks.fetch({update: true}));
- window.setInterval(function() {
- fruitbar.xhrs.push(fruitbar.projects.fetch({update: true}));
+ fruitbar.xhrs.push(fruitbar.fetchAll('/' + encodeURIComponent(fruitbar.workspace) + '/all/'));
Backbone.history.start();