Skip to content

Commit

Permalink
DEV Clean Up
Browse files Browse the repository at this point in the history
Comment and minor code clean up
  • Loading branch information
cdcabrera committed Aug 9, 2017
1 parent ae50d6f commit 6c9d67f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 267 deletions.
91 changes: 1 addition & 90 deletions app/scripts/controllers/provisionedService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ angular.module('openshiftConsole')
$routeParams,
DataService,
ProjectsService) {
$scope.projectName = $routeParams.project;
$scope.displayName = null;
$scope.serviceInstance = null;
$scope.serviceInstances = null;
$scope.serviceClasses = {};
$scope.alerts = {};
//$scope.renderOptions = $scope.renderOptions || {};
//$scope.renderOptions.hideFilterWidget = true;

$scope.breadcrumbs = [
{
Expand All @@ -25,54 +22,8 @@ angular.module('openshiftConsole')
}
];

$scope.podFailureReasons = {
"Pending": "This pod will not receive traffic until all of its containers have been created."
};

//var allPods = {};
var watches = [];

// receives routes for the current service and maps service ports to each route name
var getPortsByRoute = function() {
if(!$scope.serviceInstance) {
return;
}

$scope.portsByRoute = {};

_.each($scope.serviceInstance.spec.ports, function(port) {
var reachedByRoute = false;
if(port.nodePort) {
$scope.showNodePorts = true;
}

_.each($scope.routesForService, function(route) {
if(!route.spec.port || route.spec.port.targetPort === port.name ||
route.spec.port.targetPort === port.targetPort) {
$scope.portsByRoute[route.metadata.name] = $scope.portsByRoute[route.metadata.name] || [];
$scope.portsByRoute[route.metadata.name].push(port);
reachedByRoute = true;
}
});

if(!reachedByRoute) {
$scope.portsByRoute[''] = $scope.portsByRoute[''] || [];
$scope.portsByRoute[''].push(port);
}
});
};

// receive pods for the current service scope only when the service object is available
/*var getPodsForService = function() {
$scope.podsForService = {};
if (!$scope.serviceInstance) {
return;
}
var ls = new LabelSelector($scope.serviceInstance.spec.selector);
$scope.podsForService = ls.select(allPods);
};*/

var setDisplayName = function() {
if(!$scope.serviceInstance || !$scope.serviceClasses) {
return;
Expand All @@ -85,9 +36,6 @@ angular.module('openshiftConsole')
$scope.loaded = true;
$scope.serviceInstance = service;

//getPodsForService();
getPortsByRoute();

if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
Expand All @@ -102,10 +50,6 @@ angular.module('openshiftConsole')
$scope.project = project;
$scope.projectContext = context;

//DataService.prototype.get = function(resource, name, context, opts) {
//DataService.prototype.watch = function(resource, context, callback, opts) {
//DataService.prototype.watchObject = function(resource, name, context, callback, opts) {

DataService
.get({
group: 'servicecatalog.k8s.io',
Expand All @@ -118,6 +62,7 @@ angular.module('openshiftConsole')
group: 'servicecatalog.k8s.io',
resource: 'instances'
}, $routeParams.instance, context, serviceResolved));

}, function(error) {
$scope.loaded = true;
$scope.alerts["load"] = {
Expand All @@ -142,40 +87,6 @@ angular.module('openshiftConsole')
$scope.serviceInstances = services.by("metadata.name");
}));

/*watches.push(DataService.watch("pods", context, function(pods) {
allPods = pods.by("metadata.name");
getPodsForService();
}));*/

/*watches.push(DataService.watch("endpoints", context, function(endpoints) {
$scope.podsWithEndpoints = {};
var svcEndpoint = endpoints.by("metadata.name")[$routeParams.instance];
if (!svcEndpoint) {
return;
}
_.each(svcEndpoint.subsets, function(subset) {
_.each(subset.addresses, function(address) {
if (_.get(address, "targetRef.kind") === "Pod") {
$scope.podsWithEndpoints[address.targetRef.name] = true;
}
});
});
}));*/

watches.push(DataService.watch("routes", context, function(routes) {
$scope.routesForService = {};
angular.forEach(routes.by("metadata.name"), function(route) {
if (route.spec.to.kind === "Service" &&
route.spec.to.name === $routeParams.instance) {
$scope.routesForService[route.metadata.name] = route;
}
});

getPortsByRoute();
Logger.log("routes (subscribe)", $scope.routesByService);
}));

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
Expand Down
116 changes: 44 additions & 72 deletions app/scripts/controllers/provisionedServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,11 @@ angular.module('openshiftConsole')
LabelFilter,
Logger,
ProjectsService) {

//var overview = this;
//var limitWatches = $filter('isIE')() || $filter('isEdge')();
//var DEFAULT_POLL_INTERVAL = 60 * 1000; // milliseconds

// Enable service catalog features if the new experience is enabled and the
// servicecatalog.k8s.io resources are available.
var SERVICE_CATALOG_ENABLED =
_.get(Constants, 'ENABLE_TECH_PREVIEW_FEATURE.service_catalog_landing_page') &&
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'serviceclasses' }) &&
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'instances' }) &&
APIService.apiInfo({ group: 'servicecatalog.k8s.io', resource: 'bindings' });

$scope.projectName = $routeParams.project;
$scope.serviceInstances = {};
$scope.unfilteredServiceInstances = {};
//$scope.routesByService = {};
//$scope.routes = {};
$scope.labelSuggestions = {};
$scope.alerts = $scope.alerts || {};
$scope.emptyMessage = "Loading...";
$scope.emptyMessageRoutes = "Loading...";

var watches = [];

Expand Down Expand Up @@ -176,68 +159,57 @@ angular.module('openshiftConsole')
.then(_.spread(function(project, context) {
$scope.project = project;

var canI = $filter('canI');

if (SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'instances'
}, context, function(serviceInstances) {
$scope.emptyMessage = "No provisioned services to show";
state.unfilteredServiceInstances = serviceInstances.by('metadata.name');

//_.each(state.unfilteredServiceInstances, function (instance) {
// var notifications = ResourceAlertsService.getServiceInstanceAlerts(instance);
// setNotifications(instance, notifications);
//});

sortServiceInstances();
updateFilter();
updateFilterWarning();

//updateLabelSuggestions(state.serviceInstances);
LabelFilter.addLabelSuggestionsFromResources(state.unfilteredServiceInstances, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);

Logger.log("provisioned services (subscribe)", state.unfilteredServiceInstances);

//}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
}));
}

if (SERVICE_CATALOG_ENABLED && canI({resource: 'bindings', group: 'servicecatalog.k8s.io'}, 'watch')) {
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'bindings'
}, context, function(bindings) {
state.bindings = bindings.by('metadata.name');
state.bindingsByInstanceRef = _.groupBy(state.bindings, 'spec.instanceRef.name');
groupBindings();
//refreshSecrets(context);
//}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
}));
}

if (SERVICE_CATALOG_ENABLED && canI({resource: 'instances', group: 'servicecatalog.k8s.io'}, 'watch')) {
DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, context, function(serviceClasses) {
state.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
});
}
watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'instances'
}, context, function(serviceInstances) {
$scope.emptyMessage = "No provisioned services to show";
state.unfilteredServiceInstances = serviceInstances.by('metadata.name');

//_.each(state.unfilteredServiceInstances, function (instance) {
// var notifications = ResourceAlertsService.getServiceInstanceAlerts(instance);
// setNotifications(instance, notifications);
//});

sortServiceInstances();
updateFilter();
updateFilterWarning();

//updateLabelSuggestions(state.serviceInstances);
LabelFilter.addLabelSuggestionsFromResources(state.unfilteredServiceInstances, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);

Logger.log("provisioned services (subscribe)", state.unfilteredServiceInstances);
}));

watches.push(DataService.watch({
group: 'servicecatalog.k8s.io',
resource: 'bindings'
}, context, function(bindings) {
state.bindings = bindings.by('metadata.name');
state.bindingsByInstanceRef = _.groupBy(state.bindings, 'spec.instanceRef.name');
groupBindings();
//refreshSecrets(context);
}));

DataService.list({
group: 'servicecatalog.k8s.io',
resource: 'serviceclasses'
}, context, function(serviceClasses) {
state.serviceClasses = serviceClasses.by('metadata.name');
sortServiceInstances();
updateFilter();
});

function updateFilterWarning() {
if (!LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.serviceInstances) && !_.isEmpty($scope.unfilteredServiceInstances)) {
$scope.alerts["services"] = {
$scope.alerts["all-instances-filtered"] = {
type: "warning",
details: "The active filters are hiding all services."
details: "The active filters are hiding all provisioned services."
};
}
else {
delete $scope.alerts["services"];
delete $scope.alerts["all-instances-filtered"];
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/views/browse/provisioned-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ <h1 class="contains-actions">
class="dropdown-toggle actions-dropdown-kebab visible-xs-inline"
data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
<ul class="dropdown-menu dropdown-menu-right actions action-button">
<li ng-if="'routes' | canI : 'create'">
<a ng-href="project/{{project.metadata.name}}/create-route?instance={{serviceInstance.metadata.name}}"
role="button">Create Route</a>
</li>
<li ng-if="{resource: 'instances', group: 'servicecatalog.k8s.io'} | canI : 'update'">
<a ng-href="{{serviceInstance | editYamlURL}}" role="button">Edit YAML</a>
</li>
Expand Down
23 changes: 8 additions & 15 deletions app/views/provisioned.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<div class="page-header page-header-bleed-right page-header-bleed-left">
<h1>
Provisioned Services
<span class="page-header-link">
<a ng-href="{{'services' | helpLink}}" target="_blank">
<!--<span class="page-header-link">
<a ng-href="{{'service-catalog' | helpLink}}" target="_blank">
Learn More <i class="fa fa-external-link" aria-hidden="true"></i>
</a>
</span>
</span>-->
</h1>
</div>
<div class="data-toolbar">
Expand All @@ -38,31 +38,24 @@ <h1>
<th>Status</th>
<th>Created</th>
<th>Bindings</th>

<!--<th>Name</th>
<th>Cluster IP</th>
<th>External IP</th>
<th>Ports</th>
<th>Selector</th>
<th>Age</th>-->
</tr>
</thead>
<tbody ng-if="(serviceInstances | hashSize) === 0">
<tbody ng-if="(serviceInstances | size) === 0">
<tr>
<td colspan="4"><em>{{emptyMessage}}</em></td>
</tr>
</tbody>
<tbody ng-if="(serviceInstances | hashSize) > 0">
<tr ng-repeat="serviceInstance in serviceInstances | orderObjectsByDate : true">
<tbody ng-if="(serviceInstances | size) > 0">
<tr ng-repeat="serviceInstance in serviceInstances track by (serviceInstance | uid)">
<td data-title="Name"><a ng-href="{{serviceInstance | navigateResourceURL}}">{{serviceInstance | serviceInstanceDisplayName:serviceClasses}}</a></td>

<td data-title="Status">
<div row class="status">
<!--<div row class="status">
<status-icon status="serviceInstance | deploymentStatus" disable-animation></status-icon>
<span flex>
{{serviceInstance | deploymentStatus}}
</span>
</div>
</div>-->
</td>
<td data-title="Created">
<span am-time-ago="serviceInstance.metadata.creationTimestamp" am-without-suffix="true"></span> ago
Expand Down
Loading

0 comments on commit 6c9d67f

Please sign in to comment.