From 19409360ca7d4c00d070b16bbfcc6cd02543cdca Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Tue, 4 Mar 2014 21:57:12 -0500 Subject: Improve comments --- assets/css/app.css | 74 +++++++++++++++++++++++++++++++----------- controllers/base.php | 3 ++ controllers/task.php | 50 ++++++++++++++++------------ locales/fr_FR/translations.php | 8 +++-- locales/pl_PL/translations.php | 4 ++- models/acl.php | 2 +- models/comment.php | 50 ++++++++++++++++++++++++++++ models/task.php | 35 -------------------- templates/task_edit.php | 1 + templates/task_show.php | 26 ++++++++------- 10 files changed, 162 insertions(+), 91 deletions(-) create mode 100644 models/comment.php 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 @@ +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 @@
+
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 @@

-
+
@@ -64,22 +64,24 @@ - -

-
-
+ -
- -
-
+ + +
+
+ +
+ +
+ -- cgit v1.2.3