Task state and priority editing

This commit is contained in:
Tom Willemse 2013-07-04 23:55:43 +02:00
parent 6edd373ad9
commit 12ee321c64
4 changed files with 70 additions and 22 deletions

View file

@ -21,13 +21,13 @@
(define-method post-task (story-id description reporter) (define-method post-task (story-id description reporter)
"Post a new task for a story.") "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.") "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.") "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.")) "Change the priority of a story in direction DIR."))
(restas:define-module #:scrumli (restas:define-module #:scrumli

View file

@ -46,8 +46,10 @@
(defmethod datastore-get-story ((datastore pg-datastore) id) (defmethod datastore-get-story ((datastore pg-datastore) id)
(with-connection (connection-spec datastore) (with-connection (connection-spec datastore)
(append (query (:select :* :from 'story :where (:= 'id id)) :alist) (append (query (:select :* :from 'story :where (:= 'id id)) :alist)
`((tasks . ,(query (:select :* :from 'task `((tasks . ,(query (:order-by
(:select :* :from 'task
:where (:= 'story-id id)) :where (:= 'story-id id))
'priority)
:alists)))))) :alists))))))
(defmethod datastore-post-story (defmethod datastore-post-story
@ -74,23 +76,24 @@
:assignee ""))) :assignee "")))
(save-dao obj)))) (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) (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) (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 (defmethod datastore-story-change-priority
((datastore pg-datastore) id dir) ((datastore pg-datastore) type id dir)
(with-connection (connection-spec datastore) (with-connection (connection-spec datastore)
(let* ((current-priority (query (:select 'priority :from 'story (let* ((current-priority (query (:select 'priority :from type
:where (:= 'id id)) :where (:= 'id id))
:single)) :single))
(next-priority (funcall (ecase dir (:up #'-) (:down #'+)) (next-priority (funcall (ecase dir (:up #'-) (:down #'+))
current-priority 1))) current-priority 1)))
(execute (:update 'story :set 'priority current-priority (execute (:update type :set 'priority current-priority
:where (:= 'priority next-priority))) :where (:= 'priority next-priority)))
(execute (:update 'story :set 'priority next-priority (execute (:update type :set 'priority next-priority
:where (:= 'id id)))))) :where (:= 'id id))))))

View file

@ -90,18 +90,36 @@
(define-route stories-state ("stories/state" :method :post) (define-route stories-state ("stories/state" :method :post)
(if (logged-in-p) (if (logged-in-p)
(let* ((id (hunchentoot:post-parameter "id")) (let* ((id (hunchentoot:post-parameter "id"))
(current-state (story-get-state id))) (current-state (story-get-state 'story id)))
(story-set-state id (ecase (intern current-state :scrumli) (story-set-state 'story id (ecase (intern current-state :scrumli)
(todo "DOING") (todo "DOING")
(doing "DONE") (doing "DONE")
(done "TODO"))) (done "TODO")))
200) 200)
403)) 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) (define-route stories-priority ("stories/:dir" :method :post)
(if (logged-in-p) (if (logged-in-p)
(let* ((id (hunchentoot:post-parameter "id"))) (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) 200)
403)) 403))

View file

@ -9,17 +9,44 @@ var StateIcon = React.createClass({
}); });
var StoryTaskRow = 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() { render: function() {
var state = " " + this.props.task.state; var state = " " + this.props.task.state;
return ( return (
<tr> <tr>
<td class="span1"> <td class="span1">
<i class="icon-arrow-up"></i> <i class="icon-arrow-up" onClick={this.moveUp}></i>
<i class="icon-arrow-down"></i> <i class="icon-arrow-down" onClick={this.moveDown}></i>
</td> </td>
<td class="span2"> <td class="span2">
<span> <span onClick={this.changeState}>
<StateIcon state={this.props.task.state} /> <StateIcon state={this.props.task.state} />
{state} {state}
</span> </span>