diff options
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); })(); |