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 @@ ...@@ -17,4 +17,7 @@
module.exports = function ($scope, application) { module.exports = function ($scope, application) {
$scope.application = application; $scope.application = application;
if (!application.capablities) {
application.getCapabilities();
}
}; };
...@@ -26,42 +26,47 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic ...@@ -26,42 +26,47 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
Notification.notify(title, options); Notification.notify(title, options);
}; };
$scope.loadData = function () { var refresh = function(app) {
Application.query(function (applications) { app.info = {};
function refresh(app) { app.needRefresh = true;
app.refreshing = true; //find application in known applications and copy state --> less flickering
app.info = {}; for (var j = 0; $scope.applications && j < $scope.applications.length; j++) {
if (app.id === $scope.applications[j].id) {
//find application in known applications and copy state --> less flickering app.infoShort = $scope.applications[j].infoShort;
for (var j = 0; $scope.applications && j < $scope.applications.length; j++) { app.infoDetails = $scope.applications[j].infoDetails;
if (app.id === $scope.applications[j].id) { app.version = $scope.applications[j].version;
app.infoShort = $scope.applications[j].infoShort; app.capabilities = $scope.applications[j].capabilities;
app.infoDetails = $scope.applications[j].infoDetails; if (app.statusInfo.status !== $scope.applications[j].statusInfo.status) {
app.version = $scope.applications[j].version; createNote(app); //issue notifiaction on state change
//issue notifiaction on state change } else {
if (app.statusInfo.status !== $scope.applications[j].statusInfo.status) { app.needRefresh = false; //if state hasn't change don't fetch info
createNote(app);
}
break;
}
} }
app.getInfo().then(function(info) { break;
app.version = info.version;
app.infoDetails = null;
app.infoShort = '';
delete info.version;
var infoYml = $filter('yaml')(info);
if (infoYml !== '{}\n') {
app.infoShort = $filter('limitLines')(infoYml, 3);
if (app.infoShort !== infoYml) {
app.infoDetails = $filter('limitLines')(infoYml, 32000, 3);
}
}
}).finally(function(){
app.refreshing = false;
});
} }
}
if (app.needRefresh) {
app.refreshing = true;
app.getCapabilities();
app.getInfo().then(function(info) {
app.version = info.version;
app.infoDetails = null;
app.infoShort = '';
delete info.version;
var infoYml = $filter('yaml')(info);
if (infoYml !== '{}\n') {
app.infoShort = $filter('limitLines')(infoYml, 3);
if (app.infoShort !== infoYml) {
app.infoDetails = $filter('limitLines')(infoYml, 32000, 3);
}
}
}).finally(function(){
app.refreshing = false;
});
}
};
$scope.loadData = function () {
Application.query(function (applications) {
for (var i = 0; i < applications.length; i++) { for (var i = 0; i < applications.length; i++) {
refresh(applications[i]); refresh(applications[i]);
} }
...@@ -103,8 +108,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic ...@@ -103,8 +108,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
//initial load //initial load
$scope.loadData(); $scope.loadData();
// reload site every 30 seconds // reload site every 10 seconds
$interval(function () { var intervalPromise = $interval(function () {
$scope.loadData(); $scope.loadData();
}, 10000); }, 10000);
$scope.$on('$destroy', function () { $interval.cancel(intervalPromise); });
}; };
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
'use strict'; 'use strict';
var angular = require('angular');
module.exports = function ($resource, $http, $q) { module.exports = function ($resource, $http, $q) {
...@@ -26,43 +25,14 @@ 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( var Application = $resource(
'api/applications/:id', { id: '@id' }, { 'api/applications/:id', { id: '@id' }, {
query: { method: 'GET', query: { method: 'GET', isArray: true },
isArray: true, get: { method: 'GET' },
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;
}
},
remove: { method: 'DELETE' } remove: { method: 'DELETE' }
}); });
var convert = function (request, isArray) { var convert = function (request, isArray) {
isArray = isArray || false; isArray = isArray || false;
var deferred = $q.defer(); var deferred = $q.defer();
...@@ -79,6 +49,21 @@ module.exports = function ($resource, $http, $q) { ...@@ -79,6 +49,21 @@ module.exports = function ($resource, $http, $q) {
return deferred.promise; 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 () { Application.prototype.getHealth = function () {
return convert($http.get('api/applications/' + this.id + '/health')); 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