diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-05 16:47:32 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-03-05 16:47:32 +0100 |
commit | 7ca173de3de046501d79164da0c8c8871a03089b (patch) | |
tree | 16d857cf2ab7fd8b7b3c29efbacd6b01c2eacec7 /web/static/app/diller/client.js | |
parent | dda9ef2ae7971bceaa792e328c8489cb0695b77e (diff) | |
download | diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.gz diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.bz2 diller-server-7ca173de3de046501d79164da0c8c8871a03089b.tar.xz diller-server-7ca173de3de046501d79164da0c8c8871a03089b.zip |
web:
o Adding an API method to get per-hour aggregate values. Doesn't use the by_hour table yet.
o Adding a simple line graph component that can graph a single property's value.
Diffstat (limited to 'web/static/app/diller/client.js')
-rw-r--r-- | web/static/app/diller/client.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/web/static/app/diller/client.js b/web/static/app/diller/client.js new file mode 100644 index 0000000..6641ffb --- /dev/null +++ b/web/static/app/diller/client.js @@ -0,0 +1,72 @@ +(function () { + function extractData(res) { + return res && res.data; + } + + function Property($http, DillerRpc, propertyId) { + function getInterval(interval) { + + // moment().subtract(24, 'hour') + var req = DillerRpc.getValuesReq(propertyId); + req.params = { + from: interval.getFrom().toISOString() + }; + return $http(req).then(extractData); + } + + /** @lends Property.prototype */ + return { + getInterval: getInterval + }; + } + + function Device($http, DillerRpc, deviceId) { + var properties = {}; + + /** + * @param propertyId + * @returns {Property} + */ + function getProperty(propertyId) { + var p = properties[propertyId]; + + if (!p) { + p = new Property($http, DillerRpc, propertyId); + properties[propertyId] = p; + } + + return p; + } + + /** @lends Device.prototype */ + return { + getProperty: getProperty + }; + } + + function DillerClient($timeout, $http, DillerRpc) { + + var devices = {}; + + function getDevice(deviceId) { + var d = devices[deviceId]; + + if (!d) { + d = new Device($http, DillerRpc, deviceId); + devices[deviceId] = d; + } + + return d; + } + + /** @lends DillerClient.prototype */ + return { + getDevice: getDevice + }; + } + + angular + .module('diller.client', []) + .service('DillerClient', DillerClient) + .service('DillerRpc', window.DillerRpc); +})(); |