Skip to content

Commit b07598b

Browse files
committed
sorted and pre-selected instances
1 parent 89ca4dd commit b07598b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

app/scripts/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
8989
],
9090

9191
ENABLE_TECH_PREVIEW_FEATURE: {
92-
service_catalog_landing_page: true,
93-
pod_presets: true
92+
service_catalog_landing_page: false,
93+
pod_presets: false
9494
},
9595

9696
SAMPLE_PIPELINE_TEMPLATE: {

app/scripts/directives/bindService.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,46 @@ function BindService($filter,
3434

3535
ctrl.$onInit = function() {
3636
// TODO: handle not having any service instances, or handle path where coming into binding from svc instance
37-
// TODO: need serviceInstances as an array first
38-
// ctrl.serviceToBind = _.get(_.head(ctrl.serviceInstances), 'metadata.name');
39-
4037
ctrl.gotoStep(ctrl.steps[0]);
4138
};
4239

40+
var statusCondition = $filter('statusCondition');
41+
ctrl.$onChanges = function(changes) {
42+
if (changes.serviceInstances && !ctrl.serviceToBind) {
43+
var newestReady;
44+
var newestNotReady;
45+
_.each(ctrl.serviceInstances, function(instance) {
46+
var ready = _.get(statusCondition(instance, 'Ready'), 'status', 'False') === 'True';
47+
if (ready && (!newestReady || instance.metadata.creationTimestamp > newestReady.metadata.creationTimestamp)) {
48+
newestReady = instance;
49+
}
50+
if (!ready && (!newestNotReady || instance.metadata.creationTimestamp > newestNotReady.metadata.creationTimestamp)) {
51+
newestNotReady = instance;
52+
}
53+
});
54+
ctrl.serviceToBind = _.get(newestReady, 'metadata.name') || _.get(newestNotReady, 'metadata.name');
55+
}
56+
57+
// wait till both service instances and service classes are available so that the sort is stable and items dont jump around
58+
if (changes.serviceInstances && ctrl.serviceClasses || changes.serviceClasses && ctrl.serviceInstances) {
59+
var instances = _.toArray(ctrl.serviceInstances);
60+
instances.sort(function(left, right) {
61+
var leftName = _.get(ctrl.serviceClasses, [left.spec.serviceClassName, 'osbMetadata', 'displayName']) || left.spec.serviceClassName;
62+
var rightName = _.get(ctrl.serviceClasses, [left.spec.serviceClassName, 'osbMetadata', 'displayName']) || right.spec.serviceClassName;
63+
64+
// Fall back to sorting by `metadata.name` if the display names are the
65+
// same so that the sort is stable.
66+
if (leftName === rightName) {
67+
leftName = _.get(left, 'metadata.name', '');
68+
rightName = _.get(right, 'metadata.name', '');
69+
}
70+
71+
return leftName.localeCompare(rightName);
72+
});
73+
ctrl.orderedServiceInstances = instances;
74+
}
75+
};
76+
4377
var gotoStepID = function(id) {
4478
var step = _.find(ctrl.steps, { id: id });
4579
ctrl.gotoStep(step);

app/views/directives/bind-service/select-service.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h3 class="mar-top-none">Select a service to bind to <strong>{{ctrl.target.metad
44
for your application to use the service.
55
<form name="serviceSelection" class="mar-bottom-lg">
66
<fieldset ng-disabled="ctrl.isDisabled">
7-
<div class="radio" ng-repeat="serviceInstance in ctrl.serviceInstances">
7+
<div class="radio" ng-repeat="serviceInstance in ctrl.orderedServiceInstances">
88
<label>
99
<input type="radio" ng-model="ctrl.serviceToBind" value="{{serviceInstance.metadata.name}}">
1010
{{ctrl.serviceClasses[serviceInstance.spec.serviceClassName].osbMetadata.displayName || serviceInstance.spec.serviceClassName}}

0 commit comments

Comments
 (0)