aboutsummaryrefslogtreecommitdiff
path: root/web/static/app/app.js
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-03-05 16:47:32 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-03-05 16:47:32 +0100
commit7ca173de3de046501d79164da0c8c8871a03089b (patch)
tree16d857cf2ab7fd8b7b3c29efbacd6b01c2eacec7 /web/static/app/app.js
parentdda9ef2ae7971bceaa792e328c8489cb0695b77e (diff)
downloaddiller-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/app.js')
-rw-r--r--web/static/app/app.js179
1 files changed, 0 insertions, 179 deletions
diff --git a/web/static/app/app.js b/web/static/app/app.js
deleted file mode 100644
index 22c7f83..0000000
--- a/web/static/app/app.js
+++ /dev/null
@@ -1,179 +0,0 @@
-(function () {
- function FrontPageController(devices) {
- var ctrl = this;
-
- ctrl.devices = devices.data.devices;
- }
-
- function DeviceController($uibModal, device, DillerRpc) {
- var ctrl = this;
-
- ctrl.device = device.data.device;
-
- ctrl.propertyChunks = _(ctrl.device.properties).sortByAll(['name', 'key']).chunk(3).value();
-
- ctrl.editDeviceAttribute = function (attributeName) {
- var outer = ctrl;
- $uibModal.open({
- controller: function ($uibModalInstance) {
- var ctrl = this;
-
- ctrl.title = 'Edit device ' + attributeName;
- ctrl.label = attributeName.substr(0, 1).toUpperCase() + attributeName.substr(1);
- ctrl.value = outer.device[attributeName];
-
- ctrl.update = function () {
- DillerRpc.patchDevice(outer.device.id, {attribute: attributeName, value: ctrl.value})
- .then(function (res) {
- outer.device = res.data.device;
- $uibModalInstance.close({});
- }, function (res) {
- ctrl.error = res.data.message;
- });
- };
- },
- controllerAs: 'ctrl',
- bindToController: true,
- templateUrl: 'app/templates/edit-attribute.modal.html'
- });
- }
- }
-
- function PropertyController($timeout, $route, $uibModal, DillerRpc, device, values) {
- var ctrl = this;
-
- function updateData(device) {
- ctrl.device = device.data.device;
- ctrl.property = _.find(ctrl.device.properties, {id: $route.current.params.propertyId});
- }
- updateData(device);
- 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);
- })
- };
-
- ctrl.editPropertyAttribute = function (attributeName) {
- var outer = ctrl;
- $uibModal.open({
- controller: function ($uibModalInstance) {
- var ctrl = this;
-
- ctrl.title = 'Edit property ' + attributeName;
- ctrl.label = attributeName.substr(0, 1).toUpperCase() + attributeName.substr(1);
- ctrl.value = outer.property[attributeName];
-
- ctrl.update = function () {
- DillerRpc.patchProperty(outer.property.id, {attribute: attributeName, value: ctrl.value})
- .then(function (res) {
- updateData(res);
- $uibModalInstance.close({});
- }, function (res) {
- ctrl.error = res.data.message;
- });
- };
- },
- controllerAs: 'ctrl',
- bindToController: true,
- templateUrl: 'app/templates/edit-attribute.modal.html'
- });
- }
- }
-
- function TimestampFilter() {
- return function (value) {
- if (!value) {
- return;
- }
-
- return moment(value).startOf('second').fromNow();
- }
- }
-
- function 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) {
- $routeProvider
- .when('/', {
- controller: FrontPageController,
- controllerAs: 'ctrl',
- templateUrl: 'app/templates/front-page.html',
- resolve: {
- devices: DillerRpcResolve.getDevices
- }
- })
- .when('/device/:deviceId', {
- controller: DeviceController,
- controllerAs: 'ctrl',
- templateUrl: 'app/templates/device.html',
- resolve: {
- device: DillerRpcResolve.getDevice
- }
- })
- .when('/device/:deviceId/property/:propertyId', {
- controller: PropertyController,
- controllerAs: 'ctrl',
- templateUrl: 'app/templates/property.html',
- resolve: {
- device: DillerRpcResolve.getDevice,
- values: DillerRpcResolve.getValues
- }
- })
- .otherwise({
- redirectTo: '/'
- });
- }
-
- function run($log) {
- window.console = $log;
- }
-
- function DillerConfig() {
- var head = document.getElementsByTagName('head')[0];
- var base = head.getElementsByTagName('base')[0];
- var baseUrl = base.href.replace(/\/$/, '');
- return {
- baseUrl: baseUrl
- };
- }
-
- angular
- .module('Diller', ['ngRoute', 'ui.bootstrap'])
- .config(config)
- .run(run)
- .filter('timestamp', TimestampFilter)
- .directive('dlTimestamp', DlTimestampDirective)
- .directive('dlDots', DlDotsDirective)
- .service('DillerConfig', DillerConfig)
- .service('DillerRpc', DillerRpc);
-})();