Commit 01fbf73d by Johannes Edmeier

Reduce fetching of /info and /configprops

/info and /configprops are from now on only fetched in the overview on first render and whenever the status of an application changes. closes #95
parent f6f9552a
......@@ -17,4 +17,7 @@
module.exports = function ($scope, application) {
$scope.application = application;
if (!application.capablities) {
application.getCapabilities();
}
};
......@@ -26,25 +26,27 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
Notification.notify(title, options);
};
$scope.loadData = function () {
Application.query(function (applications) {
function refresh(app) {
app.refreshing = true;
var refresh = function(app) {
app.info = {};
app.needRefresh = true;
//find application in known applications and copy state --> less flickering
for (var j = 0; $scope.applications && j < $scope.applications.length; j++) {
if (app.id === $scope.applications[j].id) {
app.infoShort = $scope.applications[j].infoShort;
app.infoDetails = $scope.applications[j].infoDetails;
app.version = $scope.applications[j].version;
//issue notifiaction on state change
app.capabilities = $scope.applications[j].capabilities;
if (app.statusInfo.status !== $scope.applications[j].statusInfo.status) {
createNote(app);
createNote(app); //issue notifiaction on state change
} else {
app.needRefresh = false; //if state hasn't change don't fetch info
}
break;
}
}
if (app.needRefresh) {
app.refreshing = true;
app.getCapabilities();
app.getInfo().then(function(info) {
app.version = info.version;
app.infoDetails = null;
......@@ -61,7 +63,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
app.refreshing = false;
});
}
};
$scope.loadData = function () {
Application.query(function (applications) {
for (var i = 0; i < applications.length; i++) {
refresh(applications[i]);
}
......@@ -103,8 +108,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
//initial load
$scope.loadData();
// reload site every 30 seconds
$interval(function () {
// reload site every 10 seconds
var intervalPromise = $interval(function () {
$scope.loadData();
}, 10000);
$scope.$on('$destroy', function () { $interval.cancel(intervalPromise); });
};
......@@ -14,7 +14,6 @@
* limitations under the License.
*/
'use strict';
var angular = require('angular');
module.exports = function ($resource, $http, $q) {
......@@ -26,43 +25,14 @@ module.exports = function ($resource, $http, $q) {
}
};
var getCapabilities = function(application) {
application.capabilities = {};
if (application.managementUrl) {
$http.get('api/applications/' + application.id + '/configprops').success(function(configprops) {
application.capabilities.logfile = isEndpointPresent('logfileMvcEndpoint', configprops);
application.capabilities.activiti = isEndpointPresent('processEngineEndpoint', configprops);
application.capabilities.restart = isEndpointPresent('restartEndpoint', configprops);
application.capabilities.refresh = isEndpointPresent('refreshEndpoint', configprops);
application.capabilities.pause = isEndpointPresent('pauseEndpoint', configprops);
application.capabilities.resume = isEndpointPresent('resumeEndpoint', configprops);
});
}
};
var Application = $resource(
'api/applications/:id', { id: '@id' }, {
query: { method: 'GET',
isArray: true,
transformResponse: function(data) {
var apps = angular.fromJson(data);
for (var i = 0; i < apps.length; i++) {
getCapabilities(apps[i]);
}
return apps;
}
},
get: { method: 'GET',
transformResponse: function(data) {
var app = angular.fromJson(data);
getCapabilities(app);
return app;
}
},
query: { method: 'GET', isArray: true },
get: { method: 'GET' },
remove: { method: 'DELETE' }
});
var convert = function (request, isArray) {
isArray = isArray || false;
var deferred = $q.defer();
......@@ -79,6 +49,21 @@ module.exports = function ($resource, $http, $q) {
return deferred.promise;
};
Application.prototype.getCapabilities = function() {
var application = this;
this.capabilities = {};
if (this.managementUrl) {
$http.get('api/applications/' + application.id + '/configprops').success(function(configprops) {
application.capabilities.logfile = isEndpointPresent('logfileMvcEndpoint', configprops);
application.capabilities.activiti = isEndpointPresent('processEngineEndpoint', configprops);
application.capabilities.restart = isEndpointPresent('restartEndpoint', configprops);
application.capabilities.refresh = isEndpointPresent('refreshEndpoint', configprops);
application.capabilities.pause = isEndpointPresent('pauseEndpoint', configprops);
application.capabilities.resume = isEndpointPresent('resumeEndpoint', configprops);
});
}
};
Application.prototype.getHealth = function () {
return convert($http.get('api/applications/' + this.id + '/health'));
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment