Add comments sorting

This commit is contained in:
Frederic Guillot 2015-10-11 18:21:54 -04:00
parent c77c9443e9
commit ffe615d201
10 changed files with 79 additions and 14 deletions

View File

@ -1,3 +1,10 @@
Version 1.0.20 (unreleased)
---------------------------
Improvements:
* Allow to change comments sorting
Version 1.0.19
--------------

View File

@ -195,7 +195,7 @@ class Board extends Base
$task = $this->getTask();
$this->response->html($this->template->render('board/tooltip_comments', array(
'comments' => $this->comment->getAll($task['id'])
'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting())
)));
}

View File

@ -183,4 +183,19 @@ class Comment extends Base
$this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments'));
}
/**
* Toggle comment sorting
*
* @access public
*/
public function toggleSorting()
{
$task = $this->getTask();
$order = $this->userSession->getCommentSorting() === 'ASC' ? 'DESC' : 'ASC';
$this->userSession->setCommentSorting($order);
$this->response->redirect($this->helper->url->href('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'comments'));
}
}

View File

@ -68,7 +68,7 @@ class Task extends Base
'project' => $this->project->getById($task['project_id']),
'files' => $this->file->getAllDocuments($task['id']),
'images' => $this->file->getAllImages($task['id']),
'comments' => $this->comment->getAll($task['id']),
'comments' => $this->comment->getAll($task['id'], $this->userSession->getCommentSorting()),
'subtasks' => $subtasks,
'links' => $this->taskLink->getAllGroupedByLabel($task['id']),
'task' => $task,

View File

@ -34,9 +34,10 @@ class Comment extends Base
*
* @access public
* @param integer $task_id Task id
* @param string $sorting ASC/DESC
* @return array
*/
public function getAll($task_id)
public function getAll($task_id, $sorting = 'ASC')
{
return $this->db
->table(self::TABLE)
@ -51,7 +52,7 @@ class Comment extends Base
User::TABLE.'.email'
)
->join(User::TABLE, 'id', 'user_id')
->orderBy(self::TABLE.'.date_creation', 'ASC')
->orderBy(self::TABLE.'.date_creation', $sorting)
->eq(self::TABLE.'.task_id', $task_id)
->findAll();
}

View File

@ -154,4 +154,26 @@ class UserSession extends Base
{
$_SESSION['board_collapsed'][$project_id] = $collapsed;
}
/**
* Set comments sorting
*
* @access public
* @param string $order
*/
public function setCommentSorting($order)
{
$this->session['comment_sorting'] = $order;
}
/**
* Get comments sorting direction
*
* @access public
* @return string
*/
public function getCommentSorting()
{
return $this->session['comment_sorting'] ?: 'ASC';
}
}

View File

@ -1,7 +1,13 @@
<?php if (! empty($comments)): ?>
<div id="comments" class="task-show-section">
<div class="page-header">
<h2><?= t('Comments') ?></h2>
<h2>
<?= t('Comments') ?>
<span class="comment-sorting">
<i class="fa fa-sort"></i>
<?= $this->url->link(t('change sorting'), 'comment', 'toggleSorting', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>
</span>
</h2>
</div>
<?php foreach ($comments as $comment): ?>
@ -16,13 +22,13 @@
<?php if (! isset($not_editable)): ?>
<?= $this->render('comment/create', array(
'skip_cancel' => true,
'values' => array(
'user_id' => $this->user->getId(),
'task_id' => $task['id'],
),
'errors' => array(),
'task' => $task
'skip_cancel' => true,
'values' => array(
'user_id' => $this->user->getId(),
'task_id' => $task['id'],
),
'errors' => array(),
'task' => $task
)) ?>
<?php endif ?>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -69,6 +69,20 @@
max-width: 800px;
}
.comment-sorting {
font-size: 0.5em;
}
span.comment-sorting a {
color: #555;
font-weight: normal;
text-decoration: none;
}
span.comment-sorting a:hover {
color: #aaa;
}
#comments .comment-textarea {
height: 80px;
width: 500px;