diff --git a/defmodule.lisp b/defmodule.lisp index 2cc9148..00a1841 100644 --- a/defmodule.lisp +++ b/defmodule.lisp @@ -21,13 +21,13 @@ (define-method post-task (story-id description reporter) "Post a new task for a story.") - (define-method story-get-state (id) + (define-method story-get-state (type id) "Get the state of a story.") - (define-method story-set-state (id state) + (define-method story-set-state (type id state) "Set the state of a story.") - (define-method story-change-priority (id dir) + (define-method story-change-priority (type id dir) "Change the priority of a story in direction DIR.")) (restas:define-module #:scrumli diff --git a/pg-datastore.lisp b/pg-datastore.lisp index d6b3e54..0952ab0 100644 --- a/pg-datastore.lisp +++ b/pg-datastore.lisp @@ -46,8 +46,10 @@ (defmethod datastore-get-story ((datastore pg-datastore) id) (with-connection (connection-spec datastore) (append (query (:select :* :from 'story :where (:= 'id id)) :alist) - `((tasks . ,(query (:select :* :from 'task - :where (:= 'story-id id)) + `((tasks . ,(query (:order-by + (:select :* :from 'task + :where (:= 'story-id id)) + 'priority) :alists)))))) (defmethod datastore-post-story @@ -74,23 +76,24 @@ :assignee ""))) (save-dao obj)))) -(defmethod datastore-story-get-state ((datastore pg-datastore) id) +(defmethod datastore-story-get-state ((datastore pg-datastore) type id) (with-connection (connection-spec datastore) - (query (:select 'state :from 'story :where (:= 'id id)) :single))) + (query (:select 'state :from type :where (:= 'id id)) :single))) -(defmethod datastore-story-set-state ((datastore pg-datastore) id state) +(defmethod datastore-story-set-state + ((datastore pg-datastore) type id state) (with-connection (connection-spec datastore) - (execute (:update 'story :set 'state state :where (:= 'id id))))) + (execute (:update type :set 'state state :where (:= 'id id))))) (defmethod datastore-story-change-priority - ((datastore pg-datastore) id dir) + ((datastore pg-datastore) type id dir) (with-connection (connection-spec datastore) - (let* ((current-priority (query (:select 'priority :from 'story + (let* ((current-priority (query (:select 'priority :from type :where (:= 'id id)) :single)) (next-priority (funcall (ecase dir (:up #'-) (:down #'+)) current-priority 1))) - (execute (:update 'story :set 'priority current-priority + (execute (:update type :set 'priority current-priority :where (:= 'priority next-priority))) - (execute (:update 'story :set 'priority next-priority + (execute (:update type :set 'priority next-priority :where (:= 'id id)))))) diff --git a/scrumli.lisp b/scrumli.lisp index 0f563d9..24c4469 100644 --- a/scrumli.lisp +++ b/scrumli.lisp @@ -90,18 +90,36 @@ (define-route stories-state ("stories/state" :method :post) (if (logged-in-p) (let* ((id (hunchentoot:post-parameter "id")) - (current-state (story-get-state id))) - (story-set-state id (ecase (intern current-state :scrumli) - (todo "DOING") - (doing "DONE") - (done "TODO"))) + (current-state (story-get-state 'story id))) + (story-set-state 'story id (ecase (intern current-state :scrumli) + (todo "DOING") + (doing "DONE") + (done "TODO"))) 200) 403)) +(define-route task-state ("tasks/state" :method :post) + (if (logged-in-p) + (let* ((id (hunchentoot:post-parameter "id")) + (current-state (story-get-state 'task id))) + (story-set-state 'task id (ecase (intern current-state :scrumli) + (todo "DOING") + (doing "DONE") + (done "TODO")))))) + (define-route stories-priority ("stories/:dir" :method :post) (if (logged-in-p) (let* ((id (hunchentoot:post-parameter "id"))) - (story-change-priority id (intern (string-upcase dir) :keyword)) + (story-change-priority + 'story id (intern (string-upcase dir) :keyword)) + 200) + 403)) + +(define-route task-priority ("tasks/:dir" :method :post) + (if (logged-in-p) + (let* ((id (hunchentoot:post-parameter "id"))) + (story-change-priority + 'task id (intern (string-upcase dir) :keyword)) 200) 403)) diff --git a/static/js/main.js b/static/js/main.js index fbeb1bc..5eb9a2a 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -9,17 +9,44 @@ var StateIcon = React.createClass({ }); var StoryTaskRow = React.createClass({ + changeState: React.autoBind(function(event) { + $.ajax({ + url: "/tasks/state", + type: "POST", + data: {'id': this.props.task.id}, + dataType: 'json', + mimeType: 'textPlain' + }); + }), + moveUp: React.autoBind(function(event) { + $.ajax({ + url: "tasks/up", + type: "POST", + data: {'id': this.props.task.id}, + dataType: 'json', + mimeType: 'textPlain' + }); + }), + moveDown: React.autoBind(function(event) { + $.ajax({ + url: "tasks/down", + type: "POST", + data: {'id': this.props.task.id}, + dataType: 'json', + mimeType: 'textPlain' + }); + }), render: function() { var state = " " + this.props.task.state; return ( - - + + - + {state}