Improve comments
This commit is contained in:
parent
ccc54c65cf
commit
19409360ca
|
|
@ -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;
|
||||
}
|
||||
|
||||
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;
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
|
||||
if ($valid) {
|
||||
$this->task->addComment(array(
|
||||
'task_id' => $task_id,
|
||||
'comment' => $values['comment'],
|
||||
'user_id' => $this->acl->getUserId()
|
||||
));
|
||||
list($valid, $errors) = $this->comment->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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) ?>
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue