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)
"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

View file

@ -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
`((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))))))

View file

@ -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)
(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))

View file

@ -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 (
<tr>
<td class="span1">
<i class="icon-arrow-up"></i>
<i class="icon-arrow-down"></i>
<i class="icon-arrow-up" onClick={this.moveUp}></i>
<i class="icon-arrow-down" onClick={this.moveDown}></i>
</td>
<td class="span2">
<span>
<span onClick={this.changeState}>
<StateIcon state={this.props.task.state} />
{state}
</span>