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

feat: Task Allocation Rules sub category support #119

Merged
merged 7 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
OLCS.ready(function() {
"use strict";

OLCS.cascadeInput({
source: "#category",
dest: "#subCategory",
url: "/list/task-sub-categories",
emptyLabel: "Not applicable"
});
});
2 changes: 1 addition & 1 deletion module/Admin/assets/js/inline/forms/task-alpha-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 31 additions & 13 deletions module/Admin/src/Controller/TaskAllocationRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,11 +32,18 @@
* @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';
Expand Down Expand Up @@ -90,18 +98,22 @@
];

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);
}
/**
Expand Down Expand Up @@ -168,12 +180,18 @@
*/
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;

Expand All @@ -190,9 +208,9 @@
/**
* Alter the Task allocation rule form when adding
*
* @param Form $form Form

Check failure on line 211 in module/Admin/src/Controller/TaskAllocationRulesController.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedDocblockClass

module/Admin/src/Controller/TaskAllocationRulesController.php:211:15: UndefinedDocblockClass: Docblock-defined class, interface or enum named Admin\Controller\Form does not exist (see https://psalm.dev/200)
*
* @return Form

Check failure on line 213 in module/Admin/src/Controller/TaskAllocationRulesController.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedDocblockClass

module/Admin/src/Controller/TaskAllocationRulesController.php:213:16: UndefinedDocblockClass: Docblock-defined class, interface or enum named Admin\Controller\Form does not exist (see https://psalm.dev/200)
*/
protected function alterFormForAdd($form)
{
Expand Down Expand Up @@ -273,9 +291,9 @@
/**
* Alter form for add alpha split
*
* @param Form $form Form

Check failure on line 294 in module/Admin/src/Controller/TaskAllocationRulesController.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedDocblockClass

module/Admin/src/Controller/TaskAllocationRulesController.php:294:15: UndefinedDocblockClass: Docblock-defined class, interface or enum named Admin\Controller\Form does not exist (see https://psalm.dev/200)
*
* @return Form

Check failure on line 296 in module/Admin/src/Controller/TaskAllocationRulesController.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedDocblockClass

module/Admin/src/Controller/TaskAllocationRulesController.php:296:16: UndefinedDocblockClass: Docblock-defined class, interface or enum named Admin\Controller\Form does not exist (see https://psalm.dev/200)
*/
protected function alterFormForAddAlphasplit($form)
{
Expand All @@ -288,7 +306,7 @@
/**
* Alter form for add alpha split
*
* @param Form $form Form

Check failure on line 309 in module/Admin/src/Controller/TaskAllocationRulesController.php

View workflow job for this annotation

GitHub Actions / static-analysis / Psalm - 7.4

UndefinedDocblockClass

module/Admin/src/Controller/TaskAllocationRulesController.php:309:15: UndefinedDocblockClass: Docblock-defined class, interface or enum named Admin\Controller\Form does not exist (see https://psalm.dev/200)
*
* @return Form
*/
Expand All @@ -312,7 +330,7 @@
{
$teamId = $this->params()->fromRoute('team');
if ((int)$teamId) {
$this->userListInternal->setTeamId($teamId);
$this->userListInternalDataService->setTeamId($teamId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}
16 changes: 16 additions & 0 deletions module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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": ""})
Expand Down
6 changes: 6 additions & 0 deletions module/Admin/src/Table/Tables/task-allocation-rules.table.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
return '<a class="govuk-link" href="'. $url . '">' . $row['category']['description'] .'</a>';
}
],
[
'title' => 'Sub Category',
'formatter' => function ($row) {
return $row['subCategory']['subCategoryName'] ?? 'Not applicable';
}
jerotire marked this conversation as resolved.
Show resolved Hide resolved
],
[
'title' => 'Criteria',
'formatter' => TaskAllocationCriteria::class,
Expand Down
2 changes: 2 additions & 0 deletions module/Olcs/src/Data/Mapper/TaskAllocationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand Down
15 changes: 10 additions & 5 deletions test/Olcs/src/Data/Mapper/TaskAllocationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Olcs\Data\Mapper\TaskAllocationRule as Sut;

/**
* TaskAllocationRuleTest
*
* @author Mat Evans <[email protected]>
*/
class TaskAllocationRuleTest extends MockeryTestCase
{
public function testMapFromResult()
Expand All @@ -18,6 +13,7 @@ public function testMapFromResult()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => ['id' => 'GOODS'],
'isMlh' => '',
'trafficArea' => 'TA',
Expand All @@ -29,6 +25,7 @@ public function testMapFromResult()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'GOODS',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -46,6 +43,7 @@ public function testMapFromResultAlphaSplit()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => ['id' => 'GOODS'],
'isMlh' => '',
'trafficArea' => 'TA',
Expand All @@ -58,6 +56,7 @@ public function testMapFromResultAlphaSplit()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'GOODS',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -83,6 +82,7 @@ public function testMapFromForm()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'lcat_gv',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -95,6 +95,7 @@ public function testMapFromForm()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'lcat_gv',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -111,6 +112,7 @@ public function testMapFromFormWithTeamId()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'na',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -123,6 +125,7 @@ public function testMapFromFormWithTeamId()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => null,
'isMlh' => null,
'trafficArea' => 'TA',
Expand All @@ -139,6 +142,7 @@ public function testMapFromFormWithAlphaSplit()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'lcat_gv',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand All @@ -151,6 +155,7 @@ public function testMapFromFormWithAlphaSplit()
'id' => 1404,
'version' => 33,
'category' => 'CAT',
'subCategory' => 'SUBCAT',
'goodsOrPsv' => 'lcat_gv',
'isMlh' => 'N',
'trafficArea' => 'TA',
Expand Down
Loading