|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +angular.module('openshiftConsole') |
| 4 | + .controller('ServiceInstanceController', function ($scope, |
| 5 | + $filter, |
| 6 | + $routeParams, |
| 7 | + DataService, |
| 8 | + ProjectsService, |
| 9 | + ServiceInstancesService) { |
| 10 | + $scope.alerts = {}; |
| 11 | + $scope.projectName = $routeParams.project; |
| 12 | + $scope.serviceInstance = null; |
| 13 | + $scope.serviceClass = null; |
| 14 | + $scope.serviceClasses = null; |
| 15 | + |
| 16 | + $scope.breadcrumbs = [ |
| 17 | + { |
| 18 | + title: "Provisioned Services", |
| 19 | + link: "project/" + $routeParams.project + "/browse/service-instances" |
| 20 | + } |
| 21 | + ]; |
| 22 | + |
| 23 | + $scope.deprovision = function() { |
| 24 | + ServiceInstancesService.deprovision($scope.serviceInstance); |
| 25 | + }; |
| 26 | + |
| 27 | + var watches = []; |
| 28 | + |
| 29 | + var updateBreadcrumbs = function() { |
| 30 | + if(!$scope.serviceInstance || !$scope.serviceClasses) { |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + $scope.breadcrumbs.push({ |
| 35 | + title: $filter('serviceInstanceDisplayName')($scope.serviceInstance, $scope.serviceClasses) |
| 36 | + }); |
| 37 | + }; |
| 38 | + |
| 39 | + var updateServiceClassMetadata = function() { |
| 40 | + if(!$scope.serviceInstance || !$scope.serviceClasses) { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + var serviceClassName = _.get($scope.serviceInstance.spec, 'serviceClassName'); |
| 45 | + $scope.serviceClass = _.get($scope.serviceClasses, [serviceClassName]); |
| 46 | + $scope.plan = _.find(_.get($scope.serviceClass, 'plans'), {name: $scope.serviceInstance.spec.planName }); |
| 47 | + }; |
| 48 | + |
| 49 | + var serviceResolved = function(service, action) { |
| 50 | + $scope.loaded = true; |
| 51 | + $scope.serviceInstance = service; |
| 52 | + |
| 53 | + if (action === "DELETED") { |
| 54 | + $scope.alerts["deleted"] = { |
| 55 | + type: "warning", |
| 56 | + message: "This provisioned service has been deleted." |
| 57 | + }; |
| 58 | + } |
| 59 | + |
| 60 | + updateServiceClassMetadata(); |
| 61 | + }; |
| 62 | + |
| 63 | + ProjectsService |
| 64 | + .get($routeParams.project) |
| 65 | + .then(_.spread(function(project, context) { |
| 66 | + $scope.project = project; |
| 67 | + $scope.projectContext = context; |
| 68 | + |
| 69 | + DataService |
| 70 | + .get({ |
| 71 | + group: 'servicecatalog.k8s.io', |
| 72 | + resource: 'serviceinstances' |
| 73 | + }, $routeParams.instance, context, { errorNotification: false }) |
| 74 | + .then(function(service) { |
| 75 | + |
| 76 | + serviceResolved(service); |
| 77 | + updateBreadcrumbs(); |
| 78 | + |
| 79 | + watches.push(DataService.watchObject({ |
| 80 | + group: 'servicecatalog.k8s.io', |
| 81 | + resource: 'serviceinstances' |
| 82 | + }, $routeParams.instance, context, serviceResolved)); |
| 83 | + |
| 84 | + }, function(error) { |
| 85 | + $scope.loaded = true; |
| 86 | + $scope.alerts["load"] = { |
| 87 | + type: "error", |
| 88 | + message: "The service details could not be loaded.", |
| 89 | + details: $filter('getErrorDetails')(error) |
| 90 | + }; |
| 91 | + }); |
| 92 | + |
| 93 | + DataService.list({ |
| 94 | + group: 'servicecatalog.k8s.io', |
| 95 | + resource: 'serviceclasses' |
| 96 | + }, context, function(serviceClasses) { |
| 97 | + $scope.serviceClasses = serviceClasses.by('metadata.name'); |
| 98 | + updateServiceClassMetadata(); |
| 99 | + updateBreadcrumbs(); |
| 100 | + }); |
| 101 | + |
| 102 | + $scope.$on('$destroy', function(){ |
| 103 | + DataService.unwatchAll(watches); |
| 104 | + }); |
| 105 | + |
| 106 | + })); |
| 107 | + }); |
0 commit comments