Skip to content

Commit

Permalink
Merge pull request openshift#8676 from benjaminapetersen/bpeterse/tre…
Browse files Browse the repository at this point in the history
…llo-data-selector-updates

Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed May 5, 2016
2 parents a3cacac + 2841719 commit 3bfe625
Show file tree
Hide file tree
Showing 5 changed files with 671 additions and 588 deletions.
106 changes: 58 additions & 48 deletions assets/app/scripts/controllers/buildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ angular.module('openshiftConsole')
editor.$blockScrolling = Infinity;
};

var orderByDate = $filter('orderObjectsByDate');

var updateCanBuild = function() {
if (!$scope.buildConfig || !$scope.buildConfigBuildsInProgress) {
$scope.canBuild = false;
Expand Down Expand Up @@ -79,6 +81,62 @@ angular.module('openshiftConsole')
$scope.paused = BuildsService.isPaused($scope.buildConfig);
updateCanBuild();
}));


watches.push(DataService.watch("builds", context, function(builds, action, build) {
$scope.emptyMessage = "No builds to show";
// TODO we should send the ?labelSelector=buildconfig=<name> on the API request
// to only load the buildconfig's builds, but this requires some DataService changes
if (!action) {
$scope.unfilteredBuilds = builds.by("metadata.name");

// Loading of the page that will create buildConfigBuildsInProgress structure, which will associate running build to his buildConfig.
$scope.buildConfigBuildsInProgress = BuildsService.associateRunningBuildToBuildConfig($scope.unfilteredBuilds);
} else if (build.metadata.labels && build.metadata.labels.buildconfig === $routeParams.buildconfig) {
var buildName = build.metadata.name;
var buildConfigName = $routeParams.buildconfig;
switch (action) {
case 'ADDED':
case 'MODIFIED':
$scope.unfilteredBuilds[buildName] = build;
// After the build ends remove him from the buildConfigBuildsInProgress structure.
if ($filter('isIncompleteBuild')(build)){
$scope.buildConfigBuildsInProgress[buildConfigName] = $scope.buildConfigBuildsInProgress[buildConfigName] || {};
$scope.buildConfigBuildsInProgress[buildConfigName][buildName] = build;
} else if ($scope.buildConfigBuildsInProgress[buildConfigName]) {
delete $scope.buildConfigBuildsInProgress[buildConfigName][buildName];
}
break;
case 'DELETED':
delete $scope.unfilteredBuilds[buildName];
if ($scope.buildConfigBuildsInProgress[buildConfigName]){
delete $scope.buildConfigBuildsInProgress[buildConfigName][buildName];
}
break;
}
}

$scope.builds = LabelFilter.getLabelSelector().select($scope.unfilteredBuilds);
updateCanBuild();
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredBuilds, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);

// Sort now to avoid sorting on every digest loop.
$scope.orderedBuilds = orderByDate($scope.builds, true);
$scope.latestBuild = $scope.orderedBuilds.length ? $scope.orderedBuilds[0] : null;
},
// params object for filtering
{
// http is passed to underlying $http calls
http: {
params: {
labelSelector: 'buildconfig='+$scope.buildConfigName
}
}
}));


},
// failure
function(e) {
Expand All @@ -91,56 +149,8 @@ angular.module('openshiftConsole')
}
);

var orderByDate = $filter('orderObjectsByDate');
watches.push(DataService.watch("builds", context, function(builds, action, build) {
$scope.emptyMessage = "No builds to show";
// TODO we should send the ?labelSelector=buildconfig=<name> on the API request
// to only load the buildconfig's builds, but this requires some DataService changes
if (!action) {
$scope.unfilteredBuilds = {};
var allBuilds = builds.by("metadata.name");
angular.forEach(allBuilds, function(build, name) {
if (build.metadata.labels && build.metadata.labels.buildconfig === $routeParams.buildconfig) {
$scope.unfilteredBuilds[name] = build;
}
});

// Loading of the page that will create buildConfigBuildsInProgress structure, which will associate running build to his buildConfig.
$scope.buildConfigBuildsInProgress = BuildsService.associateRunningBuildToBuildConfig($scope.unfilteredBuilds);
} else if (build.metadata.labels && build.metadata.labels.buildconfig === $routeParams.buildconfig) {
var buildName = build.metadata.name;
var buildConfigName = $routeParams.buildconfig;
switch (action) {
case 'ADDED':
case 'MODIFIED':
$scope.unfilteredBuilds[buildName] = build;
// After the build ends remove him from the buildConfigBuildsInProgress structure.
if ($filter('isIncompleteBuild')(build)){
$scope.buildConfigBuildsInProgress[buildConfigName] = $scope.buildConfigBuildsInProgress[buildConfigName] || {};
$scope.buildConfigBuildsInProgress[buildConfigName][buildName] = build;
} else if ($scope.buildConfigBuildsInProgress[buildConfigName]) {
delete $scope.buildConfigBuildsInProgress[buildConfigName][buildName];
}
break;
case 'DELETED':
delete $scope.unfilteredBuilds[buildName];
if ($scope.buildConfigBuildsInProgress[buildConfigName]){
delete $scope.buildConfigBuildsInProgress[buildConfigName][buildName];
}
break;
}
}

$scope.builds = LabelFilter.getLabelSelector().select($scope.unfilteredBuilds);
updateCanBuild();
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredBuilds, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);

// Sort now to avoid sorting on every digest loop.
$scope.orderedBuilds = orderByDate($scope.builds, true);
$scope.latestBuild = $scope.orderedBuilds.length ? $scope.orderedBuilds[0] : null;
}));

