From 8226d84cfddb1862d191a8e933ee28d4a8917ac0 Mon Sep 17 00:00:00 2001 From: benjaminapetersen Date: Wed, 12 Oct 2016 13:47:18 -0400 Subject: [PATCH] Update pvc controller to share get,watch callback --- .../controllers/persistentVolumeClaim.js | 41 +++++++++---------- dist/scripts/scripts.js | 14 +++---- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/scripts/controllers/persistentVolumeClaim.js b/app/scripts/controllers/persistentVolumeClaim.js index da4a095be1..8bb1974cf1 100644 --- a/app/scripts/controllers/persistentVolumeClaim.js +++ b/app/scripts/controllers/persistentVolumeClaim.js @@ -25,38 +25,35 @@ angular.module('openshiftConsole') ]; var watches = []; - + + var pvcResolved = function(pvc, action) { + $scope.pvc = pvc; + $scope.loaded = true; + if (action === "DELETED") { + $scope.alerts["deleted"] = { + type: "warning", + message: "This persistent volume claim has been deleted." + }; + } + }; + ProjectsService .get($routeParams.project) .then(_.spread(function(project, context) { $scope.project = project; - DataService.get("persistentvolumeclaims", $routeParams.pvc, context).then( - // success - function(pvc) { - $scope.loaded = true; - $scope.pvc = pvc; - - // If we found the item successfully, watch for changes on it - watches.push(DataService.watchObject("persistentvolumeclaims", $routeParams.pvc, context, function(pvc, action) { - if (action === "DELETED") { - $scope.alerts["deleted"] = { - type: "warning", - message: "This persistent volume claim has been deleted." - }; - } - $scope.pvc = pvc; - })); - }, - // failure - function(e) { + DataService + .get("persistentvolumeclaims", $routeParams.pvc, context) + .then(function(pvc) { + pvcResolved(pvc); + watches.push(DataService.watchObject("persistentvolumeclaims", $routeParams.pvc, context, pvcResolved)); + }, function(e) { $scope.loaded = true; $scope.alerts["load"] = { type: "error", message: "The persistent volume claim details could not be loaded.", details: "Reason: " + $filter('getErrorDetails')(e) }; - } - ); + }); $scope.$on('$destroy', function(){ DataService.unwatchAll(watches); diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index c3868e6b65..e4d453d7cd 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -5433,15 +5433,15 @@ link:"project/" + b.project + "/browse/storage" }, { title:b.pvc } ]; -var f = []; -d.get(b.project).then(_.spread(function(d, g) { -a.project = d, c.get("persistentvolumeclaims", b.pvc, g).then(function(d) { -a.loaded = !0, a.pvc = d, f.push(c.watchObject("persistentvolumeclaims", b.pvc, g, function(b, c) { -"DELETED" === c && (a.alerts.deleted = { +var f = [], g = function(b, c) { +a.pvc = b, a.loaded = !0, "DELETED" === c && (a.alerts.deleted = { type:"warning", message:"This persistent volume claim has been deleted." -}), a.pvc = b; -})); +}); +}; +d.get(b.project).then(_.spread(function(d, h) { +a.project = d, c.get("persistentvolumeclaims", b.pvc, h).then(function(a) { +g(a), f.push(c.watchObject("persistentvolumeclaims", b.pvc, h, g)); }, function(b) { a.loaded = !0, a.alerts.load = { type:"error",