Subtasks events refactoring and show delete in activity stream
This commit is contained in:
@@ -151,6 +151,7 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Core\Filter\LexerBuilder $taskLexer
|
||||
* @property \Kanboard\Core\Filter\LexerBuilder $projectActivityLexer
|
||||
* @property \Kanboard\Job\CommentEventJob $commentEventJob
|
||||
* @property \Kanboard\Job\SubtaskEventJob $subtaskEventJob
|
||||
* @property \Kanboard\Job\TaskFileEventJob $taskFileEventJob
|
||||
* @property \Kanboard\Job\ProjectFileEventJob $projectFileEventJob
|
||||
* @property \Kanboard\Job\NotificationJob $notificationJob
|
||||
|
||||
79
app/EventBuilder/SubtaskEventBuilder.php
Normal file
79
app/EventBuilder/SubtaskEventBuilder.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\EventBuilder;
|
||||
|
||||
use Kanboard\Event\SubtaskEvent;
|
||||
use Kanboard\Event\GenericEvent;
|
||||
|
||||
/**
|
||||
* Class SubtaskEventBuilder
|
||||
*
|
||||
* @package Kanboard\EventBuilder
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubtaskEventBuilder extends BaseEventBuilder
|
||||
{
|
||||
/**
|
||||
* SubtaskId
|
||||
*
|
||||
* @access protected
|
||||
* @var int
|
||||
*/
|
||||
protected $subtaskId = 0;
|
||||
|
||||
/**
|
||||
* Changed values
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $values = array();
|
||||
|
||||
/**
|
||||
* Set SubtaskId
|
||||
*
|
||||
* @param int $subtaskId
|
||||
* @return $this
|
||||
*/
|
||||
public function withSubtaskId($subtaskId)
|
||||
{
|
||||
$this->subtaskId = $subtaskId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set values
|
||||
*
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function withValues(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build event data
|
||||
*
|
||||
* @access public
|
||||
* @return GenericEvent|null
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$eventData = array();
|
||||
$eventData['subtask'] = $this->subtaskModel->getById($this->subtaskId, true);
|
||||
|
||||
if (empty($eventData['subtask'])) {
|
||||
$this->logger->debug(__METHOD__.': Subtask not found');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! empty($this->values)) {
|
||||
$eventData['changes'] = array_diff_assoc($this->values, $eventData['subtask']);
|
||||
}
|
||||
|
||||
$eventData['task'] = $this->taskFinderModel->getDetails($eventData['subtask']['task_id']);
|
||||
return new SubtaskEvent($eventData);
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,6 @@ class NotificationJob extends BaseJob
|
||||
case 'Kanboard\Event\TaskEvent':
|
||||
$values['task'] = $this->taskFinderModel->getDetails($event['task_id']);
|
||||
break;
|
||||
case 'Kanboard\Event\SubtaskEvent':
|
||||
$values['subtask'] = $this->subtaskModel->getById($event['id'], true);
|
||||
$values['task'] = $this->taskFinderModel->getDetails($values['subtask']['task_id']);
|
||||
break;
|
||||
default:
|
||||
$values = $event;
|
||||
}
|
||||
|
||||
48
app/Job/SubtaskEventJob.php
Normal file
48
app/Job/SubtaskEventJob.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Job;
|
||||
|
||||
use Kanboard\EventBuilder\SubtaskEventBuilder;
|
||||
|
||||
/**
|
||||
* Class SubtaskEventJob
|
||||
*
|
||||
* @package Kanboard\Job
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class SubtaskEventJob extends BaseJob
|
||||
{
|
||||
/**
|
||||
* Set job params
|
||||
*
|
||||
* @param int $subtaskId
|
||||
* @param string $eventName
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function withParams($subtaskId, $eventName, array $values = array())
|
||||
{
|
||||
$this->jobParams = array($subtaskId, $eventName, $values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute job
|
||||
*
|
||||
* @param int $subtaskId
|
||||
* @param string $eventName
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function execute($subtaskId, $eventName, array $values = array())
|
||||
{
|
||||
$event = SubtaskEventBuilder::getInstance($this->container)
|
||||
->withSubtaskId($subtaskId)
|
||||
->withValues($values)
|
||||
->build();
|
||||
|
||||
if ($event !== null) {
|
||||
$this->dispatcher->dispatch($eventName, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,8 @@ class NotificationModel extends Base
|
||||
return e('%s updated a subtask for the task #%d', $event_author, $event_data['task']['id']);
|
||||
case SubtaskModel::EVENT_CREATE:
|
||||
return e('%s created a subtask for the task #%d', $event_author, $event_data['task']['id']);
|
||||
case SubtaskModel::EVENT_DELETE:
|
||||
return e('%s removed a subtask for the task #%d', $event_author, $event_data['task']['id']);
|
||||
case CommentModel::EVENT_UPDATE:
|
||||
return e('%s updated a comment on the task #%d', $event_author, $event_data['task']['id']);
|
||||
case CommentModel::EVENT_CREATE:
|
||||
@@ -110,6 +112,8 @@ class NotificationModel extends Base
|
||||
return e('New subtask on task #%d', $event_data['subtask']['task_id']);
|
||||
case SubtaskModel::EVENT_UPDATE:
|
||||
return e('Subtask updated on task #%d', $event_data['subtask']['task_id']);
|
||||
case SubtaskModel::EVENT_DELETE:
|
||||
return e('Subtask removed on task #%d', $event_data['subtask']['task_id']);
|
||||
case TaskModel::EVENT_CREATE:
|
||||
return e('New task #%d: %s', $event_data['task']['id'], $event_data['task']['title']);
|
||||
case TaskModel::EVENT_UPDATE:
|
||||
@@ -157,6 +161,7 @@ class NotificationModel extends Base
|
||||
return $event_data['comment']['task_id'];
|
||||
case SubtaskModel::EVENT_CREATE:
|
||||
case SubtaskModel::EVENT_UPDATE:
|
||||
case SubtaskModel::EVENT_DELETE:
|
||||
return $event_data['subtask']['task_id'];
|
||||
case TaskModel::EVENT_CREATE:
|
||||
case TaskModel::EVENT_UPDATE:
|
||||
|
||||
@@ -66,7 +66,7 @@ class SubtaskModel extends Base
|
||||
->join(TaskModel::TABLE, 'id', 'task_id')
|
||||
->findOneColumn(TaskModel::TABLE . '.project_id') ?: 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get available status
|
||||
*
|
||||
@@ -235,10 +235,7 @@ class SubtaskModel extends Base
|
||||
$subtask_id = $this->db->table(self::TABLE)->persist($values);
|
||||
|
||||
if ($subtask_id !== false) {
|
||||
$this->container['dispatcher']->dispatch(
|
||||
self::EVENT_CREATE,
|
||||
new SubtaskEvent(array('id' => $subtask_id) + $values)
|
||||
);
|
||||
$this->queueManager->push($this->subtaskEventJob->withParams($subtask_id, self::EVENT_CREATE));
|
||||
}
|
||||
|
||||
return $subtask_id;
|
||||
@@ -255,13 +252,10 @@ class SubtaskModel extends Base
|
||||
public function update(array $values, $fire_events = true)
|
||||
{
|
||||
$this->prepare($values);
|
||||
$subtask = $this->getById($values['id']);
|
||||
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
|
||||
|
||||
if ($result && $fire_events) {
|
||||
$event = $subtask;
|
||||
$event['changes'] = array_diff_assoc($values, $subtask);
|
||||
$this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new SubtaskEvent($event));
|
||||
$this->queueManager->push($this->subtaskEventJob->withParams($values['id'], self::EVENT_UPDATE, $values));
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -377,14 +371,8 @@ class SubtaskModel extends Base
|
||||
*/
|
||||
public function remove($subtask_id)
|
||||
{
|
||||
$subtask = $this->getById($subtask_id);
|
||||
$result = $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
|
||||
|
||||
if ($result) {
|
||||
$this->container['dispatcher']->dispatch(self::EVENT_DELETE, new SubtaskEvent($subtask));
|
||||
}
|
||||
|
||||
return $result;
|
||||
$this->subtaskEventJob->execute($subtask_id, self::EVENT_DELETE);
|
||||
return $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,12 +26,6 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'AverageLeadCycleTimeAnalytic',
|
||||
'AverageTimeSpentColumnAnalytic',
|
||||
),
|
||||
'Job' => array(
|
||||
'CommentEventJob',
|
||||
'TaskFileEventJob',
|
||||
'ProjectFileEventJob',
|
||||
'NotificationJob',
|
||||
),
|
||||
'Model' => array(
|
||||
'ActionModel',
|
||||
'ActionParameterModel',
|
||||
|
||||
52
app/ServiceProvider/JobProvider.php
Normal file
52
app/ServiceProvider/JobProvider.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\ServiceProvider;
|
||||
|
||||
use Kanboard\Job\CommentEventJob;
|
||||
use Kanboard\Job\NotificationJob;
|
||||
use Kanboard\Job\ProjectFileEventJob;
|
||||
use Kanboard\Job\SubtaskEventJob;
|
||||
use Kanboard\Job\TaskFileEventJob;
|
||||
use Pimple\Container;
|
||||
use Pimple\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* Class JobProvider
|
||||
*
|
||||
* @package Kanboard\ServiceProvider
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class JobProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Register providers
|
||||
*
|
||||
* @access public
|
||||
* @param \Pimple\Container $container
|
||||
* @return \Pimple\Container
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['commentEventJob'] = $container->factory(function ($c) {
|
||||
return new CommentEventJob($c);
|
||||
});
|
||||
|
||||
$container['subtaskEventJob'] = $container->factory(function ($c) {
|
||||
return new SubtaskEventJob($c);
|
||||
});
|
||||
|
||||
$container['taskFileEventJob'] = $container->factory(function ($c) {
|
||||
return new TaskFileEventJob($c);
|
||||
});
|
||||
|
||||
$container['projectFileEventJob'] = $container->factory(function ($c) {
|
||||
return new ProjectFileEventJob($c);
|
||||
});
|
||||
|
||||
$container['notificationJob'] = $container->factory(function ($c) {
|
||||
return new NotificationJob($c);
|
||||
});
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,11 @@ use Pimple\ServiceProviderInterface;
|
||||
class QueueProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers services on the given container.
|
||||
* Register providers
|
||||
*
|
||||
* @param Container $container
|
||||
* @access public
|
||||
* @param \Pimple\Container $container
|
||||
* @return \Pimple\Container
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn
|
||||
TaskModel::EVENT_ASSIGNEE_CHANGE => 'handleEvent',
|
||||
SubtaskModel::EVENT_CREATE => 'handleEvent',
|
||||
SubtaskModel::EVENT_UPDATE => 'handleEvent',
|
||||
SubtaskModel::EVENT_DELETE => 'handleEvent',
|
||||
CommentModel::EVENT_CREATE => 'handleEvent',
|
||||
CommentModel::EVENT_UPDATE => 'handleEvent',
|
||||
CommentModel::EVENT_REMOVE => 'handleEvent',
|
||||
|
||||
15
app/Template/event/subtask_delete.php
Normal file
15
app/Template/event/subtask_delete.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<p class="activity-title">
|
||||
<?= e('%s removed a subtask for the task %s',
|
||||
$this->text->e($author),
|
||||
$this->url->link(t('#%d', $task['id']), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))
|
||||
) ?>
|
||||
<span class="activity-date"><?= $this->dt->datetime($date_creation) ?></span>
|
||||
</p>
|
||||
<div class="activity-description">
|
||||
<p class="activity-task-title"><?= $this->text->e($task['title']) ?></p>
|
||||
<ul>
|
||||
<li>
|
||||
<?= $this->text->e($subtask['title']) ?> (<strong><?= $this->text->e($subtask['status_name']) ?></strong>)
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
11
app/Template/notification/subtask_delete.php
Normal file
11
app/Template/notification/subtask_delete.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<h2><?= $this->text->e($task['title']) ?> (#<?= $task['id'] ?>)</h2>
|
||||
|
||||
<h3><?= t('Subtask removed') ?></h3>
|
||||
|
||||
<ul>
|
||||
<li><?= t('Title:') ?> <?= $this->text->e($subtask['title']) ?></li>
|
||||
<li><?= t('Status:') ?> <?= $this->text->e($subtask['status_name']) ?></li>
|
||||
<li><?= t('Assignee:') ?> <?= $this->text->e($subtask['name'] ?: $subtask['username'] ?: '?') ?></li>
|
||||
</ul>
|
||||
|
||||
<?= $this->render('notification/footer', array('task' => $task, 'application_url' => $application_url)) ?>
|
||||
@@ -46,6 +46,7 @@ $container->register(new Kanboard\ServiceProvider\ActionProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\ExternalLinkProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\AvatarProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\FilterProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\JobProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\QueueProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\ApiProvider());
|
||||
$container->register(new Kanboard\ServiceProvider\CommandProvider());
|
||||
|
||||
Reference in New Issue
Block a user