diff --git a/module/Admin/assets/js/inline/forms/selected-category-subcategory-filtering.js b/module/Admin/assets/js/inline/forms/selected-category-subcategory-filtering.js new file mode 100644 index 0000000000..22756f96b2 --- /dev/null +++ b/module/Admin/assets/js/inline/forms/selected-category-subcategory-filtering.js @@ -0,0 +1,10 @@ +OLCS.ready(function() { + "use strict"; + + OLCS.cascadeInput({ + source: "#category", + dest: "#subCategory", + url: "/list/task-sub-categories", + emptyLabel: "Not applicable" + }); +}); diff --git a/module/Admin/assets/js/inline/forms/task-alpha-split.js b/module/Admin/assets/js/inline/forms/task-alpha-split.js index dca224e2d8..4ab6a86777 100644 --- a/module/Admin/assets/js/inline/forms/task-alpha-split.js +++ b/module/Admin/assets/js/inline/forms/task-alpha-split.js @@ -14,7 +14,7 @@ OLCS.ready(function() { // if not ID then adding, therefore remove alpha-split option $(this).find('option[value="alpha-split"]').remove() } - }) + }); OLCS.cascadeForm({ cascade: false, diff --git a/module/Admin/src/Controller/TaskAllocationRulesController.php b/module/Admin/src/Controller/TaskAllocationRulesController.php index bdd61abd3b..36768ca1b0 100644 --- a/module/Admin/src/Controller/TaskAllocationRulesController.php +++ b/module/Admin/src/Controller/TaskAllocationRulesController.php @@ -16,6 +16,7 @@ use Laminas\Navigation\Navigation; use Olcs\Controller\AbstractInternalController; use Olcs\Data\Mapper\TaskAllocationRule as Mapper; +use Olcs\Service\Data\SubCategory; use Olcs\Service\Data\UserListInternal; class TaskAllocationRulesController extends AbstractInternalController @@ -31,11 +32,18 @@ class TaskAllocationRulesController extends AbstractInternalController * @var array */ protected $inlineScripts = [ - 'editAction' => ['table-actions', 'forms/task-alpha-split'], - 'addAction' => ['table-actions', 'forms/task-alpha-split'], + 'editAction' => [ + 'table-actions', + 'forms/task-alpha-split', + 'forms/selected-category-subcategory-filtering', + ], + 'addAction' => [ + 'table-actions', + 'forms/task-alpha-split', + 'forms/selected-category-subcategory-filtering', + ], ]; - // list protected $tableName = 'task-allocation-rules'; protected $defaultTableSortField = 'categoryDescription,criteria,trafficAreaName'; @@ -90,18 +98,22 @@ class TaskAllocationRulesController extends AbstractInternalController ]; protected TableFactory $tableFactory; - protected UserListInternal $userListInternal; + protected UserListInternal $userListInternalDataService; + + protected SubCategory $subCategoryDataService; public function __construct( - TranslationHelperService $translationHelperService, - FormHelperService $formHelper, + TranslationHelperService $translationHelperService, + FormHelperService $formHelper, FlashMessengerHelperService $flashMessengerHelperService, - Navigation $navigation, - TableFactory $tableFactory, - UserListInternal $userListInternal + Navigation $navigation, + TableFactory $tableFactory, + UserListInternal $userListInternalDataService, + SubCategory $subCategoryDataService ) { $this->tableFactory = $tableFactory; - $this->userListInternal = $userListInternal; + $this->userListInternalDataService = $userListInternalDataService; + $this->subCategoryDataService = $subCategoryDataService; parent::__construct($translationHelperService, $formHelper, $flashMessengerHelperService, $navigation); } /** @@ -168,12 +180,18 @@ protected function getAlphaSplitTable() */ public function alterFormForEdit(\Common\Form\Form $form, $formData) { - // Setup the initial list of users in the dropdown dependant on the team + // Setup initial user list based on current team if (isset($formData['details']['team']['id'])) { - $this->userListInternal + $this->userListInternalDataService ->setTeamId($formData['details']['team']['id']); } + // Setup initial sub-categories filter based on current category + if (isset($formData['details']['category']['id'])) { + $this->subCategoryDataService + ->setCategory($formData['details']['category']['id']); + } + /* @var $formHelper \Common\Service\Helper\FormHelperService */ $formHelper = $this->formHelperService; @@ -312,7 +330,7 @@ protected function setUpUserList() { $teamId = $this->params()->fromRoute('team'); if ((int)$teamId) { - $this->userListInternal->setTeamId($teamId); + $this->userListInternalDataService->setTeamId($teamId); } } diff --git a/module/Admin/src/Controller/TaskAllocationRulesControllerFactory.php b/module/Admin/src/Controller/TaskAllocationRulesControllerFactory.php index f695409a8d..4fc04c05d3 100644 --- a/module/Admin/src/Controller/TaskAllocationRulesControllerFactory.php +++ b/module/Admin/src/Controller/TaskAllocationRulesControllerFactory.php @@ -7,6 +7,7 @@ use Common\Service\Helper\FormHelperService; use Common\Service\Helper\TranslationHelperService; use Common\Service\Table\TableFactory; +use Olcs\Service\Data\SubCategory; use Psr\Container\ContainerInterface; use Laminas\Navigation\Navigation; use Laminas\ServiceManager\Factory\FactoryInterface; @@ -34,13 +35,16 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $userListInternal = $container->get(PluginManager::class)->get(UserListInternal::class); assert($userListInternal instanceof UserListInternal); + $subCategory = $container->get(PluginManager::class)->get(SubCategory::class); + return new TaskAllocationRulesController( $translationHelper, $formHelperService, $flashMessenger, $navigation, $tableFactory, - $userListInternal + $userListInternal, + $subCategory ); } } diff --git a/module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php b/module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php index 485dbe0d19..8502df9cf6 100644 --- a/module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php +++ b/module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php @@ -16,6 +16,12 @@ class TaskAllocationRule use VersionTrait, IdTrait; + /** + * @Form\Attributes({"value": "Criteria:"}) + * @Form\Type("Common\Form\Elements\Types\GuidanceTranslated") + */ + public $headingCriteria = null; + /** * @Form\Attributes({"id":"category","placeholder":""}) * @Form\Options({ @@ -32,6 +38,22 @@ class TaskAllocationRule */ public $category = null; + /** + * @Form\Attributes({"id":"subCategory","placeholder":""}) + * @Form\Options({ + * "short-label": "Sub category", + * "label": "Sub category", + * "service_name": "Olcs\Service\Data\SubCategory", + * "context": { + * "isTaskCategory": "Y" + * }, + * "empty_option": "Not applicable" + * }) + * @Form\Required(false) + * @Form\Type("DynamicSelect") + */ + public $subCategory = null; + /** * @Form\Name("goodsOrPsv") * @Form\Attributes({"id": ""}) @@ -88,6 +110,12 @@ class TaskAllocationRule */ public $trafficArea = null; + /** + * @Form\Attributes({"value": "Assign to:"}) + * @Form\Type("Common\Form\Elements\Types\GuidanceTranslated") + */ + public $headingAssignTo = null; + /** * @Form\Type("Hidden") */ diff --git a/module/Admin/src/Table/Tables/task-allocation-rules.table.php b/module/Admin/src/Table/Tables/task-allocation-rules.table.php index 974c161285..58f005a76a 100644 --- a/module/Admin/src/Table/Tables/task-allocation-rules.table.php +++ b/module/Admin/src/Table/Tables/task-allocation-rules.table.php @@ -32,6 +32,10 @@ return '' . $row['category']['description'] .''; } ], + [ + 'title' => 'Sub Category', + 'formatter' => fn($row) => $row['subCategory']['subCategoryName'] ?? 'N/A' + ], [ 'title' => 'Criteria', 'formatter' => TaskAllocationCriteria::class, diff --git a/module/Olcs/src/Data/Mapper/TaskAllocationRule.php b/module/Olcs/src/Data/Mapper/TaskAllocationRule.php index fbacab31ac..ddae355ccd 100644 --- a/module/Olcs/src/Data/Mapper/TaskAllocationRule.php +++ b/module/Olcs/src/Data/Mapper/TaskAllocationRule.php @@ -35,6 +35,7 @@ public static function mapFromResult(array $data) 'id' => $data['id'], 'version' => $data['version'], 'category' => $data['category'], + 'subCategory' => $data['subCategory'], 'goodsOrPsv' => $data['goodsOrPsv']['id'] ?? 'na', 'isMlh' => $data['isMlh'] ? 'Y' : 'N', 'trafficArea' => $data['trafficArea'], @@ -60,6 +61,7 @@ public static function mapFromForm(array $formData) 'id' => $details['id'], 'version' => $details['version'], 'category' => $details['category'], + 'subCategory' => $details['subCategory'], 'goodsOrPsv' => $details['goodsOrPsv'], 'trafficArea' => $details['trafficArea'], 'team' => $details['team'], diff --git a/test/Olcs/src/Data/Mapper/TaskAllocationRuleTest.php b/test/Olcs/src/Data/Mapper/TaskAllocationRuleTest.php index 86c7724955..d81dc4af4c 100644 --- a/test/Olcs/src/Data/Mapper/TaskAllocationRuleTest.php +++ b/test/Olcs/src/Data/Mapper/TaskAllocationRuleTest.php @@ -5,11 +5,6 @@ use Mockery\Adapter\Phpunit\MockeryTestCase; use Olcs\Data\Mapper\TaskAllocationRule as Sut; -/** - * TaskAllocationRuleTest - * - * @author Mat Evans - */ class TaskAllocationRuleTest extends MockeryTestCase { public function testMapFromResult() @@ -18,6 +13,7 @@ public function testMapFromResult() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => ['id' => 'GOODS'], 'isMlh' => '', 'trafficArea' => 'TA', @@ -29,6 +25,7 @@ public function testMapFromResult() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'GOODS', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -46,6 +43,7 @@ public function testMapFromResultAlphaSplit() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => ['id' => 'GOODS'], 'isMlh' => '', 'trafficArea' => 'TA', @@ -58,6 +56,7 @@ public function testMapFromResultAlphaSplit() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'GOODS', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -83,6 +82,7 @@ public function testMapFromForm() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'lcat_gv', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -95,6 +95,7 @@ public function testMapFromForm() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'lcat_gv', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -111,6 +112,7 @@ public function testMapFromFormWithTeamId() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'na', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -123,6 +125,7 @@ public function testMapFromFormWithTeamId() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => null, 'isMlh' => null, 'trafficArea' => 'TA', @@ -139,6 +142,7 @@ public function testMapFromFormWithAlphaSplit() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'lcat_gv', 'isMlh' => 'N', 'trafficArea' => 'TA', @@ -151,6 +155,7 @@ public function testMapFromFormWithAlphaSplit() 'id' => 1404, 'version' => 33, 'category' => 'CAT', + 'subCategory' => 'SUBCAT', 'goodsOrPsv' => 'lcat_gv', 'isMlh' => 'N', 'trafficArea' => 'TA',