function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && $.isEmptyObject($scope.builds) && !$.isEmptyObject($scope.unfilteredBuilds)) {
Expand Down
103 changes: 59 additions & 44 deletions assets/app/scripts/controllers/deploymentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ angular.module('openshiftConsole')
ImageStreamResolver,
Navigate,
ProjectsService,
LabelFilter) {
LabelFilter,
labelNameFilter) {
$scope.projectName = $routeParams.project;
$scope.deploymentConfigName = $routeParams.deploymentconfig;
$scope.deploymentConfig = null;
Expand Down Expand Up @@ -100,6 +101,63 @@ angular.module('openshiftConsole')
updateHPAWarnings();
ImageStreamResolver.fetchReferencedImageStreamImages([deploymentConfig.spec.template], $scope.imagesByDockerReference, $scope.imageStreamImageRefByDockerReference, context);
}));


watches.push(DataService.watch("replicationcontrollers", context, function(deployments, action, deployment) {
// TODO we should add this back in and show the pod template on this page
// extractPodTemplates();
// ImageStreamResolver.fetchReferencedImageStreamImages($scope.podTemplates, $scope.imagesByDockerReference, $scope.imageStreamImageRefByDockerReference, $scope);
$scope.emptyMessage = "No deployments to show";
if (!action) {
var deploymentsByDeploymentConfig = DeploymentsService.associateDeploymentsToDeploymentConfig(deployments.by("metadata.name"));
$scope.unfilteredDeployments = deploymentsByDeploymentConfig[$routeParams.deploymentconfig] || {};
angular.forEach($scope.unfilteredDeployments, function(deployment) {
deployment.causes = $filter('deploymentCauses')(deployment);
});
// Loading of the page that will create deploymentConfigDeploymentsInProgress structure, which will associate running deployment to his deploymentConfig.
$scope.deploymentConfigDeploymentsInProgress = DeploymentsService.associateRunningDeploymentToDeploymentConfig(deploymentsByDeploymentConfig);
} else if (DeploymentsService.deploymentBelongsToConfig(deployment, $routeParams.deploymentconfig)) {
var deploymentName = deployment.metadata.name;
var deploymentConfigName = $routeParams.deploymentconfig;
switch (action) {
case 'ADDED':
case 'MODIFIED':
$scope.unfilteredDeployments[deploymentName] = deployment;
// When deployment is retried, associate him to his deploymentConfig and add him into deploymentConfigDeploymentsInProgress structure.
if ($filter('deploymentIsInProgress')(deployment)){
$scope.deploymentConfigDeploymentsInProgress[deploymentConfigName] = $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName] || {};
$scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName] = deployment;
} else if ($scope.deploymentConfigDeploymentsInProgress[deploymentConfigName]) { // After the deployment ends remove him from the deploymentConfigDeploymentsInProgress structure.
delete $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName];
}
deployment.causes = $filter('deploymentCauses')(deployment);
break;
case 'DELETED':
delete $scope.unfilteredDeployments[deploymentName];
if ($scope.deploymentConfigDeploymentsInProgress[deploymentConfigName]) {
delete $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName];
}
break;
}
}

$scope.deployments = LabelFilter.getLabelSelector().select($scope.unfilteredDeployments);
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredDeployments, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
},
// params object for filtering
{
// http is passed to underlying $http calls
http: {
params: {
labelSelector: labelNameFilter('deploymentConfig')+'='+ $scope.deploymentConfigName
}
}
}
));


},
// failure
function(e) {
Expand All @@ -126,50 +184,7 @@ angular.module('openshiftConsole')
updateHPAWarnings();
});

