Skip to content

Commit

Permalink
fix(core/tasks): fix deep linking to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed May 12, 2017
1 parent cf6c38e commit 98206c8
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions app/scripts/modules/core/task/tasks.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = angular.module('spinnaker.core.task.controller', [
CONFIRMATION_MODAL_SERVICE,
DISPLAYABLE_TASKS_FILTER
])
.controller('TasksCtrl', function ($scope, $state, $q, app, viewStateCache, taskWriter, confirmationModalService) {
.controller('TasksCtrl', function ($scope, $state, $stateParams, $q, app, viewStateCache, taskWriter, confirmationModalService) {

if (app.notFound) {
return;
Expand Down Expand Up @@ -54,8 +54,19 @@ module.exports = angular.module('spinnaker.core.task.controller', [
viewState.itemsPerPage = tasksViewStateCache.get('#common') ? tasksViewStateCache.get('#common').itemsPerPage : 20;

$scope.viewState = viewState;
setTaskFilter();
}

const setTaskFilter = () => {
const taskId = $stateParams.taskId;
if (!$scope.viewState.expandedTasks.includes(taskId)) {
controller.toggleDetails(taskId);
}
$scope.viewState.nameFilter = taskId;
$scope.viewState.taskStateFilter = '';
controller.sortTasksAndResetPaginator();
};

controller.taskStateFilter = 'All';
controller.application = application;

Expand Down Expand Up @@ -242,19 +253,6 @@ module.exports = angular.module('spinnaker.core.task.controller', [
$scope.$watch('viewState.taskStateFilter', controller.sortTasksAndResetPaginator);
$scope.$watch('viewState', cacheViewState, true);

// The taskId will not be available in the $stateParams that would be passed into this controller
// because that field belongs to a child state. So we have to watch for a $stateChangeSuccess event, then set
// the value on the scope
$scope.$on('$stateChangeSuccess', function(event, toState, toParams) {
var taskId = toParams.taskId;
if (!$scope.viewState.expandedTasks.includes(taskId)) {
controller.toggleDetails(taskId);
}
$scope.viewState.nameFilter = taskId;
$scope.viewState.taskStateFilter = '';
controller.sortTasksAndResetPaginator();
});

initializeViewState();

application.tasks.activate();
Expand Down

0 comments on commit 98206c8

Please sign in to comment.