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

feat: Close Conversation Front-end #13

Merged
merged 7 commits into from
Jan 12, 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
1 change: 1 addition & 0 deletions module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
Olcs\Controller\Messages\LicenceConversationListController::class=> Olcs\Controller\Factory\Messages\LicenceConversationListControllerFactory::class,
Olcs\Controller\Messages\LicenceDisableConversationListController::class=> Olcs\Controller\Factory\Messages\LicenceDisableConversationListControllerFactory::class,
Olcs\Controller\Messages\LicenceNewConversationController::class=> Olcs\Controller\Factory\Messages\LicenceNewConversationControllerFactory::class,
Olcs\Controller\Messages\LicenceCloseConversationController::class => Olcs\Controller\Factory\Messages\LicenceCloseConversationControllerFactory::class,
OperatorControllers\OperatorFeesController::class => OperatorControllerFactories\OperatorFeesControllerFactory::class,
OperatorControllers\OperatorProcessingTasksController::class => OperatorControllerFactories\OperatorProcessingTasksControllerFactory::class,
OperatorControllers\UnlicensedBusinessDetailsController::class => OperatorControllerFactories\UnlicensedBusinessDetailsControllerFactory::class,
Expand Down
11 changes: 11 additions & 0 deletions module/Olcs/config/routes.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,17 @@
],
'may_terminate' => true,
],
'close' => [
'type' => 'segment',
'options' => [
'route' => ':conversation/close[/]',
'defaults' => [
'controller' => Olcs\Controller\Messages\LicenceCloseConversationController::class,
'action' => 'confirm'
],
],
'may_terminate' => true,
],
'disable' => [
'type' => 'segment',
'options' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Olcs\Controller\Factory\Messages;

use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Helper\TranslationHelperService;
use Common\Service\Script\ScriptFactory;
use Common\Service\Table\TableFactory;
use Laminas\Navigation\Navigation;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\HelperPluginManager;
use Olcs\Controller\Messages\LicenceCloseConversationController;
use Olcs\Controller\Messages\LicenceNewConversationController;
use Olcs\Controller\TaskController;
use Olcs\Service\Data\SubCategory;
use Olcs\Service\Data\UserListInternalExcludingLimitedReadOnlyUsers;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class LicenceCloseConversationControllerFactory implements FactoryInterface
{
public function __invoke(
ContainerInterface $container,
string $requestedName,
?array $options = null
): LicenceCloseConversationController
{
$container = method_exists($container, 'getServiceLocator') ? $container->getServiceLocator() : $container;

$scriptFactory = $container->get(ScriptFactory::class);
$formHelper = $container->get(FormHelperService::class);
$tableFactory = $container->get(TableFactory::class);
$viewHelperManager = $container->get(HelperPluginManager::class);
$flashMessengerHelperService = $container->get(FlashMessengerHelperService::class);

return new LicenceCloseConversationController(
$scriptFactory,
$formHelper,
$tableFactory,
$viewHelperManager,
$flashMessengerHelperService,
);
}

public function createService(ServiceLocatorInterface $serviceLocator): LicenceCloseConversationController
{
return $this->__invoke($serviceLocator, LicenceCloseConversationController::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@
class LicenceConversationMessagesControllerFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param ContainerInterface $container
* @param $requestedName
* @param array|null $options
* @param array|null $options
* @return LicenceConversationMessagesController
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): LicenceConversationMessagesController
{
$container = method_exists($container, 'getServiceLocator') ? $container->getServiceLocator() : $container;

$formHelper = $container->get(FormHelperService::class);

$translationHelper = $container->get(TranslationHelperService::class);

$flashMessenger = $container->get(FlashMessengerHelperService::class);
$scriptsFactory = $container->get(ScriptFactory::class);

$navigation = $container->get('navigation');

return new LicenceConversationMessagesController(
$translationHelper,
$formHelper,
$flashMessenger,
$navigation
$navigation,
$scriptsFactory
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Olcs\Controller\Messages;

use Common\Controller\Interfaces\ToggleAwareInterface;
use Common\FeatureToggle;
use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Script\ScriptFactory;
use Common\Service\Table\TableFactory;
use Dvsa\Olcs\Transfer\Command\Messaging\Close;
use Laminas\Http\Response;
use Laminas\View\HelperPluginManager;
use Laminas\View\Model\ViewModel;
use Olcs\Controller\AbstractController;
use Olcs\Data\Mapper\Task;
use Olcs\Form\Model\Form\CloseConversation;

class LicenceCloseConversationController extends AbstractController implements ToggleAwareInterface
{
protected array $toggleConfig = [
'default' => [FeatureToggle::MESSAGING],
];
private FlashMessengerHelperService $flashMessengerHelperService;

public function __construct(
ScriptFactory $scriptFactory,
FormHelperService $formHelper,
TableFactory $tableFactory,
HelperPluginManager $viewHelperManager,
FlashMessengerHelperService $flashMessengerHelperService
)
{
parent::__construct($scriptFactory, $formHelper, $tableFactory, $viewHelperManager);

$this->flashMessengerHelperService = $flashMessengerHelperService;
}

/**
* @return ViewModel|Response
*/
public function confirmAction()
{
$form = $this->getForm(CloseConversation::class);
$form->get('id')->setValue($this->params()->fromRoute('conversation'));

if ($this->getRequest()->isPost()) {
$closeCommand = Close::create(['id' => $this->params()->fromRoute('conversation')]);
$response = $this->handleCommand($closeCommand);

if ($response->isOk()) {
$this->flashMessengerHelperService->addSuccessMessage('conversation-closed-success');

$params = [
'licence' => $this->params()->fromRoute('licence'),
'action' => 'close',
];
return $this->redirect()->toRouteAjax('licence/conversation', $params);
} else if ($response->isClientError()) {
Task::mapFormErrors($response->getResult()['messages'], $form, $this->flashMessengerHelperService);
} else {
$this->flashMessengerHelperService->addUnknownError();
}
}

$view = new ViewModel(['form' => $form]);
$view->setTemplate('pages/form');

return $this->renderView($view, 'End Conversation');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

namespace Olcs\Controller\Messages;

use Common\Service\Helper\FlashMessengerHelperService;
use Common\Service\Helper\FormHelperService;
use Common\Service\Helper\TranslationHelperService;
use Common\Service\Script\ScriptFactory;
use Common\Service\Table\TableBuilder;
use Laminas\Navigation\Navigation;
use Laminas\View\Model\ViewModel;
use Olcs\Controller\AbstractInternalController;
use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation;
use Olcs\Controller\Interfaces\LeftViewProvider;
use Olcs\Controller\Interfaces\LicenceControllerInterface;
use Common\Controller\Interfaces\ToggleAwareInterface;
use Common\FeatureToggle;
use Olcs\Mvc\Controller\Plugin\Table;

class LicenceConversationMessagesController extends AbstractInternalController implements LeftViewProvider, LicenceControllerInterface, ToggleAwareInterface
{
protected $navigationId = 'conversations';
protected $listVars = ['licence','conversation'];
protected $listVars = ['licence', 'conversation'];
protected $listDto = ByConversation::class;
protected $tableName = 'messages-list';
protected $routeIdentifier = 'messages';
Expand All @@ -22,30 +29,75 @@ class LicenceConversationMessagesController extends AbstractInternalController i
FeatureToggle::MESSAGING
],
];
protected ScriptFactory $scriptFactory;

public function __construct(
TranslationHelperService $translationHelper,
FormHelperService $formHelper,
FlashMessengerHelperService $flashMessenger,
Navigation $navigation,
ScriptFactory $scriptFactory
)
{
parent::__construct($translationHelper, $formHelper, $flashMessenger, $navigation);

$this->scriptFactory = $scriptFactory;
}

/**
* @inheritDoc
*/
public function indexAction()
{
$this->scriptFactory->loadFiles(['table-actions']);

if (!$this->getRequest()->isPost()) {
return parent::indexAction();
}

$action = strtolower($this->params()->fromPost('action'));
switch ($action) {
case 'end and archive conversation':
$params = [
'licence' => $this->params()->fromRoute('licence'),
'conversation' => $this->params()->fromRoute('conversation'),
'action' => $this->params()->fromRoute('confirm'),
];
return $this->redirect()->toRoute('licence/conversation/close', $params);
}
}

/**
* Get left view
*
* @return ViewModel
* @param TableBuilder $table
* @param array $data
*/
public function getLeftView()
protected function alterTable($table, $data): TableBuilder
{
if (!$data['extra']['conversation']['isClosed']) {
return $table;
}

$crud = $table->getSetting('crud');
$crud['actions']['end and archive conversation']['class'] .= ' govuk-button--disabled';
$crud['actions']['end and archive conversation']['disabled'] = 'disabled';
$table->setSetting('crud', $crud);

return $table;
}

public function getLeftView(): ViewModel
{
$view = new ViewModel();
$view->setTemplate('sections/messages/partials/left');

return $view;
}

/**
* Get right view
*
* @return ViewModel
*/
public function getRightView()
public function getRightView(): ViewModel
{
$view = new ViewModel();
$view->setTemplate('sections/licence/partials/right');

return $view;
}
}
}
43 changes: 43 additions & 0 deletions module/Olcs/src/Form/Model/Fieldset/CloseConversationActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Olcs\Form\Model\Fieldset;

use Laminas\Form\Annotation as Form;

/**
* @codeCoverageIgnore No methods
* @Form\Name("main")
* @Form\Attributes({"class": "govuk-button-group"})
*/
class CloseConversationActions
{
/**
* @Form\Attributes({
* "type": "submit",
* "data-module": "govuk-button",
wadedvsa marked this conversation as resolved.
Show resolved Hide resolved
* "class": "govuk-button govuk-button--warning",
* "id": "close"
* })
* @Form\Options({
* "label": "End and archive conversation"
* })
* @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class)
*/
public ?ActionButton $close = null;

/**
* @Form\Attributes({
* "data-module": "govuk-button",
* "type": "cancel",
* "class": "govuk-link action-button-link",
* "id": "cancel"
* })
* @Form\Options({
* "label": "Cancel"
* })
* @Form\Type(\Common\Form\Elements\InputFilters\ActionButton::class)
*/
public ?ActionButton $cancel = null;
}
21 changes: 21 additions & 0 deletions module/Olcs/src/Form/Model/Fieldset/CloseConversationText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Olcs\Form\Model\Fieldset;

use Laminas\Form\Annotation as Form;

/**
* @Form\Name("main")
*/
class CloseConversationText
{
/**
* @Form\Type(\Common\Form\Elements\Types\PlainText::class)
* @Form\Attributes({
* "value": "The conversation will be removed from the Inbox and a transcript will be archived in docs and attachments tab."
* })
*/
public ?PlainText $text = null;
}
Loading
Loading