From 7d860bff4141937dfe4bf509d29d21afd1fcbe1c Mon Sep 17 00:00:00 2001 From: Ken Fukuyama <kenfdev@gmail.com> Date: Mon, 5 Mar 2018 00:31:41 +0900 Subject: [PATCH] fixed unexpected behavior where the selected function properties don't get updated after adding/deleting a different function. Signed-off-by: Ken Fukuyama <kenfdev@gmail.com> --- gateway/assets/index.html | 2 +- gateway/assets/script/bootstrap.js | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gateway/assets/index.html b/gateway/assets/index.html index bcc0812e..b660f9a0 100644 --- a/gateway/assets/index.html +++ b/gateway/assets/index.html @@ -72,7 +72,7 @@ <div flex></div> </md-content> - <md-content flex layout="column" ng-repeat="function in functions" ng-show="function.name == selectedFunction.name"> + <md-content flex layout="column" ng-repeat="function in functions" ng-if="function.name == selectedFunction.name"> <md-card md-theme="default" md-theme-watch> <md-card-title> diff --git a/gateway/assets/script/bootstrap.js b/gateway/assets/script/bootstrap.js index 665747f2..b863c1ca 100644 --- a/gateway/assets/script/bootstrap.js +++ b/gateway/assets/script/bootstrap.js @@ -4,8 +4,8 @@ var app = angular.module('faasGateway', ['ngMaterial', 'faasGateway.funcStore']); -app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', '$mdToast', '$mdSidenav', - function($scope, $log, $http, $location, $timeout, $mdDialog, $mdToast, $mdSidenav) { +app.controller("home", ['$scope', '$log', '$http', '$location', '$interval', '$filter', '$mdDialog', '$mdToast', '$mdSidenav', + function($scope, $log, $http, $location, $interval, $filter, $mdDialog, $mdToast, $mdSidenav) { var newFuncTabIdx = 0; $scope.functions = []; $scope.invocationInProgress = false; @@ -31,19 +31,15 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', '$md labels: {} }; - $scope.isReady = function(selectedFunction) { - return (selectedFunction.ready != undefined && selectedFunction.ready == true); - } - $scope.invocation.request = ""; var fetchFunctionsDelay = 3500; var queryFunctionDelay = 2500; - var fetchFunctionsInterval = setInterval(function() { + var fetchFunctionsInterval = $interval(function() { refreshData(); }, fetchFunctionsDelay); - var queryFunctionInterval = setInterval(function() { + var queryFunctionInterval = $interval(function() { if($scope.selectedFunction && $scope.selectedFunction.name) { refreshFunction($scope.selectedFunction); } @@ -169,6 +165,14 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', '$md if (response && response.data) { if (previousItems.length != response.data.length) { $scope.functions = response.data; + + // update the selected function object because the newly fetched object from the API becomes a different object + var filteredSelectedFunction = $filter('filter')($scope.functions, {name: $scope.selectedFunction.name}, true); + if (filteredSelectedFunction && filteredSelectedFunction.length > 0) { + $scope.selectedFunction = filteredSelectedFunction[0]; + } else { + $scope.selectedFunction = undefined; + } } else { for (var i = 0; i < $scope.functions.length; i++) { for (var j = 0; j < response.data.length; j++) { -- GitLab