Improve comments

This commit is contained in:
Frédéric Guillot
2014-03-04 21:57:12 -05:00
parent ccc54c65cf
commit 19409360ca
10 changed files with 162 additions and 91 deletions

View File

@@ -189,7 +189,7 @@ textarea.form-error {
} }
.form-help { .form-help {
font-size: 0.9em; font-size: 0.8em;
color: brown; color: brown;
margin-bottom: 15px; margin-bottom: 15px;
} }
@@ -532,22 +532,70 @@ article .task-score {
top: 5px; top: 5px;
} }
ul#comments { #description {
list-style-type: none; border-left: 5px solid #000;
background: #f0f0f0;
padding: 10px;
} }
ul#comments li { /* 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;
}
/* comments */
.comment {
margin: 10px 0; margin: 10px 0;
padding: 10px 0 10px 10px; padding: 10px;
border-left: 5px solid #000; border-left: 5px solid #000;
} }
ul#comments li:nth-child(odd) { .comment:nth-child(odd) {
background-color: #f0f0f0; background-color: #f0f0f0;
} }
ul#comments li p:first-child { .comment:nth-child(even) {
background-color: #ddd;
}
.comment p:first-child {
font-size: .8em; 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 */ /* task colors */
@@ -593,18 +641,6 @@ tr td.task-orange,
border-color: rgb(255, 172, 98); 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 */ /* config page */
.listing, .listing,
.settings { .settings {

View File

@@ -15,6 +15,7 @@ require __DIR__.'/../models/user.php';
require __DIR__.'/../models/project.php'; require __DIR__.'/../models/project.php';
require __DIR__.'/../models/task.php'; require __DIR__.'/../models/task.php';
require __DIR__.'/../models/board.php'; require __DIR__.'/../models/board.php';
require __DIR__.'/../models/comment.php';
abstract class Base abstract class Base
{ {
@@ -28,6 +29,7 @@ abstract class Base
protected $board; protected $board;
protected $config; protected $config;
protected $acl; protected $acl;
protected $comment;
public function __construct() public function __construct()
{ {
@@ -41,6 +43,7 @@ abstract class Base
$this->task = new \Model\Task; $this->task = new \Model\Task;
$this->board = new \Model\Board; $this->board = new \Model\Board;
$this->acl = new \Model\Acl; $this->acl = new \Model\Acl;
$this->comment = new \Model\Comment;
} }
public function beforeAction($controller, $action) public function beforeAction($controller, $action)

View File

@@ -45,43 +45,53 @@ class Task extends Base
$task = $this->task->getById($this->request->getIntegerParam('task_id'), true); $task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
if (! $task) $this->notfound(); if (! $task) $this->notfound();
$this->checkProjectPermissions($task['project_id']); $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( $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, 'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']), 'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->task->getColors(), 'colors_list' => $this->task->getColors(),
'menu' => 'tasks', 'menu' => 'tasks',
'title' => $task['title'], 'title' => $task['title'],
'comments' => $comments,
'errors' => $errors,
'values' => $values
))); )));
} }
//add a comment // Add a comment
public function comment(array $values, $task_id) public function comment()
{ {
$errors = array(); $task = $this->task->getById($this->request->getIntegerParam('task_id'), true);
$values = $this->request->getValues();
if ($_POST) { if (! $task) $this->notfound();
list($valid, $errors) = $this->task->validateComment($values); $this->checkProjectPermissions($task['project_id']);
if ($valid) { list($valid, $errors) = $this->comment->validateCreation($values);
$this->task->addComment(array(
'task_id' => $task_id, if ($valid) {
'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 // Display a form to create a new task

View File

@@ -202,7 +202,9 @@ return array(
'Everybody have access to this project.' => 'Tout le monde a accès au projet.', '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.', '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', '%B %e, %G at %k:%M %p' => '%e %B %G à %k:%M',
//Comments => '', 'Comments' => 'Commentaires',
//'No comments' => '', 'Post comment' => 'Commenter',
//'Post comment' => '', 'Write your text in Markdown' => 'Écrivez votre texte en Markdown',
'Leave a comment' => 'Laissez un commentaire',
'Comment is required' => 'Le commentaire est obligatoire',
); );

View File

@@ -207,6 +207,8 @@ return array(
'You are not allowed to access to this project.' => 'Nie masz dostępu do tego projektu.', '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', '%B %e, %G at %k:%M %p' => '%e %B %G o %k:%M',
'Comments' => 'Komentarze', 'Comments' => 'Komentarze',
'No comments' => 'Brak komentarzy',
'Post comment' => 'Dodaj komentarz', 'Post comment' => 'Dodaj komentarz',
//'Write your text in Markdown' => '',
//'Leave a comment' => '',
//'Comment is required' => '',
); );

View File

@@ -16,7 +16,7 @@ class Acl extends Base
'app' => array('index'), 'app' => array('index'),
'board' => array('index', 'show', 'assign', 'assigntask', 'save'), 'board' => array('index', 'show', 'assign', 'assigntask', 'save'),
'project' => array('tasks', 'index', 'forbidden'), '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'), 'user' => array('index', 'edit', 'update', 'forbidden', 'logout', 'index'),
'config' => array('index'), 'config' => array('index'),
); );

50
models/comment.php Normal file
View File

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

View File

@@ -8,7 +8,6 @@ use \SimpleValidator\Validators;
class Task extends Base class Task extends Base
{ {
const TABLE = 'tasks'; const TABLE = 'tasks';
const COMMENTS = 'comments';
public function getColors() 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)) public function getAllByProjectId($project_id, array $status = array(1, 0))
{ {
return $this->db->table(self::TABLE) return $this->db->table(self::TABLE)
@@ -188,25 +172,6 @@ class Task extends Base
->update(array('column_id' => $column_id, 'position' => $position)); ->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) public function validateCreation(array $values)
{ {
$v = new Validator($values, array( $v = new Validator($values, array(

View File

@@ -25,6 +25,7 @@
<?= Helper\form_label(t('Description'), 'description') ?> <?= Helper\form_label(t('Description'), 'description') ?>
<?= Helper\form_textarea('description', $values, $errors) ?><br/> <?= 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) ?> <?= Helper\form_checkbox('another_task', t('Create another task'), 1) ?>

View File

@@ -55,7 +55,7 @@
<?php if ($task['description']): ?> <?php if ($task['description']): ?>
<h3><?= t('Description') ?></h3> <h3><?= t('Description') ?></h3>
<article id="description"> <article id="description" class="markdown">
<?= Helper\markdown($task['description']) ?: t('There is no description.') ?> <?= Helper\markdown($task['description']) ?: t('There is no description.') ?>
</article> </article>
<?php endif ?> <?php endif ?>
@@ -64,22 +64,24 @@
<?php if ($comments): ?> <?php if ($comments): ?>
<ul id="comments"> <ul id="comments">
<?php foreach ($comments as $comment): ?> <?php foreach ($comments as $comment): ?>
<li> <div class="comment markdown" id="comment-<?= $comment['id'] ?>">
<p><?= $comment['username'] ?> @ <?= dt('%B %e, %G at %k:%M %p', $comment['date']) ?></p> <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']) ?> <?= Helper\markdown($comment['comment']) ?>
</li> </div>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>
<?php else: ?>
<p><?= t('No comments') ?></p>
<?php endif ?> <?php endif ?>
<form method="post" action="?controller=task&amp;action=show&amp;task_id=<?= $task['id'] ?>" autocomplete="off"> <form method="post" action="?controller=task&amp;action=comment&amp;task_id=<?= $task['id'] ?>" autocomplete="off">
<?= Helper\form_textarea('comment', $values, $errors) ?><br/>
<div class="form-actions"> <?= Helper\form_hidden('task_id', $comment_values) ?>
<input type="submit" value="<?= t('Post comment') ?>" class="btn btn-blue"/> <?= Helper\form_hidden('user_id', $comment_values) ?>
</div> <?= Helper\form_textarea('comment', $comment_values, $comment_errors, array('required', 'placeholder="'.t('Leave a comment').'"'), 'comment-textarea') ?><br/>
</form> <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>
</section> </section>