Added initial cache service for groups, hosts, applications and

items caching on client side.
This commit is contained in:
Alexander Zobnin
2016-01-11 21:53:53 +03:00
parent e0b1978fa6
commit dc00766458
3 changed files with 115 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
define([
'angular',
'lodash'
],
function (angular, _) {
'use strict';
var module = angular.module('grafana.services');
module.factory('ZabbixCache', function($q, backendSrv) {
function ZabbixCache(zabbixAPI, lifetime) {
var self = this;
this.zabbixAPI = zabbixAPI;
this.lifetime = lifetime;
var promises = [
this.zabbixAPI.getGroups(),
this.zabbixAPI.getHosts(),
this.zabbixAPI.getApplications(),
this.zabbixAPI.getItems()
];
$q.all(promises).then(function (results) {
console.log(results);
if (results.length) {
self._groups = results[0];
self._hosts = results[1];
self._applications = groupApplications(results[2]);
self._items = results[3];
}
});
}
var p = ZabbixCache.prototype;
p.getHosts = function() {
return this._hosts;
};
/**
* Group Zabbix applications by name
* @param {[type]} applications [description]
* @return {[type]} [description]
*/
function groupApplications(applications) {
return _.map(_.groupBy(applications, 'name'), function (value, key) {
return {
name: key,
ids: _.map(value, 'applicationid')
};
});
}
return ZabbixCache;
});
});