diff options
author | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
---|---|---|
committer | Frédéric Guillot <contact@fredericguillot.com> | 2014-03-04 21:57:12 -0500 |
commit | 19409360ca7d4c00d070b16bbfcc6cd02543cdca (patch) | |
tree | 3eb3a3d0fce2d74c550135f3119182e1d1aa0fe2 | |
parent | ccc54c65cf2191e35bd0294c0ffbae761b29f151 (diff) |
Improve comments
-rw-r--r-- | assets/css/app.css | 74 | ||||
-rw-r--r-- | controllers/base.php | 3 | ||||
-rw-r--r-- | controllers/task.php | 50 | ||||
-rw-r--r-- | locales/fr_FR/translations.php | 8 | ||||
-rw-r--r-- | locales/pl_PL/translations.php | 4 | ||||
-rw-r--r-- | models/acl.php | 2 | ||||
-rw-r--r-- | models/comment.php | 50 | ||||
-rw-r--r-- | models/task.php | 35 | ||||
-rw-r--r-- | templates/task_edit.php | 1 | ||||
-rw-r--r-- | templates/task_show.php | 26 |
10 files changed, 162 insertions, 91 deletions
diff --git a/assets/css/app.css b/assets/css/app.css index 270b5c13..c99a1eac 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -189,7 +189,7 @@ textarea.form-error { } .form-help { - font-size: 0.9em; + font-size: 0.8em; color: brown; margin-bottom: 15px; } @@ -532,22 +532,70 @@ article .task-score { top: 5px; } -ul#comments { - list-style-type: none; +#description { + border-left: 5px solid #000; + background: #f0f0f0; + padding: 10px; +} + +/* markdown content */ +.markdown { + line-height: 1.4em; +} + +.markdown ol, +.markdown ul { + margin-left: 25px; + margin-top: 10px; + margin-bottom: 10px; +} + +.markdown pre { + background: #fff; + padding: 10px; + border-radius: 5px; + overflow: auto; + color: #000; } -ul#comments li { +/* comments */ +.comment { margin: 10px 0; - padding: 10px 0 10px 10px; + padding: 10px; border-left: 5px solid #000; } -ul#comments li:nth-child(odd) { +.comment:nth-child(odd) { background-color: #f0f0f0; } -ul#comments li p:first-child { +.comment:nth-child(even) { + background-color: #ddd; +} + +.comment p:first-child { font-size: .8em; + margin-bottom: 10px; + border-bottom: 1px dotted #000; +} + +.comment p:first-child a { + color: #000; + text-decoration: none; +} + +.comment p:first-child a:hover, +.comment p:first-child a:focus { + text-decoration: underline; +} + +.comment .username { + font-weight: bold; +} + +.comment-textarea { + height: 70px; + width: 500px; } /* task colors */ @@ -593,18 +641,6 @@ tr td.task-orange, border-color: rgb(255, 172, 98); } -#description { - border-left: 5px solid #000; - background: #f0f0f0; - padding-left: 10px; - padding-top: 10px; - padding-bottom: 10px; -} - -#description li { - margin-left: 25px; -} - /* config page */ .listing, .settings { diff --git a/controllers/base.php b/controllers/base.php index cf423402..6dc9c0be 100644 --- a/controllers/base.php +++ b/controllers/base.php @@ -15,6 +15,7 @@ require __DIR__.'/../models/user.php'; require __DIR__.'/../models/project.php'; require __DIR__.'/../models/task.php'; require __DIR__.'/../models/board.php'; +require __DIR__.'/../models/comment.php'; abstract class Base { @@ -28,6 +29,7 @@ abstract class Base protected $board; protected $config; protected $acl; + protected $comment; public function __construct() { @@ -41,6 +43,7 @@ abstract class Base $this->task = new \Model\Task; $this->board = new \Model\Board; $this->acl = new \Model\Acl; + $this->comment = new \Model\Comment; } public function beforeAction($controller, $action) diff --git a/controllers/task.php b/controllers/task.php index 75d08958..a895d6b2 100644 --- a/controllers/task.php +++ b/controllers/task.php @@ -45,43 +45,53 @@ class Task extends Base $task = $this->task->getById($this->request->getIntegerParam('task_id'), true); if (! $task) $this->notfound(); - $this->checkProjectPermissions($task['project_id']); - $values = $values = $this->request->getValues(); - $errors = $this->comment($values, $task['id']); - $comments = $this->task->getCommentsByTask($task['id']); - $this->response->html($this->template->layout('task_show', array( + 'comments' => $this->comment->getAll($task['id']), + 'comment_errors' => array(), + 'comment_values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title'], - 'comments' => $comments, - 'errors' => $errors, - 'values' => $values ))); } - //add a comment - public function comment(array $values, $task_id) + // Add a comment + public function comment() { - $errors = array(); + $task = $this->task->getById($this->request->getIntegerParam('task_id'), true); + $values = $this->request->getValues(); - if ($_POST) { - list($valid, $errors) = $this->task->validateComment($values); + if (! $task) $this->notfound(); + $this->checkProjectPermissions($task['project_id']); + + list($valid, $errors) = $this->comment->validateCreation($values); + + if ($valid) { - if ($valid) { - $this->task->addComment(array( - 'task_id' => $task_id, - 'comment' => $values['comment'], - 'user_id' => $this->acl->getUserId() - )); + if ($this->comment->create($values)) { + $this->session->flash(t('Comment added successfully.')); } + else { + $this->session->flashError(t('Unable to create your comment.')); + } + + $this->response->redirect('?controller=task&action=show&task_id='.$task['id']); } - return $errors; + $this->response->html($this->template->layout('task_show', array( + 'comments' => $this->comment->getAll($task['id']), + 'comment_errors' => $errors, + 'comment_values' => $values, + 'task' => $task, + 'columns_list' => $this->board->getColumnsList($task['project_id']), + 'colors_list' => $this->task->getColors(), + 'menu' => 'tasks', + 'title' => $task['title'], + ))); } // Display a form to create a new task diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index fb9ce4bc..7cf8bfe1 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -202,7 +202,9 @@ return array( 'Everybody have access to this project.' => 'Tout le monde a accès au projet.', 'You are not allowed to access to this project.' => 'Vous n\'êtes pas autorisé à accéder à ce projet.', '%B %e, %G at %k:%M %p' => '%e %B %G à %k:%M', - //Comments => '', - //'No comments' => '', - //'Post comment' => '', + 'Comments' => 'Commentaires', + 'Post comment' => 'Commenter', + 'Write your text in Markdown' => 'Écrivez votre texte en Markdown', + 'Leave a comment' => 'Laissez un commentaire', + 'Comment is required' => 'Le commentaire est obligatoire', ); diff --git a/locales/pl_PL/translations.php b/locales/pl_PL/translations.php index 884f6262..a076ee9e 100644 --- a/locales/pl_PL/translations.php +++ b/locales/pl_PL/translations.php @@ -207,6 +207,8 @@ return array( 'You are not allowed to access to this project.' => 'Nie masz dostępu do tego projektu.', '%B %e, %G at %k:%M %p' => '%e %B %G o %k:%M', 'Comments' => 'Komentarze', - 'No comments' => 'Brak komentarzy', 'Post comment' => 'Dodaj komentarz', + //'Write your text in Markdown' => '', + //'Leave a comment' => '', + //'Comment is required' => '', ); diff --git a/models/acl.php b/models/acl.php index 7c363272..468022cb 100644 --- a/models/acl.php +++ b/models/acl.php @@ -16,7 +16,7 @@ class Acl extends Base 'app' => array('index'), 'board' => array('index', 'show', 'assign', 'assigntask', 'save'), 'project' => array('tasks', 'index', 'forbidden'), - 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'confirmclose', 'open', 'confirmopen'), + 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'confirmclose', 'open', 'confirmopen', 'comment'), 'user' => array('index', 'edit', 'update', 'forbidden', 'logout', 'index'), 'config' => array('index'), ); diff --git a/models/comment.php b/models/comment.php new file mode 100644 index 00000000..e0944249 --- /dev/null +++ b/models/comment.php @@ -0,0 +1,50 @@ +<?php + +namespace Model; + +use \SimpleValidator\Validator; +use \SimpleValidator\Validators; + +class Comment extends Base +{ + const TABLE = 'comments'; + + public function getAll($task_id) + { + return $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.id', + self::TABLE.'.date', + self::TABLE.'.comment', + \Model\User::TABLE.'.username' + ) + ->join(\Model\User::TABLE, 'id', 'user_id') + ->orderBy(self::TABLE.'.date', 'ASC') + ->eq(self::TABLE.'.task_id', $task_id) + ->findAll(); + } + + public function create(array $values) + { + $values['date'] = time(); + + return (bool) $this->db->table(self::TABLE)->save($values); + } + + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\Required('task_id', t('This value is required')), + new Validators\Integer('task_id', t('This value must be an integer')), + new Validators\Required('user_id', t('This value is required')), + new Validators\Integer('user_id', t('This value must be an integer')), + new Validators\Required('comment', t('Comment is required')) + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} diff --git a/models/task.php b/models/task.php index 5ee202c3..e542e8e0 100644 --- a/models/task.php +++ b/models/task.php @@ -8,7 +8,6 @@ use \SimpleValidator\Validators; class Task extends Base { const TABLE = 'tasks'; - const COMMENTS = 'comments'; public function getColors() { @@ -58,21 +57,6 @@ class Task extends Base } } - public function getCommentsByTask($task_id) - { - return $this->db - ->table(self::COMMENTS) - ->columns( - self::COMMENTS.'.date', - self::COMMENTS.'.comment', - \Model\User::TABLE.'.username' - ) - ->join(\Model\User::TABLE, 'id', 'user_id') - ->orderBy(self::COMMENTS.'.date', 'ASC') - ->eq(self::COMMENTS.'.task_id', $task_id) - ->findAll(); - } - public function getAllByProjectId($project_id, array $status = array(1, 0)) { return $this->db->table(self::TABLE) @@ -188,25 +172,6 @@ class Task extends Base ->update(array('column_id' => $column_id, 'position' => $position)); } - public function addComment($values) - { - $values['date'] = time(); - - return (bool) $this->db->table(self::COMMENTS)->save($values); - } - - public function validateComment(array $values) - { - $v = new Validator($values, array( - new Validators\Required('comment', t('Comment is required')) - )); - - return array( - $v->execute(), - $v->getErrors() - ); - } - public function validateCreation(array $values) { $v = new Validator($values, array( diff --git a/templates/task_edit.php b/templates/task_edit.php index c4f806fd..e400e790 100644 --- a/templates/task_edit.php +++ b/templates/task_edit.php @@ -25,6 +25,7 @@ <?= Helper\form_label(t('Description'), 'description') ?> <?= Helper\form_textarea('description', $values, $errors) ?><br/> + <div class="form-help"><a href="http://en.wikipedia.org/wiki/Markdown#Example" target="_blank"><?= t('Write your text in Markdown') ?></a></div> <?= Helper\form_checkbox('another_task', t('Create another task'), 1) ?> diff --git a/templates/task_show.php b/templates/task_show.php index e910c951..3e38d765 100644 --- a/templates/task_show.php +++ b/templates/task_show.php @@ -55,7 +55,7 @@ <?php if ($task['description']): ?> <h3><?= t('Description') ?></h3> - <article id="description"> + <article id="description" class="markdown"> <?= Helper\markdown($task['description']) ?: t('There is no description.') ?> </article> <?php endif ?> @@ -64,22 +64,24 @@ <?php if ($comments): ?> <ul id="comments"> <?php foreach ($comments as $comment): ?> - <li> - <p><?= $comment['username'] ?> @ <?= dt('%B %e, %G at %k:%M %p', $comment['date']) ?></p> + <div class="comment markdown" id="comment-<?= $comment['id'] ?>"> + <p><span class="username"><?= Helper\escape($comment['username']) ?></span> @ <a href="#comment-<?= $comment['id'] ?>"><?= dt('%B %e, %G at %k:%M %p', $comment['date']) ?></a></p> <?= Helper\markdown($comment['comment']) ?> - </li> + </div> <?php endforeach ?> </ul> - <?php else: ?> - <p><?= t('No comments') ?></p> <?php endif ?> - <form method="post" action="?controller=task&action=show&task_id=<?= $task['id'] ?>" autocomplete="off"> - <?= Helper\form_textarea('comment', $values, $errors) ?><br/> + <form method="post" action="?controller=task&action=comment&task_id=<?= $task['id'] ?>" autocomplete="off"> - <div class="form-actions"> - <input type="submit" value="<?= t('Post comment') ?>" class="btn btn-blue"/> - </div> - </form> + <?= Helper\form_hidden('task_id', $comment_values) ?> + <?= Helper\form_hidden('user_id', $comment_values) ?> + <?= Helper\form_textarea('comment', $comment_values, $comment_errors, array('required', 'placeholder="'.t('Leave a comment').'"'), 'comment-textarea') ?><br/> + <div class="form-help"><a href="http://en.wikipedia.org/wiki/Markdown#Example" target="_blank"><?= t('Write your text in Markdown') ?></a></div> + + <div class="form-actions"> + <input type="submit" value="<?= t('Post comment') ?>" class="btn btn-blue"/> + </div> + </form> </section> </section> |