Skip to content

Use new ApplicationsService.getApplications utility #2034

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

Merged
merged 1 commit into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
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
56 changes: 5 additions & 51 deletions app/scripts/directives/addSecretToApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'$filter',
'$scope',
'APIService',
'ApplicationsService',
'DataService',
'Navigate',
'NotificationsService',
Expand All @@ -21,63 +22,16 @@
templateUrl: 'views/directives/add-secret-to-application.html'
});

function AddSecretToApplication($filter, $scope, APIService, DataService, Navigate, NotificationsService, StorageService) {
function AddSecretToApplication($filter, $scope, APIService, ApplicationsService, DataService, Navigate, NotificationsService, StorageService) {
var ctrl = this;
var deploymentConfigs;
var deployments;
var replicationControllers;
var replicaSets;
var statefulSets;

var sortApplications = function() {
// Don't waste time sorting on each data load, just sort when we have them all
if (deploymentConfigs && deployments && replicationControllers && replicaSets && statefulSets) {
var apiObjects = deploymentConfigs.concat(deployments)
.concat(replicationControllers)
.concat(replicaSets)
.concat(statefulSets);
ctrl.applications = _.sortBy(apiObjects, ['metadata.name', 'kind']);
ctrl.updating = false;
}
};

var getApplications = function() {
var hasDeploymentFilter = $filter('hasDeployment');
var hasDeploymentConfigFilter = $filter('hasDeploymentConfig');

ctrl.updating = true;
var context = {
namespace: ctrl.project.metadata.name
};
// Load all the "application" types
DataService.list('deploymentconfigs', context).then(function(deploymentConfigData) {
deploymentConfigs = _.toArray(deploymentConfigData.by('metadata.name'));
sortApplications();
});
DataService.list('replicationcontrollers', context).then(function(replicationControllerData) {
replicationControllers = _.reject(replicationControllerData.by('metadata.name'), hasDeploymentConfigFilter);
sortApplications();
});
DataService.list({
group: 'apps',
resource: 'deployments'
}, context).then(function(deploymentData) {
deployments = _.toArray(deploymentData.by('metadata.name'));
sortApplications();
});
DataService.list({
group: 'extensions',
resource: 'replicasets'
}, context).then(function(replicaSetData) {
replicaSets = _.reject(replicaSetData.by('metadata.name'), hasDeploymentFilter);
sortApplications();
});
DataService.list({
group: 'apps',
resource: 'statefulsets'
}, context).then(function(statefulSetData) {
statefulSets = _.toArray(statefulSetData.by('metadata.name'));
sortApplications();
ApplicationsService.getApplications(context).then(function(applications) {
ctrl.applications = applications;
ctrl.updating = false;
});
};

Expand Down
50 changes: 5 additions & 45 deletions app/scripts/directives/bindService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
controller: [
'$scope',
'$filter',
'ApplicationsService',
'DataService',
'BindingService',
BindService
Expand All @@ -20,6 +21,7 @@

function BindService($scope,
$filter,
ApplicationsService,
DataService,
BindingService) {
var ctrl = this;
Expand Down Expand Up @@ -59,20 +61,6 @@
}
};

var deploymentConfigs, deployments, replicationControllers, replicaSets, statefulSets;
var sortApplications = function() {
// Don't waste time sorting on each data load, just sort when we have them all
if (deploymentConfigs && deployments && replicationControllers && replicaSets && statefulSets) {
var apiObjects = [].concat(deploymentConfigs)
.concat(deployments)
.concat(replicationControllers)
.concat(replicaSets)
.concat(statefulSets);
ctrl.applications = _.sortBy(apiObjects, ['metadata.name', 'kind']);
ctrl.bindType = ctrl.applications.length ? "application" : "secret-only";
}
};

var showBind = function() {
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';
if (ctrl.podPresets && !selectionValidityWatcher) {
Expand Down Expand Up @@ -106,41 +94,13 @@
ctrl.bindService();
};


var loadApplications = function() {
var context = {
namespace: _.get(ctrl.target, 'metadata.namespace')
};

// Load all the "application" types
DataService.list('deploymentconfigs', context).then(function(deploymentConfigData) {
deploymentConfigs = _.toArray(deploymentConfigData.by('metadata.name'));
sortApplications();
});
DataService.list('replicationcontrollers', context).then(function(replicationControllerData) {
replicationControllers = _.reject(replicationControllerData.by('metadata.name'), $filter('hasDeploymentConfig'));
sortApplications();
});
DataService.list({
group: 'apps',
resource: 'deployments'
}, context).then(function(deploymentData) {
deployments = _.toArray(deploymentData.by('metadata.name'));
sortApplications();
});
DataService.list({
group: 'extensions',
resource: 'replicasets'
}, context).then(function(replicaSetData) {
replicaSets = _.reject(replicaSetData.by('metadata.name'), $filter('hasDeployment'));
sortApplications();
});
DataService.list({
group: 'apps',
resource: 'statefulsets'
}, context).then(function(statefulSetData) {
statefulSets = _.toArray(statefulSetData.by('metadata.name'));
sortApplications();
ApplicationsService.getApplications(context).then(function(applications) {
ctrl.applications = applications;
ctrl.bindType = ctrl.applications.length ? "application" : "secret-only";
});
};

Expand Down
Loading