diff --git a/module/Olcs/config/module.config.php b/module/Olcs/config/module.config.php index 653757f1fc..c9935cff7a 100644 --- a/module/Olcs/config/module.config.php +++ b/module/Olcs/config/module.config.php @@ -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, diff --git a/module/Olcs/config/routes.config.php b/module/Olcs/config/routes.config.php index b3a0389a98..ebbec22b67 100644 --- a/module/Olcs/config/routes.config.php +++ b/module/Olcs/config/routes.config.php @@ -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' => [ diff --git a/module/Olcs/src/Controller/Factory/Messages/LicenceCloseConversationControllerFactory.php b/module/Olcs/src/Controller/Factory/Messages/LicenceCloseConversationControllerFactory.php new file mode 100644 index 0000000000..fe00eb7e69 --- /dev/null +++ b/module/Olcs/src/Controller/Factory/Messages/LicenceCloseConversationControllerFactory.php @@ -0,0 +1,54 @@ +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); + } +} diff --git a/module/Olcs/src/Controller/Factory/Messages/LicenceConversationMessagesControllerFactory.php b/module/Olcs/src/Controller/Factory/Messages/LicenceConversationMessagesControllerFactory.php index 2fa87676f6..ed944171de 100644 --- a/module/Olcs/src/Controller/Factory/Messages/LicenceConversationMessagesControllerFactory.php +++ b/module/Olcs/src/Controller/Factory/Messages/LicenceConversationMessagesControllerFactory.php @@ -17,20 +17,18 @@ 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'); @@ -38,7 +36,8 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $translationHelper, $formHelper, $flashMessenger, - $navigation + $navigation, + $scriptsFactory ); } diff --git a/module/Olcs/src/Controller/Messages/LicenceCloseConversationController.php b/module/Olcs/src/Controller/Messages/LicenceCloseConversationController.php new file mode 100644 index 0000000000..5060a5eb84 --- /dev/null +++ b/module/Olcs/src/Controller/Messages/LicenceCloseConversationController.php @@ -0,0 +1,73 @@ + [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'); + } +} diff --git a/module/Olcs/src/Controller/Messages/LicenceConversationMessagesController.php b/module/Olcs/src/Controller/Messages/LicenceConversationMessagesController.php index 04b2e65ba3..ec4bccb0f1 100644 --- a/module/Olcs/src/Controller/Messages/LicenceConversationMessagesController.php +++ b/module/Olcs/src/Controller/Messages/LicenceConversationMessagesController.php @@ -2,6 +2,12 @@ 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; @@ -9,11 +15,12 @@ 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'; @@ -22,13 +29,63 @@ 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'); @@ -36,16 +93,11 @@ public function getLeftView() 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; } -} \ No newline at end of file +} diff --git a/module/Olcs/src/Form/Model/Fieldset/CloseConversationActions.php b/module/Olcs/src/Form/Model/Fieldset/CloseConversationActions.php new file mode 100644 index 0000000000..815d2dcac4 --- /dev/null +++ b/module/Olcs/src/Form/Model/Fieldset/CloseConversationActions.php @@ -0,0 +1,43 @@ + 'There are no message records linked to this conversation to display' ], 'settings' => [ + 'crud' => [ + 'actions' => [ + 'end and archive conversation' => [ + 'requireRows' => true, + 'class' => 'govuk-button govuk-button--warning', + 'label' => 'End and Archive Conversation', + ], + ], + ], 'paginate' => [ 'limit' => [ 'options' => [10, 25, 50],