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

Commit

Permalink
feat: Task Allocation Rules sub category support (#119)
Browse files Browse the repository at this point in the history
* feat: Task Allocation Rules sub category support

* fix: unit tests

* fix: undone changes to file

* fix: refactor

* fix: refactor
  • Loading branch information
jerotire authored Mar 18, 2024
1 parent 5ca930a commit 468f7fd
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 20 deletions.
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 @@ 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';
Expand Down Expand Up @@ -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);
}
/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -312,7 +330,7 @@ protected function setUpUserList()
{
$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
);
}
}
28 changes: 28 additions & 0 deletions module/Admin/src/Form/Model/Fieldset/TaskAllocationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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": ""})
Expand Down Expand Up @@ -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")
*/
Expand Down
4 changes: 4 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,10 @@
return '<a class="govuk-link" href="'. $url . '">' . $row['category']['description'] .'</a>';
}
],
[
'title' => 'Sub Category',
'formatter' => fn($row) => $row['subCategory']['subCategoryName'] ?? 'N/A'
],
[
'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

0 comments on commit 468f7fd

Please sign in to comment.