2014-06-01 20:50:14 +00:00
|
|
|
// Copyright (C) 2014 Jakob Borg and other contributors. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
/*jslint browser: true, continue: true, plusplus: true */
|
|
|
|
/*global $: false, angular: false */
|
|
|
|
|
2014-05-28 18:06:48 +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', []);
|
2014-04-30 20:02:34 +00:00
|
|
|
var urlbase = 'rest';
|
2014-01-05 22:54:57 +00:00
|
|
|
|
2014-06-04 19:20:07 +00:00
|
|
|
syncthing.config(function ($httpProvider) {
|
|
|
|
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
|
|
|
|
$httpProvider.defaults.xsrfCookieName = 'CSRF-Token';
|
|
|
|
});
|
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
syncthing.controller('SyncthingCtrl', function ($scope, $http) {
|
2014-04-16 13:16:44 +00:00
|
|
|
var prevDate = 0;
|
2014-05-19 22:58:05 +00:00
|
|
|
var getOK = true;
|
2014-04-16 13:16:44 +00:00
|
|
|
var restarting = false;
|
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-05-28 15:26:38 +00:00
|
|
|
$scope.protocolChanged = false;
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.errors = [];
|
|
|
|
$scope.seenError = '';
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.model = {};
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repos = {};
|
2014-06-11 18:04:23 +00:00
|
|
|
$scope.reportData = {};
|
|
|
|
$scope.reportPreview = false;
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.needActions = {
|
|
|
|
'rm': 'Del',
|
|
|
|
'rmdir': 'Del (dir)',
|
|
|
|
'sync': 'Sync',
|
|
|
|
'touch': 'Update',
|
|
|
|
}
|
|
|
|
$scope.needIcons = {
|
|
|
|
'rm': 'remove',
|
|
|
|
'rmdir': 'remove',
|
|
|
|
'sync': 'download',
|
|
|
|
'touch': 'asterisk',
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
// Strings before bools look better
|
|
|
|
$scope.settings = [
|
2014-06-11 18:04:23 +00:00
|
|
|
{id: 'ListenStr', descr: 'Sync Protocol Listen Addresses', type: 'text'},
|
|
|
|
{id: 'MaxSendKbps', descr: 'Outgoing Rate Limit (KiB/s)', type: 'number'},
|
|
|
|
{id: 'RescanIntervalS', descr: 'Rescan Interval (s)', type: 'number'},
|
|
|
|
{id: 'ReconnectIntervalS', descr: 'Reconnect Interval (s)', type: 'number'},
|
|
|
|
{id: 'ParallelRequests', descr: 'Max Outstanding Requests', type: 'number'},
|
|
|
|
{id: 'MaxChangeKbps', descr: 'Max File Change Rate (KiB/s)', type: 'number'},
|
|
|
|
|
|
|
|
{id: 'LocalAnnPort', descr: 'Local Discovery Port', type: 'number'},
|
|
|
|
{id: 'LocalAnnEnabled', descr: 'Local Discovery', type: 'bool'},
|
|
|
|
{id: 'GlobalAnnEnabled', descr: 'Global Discovery', type: 'bool'},
|
2014-04-09 21:00:23 +00:00
|
|
|
{id: 'StartBrowser', descr: 'Start Browser', type: 'bool'},
|
2014-04-18 11:39:51 +00:00
|
|
|
{id: 'UPnPEnabled', descr: 'Enable UPnP', type: 'bool'},
|
2014-06-11 18:04:23 +00:00
|
|
|
{id: 'UREnabled', descr: 'Anonymous Usage Reporting', 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},
|
2014-05-21 12:04:16 +00:00
|
|
|
{id: 'UseTLS', descr: 'Use HTTPS for GUI', type: 'bool', restart: true},
|
2014-06-04 20:00:55 +00:00
|
|
|
{id: 'APIKey', descr: 'API Key', type: 'apikey'},
|
2014-04-09 21:00:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
function getSucceeded() {
|
2014-05-19 22:58:05 +00:00
|
|
|
if (!getOK) {
|
2014-05-11 17:43:38 +00:00
|
|
|
$scope.init();
|
2014-01-09 09:31:27 +00:00
|
|
|
$('#networkError').modal('hide');
|
2014-05-19 22:58:05 +00:00
|
|
|
getOK = true;
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
2014-04-16 13:16:44 +00:00
|
|
|
if (restarting) {
|
2014-05-11 17:43:38 +00:00
|
|
|
$scope.init();
|
2014-04-16 13:16:44 +00:00
|
|
|
$('#restarting').modal('hide');
|
2014-05-24 19:08:53 +00:00
|
|
|
$('#shutdown').modal('hide');
|
2014-04-16 13:16:44 +00:00
|
|
|
restarting = false;
|
|
|
|
}
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
function getFailed() {
|
2014-04-16 13:16:44 +00:00
|
|
|
if (restarting) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-19 22:58:05 +00:00
|
|
|
if (getOK) {
|
2014-01-09 09:31:27 +00:00
|
|
|
$('#networkError').modal({backdrop: 'static', keyboard: false});
|
2014-05-19 22:58:05 +00:00
|
|
|
getOK = false;
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-05 22:54:57 +00:00
|
|
|
$scope.refresh = function () {
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.get(urlbase + '/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();
|
|
|
|
});
|
2014-05-14 10:55:00 +00:00
|
|
|
Object.keys($scope.repos).forEach(function (id) {
|
2014-06-19 22:27:54 +00:00
|
|
|
if (typeof $scope.model[id] === 'undefined') {
|
|
|
|
// Never fetched before
|
|
|
|
$http.get(urlbase + '/model?repo=' + encodeURIComponent(id)).success(function (data) {
|
|
|
|
$scope.model[id] = data;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$http.get(urlbase + '/model/version?repo=' + encodeURIComponent(id)).success(function (data) {
|
|
|
|
if (data.version > $scope.model[id].version) {
|
|
|
|
$http.get(urlbase + '/model?repo=' + encodeURIComponent(id)).success(function (data) {
|
|
|
|
$scope.model[id] = data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.get(urlbase + '/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
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.connections = data;
|
|
|
|
});
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.get(urlbase + '/errors').success(function (data) {
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.errors = data;
|
|
|
|
});
|
2014-01-05 22:54:57 +00:00
|
|
|
};
|
|
|
|
|
2014-04-14 07:58:17 +00:00
|
|
|
$scope.repoStatus = function (repo) {
|
|
|
|
if (typeof $scope.model[repo] === 'undefined') {
|
|
|
|
return 'Unknown';
|
|
|
|
}
|
|
|
|
|
2014-04-27 19:53:27 +00:00
|
|
|
if ($scope.model[repo].invalid !== '') {
|
|
|
|
return 'Stopped';
|
|
|
|
}
|
|
|
|
|
2014-04-14 07:58:17 +00:00
|
|
|
var state = '' + $scope.model[repo].state;
|
|
|
|
state = state[0].toUpperCase() + state.substr(1);
|
|
|
|
|
|
|
|
if (state == "Syncing" || state == "Idle") {
|
|
|
|
state += " (" + $scope.syncPercentage(repo) + "%)";
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-04-14 07:58:17 +00:00
|
|
|
|
|
|
|
$scope.repoClass = function (repo) {
|
|
|
|
if (typeof $scope.model[repo] === 'undefined') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'info';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 19:53:27 +00:00
|
|
|
if ($scope.model[repo].invalid !== '') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'danger';
|
2014-04-27 19:53:27 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 07:58:17 +00:00
|
|
|
var state = '' + $scope.model[repo].state;
|
|
|
|
if (state == 'idle') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'success';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
|
|
|
if (state == 'syncing') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'primary';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'info';
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-04-14 07:58:17 +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;
|
2014-05-20 17:36:37 +00:00
|
|
|
return Math.floor(pct);
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
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) {
|
2014-05-24 19:06:46 +00:00
|
|
|
return 'Up to Date';
|
2014-02-13 11:41:37 +00:00
|
|
|
} 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-05-20 17:36:37 +00:00
|
|
|
$scope.findNode = function (nodeID) {
|
|
|
|
var matches = $scope.nodes.filter(function (n) { return n.NodeID == nodeID; });
|
|
|
|
if (matches.length != 1) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return matches[0];
|
|
|
|
};
|
|
|
|
|
2014-02-05 21:49:26 +00:00
|
|
|
$scope.nodeName = function (nodeCfg) {
|
2014-05-21 19:07:37 +00:00
|
|
|
if (typeof nodeCfg === 'undefined') {
|
|
|
|
return "";
|
|
|
|
}
|
2014-02-05 21:49:26 +00:00
|
|
|
if (nodeCfg.Name) {
|
|
|
|
return nodeCfg.Name;
|
|
|
|
}
|
|
|
|
return nodeCfg.NodeID.substr(0, 6);
|
|
|
|
};
|
|
|
|
|
2014-05-16 16:42:22 +00:00
|
|
|
$scope.thisNodeName = function () {
|
2014-05-20 17:36:37 +00:00
|
|
|
var node = $scope.thisNode();
|
|
|
|
if (typeof node === 'undefined') {
|
2014-05-16 16:42:22 +00:00
|
|
|
return "(unknown node)";
|
|
|
|
}
|
2014-05-20 17:36:37 +00:00
|
|
|
if (node.Name) {
|
|
|
|
return node.Name;
|
2014-05-16 16:42:22 +00:00
|
|
|
}
|
2014-05-20 17:36:37 +00:00
|
|
|
return node.NodeID.substr(0, 6);
|
2014-05-16 16:42:22 +00:00
|
|
|
};
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editSettings = function () {
|
2014-05-21 19:54:16 +00:00
|
|
|
// Make a working copy
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.tmpOptions = angular.copy($scope.config.Options);
|
|
|
|
$scope.tmpOptions.UREnabled = ($scope.tmpOptions.URAccepted > 0);
|
|
|
|
$scope.tmpGUI = angular.copy($scope.config.GUI);
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#settings').modal({backdrop: 'static', keyboard: true});
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-06-07 02:00:46 +00:00
|
|
|
$scope.saveConfig = function() {
|
|
|
|
var cfg = JSON.stringify($scope.config);
|
|
|
|
var opts = {headers: {'Content-Type': 'application/json'}};
|
|
|
|
$http.post(urlbase + '/config', cfg, opts).success(function () {
|
|
|
|
$http.get(urlbase + '/config/sync').success(function (data) {
|
|
|
|
$scope.configInSync = data.configInSync;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.saveSettings = function () {
|
2014-05-21 18:35:51 +00:00
|
|
|
// Make sure something changed
|
2014-06-17 21:22:19 +00:00
|
|
|
var changed = !angular.equals($scope.config.Options, $scope.tmpOptions) ||
|
|
|
|
!angular.equals($scope.config.GUI, $scope.tmpGUI);
|
|
|
|
if (changed) {
|
|
|
|
// Check if usage reporting has been enabled or disabled
|
|
|
|
if ($scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted <= 0) {
|
|
|
|
$scope.tmpOptions.URAccepted = 1000;
|
|
|
|
} else if (!$scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted > 0){
|
|
|
|
$scope.tmpOptions.URAccepted = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if protocol will need to be changed on restart
|
|
|
|
if($scope.config.GUI.UseTLS !== $scope.tmpGUI.UseTLS){
|
2014-05-28 15:26:38 +00:00
|
|
|
$scope.protocolChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply new settings locally
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.config.Options = angular.copy($scope.tmpOptions);
|
|
|
|
$scope.config.GUI = angular.copy($scope.tmpGUI);
|
2014-05-21 18:35:51 +00:00
|
|
|
$scope.config.Options.ListenAddress = $scope.config.Options.ListenStr.split(',').map(function (x) { return x.trim(); });
|
2014-06-07 02:00:46 +00:00
|
|
|
|
|
|
|
$scope.saveConfig();
|
2014-05-21 18:35:51 +00:00
|
|
|
}
|
2014-05-24 19:01:21 +00:00
|
|
|
|
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 () {
|
2014-04-16 13:16:44 +00:00
|
|
|
restarting = true;
|
2014-05-21 17:35:56 +00:00
|
|
|
$('#restarting').modal({backdrop: 'static', keyboard: false});
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.post(urlbase + '/restart');
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.configInSync = true;
|
2014-05-28 15:26:38 +00:00
|
|
|
|
|
|
|
// Switch webpage protocol if needed
|
|
|
|
if($scope.protocolChanged){
|
|
|
|
var protocol = 'http';
|
|
|
|
|
|
|
|
if($scope.config.GUI.UseTLS){
|
|
|
|
protocol = 'https';
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
window.location.protocol = protocol;
|
|
|
|
}, 1000);
|
2014-05-28 15:29:08 +00:00
|
|
|
|
|
|
|
$scope.protocolChanged = false;
|
2014-05-28 15:26:38 +00:00
|
|
|
}
|
2014-02-12 11:10:44 +00:00
|
|
|
};
|
|
|
|
|
2014-05-20 17:36:37 +00:00
|
|
|
$scope.shutdown = function () {
|
2014-05-21 17:35:56 +00:00
|
|
|
restarting = true;
|
2014-05-20 17:36:37 +00:00
|
|
|
$http.post(urlbase + '/shutdown').success(function () {
|
2014-05-21 17:35:56 +00:00
|
|
|
$('#shutdown').modal({backdrop: 'static', keyboard: false});
|
2014-05-20 17:36:37 +00:00
|
|
|
});
|
|
|
|
$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-04-22 10:01:09 +00:00
|
|
|
$scope.editingSelf = (nodeCfg.NodeID == $scope.myID);
|
2014-02-11 13:34:47 +00:00
|
|
|
$scope.currentNode.AddressesStr = nodeCfg.Addresses.join(', ');
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.nodeEditor.$setPristine();
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#editNode').modal({backdrop: 'static', keyboard: true});
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-05-21 18:06:14 +00:00
|
|
|
$scope.idNode = function () {
|
|
|
|
$('#idqr').modal('show');
|
|
|
|
};
|
|
|
|
|
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-22 10:01:09 +00:00
|
|
|
$scope.editingSelf = false;
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.nodeEditor.$setPristine();
|
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-05-21 19:06:20 +00:00
|
|
|
for (var id in $scope.repos) {
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repos[id].Nodes = $scope.repos[id].Nodes.filter(function (n) {
|
2014-04-09 21:00:23 +00:00
|
|
|
return n.NodeID !== $scope.currentNode.NodeID;
|
|
|
|
});
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-06-07 02:00:46 +00:00
|
|
|
$scope.saveConfig();
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
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-01 19:23:19 +00:00
|
|
|
$('#editNode').modal('hide');
|
|
|
|
nodeCfg = $scope.currentNode;
|
2014-06-29 23:42:03 +00:00
|
|
|
nodeCfg.NodeID = nodeCfg.NodeID.replace(/ /g, '').replace(/-/g, '').toLowerCase().trim();
|
2014-02-01 19:23:19 +00:00
|
|
|
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-06-07 02:00:46 +00:00
|
|
|
$scope.saveConfig();
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$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) {
|
2014-05-20 17:36:37 +00:00
|
|
|
return n;
|
2014-02-10 19:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-05-20 17:36:37 +00:00
|
|
|
$scope.allNodes = function () {
|
|
|
|
var nodes = $scope.otherNodes();
|
|
|
|
nodes.push($scope.thisNode());
|
|
|
|
return nodes;
|
|
|
|
};
|
|
|
|
|
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;
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.post(urlbase + '/error/clear');
|
2014-02-12 22:18:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$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-05-14 10:55:00 +00:00
|
|
|
$scope.repoList = function () {
|
|
|
|
return repoList($scope.repos);
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-05-14 10:55:00 +00:00
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editRepo = function (nodeCfg) {
|
2014-05-25 18:49:08 +00:00
|
|
|
$scope.currentRepo = angular.copy(nodeCfg);
|
|
|
|
$scope.currentRepo.selectedNodes = {};
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.currentRepo.Nodes.forEach(function (n) {
|
|
|
|
$scope.currentRepo.selectedNodes[n.NodeID] = true;
|
|
|
|
});
|
2014-05-25 18:49:08 +00:00
|
|
|
if ($scope.currentRepo.Versioning && $scope.currentRepo.Versioning.Type === "simple") {
|
|
|
|
$scope.currentRepo.simpleFileVersioning = true;
|
|
|
|
$scope.currentRepo.simpleKeep = +$scope.currentRepo.Versioning.Params.keep;
|
|
|
|
}
|
|
|
|
$scope.currentRepo.simpleKeep = $scope.currentRepo.simpleKeep || 5;
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editingExisting = true;
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repoEditor.$setPristine();
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#editRepo').modal({backdrop: 'static', keyboard: true});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addRepo = function () {
|
|
|
|
$scope.currentRepo = {selectedNodes: {}};
|
|
|
|
$scope.editingExisting = false;
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repoEditor.$setPristine();
|
2014-04-09 21:00:23 +00:00
|
|
|
$('#editRepo').modal({backdrop: 'static', keyboard: true});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.saveRepo = function () {
|
|
|
|
var repoCfg, done, i;
|
|
|
|
|
|
|
|
$('#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;
|
|
|
|
|
2014-05-25 18:49:08 +00:00
|
|
|
if (repoCfg.simpleFileVersioning) {
|
|
|
|
repoCfg.Versioning = {
|
|
|
|
'Type': 'simple',
|
|
|
|
'Params': {
|
|
|
|
'keep': '' + repoCfg.simpleKeep,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
delete repoCfg.simpleFileVersioning;
|
|
|
|
delete repoCfg.simpleKeep;
|
|
|
|
} else {
|
|
|
|
delete repoCfg.Versioning;
|
|
|
|
}
|
|
|
|
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repos[repoCfg.ID] = repoCfg;
|
|
|
|
$scope.config.Repositories = repoList($scope.repos);
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-06-07 02:00:46 +00:00
|
|
|
$scope.saveConfig();
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
2014-05-24 19:13:35 +00:00
|
|
|
$scope.sharesRepo = function(repoCfg) {
|
|
|
|
var names = [];
|
|
|
|
repoCfg.Nodes.forEach(function (node) {
|
|
|
|
names.push($scope.nodeName($scope.findNode(node.NodeID)));
|
|
|
|
});
|
|
|
|
names.sort();
|
|
|
|
return names.join(", ");
|
|
|
|
};
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.deleteRepo = function () {
|
|
|
|
$('#editRepo').modal('hide');
|
|
|
|
if (!$scope.editingExisting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-14 10:55:00 +00:00
|
|
|
delete $scope.repos[$scope.currentRepo.ID];
|
|
|
|
$scope.config.Repositories = repoList($scope.repos);
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-06-07 02:00:46 +00:00
|
|
|
$scope.saveConfig();
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
2014-06-04 20:00:55 +00:00
|
|
|
$scope.setAPIKey = function (cfg) {
|
|
|
|
cfg.APIKey = randomString(30, 32);
|
|
|
|
};
|
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$scope.init = function() {
|
|
|
|
$http.get(urlbase + '/version').success(function (data) {
|
|
|
|
$scope.version = data;
|
|
|
|
});
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$http.get(urlbase + '/system').success(function (data) {
|
|
|
|
$scope.system = data;
|
|
|
|
$scope.myID = data.myID;
|
|
|
|
});
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$http.get(urlbase + '/config').success(function (data) {
|
|
|
|
$scope.config = data;
|
|
|
|
$scope.config.Options.ListenStr = $scope.config.Options.ListenAddress.join(', ');
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-11 18:25:06 +00:00
|
|
|
$scope.nodes = $scope.config.Nodes;
|
|
|
|
$scope.nodes.sort(nodeCompare);
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-14 10:55:00 +00:00
|
|
|
$scope.repos = repoMap($scope.config.Repositories);
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$scope.refresh();
|
2014-06-11 18:04:23 +00:00
|
|
|
|
2014-06-17 21:22:19 +00:00
|
|
|
if ($scope.config.Options.URAccepted == 0) {
|
2014-06-11 18:04:23 +00:00
|
|
|
// If usage reporting has been neither accepted nor declined,
|
|
|
|
// we want to ask the user to make a choice. But we don't want
|
|
|
|
// to bug them during initial setup, so we set a cookie with
|
|
|
|
// the time of the first visit. When that cookie is present
|
|
|
|
// and the time is more than four hours ago, we ask the
|
|
|
|
// question.
|
|
|
|
|
|
|
|
var firstVisit = document.cookie.replace(/(?:(?:^|.*;\s*)firstVisit\s*\=\s*([^;]*).*$)|^.*$/, "$1");
|
|
|
|
if (!firstVisit) {
|
|
|
|
document.cookie = "firstVisit=" + Date.now() + ";max-age=" + 30*24*3600;
|
|
|
|
} else {
|
|
|
|
if (+firstVisit < Date.now() - 4*3600*1000){
|
|
|
|
$('#ur').modal({backdrop: 'static', keyboard: false});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-11 17:43:38 +00:00
|
|
|
});
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$http.get(urlbase + '/config/sync').success(function (data) {
|
|
|
|
$scope.configInSync = data.configInSync;
|
|
|
|
});
|
2014-06-11 18:04:23 +00:00
|
|
|
|
|
|
|
$http.get(urlbase + '/report').success(function (data) {
|
|
|
|
$scope.reportData = data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.acceptUR = function () {
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.config.Options.URAccepted = 1000; // Larger than the largest existing report version
|
2014-06-11 18:04:23 +00:00
|
|
|
$scope.saveConfig();
|
|
|
|
$('#ur').modal('hide');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.declineUR = function () {
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.config.Options.URAccepted = -1;
|
2014-06-11 18:04:23 +00:00
|
|
|
$scope.saveConfig();
|
|
|
|
$('#ur').modal('hide');
|
2014-05-11 17:43:38 +00:00
|
|
|
};
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.showNeed = function (repo) {
|
|
|
|
$scope.neededLoaded = false;
|
|
|
|
$('#needed').modal({backdrop: 'static', keyboard: true});
|
|
|
|
$http.get(urlbase + "/need?repo=" + encodeURIComponent(repo)).success(function (data) {
|
|
|
|
$scope.needed = data;
|
|
|
|
$scope.neededLoaded = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.needAction = function (file) {
|
|
|
|
var fDelete = 4096;
|
|
|
|
var fDirectory = 16384;
|
|
|
|
|
|
|
|
if ((file.Flags & (fDelete+fDirectory)) === fDelete+fDirectory) {
|
|
|
|
return 'rmdir';
|
|
|
|
} else if ((file.Flags & fDelete) === fDelete) {
|
|
|
|
return 'rm';
|
|
|
|
} else if ((file.Flags & fDirectory) === fDirectory) {
|
|
|
|
return 'touch';
|
|
|
|
} else {
|
|
|
|
return 'sync';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-16 08:47:02 +00:00
|
|
|
$scope.override = function (repo) {
|
|
|
|
$http.post(urlbase + "/model/override?repo=" + encodeURIComponent(repo)).success(function () {
|
|
|
|
$scope.refresh();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-07-07 10:58:56 +00:00
|
|
|
$scope.about = function () {
|
|
|
|
$('#about').modal('show');
|
|
|
|
};
|
|
|
|
|
2014-05-11 17:43:38 +00:00
|
|
|
$scope.init();
|
2014-05-19 22:58:05 +00:00
|
|
|
setInterval($scope.refresh, 10000);
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
|
|
|
|
2014-05-14 10:55:00 +00:00
|
|
|
function nodeCompare(a, b) {
|
|
|
|
if (typeof a.Name !== 'undefined' && typeof b.Name !== 'undefined') {
|
|
|
|
if (a.Name < b.Name)
|
|
|
|
return -1;
|
|
|
|
return a.Name > b.Name;
|
|
|
|
}
|
|
|
|
if (a.NodeID < b.NodeID) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return a.NodeID > b.NodeID;
|
|
|
|
}
|
|
|
|
|
|
|
|
function repoCompare(a, b) {
|
|
|
|
if (a.Directory < b.Directory) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return a.Directory > b.Directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
function repoMap(l) {
|
|
|
|
var m = {};
|
|
|
|
l.forEach(function (r) {
|
|
|
|
m[r.ID] = r;
|
|
|
|
});
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
function repoList(m) {
|
|
|
|
var l = [];
|
|
|
|
for (var id in m) {
|
2014-05-28 15:26:38 +00:00
|
|
|
l.push(m[id]);
|
2014-05-14 10:55:00 +00:00
|
|
|
}
|
|
|
|
l.sort(repoCompare);
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
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-06-04 20:00:55 +00:00
|
|
|
function randomString(len, bits)
|
|
|
|
{
|
|
|
|
bits = bits || 36;
|
|
|
|
var outStr = "", newStr;
|
|
|
|
while (outStr.length < len)
|
|
|
|
{
|
|
|
|
newStr = Math.random().toString(bits).slice(2);
|
|
|
|
outStr += newStr.slice(0, Math.min(newStr.length, (len - outStr.length)));
|
|
|
|
}
|
2014-06-29 23:42:03 +00:00
|
|
|
return outStr.toLowerCase();
|
2014-06-04 20:00:55 +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-05-20 17:36:37 +00:00
|
|
|
syncthing.filter('shortPath', function () {
|
|
|
|
return function (input) {
|
|
|
|
if (input === undefined)
|
|
|
|
return "";
|
|
|
|
var parts = input.split(/[\/\\]/);
|
|
|
|
if (!parts || parts.length <= 3) {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
return ".../" + parts.slice(parts.length-2).join("/");
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-05-13 04:58:04 +00:00
|
|
|
});
|
|
|
|
|
2014-06-14 08:58:36 +00:00
|
|
|
syncthing.filter('basename', function () {
|
|
|
|
return function (input) {
|
|
|
|
if (input === undefined)
|
|
|
|
return "";
|
|
|
|
var parts = input.split(/[\/\\]/);
|
|
|
|
if (!parts || parts.length < 1) {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
return parts[parts.length-1];
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-05-28 03:16:11 +00:00
|
|
|
syncthing.filter('clean', function () {
|
|
|
|
return function (input) {
|
|
|
|
return encodeURIComponent(input).replace(/%/g, '');
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-05-28 03:16:11 +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
|
|
|
});
|
2014-05-14 10:55:00 +00:00
|
|
|
|
|
|
|
syncthing.directive('uniqueRepo', function() {
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elm, attrs, ctrl) {
|
|
|
|
ctrl.$parsers.unshift(function(viewValue) {
|
|
|
|
if (scope.editingExisting) {
|
|
|
|
// we shouldn't validate
|
|
|
|
ctrl.$setValidity('uniqueRepo', true);
|
|
|
|
} else if (scope.repos[viewValue]) {
|
|
|
|
// the repo exists already
|
|
|
|
ctrl.$setValidity('uniqueRepo', false);
|
|
|
|
} else {
|
|
|
|
// the repo is unique
|
|
|
|
ctrl.$setValidity('uniqueRepo', true);
|
|
|
|
}
|
|
|
|
return viewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-05-28 03:16:11 +00:00
|
|
|
|
|
|
|
syncthing.directive('validNodeid', function() {
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elm, attrs, ctrl) {
|
|
|
|
ctrl.$parsers.unshift(function(viewValue) {
|
|
|
|
if (scope.editingExisting) {
|
|
|
|
// we shouldn't validate
|
|
|
|
ctrl.$setValidity('validNodeid', true);
|
|
|
|
} else {
|
2014-06-29 23:42:03 +00:00
|
|
|
var cleaned = viewValue.replace(/ /g, '').replace(/-/g, '').toLowerCase().trim();
|
|
|
|
if (cleaned.match(/^[a-z2-7]{52}$/)) {
|
2014-05-28 03:16:11 +00:00
|
|
|
ctrl.$setValidity('validNodeid', true);
|
|
|
|
} else {
|
|
|
|
ctrl.$setValidity('validNodeid', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return viewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|