Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 24 additions & 8 deletions src/app/units/states/tasks/definition/definition.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
angular.module('doubtfire.units.states.tasks.definition', [
])
angular.module('doubtfire.units.states.tasks.definition', [])

#
# Mark tasks by task definition ID
Expand All @@ -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
)
)
5 changes: 5 additions & 0 deletions src/app/units/states/tasks/definition/definition.tpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- units/states/tasks/definition/definition.tpl.html -->
<div class="task-definition-view">
<!-- Reuse the Inbox UI, but keep definition state owning its own template -->
<div ng-include="'units/states/tasks/inbox/inbox.tpl.html'"></div>
</div>