watches.push(DataService.watch("replicationcontrollers", context, function(deployments, action, deployment) {
// TODO we should add this back in and show the pod template on this page
// extractPodTemplates();
// ImageStreamResolver.fetchReferencedImageStreamImages($scope.podTemplates, $scope.imagesByDockerReference, $scope.imageStreamImageRefByDockerReference, $scope);
$scope.emptyMessage = "No deployments to show";

if (!action) {
var deploymentsByDeploymentConfig = DeploymentsService.associateDeploymentsToDeploymentConfig(deployments.by("metadata.name"));
$scope.unfilteredDeployments = deploymentsByDeploymentConfig[$routeParams.deploymentconfig] || {};
angular.forEach($scope.unfilteredDeployments, function(deployment) {
deployment.causes = $filter('deploymentCauses')(deployment);
});
// Loading of the page that will create deploymentConfigDeploymentsInProgress structure, which will associate running deployment to his deploymentConfig.
$scope.deploymentConfigDeploymentsInProgress = DeploymentsService.associateRunningDeploymentToDeploymentConfig(deploymentsByDeploymentConfig);
} else if (DeploymentsService.deploymentBelongsToConfig(deployment, $routeParams.deploymentconfig)) {
var deploymentName = deployment.metadata.name;
var deploymentConfigName = $routeParams.deploymentconfig;
switch (action) {
case 'ADDED':
case 'MODIFIED':
$scope.unfilteredDeployments[deploymentName] = deployment;
// When deployment is retried, associate him to his deploymentConfig and add him into deploymentConfigDeploymentsInProgress structure.
if ($filter('deploymentIsInProgress')(deployment)){
$scope.deploymentConfigDeploymentsInProgress[deploymentConfigName] = $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName] || {};
$scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName] = deployment;
} else if ($scope.deploymentConfigDeploymentsInProgress[deploymentConfigName]) { // After the deployment ends remove him from the deploymentConfigDeploymentsInProgress structure.
delete $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName];
}
deployment.causes = $filter('deploymentCauses')(deployment);
break;
case 'DELETED':
delete $scope.unfilteredDeployments[deploymentName];
if ($scope.deploymentConfigDeploymentsInProgress[deploymentConfigName]) {
delete $scope.deploymentConfigDeploymentsInProgress[deploymentConfigName][deploymentName];
}
break;
}
}

$scope.deployments = LabelFilter.getLabelSelector().select($scope.unfilteredDeployments);
updateFilterWarning();
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredDeployments, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
}));

watches.push(DataService.watch("imagestreams", context, function(imageStreams) {
$scope.imageStreams = imageStreams.by("metadata.name");
Expand Down
46 changes: 27 additions & 19 deletions assets/app/scripts/filters/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,36 @@ angular.module('openshiftConsole')
};
})
.filter('annotationName', function() {
return function(annotationKey) {
// This maps an annotation key to all known synonymous keys to insulate
// the referring code from key renames across API versions.
var annotationMap = {
"deploymentConfig": ["openshift.io/deployment-config.name"],
"deployment": ["openshift.io/deployment.name"],
"pod": ["openshift.io/deployer-pod.name"],
"deployerPodFor": ["openshift.io/deployer-pod-for.name"],
"deploymentStatus": ["openshift.io/deployment.phase"],
"deploymentStatusReason": ["openshift.io/deployment.status-reason"],
"deploymentCancelled": ["openshift.io/deployment.cancelled"],
"encodedDeploymentConfig": ["openshift.io/encoded-deployment-config"],
"deploymentVersion": ["openshift.io/deployment-config.latest-version"],
"displayName": ["openshift.io/display-name"],
"description": ["openshift.io/description"],
"buildNumber": ["openshift.io/build.number"],
"buildPod": ["openshift.io/build.pod-name"],
// This maps an annotation key to all known synonymous keys to insulate
// the referring code from key renames across API versions.
var annotationMap = {
"deploymentConfig": ["openshift.io/deployment-config.name"],
"deployment": ["openshift.io/deployment.name"],
"pod": ["openshift.io/deployer-pod.name"],
"deployerPodFor": ["openshift.io/deployer-pod-for.name"],
"deploymentStatus": ["openshift.io/deployment.phase"],
"deploymentStatusReason": ["openshift.io/deployment.status-reason"],
"deploymentCancelled": ["openshift.io/deployment.cancelled"],
"encodedDeploymentConfig": ["openshift.io/encoded-deployment-config"],
"deploymentVersion": ["openshift.io/deployment-config.latest-version"],
"displayName": ["openshift.io/display-name"],
"description": ["openshift.io/description"],
"buildNumber": ["openshift.io/build.number"],
"buildPod": ["openshift.io/build.pod-name"],
"jenkinsLogURL": ["openshift.io/jenkins-log-url"]
};
};
return function(annotationKey) {
return annotationMap[annotationKey] || null;
};
})
.filter('labelName', function() {
var labelMap = {
'deploymentConfig' : ["openshift.io/deployment-config.name"]
};
return function(labelKey) {
return labelMap[labelKey];
};
})
.filter('annotation', function(annotationNameFilter) {
return function(resource, key) {
if (resource && resource.metadata && resource.metadata.annotations) {
Expand Down Expand Up @@ -857,7 +865,7 @@ angular.module('openshiftConsole')
})
.filter('kindToResource', function (APIService) {
return APIService.kindToResource;
})
})
.filter('humanizeQuotaResource', function() {
return function(resourceType) {
if (!resourceType) {
Expand Down
Loading

0 comments on commit 3bfe625

Please sign in to comment.