Added basic comments on tasks
This commit is contained in:
parent
86bee36784
commit
ccc54c65cf
|
|
@ -532,6 +532,24 @@ article .task-score {
|
|||
top: 5px;
|
||||
}
|
||||
|
||||
ul#comments {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
ul#comments li {
|
||||
margin: 10px 0;
|
||||
padding: 10px 0 10px 10px;
|
||||
border-left: 5px solid #000;
|
||||
}
|
||||
|
||||
ul#comments li:nth-child(odd) {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
ul#comments li p:first-child {
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
/* task colors */
|
||||
tr td.task-blue,
|
||||
.task-blue {
|
||||
|
|
|
|||
|
|
@ -45,17 +45,45 @@ 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(
|
||||
'task' => $task,
|
||||
'columns_list' => $this->board->getColumnsList($task['project_id']),
|
||||
'colors_list' => $this->task->getColors(),
|
||||
'menu' => 'tasks',
|
||||
'title' => $task['title']
|
||||
'title' => $task['title'],
|
||||
'comments' => $comments,
|
||||
'errors' => $errors,
|
||||
'values' => $values
|
||||
)));
|
||||
}
|
||||
|
||||
//add a comment
|
||||
public function comment(array $values, $task_id)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
if ($_POST) {
|
||||
list($valid, $errors) = $this->task->validateComment($values);
|
||||
|
||||
if ($valid) {
|
||||
$this->task->addComment(array(
|
||||
'task_id' => $task_id,
|
||||
'comment' => $values['comment'],
|
||||
'user_id' => $this->acl->getUserId()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
// Display a form to create a new task
|
||||
public function create()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -201,4 +201,8 @@ return array(
|
|||
'User' => 'Utilisateur',
|
||||
'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' => '',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -205,5 +205,8 @@ return array(
|
|||
'User' => 'Użytkownik',
|
||||
'Everybody have access to this project.' => 'Każdy ma dostęp 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',
|
||||
'Comments' => 'Komentarze',
|
||||
'No comments' => 'Brak komentarzy',
|
||||
'Post comment' => 'Dodaj komentarz',
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ require __DIR__.'/schema.php';
|
|||
abstract class Base
|
||||
{
|
||||
const APP_VERSION = 'master';
|
||||
const DB_VERSION = 7;
|
||||
const DB_VERSION = 8;
|
||||
|
||||
private static $dbInstance = null;
|
||||
protected $db;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,21 @@
|
|||
|
||||
namespace Schema;
|
||||
|
||||
function version_8($pdo)
|
||||
{
|
||||
$pdo->exec(
|
||||
'CREATE TABLE comments (
|
||||
id INTEGER PRIMARY KEY,
|
||||
task_id INTEGER,
|
||||
user_id INTEGER,
|
||||
date INTEGER,
|
||||
comment TEXT,
|
||||
FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY(user_id) REFERENCES tasks(id) ON DELETE CASCADE
|
||||
)'
|
||||
);
|
||||
}
|
||||
|
||||
function version_7($pdo)
|
||||
{
|
||||
$pdo->exec("
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use \SimpleValidator\Validators;
|
|||
class Task extends Base
|
||||
{
|
||||
const TABLE = 'tasks';
|
||||
const COMMENTS = 'comments';
|
||||
|
||||
public function getColors()
|
||||
{
|
||||
|
|
@ -57,6 +58,21 @@ 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)
|
||||
|
|
@ -172,6 +188,25 @@ 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(
|
||||
|
|
|
|||
|
|
@ -60,5 +60,26 @@
|
|||
</article>
|
||||
<?php endif ?>
|
||||
|
||||
<h3><?= t('Comments') ?></h3>
|
||||
<?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>
|
||||
<?= Helper\markdown($comment['comment']) ?>
|
||||
</li>
|
||||
<?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/>
|
||||
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="<?= t('Post comment') ?>" class="btn btn-blue"/>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Reference in New Issue