UNPKG

insight-ui-mangacoin

Version:

An open-source frontend for the Insight API. The Insight API provides you with a convenient, powerful and simple way to query and broadcast data on the monacoin network and build your own services with it.

56 lines (47 loc) 1.26 kB
'use strict'; angular.module('insight.status').controller('StatusController', function($scope, $routeParams, $location, Global, Status, Sync, getSocket) { $scope.global = Global; $scope.getStatus = function(q) { Status.get({ q: 'get' + q }, function(d) { $scope.loaded = 1; angular.extend($scope, d); }, function(e) { $scope.error = 'API ERROR: ' + e.data; }); }; $scope.humanSince = function(time) { var m = moment.unix(time / 1000); return m.max().fromNow(); }; var _onSyncUpdate = function(sync) { $scope.sync = sync; }; var _startSocket = function () { socket.emit('subscribe', 'sync'); socket.on('status', function(sync) { _onSyncUpdate(sync); }); }; var socket = getSocket($scope); socket.on('connect', function() { _startSocket(); }); $scope.getSync = function() { _startSocket(); Sync.get({}, function(sync) { _onSyncUpdate(sync); }, function(e) { var err = 'Could not get sync information' + e.toString(); $scope.sync = { error: err }; }); }; });