--- a/app.py Wed Dec 26 22:01:21 2012 +0900
+++ b/app.py Thu Dec 27 00:12:30 2012 +0900
cdb.add_index(ProjectIndex(cdb.path, 'project'))
cdb.add_index(TaskIndex(cdb.path, 'task'))
- cdb.insert({'_id': '29c21f00190f475ba2d855f810c1085e', '_t': 'project', 'name': 'Test Project', 'color': 'success'})
- cdb.insert({'_t': 'task', 'project': '29c21f00190f475ba2d855f810c1085e', 'name': 'Test Task', 'note': 'Task Note', 'done': True})
- return [project['doc'] for project in g.db.all(self.db_index, with_doc=True)]
+ def get(self, workspace):
+ return [project['doc'] for project in g.db.get_many(self.db_index, workspace, with_doc=True)]
- doc = self.doc_stub.copy()
- doc.update(request.json)
+ def post(self, workspace):
+ doc = request.json.copy()
+ doc.update(self.doc_stub)
+ doc.update({'workspace': workspace})
response = g.db.insert(doc)
- def get(self, resource_id):
+ def get(self, workspace, resource_id):
doc = g.db.get('id', resource_id, with_doc=True)
+ if doc['workspace'] != workspace:
- def put(self, resource_id):
+ def put(self, workspace, resource_id):
doc = g.db.get('id', resource_id, with_doc=True)
+ if doc['workspace'] != workspace:
response = g.db.update(doc)
- return self.get(response['_id'])
+ return self.get(workspace, response['_id'])
- def delete(self, resource_id):
+ def delete(self, workspace, resource_id):
doc = g.db.get('id', resource_id, with_doc=True)
+ if doc['workspace'] != workspace:
class Project(CRUDResource):
safe_fields = ('name', 'color')
- def delete(self, resource_id):
- g.db.run('task', 'delete_for_project', resource_id)
+ def delete(self, workspace, resource_id):
+ g.db.run('task', 'delete_for_project', workspace, resource_id)
- return super(Project, self).delete(resource_id)
+ return super(Project, self).delete(workspace, resource_id)
class TaskList(ResourceList):
safe_fields = ('name', 'note', 'done')
-api.add_resource(ProjectList, '/projects/')
-api.add_resource(Project, '/projects/<resource_id>/')
-api.add_resource(TaskList, '/tasks/')
-api.add_resource(Task, '/tasks/<resource_id>/')
+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>/')
- 'projects': [project['doc'] for project in g.db.all('project', with_doc=True)],
- 'tasks': [task['doc'] for task in g.db.all('task', with_doc=True)]
- return render_template('index.html', data=data)
+ return render_template('index.html')
--- a/fruitbar/indexes.py Wed Dec 26 22:01:21 2012 +0900
+++ b/fruitbar/indexes.py Thu Dec 27 00:12:30 2012 +0900
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '16s'
super(ProjectIndex, self).__init__(*args, **kwargs)
def make_key_value(self, data):
if data['_t'] == 'project':
- return md5(data['name'].encode('utf-8')).digest(), None
+ return md5(data['workspace'].encode('utf-8')).digest(), None
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '16s'
super(TaskIndex, self).__init__(*args, **kwargs)
def make_key_value(self, data):
- return md5(data['project'].encode('utf-8')).digest(), None
+ return md5(data['workspace'].encode('utf-8')).digest(), None
- def run_delete_for_project(self, db, project):
- for task in db.get_many('task', project, with_doc=True):
+ def run_delete_for_project(self, db, workspace, project_id):
+ for task in db.get_many('task', workspace, with_doc=True):
+ if task['doc']['project_id'] == project_id:
--- a/static/js/framework/collections.js Wed Dec 26 22:01:21 2012 +0900
+++ b/static/js/framework/collections.js Thu Dec 27 00:12:30 2012 +0900
var Projects = Backbone.Collection.extend({
+ return '/' + encodeURIComponent(fruitbar.workspace) + '/projects/';
var Tasks = Backbone.Collection.extend({
+ return '/' + encodeURIComponent(fruitbar.workspace) + '/tasks/';
--- a/static/js/framework/models.js Wed Dec 26 22:01:21 2012 +0900
+++ b/static/js/framework/models.js Thu Dec 27 00:12:30 2012 +0900
- url: this.urlRoot + encodeURIComponent(this.id) + '/',
contentType: 'application/json',
data: JSON.stringify(data)
var Project = Model.extend({
switchColor: function() {
var colorChain = [null, 'info', 'success', 'warning', 'danger'];
var Task = Model.extend({
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/js/framework/router.js Thu Dec 27 00:12:30 2012 +0900
+var Router = Backbone.Router.extend({
+ ':workspace': 'setWorkspace'
+ makeRandomString: function(length) {
+ return _.map(_.range(length), function() {
+ return (Math.random()*16|0).toString(16);
+ randomize: function() {
+ var randomString = this.makeRandomString(8);
+ this.navigate(randomString, {trigger: true, replace: true});
+ setWorkspace: function(workspace) {
+ fruitbar.workspace = workspace;
+ fruitbar.tasks.fetch();
+ fruitbar.projects.fetch();
--- a/static/js/framework/views/projects.js Wed Dec 26 22:01:21 2012 +0900
+++ b/static/js/framework/views/projects.js Thu Dec 27 00:12:30 2012 +0900
project.tasks = new Backbone.Shard({
- filter: function(task) { return task.get('project') === project.id; }
+ filter: function(task) { return task.get('project_id') === project.id; }
project.tasks.progress = function() {
project.tasks.create = function(attributes, options) {
attributes = attributes || {};
- attributes['project'] = project.id;
+ attributes['project_id'] = project.id;
return tasks.create(attributes, options);
--- a/static/js/ui.js Wed Dec 26 22:01:21 2012 +0900
+++ b/static/js/ui.js Thu Dec 27 00:12:30 2012 +0900
- fruitbar.tasks = new Tasks(data['tasks']);
- fruitbar.projects = new Projects(data['projects']);
+ window.fruitbar = {workspace: undefined};
+ fruitbar.tasks = new Tasks();
+ fruitbar.projects = new Projects();
+ fruitbar.router = new Router();
fruitbar.projectCounter = new CollectionCounterView({
el: $('.project-counter'),
+ Backbone.history.start();
window.setInterval(function() {fruitbar.projects.fetch({update: true});}, 60000);
window.setInterval(function() {fruitbar.tasks.fetch({update: true});}, 60000);
--- a/templates/index.html Wed Dec 26 22:01:21 2012 +0900
+++ b/templates/index.html Thu Dec 27 00:12:30 2012 +0900
<script type="text/javascript" src="{{ url_for('static', filename='js/framework/views/inline.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/framework/views/projects.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/framework/views/tasks.js') }}"></script>
+ <script type="text/javascript" src="{{ url_for('static', filename='js/framework/router.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/ui.js') }}"></script>
<script type="text/javascript">
- <script type="text/javascript">
- var data = {{ data|tojson|safe }};