Went through todos

This commit is contained in:
Dennis Eichhorn 2024-05-02 22:54:38 +00:00
parent 3dfe3090f3
commit 13907cbc86
4 changed files with 72 additions and 9 deletions

View File

@ -16,6 +16,7 @@ namespace Modules\Kanban\Controller;
use Modules\Admin\Models\AccountMapper;
use Modules\Admin\Models\NullAccount;
use Modules\Comments\Models\Comment;
use Modules\Kanban\Models\BoardStatus;
use Modules\Kanban\Models\CardStatus;
use Modules\Kanban\Models\CardType;
@ -53,8 +54,7 @@ final class ApiController extends Controller
*
* @return void
*
* @todo Create another notification whenever a comment is created for a card
* The card owner and all previous commentators should receive a notification
* @performance This should happen in the cli if possible?
*
* @since 1.0.0
*/
@ -82,6 +82,52 @@ final class ApiController extends Controller
}
}
/**
* Create a notification for a card
*
* @param Comment $comment Comment to create notification for
* @param RequestAbstract $request Request
*
* @return void
*
* @performance This should happen in the cli if possible?
*
* @since 1.0.0
*/
private function createCommentNotifications(Comment $comment, RequestAbstract $request) : void
{
$card = KanbanCardMapper::get()
->with('commentList')
->with('commentList/comments')
->where('commentList', $comment->list)
->execute();
$accounts = [];
if ($card->createdBy->id !== $comment->createdBy->id) {
$accounts[] = $card->createdBy->id;
}
foreach ($card->commentList->comments as $element) {
if ($element->createdBy->id !== $comment->createdBy->id) {
$accounts[] = $element->createdBy->id;
}
}
foreach ($accounts as $account) {
$notification = new Notification();
$notification->module = self::NAME;
$notification->title = $card->name;
$notification->createdBy = $card->createdBy;
$notification->createdFor = new NullAccount($account);
$notification->type = NotificationType::CREATE;
$notification->category = PermissionCategory::CARD;
$notification->element = $card->id;
$notification->redirect = '{/base}/kanban/card?{?}&id=' . $card->id;
$this->createModel($request->header->account, $notification, NotificationMapper::class, 'notification', $request->getOrigin());
}
}
/**
* Routing end-point for application behavior.
*
@ -389,4 +435,25 @@ final class ApiController extends Controller
return [];
}
/**
* Api method to create comment
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiCommentCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
$this->app->moduleManager->get('Comment', 'Api')->apiCommentCreate($request, $response, $data);
$comment = $response->getDataArray($request->uri->__toString())['response'];
$this->createCommentNotifications($comment, $request);
}
}

View File

@ -34,9 +34,6 @@ use phpOMS\Views\View;
* @link https://jingga.app
* @since 1.0.0
* @codeCoverageIgnore
*
* @todo Implement unread cards/comments notification/highlight
* https://github.com/Karaka-Management/oms-Kanban/issues/5
*/
final class BackendController extends Controller
{

View File

@ -27,10 +27,6 @@ use Modules\Tasks\Models\Task;
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*
* @todo Implement unread cards/comments notification/highlight
* See tasks for inspiration. However, here we also need to highlight the entire board for unread content
* https://github.com/Karaka-Management/oms-Kanban/issues/5
*/
class KanbanCard implements \JsonSerializable
{

View File

@ -15,6 +15,9 @@ declare(strict_types=1);
use Modules\Kanban\Models\NullKanbanBoard;
use phpOMS\Uri\UriFactory;
// @todo Allow card templates? maybe at least colors?
// https://github.com/Karaka-Management/oms-Kanban/issues/10
/** @var \Modules\Kanban\Models\KanbanBoard $board */
$board = $this->data['board'] ?? new NullKanbanBoard();
?>