Skip to content
Open
Changes from all 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
35 changes: 28 additions & 7 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,45 @@ 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

# Reuse the inbox UI directly (controller handles definition-specific behaviour)
templateUrl: "units/states/tasks/inbox/inbox.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 ?= {}

# 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
$scope.filters = {
taskDefinitionIdSelected: _.first($scope.unit.taskDefinitions)?.id
}

# Ensure filters exists (safe when navigating directly before unit loads)
$scope.filters ?= {}

setDefaultDefId = (defs) ->
return if $scope.filters.taskDefinitionIdSelected?
return unless defs? and defs.length > 0
$scope.filters.taskDefinitionIdSelected = defs[0].id

# If already loaded
setDefaultDefId($scope.unit?.taskDefinitions)

# If loaded later
$scope.$watch 'unit.taskDefinitions', (defs) ->
setDefaultDefId(defs)
)