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>
This commit is contained in:
Ken Fukuyama 2018-03-05 00:31:41 +09:00 committed by Alex Ellis
parent 02642ffb3f
commit 7d860bff41
2 changed files with 13 additions and 9 deletions

View File

@ -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>

View File

@ -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++) {