From 42783e3a9525b06056e75a3ae3154f5d50a64a8d Mon Sep 17 00:00:00 2001 From: Rajani Ishika Date: Sun, 18 Jan 2026 16:32:27 +1100 Subject: [PATCH 1/2] Refactor task definition view --- .../states/tasks/definition/definition.coffee | 32 ++++++++++++++----- .../tasks/definition/definition.tpl.html | 5 +++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/app/units/states/tasks/definition/definition.tpl.html diff --git a/src/app/units/states/tasks/definition/definition.coffee b/src/app/units/states/tasks/definition/definition.coffee index bd0bad8241..26c5f28a18 100644 --- a/src/app/units/states/tasks/definition/definition.coffee +++ b/src/app/units/states/tasks/definition/definition.coffee @@ -1,5 +1,4 @@ -angular.module('doubtfire.units.states.tasks.definition', [ -]) +angular.module('doubtfire.units.states.tasks.definition', []) # # Mark tasks by task definition ID @@ -8,23 +7,40 @@ angular.module('doubtfire.units.states.tasks.definition', [ $stateProvider.state 'units/tasks/definition', { parent: 'units/tasks' url: '/definition/{taskKey:any}' - # We can recycle the task inbox, switching the data source scope variable - templateUrl: "units/states/tasks/inbox/inbox.tpl.html" + + # Use a dedicated template for definition state (still reuses inbox internally) + templateUrl: "units/states/tasks/definition/definition.tpl.html" controller: "TaskDefinitionStateCtrl" + params: taskKey: dynamic: true + data: task: "Task Explorer" pageTitle: "_Home_" roleWhitelist: ['Tutor', 'Convenor', 'Admin', 'Auditor'] - } + } ) .controller('TaskDefinitionStateCtrl', ($scope, newTaskService) -> + + # Ensure taskData exists (prevents "Cannot set property 'source' of undefined") + $scope.taskData ?= {} + + # Reuse the inbox controller behaviour by swapping the data source $scope.taskData.source = newTaskService.queryTasksForTaskExplorer.bind(newTaskService) $scope.taskData.taskDefMode = true + + # Show inbox search UI options on the Task Explorer view $scope.showSearchOptions = true - $scope.filters = { - taskDefinitionIdSelected: _.first($scope.unit.taskDefinitions)?.id - } + + # Initialise filters safely (handles unit/taskDefinitions loading later) + $scope.filters ?= {} + $scope.filters.taskDefinitionIdSelected ?= _.first($scope.unit?.taskDefinitions)?.id + + # If taskDefinitions load after controller init, set a default once + $scope.$watch('unit.taskDefinitions', (defs) -> + return unless defs? and defs.length > 0 + $scope.filters.taskDefinitionIdSelected ?= defs[0].id + ) ) diff --git a/src/app/units/states/tasks/definition/definition.tpl.html b/src/app/units/states/tasks/definition/definition.tpl.html new file mode 100644 index 0000000000..3f2be8d061 --- /dev/null +++ b/src/app/units/states/tasks/definition/definition.tpl.html @@ -0,0 +1,5 @@ + +
+ +
+
From b228d495b1b4b8482abc429405179cc4005a7ce9 Mon Sep 17 00:00:00 2001 From: Rajani Ishika Date: Tue, 20 Jan 2026 17:51:56 +1100 Subject: [PATCH 2/2] Remove extra file and modify the old one --- .../states/tasks/definition/definition.coffee | 23 +++++++++++-------- .../tasks/definition/definition.tpl.html | 5 ---- 2 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 src/app/units/states/tasks/definition/definition.tpl.html diff --git a/src/app/units/states/tasks/definition/definition.coffee b/src/app/units/states/tasks/definition/definition.coffee index 26c5f28a18..108f82068f 100644 --- a/src/app/units/states/tasks/definition/definition.coffee +++ b/src/app/units/states/tasks/definition/definition.coffee @@ -8,8 +8,8 @@ angular.module('doubtfire.units.states.tasks.definition', []) parent: 'units/tasks' url: '/definition/{taskKey:any}' - # Use a dedicated template for definition state (still reuses inbox internally) - templateUrl: "units/states/tasks/definition/definition.tpl.html" + # Reuse the inbox UI directly (controller handles definition-specific behaviour) + templateUrl: "units/states/tasks/inbox/inbox.tpl.html" controller: "TaskDefinitionStateCtrl" params: @@ -27,20 +27,25 @@ angular.module('doubtfire.units.states.tasks.definition', []) # Ensure taskData exists (prevents "Cannot set property 'source' of undefined") $scope.taskData ?= {} - # Reuse the inbox controller behaviour by swapping the data source + # Swap the data source to definition-based query, while reusing inbox UI $scope.taskData.source = newTaskService.queryTasksForTaskExplorer.bind(newTaskService) $scope.taskData.taskDefMode = true # Show inbox search UI options on the Task Explorer view $scope.showSearchOptions = true - # Initialise filters safely (handles unit/taskDefinitions loading later) + # Ensure filters exists (safe when navigating directly before unit loads) $scope.filters ?= {} - $scope.filters.taskDefinitionIdSelected ?= _.first($scope.unit?.taskDefinitions)?.id - # If taskDefinitions load after controller init, set a default once - $scope.$watch('unit.taskDefinitions', (defs) -> + setDefaultDefId = (defs) -> + return if $scope.filters.taskDefinitionIdSelected? return unless defs? and defs.length > 0 - $scope.filters.taskDefinitionIdSelected ?= defs[0].id - ) + $scope.filters.taskDefinitionIdSelected = defs[0].id + + # If already loaded + setDefaultDefId($scope.unit?.taskDefinitions) + + # If loaded later + $scope.$watch 'unit.taskDefinitions', (defs) -> + setDefaultDefId(defs) ) diff --git a/src/app/units/states/tasks/definition/definition.tpl.html b/src/app/units/states/tasks/definition/definition.tpl.html deleted file mode 100644 index 3f2be8d061..0000000000 --- a/src/app/units/states/tasks/definition/definition.tpl.html +++ /dev/null @@ -1,5 +0,0 @@ - -
- -
-