Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

feat: Unread counter on Messages tab #70

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,13 @@
'id' => 'dashboard-messaging',
'label' => 'dashboard-nav-messaging',
'route' => 'conversations',
'pages' => array(
array(
'id' => 'messaging-create-conversation',
'label' => 'New Conversation',
'route' => 'conversations/new',
),
),
),
),
),
Expand Down Expand Up @@ -1521,7 +1528,7 @@
),
'invokables' => array(
'generatePeopleList' => \Olcs\View\Helper\GeneratePeopleList::class,
'tmCheckAnswersChangeLink' => \Olcs\View\Helper\TmCheckAnswersChangeLink::class,

Check failure on line 1531 in module/Olcs/config/module.config.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedClass

module/Olcs/config/module.config.php:1531:43: UndefinedClass: Class, interface or enum named Olcs\View\Helper\TmCheckAnswersChangeLink does not exist (see https://psalm.dev/019)

Check failure on line 1531 in module/Olcs/config/module.config.php

View workflow job for this annotation

GitHub Actions / static-analysis / PHPStan - 7.4

Class Olcs\View\Helper\TmCheckAnswersChangeLink not found.
)
),
'view_manager' => array(
Expand Down
8 changes: 7 additions & 1 deletion module/Olcs/src/Controller/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByOrganisation as ByOrganisationQuery;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Laminas\Http\Response;
use Laminas\Navigation\Navigation;
use Laminas\View\Model\ViewModel;
use LmcRbacMvc\Service\AuthorizationService;
use Olcs\Form\Model\Form\Message\Reply as ReplyForm;
Expand All @@ -34,17 +35,20 @@ class ConversationsController extends AbstractController implements ToggleAwareI
protected FlashMessengerHelperService $flashMessengerHelper;
protected TableFactory $tableFactory;
protected FormHelperService $formHelperService;
protected Navigation $navigationService;

public function __construct(
NiTextTranslation $niTextTranslationUtil,
AuthorizationService $authService,
FlashMessengerHelperService $flashMessengerHelper,
TableFactory $tableFactory,
FormHelperService $formHelperService
FormHelperService $formHelperService,
Navigation $navigationService
) {
$this->flashMessengerHelper = $flashMessengerHelper;
$this->tableFactory = $tableFactory;
$this->formHelperService = $formHelperService;
$this->navigationService = $navigationService;

parent::__construct($niTextTranslationUtil, $authService);
}
Expand Down Expand Up @@ -150,6 +154,8 @@ private function mapFormDataToCommand(\Laminas\Form\Form $form): Create
/** @return ViewModel|Response */
public function viewAction()
{
$this->navigationService->findBy('id', 'dashboard-messaging')->setActive();

$params = [
'page' => $this->params()->fromQuery('page', 1),
'limit' => $this->params()->fromQuery('limit', 10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Common\Service\Helper\FormHelperService;
use Common\Service\Table\TableFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Laminas\Navigation\Navigation;
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use LmcRbacMvc\Service\AuthorizationService;
Expand All @@ -25,13 +26,15 @@ public function __invoke(
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$tableFactory = $container->get(TableFactory::class);
$formHelperService = $container->get(FormHelperService::class);
$navigationService = $container->get(Navigation::class);

return new ConversationsController(
$niTextTranslationUtil,
$authService,
$flashMessengerHelper,
$tableFactory,
$formHelperService,
$navigationService
);
}
}
25 changes: 25 additions & 0 deletions module/Olcs/src/Controller/Listener/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Common\FeatureToggle;
use Common\Rbac\User as RbacUser;
use Common\Service\Cqrs\Query\QuerySender;
use Dvsa\Olcs\Transfer\Query\Messaging\Messages\UnreadCountByOrganisationAndUser;
use Laminas\EventManager\EventManagerInterface;
use Laminas\EventManager\ListenerAggregateInterface;
use Laminas\EventManager\ListenerAggregateTrait;
Expand Down Expand Up @@ -168,6 +169,8 @@ private function toggleMessagesTab(bool $shouldShowMessagesTab): void
{
$this->navigation->findBy('id', 'dashboard-messaging')
->setVisible($shouldShowMessagesTab);

$this->addUnreadMessagingCount();
}

private function shouldShowMessagesTab(): bool
Expand Down Expand Up @@ -201,4 +204,26 @@ public function setGovUkReferers(array $govUkReferers): void
{
$this->govUkReferers = $govUkReferers;
}

public function getUnreadMessageCount(): int
{
$userOrganisationId = $this->identity->getUserData()['organisationUsers'][0]['organisation']['id'];

$unreadByOrganisation = $this->querySender->send(
UnreadCountByOrganisationAndUser::create(
[
'organisation' => $userOrganisationId,
'user' => $this->identity->getId(),
]
)
);

return($unreadByOrganisation->getResult()['count'] ?? 0);
}

public function addUnreadMessagingCount(){
$this->navigation->findBy('id', 'dashboard-licences-applications')
->findBy('id','dashboard-messaging')
->set('unreadMessageCount', $this->getUnreadMessageCount());
}
}
3 changes: 1 addition & 2 deletions module/Olcs/src/Service/Data/MessagingAppOrLicNo.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public function formatDataForGroups(array $data): array

private function prefixArrayKey(array &$array, string $prefix): void
{
foreach ($array as $k => $v)
{
foreach ($array as $k => $v) {
$array[$prefix . $k] = $v;
unset($array[$k]);
}
Expand Down
9 changes: 9 additions & 0 deletions module/Olcs/view/partials/tabs-nav.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<?php echo $this->escapeHtml($this->translate($page->getLabel())); ?>
<?php echo $page->get('count') ? '('.$page->get('count').')' : '';?>
</a>
<?php if ($page->id == "dashboard-messaging" && $page->get('unreadMessageCount') > 0): ?>
<div class="notification-count">
<span class="notification-count__number">
<?php
echo $page->get('unreadMessageCount');
?>
</span>
</div>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
Expand Down
7 changes: 7 additions & 0 deletions test/Olcs/src/Controller/ConversationsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Laminas\Http\Response as HttpResponse;
use Laminas\Mvc\Controller\Plugin\Params;
use Dvsa\Olcs\Transfer\Command\Messaging\Message\Create as CreateMessageCommand;
use Laminas\Navigation\Navigation;
use Laminas\View\Model\ViewModel;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
Expand All @@ -36,6 +37,7 @@ public function setUp(): void
$this->mockFlashMessengerHelper = m::mock(FlashMessengerHelperService::class)->makePartial();
$this->mockTableFactory = m::mock(TableFactory::class)->makePartial();
$this->mockFormHelperService = m::mock(FormHelperService::class)->makePartial();
$this->mockNavigation = m::mock(Navigation::class)->shouldIgnoreMissing();
$this->mockForm = m::mock(Form::class);
$this->mockParams = m::mock(Params::class);

Expand All @@ -49,6 +51,7 @@ public function setUp(): void
$this->setMockedProperties($reflectionClass, 'flashMessengerHelper', $this->mockFlashMessengerHelper);
$this->setMockedProperties($reflectionClass, 'tableFactory', $this->mockTableFactory);
$this->setMockedProperties($reflectionClass, 'formHelperService', $this->mockFormHelperService);
$this->setMockedProperties($reflectionClass, 'navigationService', $this->mockNavigation);

$this->mockFormHelperService->shouldReceive('createForm')
->once()
Expand Down Expand Up @@ -120,6 +123,10 @@ public function testViewAction(): void
)
->andReturn($table);

$this->mockNavigation
->shouldReceive('findBy->setActive')
->once();

$view = $this->sut->viewAction();
$this->assertInstanceOf(ViewModel::class, $view);
$this->assertEquals($table, $view->getVariable('table'));
Expand Down
Loading
Loading