-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concept for simplifying get & watch in builds controller #133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,6 @@ angular.module('openshiftConsole') | |
$scope.selectedTab[$routeParams.tab] = true; | ||
} | ||
|
||
var buildConfigForBuild = $filter('buildConfigForBuild'); | ||
|
||
var watches = []; | ||
|
||
var setLogVars = function(build) { | ||
|
@@ -59,6 +57,44 @@ angular.module('openshiftConsole') | |
} | ||
}; | ||
|
||
var buildResolved = function(build, action) { | ||
$scope.loaded = true; | ||
$scope.build = build; | ||
setLogVars(build); | ||
var buildNumber = $filter("annotation")(build, "buildNumber"); | ||
if (buildNumber) { | ||
$scope.breadcrumbs[2].title = "#" + buildNumber; | ||
} | ||
if (action === "DELETED") { | ||
$scope.alerts["deleted"] = { | ||
type: "warning", | ||
message: "This build has been deleted." | ||
}; | ||
} | ||
}; | ||
|
||
var buildRejected = function(e) { | ||
$scope.loaded = true; | ||
$scope.alerts["load"] = { | ||
type: "error", | ||
message: "The build details could not be loaded.", | ||
details: "Reason: " + $filter('getErrorDetails')(e) | ||
}; | ||
}; | ||
|
||
var buildConfigResolved = function(buildConfig, action) { | ||
if (action === "DELETED") { | ||
$scope.alerts["deleted"] = { | ||
type: "warning", | ||
message: "Build configuration " + $scope.buildConfigName + " has been deleted." | ||
}; | ||
} | ||
$scope.buildConfig = buildConfig; | ||
$scope.paused = BuildsService.isPaused($scope.buildConfig); | ||
updateCanBuild(); | ||
}; | ||
|
||
|
||
ProjectsService | ||
.get($routeParams.project) | ||
.then(_.spread(function(project, context) { | ||
|
@@ -69,84 +105,13 @@ angular.module('openshiftConsole') | |
// context into the log-viewer directive. | ||
$scope.projectContext = context; | ||
$scope.logOptions = {}; | ||
DataService.get("builds", $routeParams.build, context).then( | ||
// success | ||
function(build) { | ||
|
||
$scope.loaded = true; | ||
$scope.build = build; | ||
setLogVars(build); | ||
var buildNumber = $filter("annotation")(build, "buildNumber"); | ||
if (buildNumber) { | ||
$scope.breadcrumbs[2].title = "#" + buildNumber; | ||
} | ||
|
||
// If we found the item successfully, watch for changes on it | ||
watches.push(DataService.watchObject("builds", $routeParams.build, context, function(build, action) { | ||
if (action === "DELETED") { | ||
$scope.alerts["deleted"] = { | ||
type: "warning", | ||
message: "This build has been deleted." | ||
}; | ||
} | ||
$scope.build = build; | ||
setLogVars(build); | ||
})); | ||
watches.push(DataService.watchObject("buildconfigs", $routeParams.buildconfig, context, function(buildConfig, action) { | ||
if (action === "DELETED") { | ||
$scope.alerts["deleted"] = { | ||
type: "warning", | ||
message: "Build configuration " + $scope.buildConfigName + " has been deleted." | ||
}; | ||
} | ||
$scope.buildConfig = buildConfig; | ||
$scope.paused = BuildsService.isPaused($scope.buildConfig); | ||
updateCanBuild(); | ||
})); | ||
}, | ||
// failure | ||
function(e) { | ||
$scope.loaded = true; | ||
$scope.alerts["load"] = { | ||
type: "error", | ||
message: "The build details could not be loaded.", | ||
details: "Reason: " + $filter('getErrorDetails')(e) | ||
}; | ||
} | ||
); | ||
|
||
watches.push(DataService.watch("builds", context, function(builds, action, build) { | ||
if (!action) { | ||
$scope.builds = BuildsService.validatedBuildsForBuildConfig($routeParams.buildconfig, builds.by('metadata.name')); | ||
} else { | ||
var buildConfigName = buildConfigForBuild(build); | ||
if (buildConfigName === $routeParams.buildconfig) { | ||
var buildName = build.metadata.name; | ||
switch (action) { | ||
case 'ADDED': | ||
case 'MODIFIED': | ||
$scope.builds[buildName] = build; | ||
break; | ||
case 'DELETED': | ||
delete $scope.builds[buildName]; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
updateCanBuild(); | ||
}, | ||
// params object for filtering | ||
{ | ||
// http is passed to underlying $http calls | ||
http: { | ||
params: { | ||
// because build config names can be > 63 chars but label values can't | ||
// and we can't do a fieldSelector on annotations. Plus old builds dont have the annotation. | ||
labelSelector: $filter('labelName')('buildConfig') + '=' + _.trunc($routeParams.buildconfig, {length: 63, omission: ''}) | ||
} | ||
} | ||
})); | ||
DataService | ||
.get("builds", $routeParams.build, context) | ||
.then(function(build) { | ||
buildResolved(build); | ||
watches.push(DataService.watchObject("builds", $routeParams.build, context, buildResolved)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now that we've plumbed the labelSelector / fieldSelector stuff, we should probably update the watchObject in DataService to tack on the fieldSelector for the name of the object so we aren't pulling a bunch of data we don't need, doesn't need to be done in this PR, just thinking out loud :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah definitely! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll create an issue for tracking that. |
||
watches.push(DataService.watchObject("buildconfigs", $routeParams.buildconfig, context, buildConfigResolved)); | ||
}, buildRejected); | ||
|
||
$scope.toggleSecret = function() { | ||
$scope.showSecret = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above eliminates the most duplication. I pulled the rest of these out for consistency only.