2014-02-10 19:54:37 +00:00
|
|
|
/*jslint browser: true, continue: true, plusplus: true */
|
|
|
|
/*global $: false, angular: false */
|
|
|
|
|
2014-02-11 13:34:47 +00:00
|
|
|
'use strict';
|
2014-02-10 19:54:37 +00:00
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
var syncthing = angular.module('syncthing', []);
|
|
|
|
|
|
|
|
syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
2014-02-10 19:54:37 +00:00
|
|
|
var prevDate = 0,
|
2014-04-09 21:00:23 +00:00
|
|
|
getOK = true;
|
2014-01-09 09:31:27 +00:00
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.connections = {};
|
|
|
|
$scope.config = {};
|
2014-02-11 13:34:47 +00:00
|
|
|
$scope.myID = '';
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.nodes = [];
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.configInSync = true;
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.errors = [];
|
|
|
|
$scope.seenError = '';
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.model = {};
|
|
|
|
$scope.repos = [];
|
2014-02-01 19:23:19 +00:00
|
|
|
|
|
|
|
// Strings before bools look better
|
|
|
|
$scope.settings = [
|
2014-04-09 21:00:23 +00:00
|
|
|
{id: 'ListenStr', descr: 'Sync Protocol Listen Addresses', type: 'text', restart: true},
|
|
|
|
{id: 'MaxSendKbps', descr: 'Outgoing Rate Limit (KBps)', type: 'number', restart: true},
|
|
|
|
{id: 'RescanIntervalS', descr: 'Rescan Interval (s)', type: 'number', restart: true},
|
|
|
|
{id: 'ReconnectIntervalS', descr: 'Reconnect Interval (s)', type: 'number', restart: true},
|
|
|
|
{id: 'ParallelRequests', descr: 'Max Outstanding Requests', type: 'number', restart: true},
|
|
|
|
{id: 'MaxChangeKbps', descr: 'Max File Change Rate (KBps)', type: 'number', restart: true},
|
|
|
|
|
|
|
|
{id: 'GlobalAnnEnabled', descr: 'Global Announce', type: 'bool', restart: true},
|
|
|
|
{id: 'LocalAnnEnabled', descr: 'Local Announce', type: 'bool', restart: true},
|
|
|
|
{id: 'StartBrowser', descr: 'Start Browser', type: 'bool'},
|
2014-02-01 19:23:19 +00:00
|
|
|
];
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.guiSettings = [
|
|
|
|
{id: 'Address', descr: 'GUI Listen Addresses', type: 'text', restart: true},
|
|
|
|
{id: 'User', descr: 'GUI Authentication User', type: 'text', restart: true},
|
|
|
|
{id: 'Password', descr: 'GUI Authentication Password', type: 'password', restart: true},
|
|
|
|
];
|
|
|
|
|
|
|
|
function getSucceeded() {
|
|
|
|
if (!getOK) {
|
2014-01-09 09:31:27 +00:00
|
|
|
$('#networkError').modal('hide');
|
2014-04-09 21:00:23 +00:00
|
|
|
getOK = true;
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
function getFailed() {
|
|
|
|
if (getOK) {
|
2014-01-09 09:31:27 +00:00
|
|
|
$('#networkError').modal({backdrop: 'static', keyboard: false});
|
2014-04-09 21:00:23 +00:00
|
|
|
getOK = false;
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
function nodeCompare(a, b) {
|
|
|
|
if (a.NodeID === $scope.myID) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (b.NodeID === $scope.myID) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a.NodeID < b.NodeID) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return a.NodeID > b.NodeID;
|
|
|
|
}
|
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
$scope.refresh = function () {
|
2014-02-11 13:34:47 +00:00
|
|
|
$http.get('/rest/system').success(function (data) {
|
2014-04-09 21:00:23 +00:00
|
|
|
getSucceeded();
|
2014-01-09 23:09:27 +00:00
|
|
|
$scope.system = data;
|
2014-01-09 09:31:27 +00:00
|
|
|
}).error(function () {
|
2014-04-09 21:00:23 +00:00
|
|
|
getFailed();
|
|
|
|
});
|
|
|
|
$scope.repos.forEach(function (repo) {
|
|
|
|
$http.get('/rest/model/' + repo.ID).success(function (data) {
|
|
|
|
$scope.model[repo.ID] = data;
|
|
|
|
});
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
2014-02-11 13:34:47 +00:00
|
|
|
$http.get('/rest/connections').success(function (data) {
|
2014-02-10 19:54:37 +00:00
|
|
|
var now = Date.now(),
|
2014-04-09 21:00:23 +00:00
|
|
|
td = (now - prevDate) / 1000,
|
|
|
|
id;
|
2014-02-10 19:54:37 +00:00
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
prevDate = now;
|
2014-02-10 19:54:37 +00:00
|
|
|
$scope.inbps = 0;
|
|
|
|
$scope.outbps = 0;
|
2014-01-05 22:54:57 +00:00
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
for (id in data) {
|
|
|
|
if (!data.hasOwnProperty(id)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-05 22:54:57 +00:00
|
|
|
try {
|
2014-01-09 09:31:27 +00:00
|
|
|
data[id].inbps = Math.max(0, 8 * (data[id].InBytesTotal - $scope.connections[id].InBytesTotal) / td);
|
|
|
|
data[id].outbps = Math.max(0, 8 * (data[id].OutBytesTotal - $scope.connections[id].OutBytesTotal) / td);
|
2014-01-05 22:54:57 +00:00
|
|
|
} catch (e) {
|
|
|
|
data[id].inbps = 0;
|
|
|
|
data[id].outbps = 0;
|
|
|
|
}
|
2014-02-11 13:34:47 +00:00
|
|
|
$scope.inbps += data[id].inbps;
|
|
|
|
$scope.outbps += data[id].outbps;
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
$scope.connections = data;
|
|
|
|
});
|
2014-02-12 22:18:41 +00:00
|
|
|
$http.get('/rest/errors').success(function (data) {
|
|
|
|
$scope.errors = data;
|
|
|
|
});
|
2014-01-05 22:54:57 +00:00
|
|
|
};
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.syncPercentage = function (repo) {
|
|
|
|
if (typeof $scope.model[repo] === 'undefined') {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
if ($scope.model[repo].globalBytes === 0) {
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pct = 100 * $scope.model[repo].inSyncBytes / $scope.model[repo].globalBytes;
|
|
|
|
return Math.ceil(pct);
|
|
|
|
};
|
|
|
|
|
2014-02-05 21:42:23 +00:00
|
|
|
$scope.nodeStatus = function (nodeCfg) {
|
2014-02-13 11:41:37 +00:00
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
|
|
|
if (conn.Completion === 100) {
|
|
|
|
return 'In Sync';
|
|
|
|
} else {
|
|
|
|
return 'Syncing (' + conn.Completion + '%)';
|
|
|
|
}
|
2014-02-05 21:42:23 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 13:34:47 +00:00
|
|
|
return 'Disconnected';
|
2014-02-05 21:42:23 +00:00
|
|
|
};
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.nodeIcon = function (nodeCfg) {
|
2014-02-13 11:41:37 +00:00
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
|
|
|
if (conn.Completion === 100) {
|
|
|
|
return 'ok';
|
|
|
|
} else {
|
|
|
|
return 'refresh';
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 13:34:47 +00:00
|
|
|
return 'minus';
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.nodeClass = function (nodeCfg) {
|
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
2014-02-13 11:41:37 +00:00
|
|
|
if (conn.Completion === 100) {
|
|
|
|
return 'success';
|
|
|
|
} else {
|
|
|
|
return 'primary';
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 13:34:47 +00:00
|
|
|
return 'info';
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.nodeAddr = function (nodeCfg) {
|
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
|
|
|
return conn.Address;
|
|
|
|
}
|
2014-04-09 21:00:23 +00:00
|
|
|
return '?';
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-13 11:41:37 +00:00
|
|
|
$scope.nodeCompletion = function (nodeCfg) {
|
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
|
|
|
return conn.Completion + '%';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.nodeVer = function (nodeCfg) {
|
|
|
|
if (nodeCfg.NodeID === $scope.myID) {
|
|
|
|
return $scope.version;
|
|
|
|
}
|
|
|
|
var conn = $scope.connections[nodeCfg.NodeID];
|
|
|
|
if (conn) {
|
|
|
|
return conn.ClientVersion;
|
|
|
|
}
|
2014-04-09 21:00:23 +00:00
|
|
|
return '?';
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-05 21:49:26 +00:00
|
|
|
$scope.nodeName = function (nodeCfg) {
|
|
|
|
if (nodeCfg.Name) {
|
|
|
|
return nodeCfg.Name;
|
|
|
|
}
|
|
|
|
return nodeCfg.NodeID.substr(0, 6);
|
|
|
|
};
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editSettings = function () {
|
|
|
|
$('#settings').modal({backdrop: 'static', keyboard: true});
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.saveSettings = function () {
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.configInSync = false;
|
2014-02-05 22:17:17 +00:00
|
|
|
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
|
2014-02-01 19:23:19 +00:00
|
|
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#settings').modal("hide");
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.restart = function () {
|
|
|
|
$http.post('/rest/restart');
|
|
|
|
$scope.configInSync = true;
|
|
|
|
};
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.editNode = function (nodeCfg) {
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.currentNode = $.extend({}, nodeCfg);
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.editingExisting = true;
|
2014-02-11 13:34:47 +00:00
|
|
|
$scope.currentNode.AddressesStr = nodeCfg.Addresses.join(', ');
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#editNode').modal({backdrop: 'static', keyboard: true});
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addNode = function () {
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.currentNode = {AddressesStr: 'dynamic'};
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.editingExisting = false;
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#editNode').modal({backdrop: 'static', keyboard: true});
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteNode = function () {
|
|
|
|
$('#editNode').modal('hide');
|
2014-02-10 19:54:37 +00:00
|
|
|
if (!$scope.editingExisting) {
|
2014-02-01 19:23:19 +00:00
|
|
|
return;
|
2014-02-10 19:54:37 +00:00
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.nodes = $scope.nodes.filter(function (n) {
|
|
|
|
return n.NodeID !== $scope.currentNode.NodeID;
|
|
|
|
});
|
|
|
|
$scope.config.Nodes = $scope.nodes;
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
for (var i = 0; i < $scope.repos.length; i++) {
|
|
|
|
$scope.repos[i].Nodes = $scope.repos[i].Nodes.filter(function (n) {
|
|
|
|
return n.NodeID !== $scope.currentNode.NodeID;
|
|
|
|
});
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.configInSync = false;
|
2014-02-10 19:54:37 +00:00
|
|
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
|
|
|
};
|
2014-02-01 19:23:19 +00:00
|
|
|
|
|
|
|
$scope.saveNode = function () {
|
2014-02-10 19:54:37 +00:00
|
|
|
var nodeCfg, done, i;
|
|
|
|
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.configInSync = false;
|
2014-02-01 19:23:19 +00:00
|
|
|
$('#editNode').modal('hide');
|
|
|
|
nodeCfg = $scope.currentNode;
|
|
|
|
nodeCfg.Addresses = nodeCfg.AddressesStr.split(',').map(function (x) { return x.trim(); });
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
done = false;
|
|
|
|
for (i = 0; i < $scope.nodes.length; i++) {
|
2014-02-01 19:23:19 +00:00
|
|
|
if ($scope.nodes[i].NodeID === nodeCfg.NodeID) {
|
|
|
|
$scope.nodes[i] = nodeCfg;
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 19:54:37 +00:00
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
$scope.nodes.push(nodeCfg);
|
|
|
|
}
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
$scope.nodes.sort(nodeCompare);
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.config.Nodes = $scope.nodes;
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.otherNodes = function () {
|
2014-04-09 21:00:23 +00:00
|
|
|
return $scope.nodes.filter(function (n){
|
|
|
|
return n.NodeID !== $scope.myID;
|
|
|
|
});
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.thisNode = function () {
|
|
|
|
var i, n;
|
|
|
|
|
|
|
|
for (i = 0; i < $scope.nodes.length; i++) {
|
|
|
|
n = $scope.nodes[i];
|
|
|
|
if (n.NodeID === $scope.myID) {
|
|
|
|
return [n];
|
|
|
|
}
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.errorList = function () {
|
2014-04-09 21:00:23 +00:00
|
|
|
return $scope.errors.filter(function (e) {
|
|
|
|
return e.Time > $scope.seenError;
|
|
|
|
});
|
2014-02-12 22:18:41 +00:00
|
|
|
};
|
2014-03-08 22:19:33 +00:00
|
|
|
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.clearErrors = function () {
|
|
|
|
$scope.seenError = $scope.errors[$scope.errors.length - 1].Time;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.friendlyNodes = function (str) {
|
|
|
|
for (var i = 0; i < $scope.nodes.length; i++) {
|
|
|
|
var cfg = $scope.nodes[i];
|
|
|
|
str = str.replace(cfg.NodeID, $scope.nodeName(cfg));
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editRepo = function (nodeCfg) {
|
|
|
|
$scope.currentRepo = $.extend({selectedNodes: {}}, nodeCfg);
|
|
|
|
$scope.currentRepo.Nodes.forEach(function (n) {
|
|
|
|
$scope.currentRepo.selectedNodes[n.NodeID] = true;
|
|
|
|
});
|
|
|
|
$scope.editingExisting = true;
|
|
|
|
$('#editRepo').modal({backdrop: 'static', keyboard: true});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addRepo = function () {
|
|
|
|
$scope.currentRepo = {selectedNodes: {}};
|
|
|
|
$scope.editingExisting = false;
|
|
|
|
$('#editRepo').modal({backdrop: 'static', keyboard: true});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.saveRepo = function () {
|
|
|
|
var repoCfg, done, i;
|
|
|
|
|
|
|
|
$scope.configInSync = false;
|
|
|
|
$('#editRepo').modal('hide');
|
|
|
|
repoCfg = $scope.currentRepo;
|
|
|
|
repoCfg.Nodes = [];
|
|
|
|
repoCfg.selectedNodes[$scope.myID] = true;
|
|
|
|
for (var nodeID in repoCfg.selectedNodes) {
|
|
|
|
if (repoCfg.selectedNodes[nodeID] === true) {
|
|
|
|
repoCfg.Nodes.push({NodeID: nodeID});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete repoCfg.selectedNodes;
|
|
|
|
|
|
|
|
done = false;
|
|
|
|
for (i = 0; i < $scope.repos.length; i++) {
|
|
|
|
if ($scope.repos[i].ID === repoCfg.ID) {
|
|
|
|
$scope.repos[i] = repoCfg;
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
$scope.repos.push(repoCfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.config.Repositories = $scope.repos;
|
|
|
|
|
|
|
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteRepo = function () {
|
|
|
|
$('#editRepo').modal('hide');
|
|
|
|
if (!$scope.editingExisting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.repos = $scope.repos.filter(function (r) {
|
|
|
|
return r.ID !== $scope.currentRepo.ID;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.config.Repositories = $scope.repos;
|
|
|
|
|
|
|
|
$scope.configInSync = false;
|
|
|
|
$http.post('/rest/config', JSON.stringify($scope.config), {headers: {'Content-Type': 'application/json'}});
|
|
|
|
};
|
|
|
|
|
|
|
|
$http.get('/rest/version').success(function (data) {
|
|
|
|
$scope.version = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
$http.get('/rest/system').success(function (data) {
|
|
|
|
$scope.system = data;
|
|
|
|
$scope.myID = data.myID;
|
|
|
|
});
|
|
|
|
|
|
|
|
$http.get('/rest/config').success(function (data) {
|
|
|
|
$scope.config = data;
|
|
|
|
$scope.config.Options.ListenStr = $scope.config.Options.ListenAddress.join(', ');
|
|
|
|
|
|
|
|
var nodes = $scope.config.Nodes;
|
|
|
|
nodes.sort(nodeCompare);
|
|
|
|
$scope.nodes = nodes;
|
|
|
|
|
|
|
|
$scope.repos = $scope.config.Repositories;
|
|
|
|
|
|
|
|
$scope.refresh();
|
|
|
|
});
|
|
|
|
|
|
|
|
$http.get('/rest/config/sync').success(function (data) {
|
|
|
|
$scope.configInSync = data.configInSync;
|
|
|
|
});
|
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
setInterval($scope.refresh, 10000);
|
|
|
|
});
|
|
|
|
|
2014-01-09 23:09:27 +00:00
|
|
|
function decimals(val, num) {
|
2014-02-10 19:54:37 +00:00
|
|
|
var digits, decs;
|
|
|
|
|
|
|
|
if (val === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
digits = Math.floor(Math.log(Math.abs(val)) / Math.log(10));
|
|
|
|
decs = Math.max(0, num - digits);
|
|
|
|
return decs;
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.filter('natural', function () {
|
|
|
|
return function (input, valid) {
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, valid));
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
2014-01-09 23:09:27 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.filter('binary', function () {
|
|
|
|
return function (input) {
|
2014-01-05 22:54:57 +00:00
|
|
|
if (input === undefined) {
|
2014-02-10 19:54:37 +00:00
|
|
|
return '0 ';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1024 * 1024 * 1024) {
|
|
|
|
input /= 1024 * 1024 * 1024;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' Gi';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1024 * 1024) {
|
|
|
|
input /= 1024 * 1024;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' Mi';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1024) {
|
|
|
|
input /= 1024;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' Ki';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
return Math.round(input) + ' ';
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.filter('metric', function () {
|
|
|
|
return function (input) {
|
2014-01-05 22:54:57 +00:00
|
|
|
if (input === undefined) {
|
2014-02-10 19:54:37 +00:00
|
|
|
return '0 ';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1000 * 1000 * 1000) {
|
|
|
|
input /= 1000 * 1000 * 1000;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' G';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1000 * 1000) {
|
|
|
|
input /= 1000 * 1000;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' M';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
if (input > 1000) {
|
|
|
|
input /= 1000;
|
2014-01-09 23:09:27 +00:00
|
|
|
return input.toFixed(decimals(input, 2)) + ' k';
|
2014-01-05 22:54:57 +00:00
|
|
|
}
|
|
|
|
return Math.round(input) + ' ';
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.filter('short', function () {
|
|
|
|
return function (input) {
|
2014-01-05 22:54:57 +00:00
|
|
|
return input.substr(0, 6);
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.filter('alwaysNumber', function () {
|
|
|
|
return function (input) {
|
2014-01-05 22:54:57 +00:00
|
|
|
if (input === undefined) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return input;
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
syncthing.directive('optionEditor', function () {
|
2014-02-01 19:23:19 +00:00
|
|
|
return {
|
|
|
|
restrict: 'C',
|
|
|
|
replace: true,
|
|
|
|
transclude: true,
|
|
|
|
scope: {
|
|
|
|
setting: '=setting',
|
|
|
|
},
|
|
|
|
template: '<input type="text" ng-model="config.Options[setting.id]"></input>',
|
|
|
|
};
|
2014-02-10 19:54:37 +00:00
|
|
|
});
|