diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-30 20:28:41 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-10-30 20:28:41 +0100 |
commit | a949af38a33cd08577ab91d6c5eb418520daefc8 (patch) | |
tree | 8251a36420396e2b26559c19d65da785f5e5b39b /web/static/app/app.js | |
parent | ecb664a8550ee787a593db6cf45907100a875a54 (diff) | |
download | diller-server-a949af38a33cd08577ab91d6c5eb418520daefc8.tar.gz diller-server-a949af38a33cd08577ab91d6c5eb418520daefc8.tar.bz2 diller-server-a949af38a33cd08577ab91d6c5eb418520daefc8.tar.xz diller-server-a949af38a33cd08577ab91d6c5eb418520daefc8.zip |
web:
o Adding 'time ago' for each value.
o Adding 'reload' button for a property.
Diffstat (limited to 'web/static/app/app.js')
-rw-r--r-- | web/static/app/app.js | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/web/static/app/app.js b/web/static/app/app.js index 5274362..6fa1f71 100644 --- a/web/static/app/app.js +++ b/web/static/app/app.js @@ -11,15 +11,62 @@ ctrl.device = device.data.device; } - function PropertyController($route, device, values) { + function PropertyController($timeout, $route, DillerRpc, device, values) { var ctrl = this; ctrl.device = device.data.device; ctrl.property = _.find(ctrl.device.properties, {id: $route.current.params.propertyId}); ctrl.values = values.data.values; + + var refreshPromise; + ctrl.refresh = function () { + $timeout.cancel(refreshPromise); + refreshPromise = $timeout(function () { + ctrl.loading = true; + }, 200); + + DillerRpc.getValues($route.current.params.propertyId).then(function (res) { + ctrl.values = res.data.values; + ctrl.loading = false; + $timeout.cancel(refreshPromise); + }) + }; + } + + function TimestampFilter() { + return function (value) { + if (!value) { + return; + } + + return moment(value).startOf('second').fromNow(); + } + } + + function DlTimestampDirective() { + console.log('DlTimestampDirective', DlTimestampDirective); + return { + restrict: 'E', + scope: { + value: '=' + }, + replace: true, + template: '<span title="{{value|date:\'medium\'}}">{{value|timestamp}}</span>' + }; + } + + function DlDotsDirective() { + return { + restrict: 'E', + scope: { + value: '=' + }, + replace: true, + template: '<span class="dl-dots"><span>.</span><span>.</span><span>.</span></span>\n' + }; } - function config($routeProvider, $locationProvider) { + function config($routeProvider) { $routeProvider .when('/', { controller: FrontPageController, @@ -49,8 +96,6 @@ .otherwise({ redirectTo: '/' }); - - //$locationProvider.html5Mode(true); } function DillerConfig() { @@ -67,6 +112,9 @@ angular .module('Diller', ['ngRoute']) .config(config) + .filter('timestamp', TimestampFilter) + .directive('dlTimestamp', DlTimestampDirective) + .directive('dlDots', DlDotsDirective) .service('DillerConfig', DillerConfig) .service('DillerRpc', DillerRpc); })(); |