2014-07-12 22:45:33 +00:00
|
|
|
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
2014-09-29 19:43:32 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
// more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-06-01 20:50:14 +00:00
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
/*jslint browser: true, continue: true, plusplus: true */
|
2014-09-18 18:05:05 +00:00
|
|
|
/*global $: false, angular: false, console: false, validLangs: false */
|
2014-02-10 19:54:37 +00:00
|
|
|
|
2014-05-28 18:06:48 +00:00
|
|
|
'use strict';
|
2014-02-10 19:54:37 +00:00
|
|
|
|
2014-07-20 11:49:26 +00:00
|
|
|
var syncthing = angular.module('syncthing', ['pascalprecht.translate']);
|
2014-04-30 20:02:34 +00:00
|
|
|
var urlbase = 'rest';
|
2014-10-06 22:42:13 +00:00
|
|
|
var guiVersion = null;
|
2014-01-05 22:54:57 +00:00
|
|
|
|
2014-07-20 11:49:26 +00:00
|
|
|
syncthing.config(function ($httpProvider, $translateProvider) {
|
2014-06-04 19:20:07 +00:00
|
|
|
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
|
|
|
|
$httpProvider.defaults.xsrfCookieName = 'CSRF-Token';
|
2014-10-06 22:42:13 +00:00
|
|
|
$httpProvider.interceptors.push(function() {
|
|
|
|
return {
|
|
|
|
response: function(response) {
|
|
|
|
var responseVersion = response.headers()['x-syncthing-version'];
|
|
|
|
if (!guiVersion) {
|
|
|
|
guiVersion = responseVersion;
|
|
|
|
} else if (guiVersion != responseVersion) {
|
|
|
|
document.location.reload(true);
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-07-20 11:49:26 +00:00
|
|
|
|
|
|
|
$translateProvider.useStaticFilesLoader({
|
2014-09-04 06:53:28 +00:00
|
|
|
prefix: 'lang/lang-',
|
2014-07-20 11:49:26 +00:00
|
|
|
suffix: '.json'
|
|
|
|
});
|
2014-06-04 19:20:07 +00:00
|
|
|
});
|
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
syncthing.controller('EventCtrl', function ($scope, $http) {
|
|
|
|
$scope.lastEvent = null;
|
|
|
|
var lastID = 0;
|
|
|
|
|
|
|
|
var successFn = function (data) {
|
2014-08-29 22:24:26 +00:00
|
|
|
// When Syncthing restarts while the long polling connection is in
|
|
|
|
// progress the browser on some platforms returns a 200 (since the
|
|
|
|
// headers has been flushed with the return code 200), with no data.
|
|
|
|
// This basically means that the connection has been reset, and the call
|
|
|
|
// was not actually sucessful.
|
|
|
|
if (!data) {
|
|
|
|
errorFn(data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-24 23:04:12 +00:00
|
|
|
$scope.$emit('UIOnline');
|
2014-07-29 09:06:52 +00:00
|
|
|
|
|
|
|
if (lastID > 0) {
|
|
|
|
data.forEach(function (event) {
|
2014-07-29 09:54:00 +00:00
|
|
|
console.log("event", event.id, event.type, event.data);
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.$emit(event.type, event);
|
|
|
|
});
|
2014-09-18 18:05:05 +00:00
|
|
|
}
|
2014-07-29 09:06:52 +00:00
|
|
|
|
|
|
|
$scope.lastEvent = data[data.length - 1];
|
|
|
|
lastID = $scope.lastEvent.id;
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
$http.get(urlbase + '/events?since=' + lastID)
|
2014-09-18 18:05:05 +00:00
|
|
|
.success(successFn)
|
|
|
|
.error(errorFn);
|
2014-07-29 09:06:52 +00:00
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
|
|
|
var errorFn = function (data) {
|
2014-08-24 23:04:12 +00:00
|
|
|
$scope.$emit('UIOffline');
|
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
setTimeout(function () {
|
2014-07-29 09:59:11 +00:00
|
|
|
$http.get(urlbase + '/events?limit=1')
|
2014-09-18 18:05:05 +00:00
|
|
|
.success(successFn)
|
|
|
|
.error(errorFn);
|
2014-07-29 09:59:11 +00:00
|
|
|
}, 1000);
|
2014-07-29 09:06:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$http.get(urlbase + '/events?limit=1')
|
|
|
|
.success(successFn)
|
|
|
|
.error(errorFn);
|
|
|
|
});
|
|
|
|
|
2014-07-22 18:27:36 +00:00
|
|
|
syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $location) {
|
2014-04-16 13:16:44 +00:00
|
|
|
var prevDate = 0;
|
2014-05-19 22:58:05 +00:00
|
|
|
var getOK = true;
|
2014-08-24 23:04:12 +00:00
|
|
|
var navigatingAway = false;
|
|
|
|
var online = false;
|
2014-04-16 13:16:44 +00:00
|
|
|
var restarting = false;
|
2014-01-09 09:31:27 +00:00
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.completion = {};
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.config = {};
|
2014-02-12 11:10:44 +00:00
|
|
|
$scope.configInSync = true;
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.connections = {};
|
2014-02-12 22:18:41 +00:00
|
|
|
$scope.errors = [];
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.model = {};
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.myID = '';
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.devices = [];
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.protocolChanged = false;
|
2014-06-11 18:04:23 +00:00
|
|
|
$scope.reportData = {};
|
|
|
|
$scope.reportPreview = false;
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folders = {};
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.seenError = '';
|
2014-09-30 22:01:32 +00:00
|
|
|
$scope.upgradeInfo = null;
|
2014-08-22 19:35:22 +00:00
|
|
|
$scope.stats = {};
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
$http.get(urlbase + "/lang").success(function (langs) {
|
2014-08-14 15:04:17 +00:00
|
|
|
// Find the first language in the list provided by the user's browser
|
|
|
|
// that is a prefix of a language we have available. That is, "en"
|
|
|
|
// sent by the browser will match "en" or "en-US", while "zh-TW" will
|
|
|
|
// match only "zh-TW" and not "zh-CN".
|
|
|
|
|
|
|
|
var lang, matching;
|
2014-07-26 20:30:29 +00:00
|
|
|
for (var i = 0; i < langs.length; i++) {
|
|
|
|
lang = langs[i];
|
2014-08-28 11:23:23 +00:00
|
|
|
if (lang.length < 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
matching = validLangs.filter(function (possibleLang) {
|
|
|
|
// The langs returned by the /rest/langs call will be in lower
|
|
|
|
// case. We compare to the lowercase version of the language
|
|
|
|
// code we have as well.
|
2014-09-18 18:05:05 +00:00
|
|
|
possibleLang = possibleLang.toLowerCase();
|
2014-08-28 11:23:23 +00:00
|
|
|
if (possibleLang.length > lang.length) {
|
2014-09-18 18:05:05 +00:00
|
|
|
return possibleLang.indexOf(lang) === 0;
|
2014-08-28 11:23:23 +00:00
|
|
|
} else {
|
2014-09-18 18:05:05 +00:00
|
|
|
return lang.indexOf(possibleLang) === 0;
|
2014-08-28 11:23:23 +00:00
|
|
|
}
|
2014-08-14 15:04:17 +00:00
|
|
|
});
|
|
|
|
if (matching.length >= 1) {
|
|
|
|
$translate.use(matching[0]);
|
2014-08-28 11:23:23 +00:00
|
|
|
return;
|
2014-07-26 20:30:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-28 11:23:23 +00:00
|
|
|
// Fallback if nothing matched
|
|
|
|
$translate.use("en");
|
2014-09-18 18:05:05 +00:00
|
|
|
});
|
2014-07-26 20:30:29 +00:00
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
$(window).bind('beforeunload', function () {
|
2014-08-24 23:04:12 +00:00
|
|
|
navigatingAway = true;
|
|
|
|
});
|
|
|
|
|
2014-07-22 18:27:36 +00:00
|
|
|
$scope.$on("$locationChangeSuccess", function () {
|
|
|
|
var lang = $location.search().lang;
|
|
|
|
if (lang) {
|
|
|
|
$translate.use(lang);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.needActions = {
|
|
|
|
'rm': 'Del',
|
|
|
|
'rmdir': 'Del (dir)',
|
|
|
|
'sync': 'Sync',
|
|
|
|
'touch': 'Update',
|
2014-09-18 18:05:05 +00:00
|
|
|
};
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.needIcons = {
|
|
|
|
'rm': 'remove',
|
|
|
|
'rmdir': 'remove',
|
|
|
|
'sync': 'download',
|
|
|
|
'touch': 'asterisk',
|
2014-09-18 18:05:05 +00:00
|
|
|
};
|
2014-06-14 08:58:36 +00:00
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.$on('UIOnline', function (event, arg) {
|
2014-08-24 23:04:12 +00:00
|
|
|
if (online && !restarting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-06 22:42:13 +00:00
|
|
|
console.log('UIOnline');
|
|
|
|
$scope.init();
|
|
|
|
online = true;
|
|
|
|
restarting = false;
|
|
|
|
$('#networkError').modal('hide');
|
|
|
|
$('#restarting').modal('hide');
|
|
|
|
$('#shutdown').modal('hide');
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('UIOffline', function (event, arg) {
|
2014-08-24 23:04:12 +00:00
|
|
|
if (navigatingAway || !online) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-29 09:59:11 +00:00
|
|
|
console.log('UIOffline');
|
2014-08-24 23:04:12 +00:00
|
|
|
online = false;
|
2014-07-29 09:06:52 +00:00
|
|
|
if (!restarting) {
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#networkError').modal();
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('StateChanged', function (event, arg) {
|
|
|
|
var data = arg.data;
|
2014-09-28 11:00:38 +00:00
|
|
|
if ($scope.model[data.folder]) {
|
|
|
|
$scope.model[data.folder].state = data.to;
|
2014-04-16 13:16:44 +00:00
|
|
|
}
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
2014-01-09 09:31:27 +00:00
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.$on('LocalIndexUpdated', function (event, arg) {
|
|
|
|
var data = arg.data;
|
2014-09-28 11:00:38 +00:00
|
|
|
refreshFolder(data.folder);
|
2014-07-29 09:06:52 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
// Update completion status for all devices that we share this folder with.
|
|
|
|
$scope.folders[data.folder].Devices.forEach(function (deviceCfg) {
|
|
|
|
refreshCompletion(deviceCfg.DeviceID, data.folder);
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('RemoteIndexUpdated', function (event, arg) {
|
|
|
|
var data = arg.data;
|
2014-09-28 11:00:38 +00:00
|
|
|
refreshFolder(data.folder);
|
|
|
|
refreshCompletion(data.device, data.folder);
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.$on('DeviceDisconnected', function (event, arg) {
|
2014-07-29 09:06:52 +00:00
|
|
|
delete $scope.connections[arg.data.id];
|
2014-09-28 11:00:38 +00:00
|
|
|
refreshDeviceStats();
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.$on('DeviceConnected', function (event, arg) {
|
2014-07-29 09:06:52 +00:00
|
|
|
if (!$scope.connections[arg.data.id]) {
|
|
|
|
$scope.connections[arg.data.id] = {
|
|
|
|
inbps: 0,
|
|
|
|
outbps: 0,
|
|
|
|
InBytesTotal: 0,
|
|
|
|
OutBytesTotal: 0,
|
|
|
|
Address: arg.data.addr,
|
|
|
|
};
|
2014-08-05 18:16:25 +00:00
|
|
|
$scope.completion[arg.data.id] = {
|
|
|
|
_total: 100,
|
|
|
|
};
|
2014-04-16 13:16:44 +00:00
|
|
|
}
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('ConfigLoaded', function (event) {
|
2014-09-18 18:05:05 +00:00
|
|
|
if ($scope.config.Options.URAccepted === 0) {
|
2014-07-29 09:06:52 +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) {
|
2014-09-18 18:05:05 +00:00
|
|
|
document.cookie = "firstVisit=" + Date.now() + ";max-age=" + 30 * 24 * 3600;
|
2014-07-29 09:06:52 +00:00
|
|
|
} else {
|
2014-09-18 18:05:05 +00:00
|
|
|
if (+firstVisit < Date.now() - 4 * 3600 * 1000) {
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#ur').modal();
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
2014-09-18 18:05:05 +00:00
|
|
|
});
|
2014-07-29 09:06:52 +00:00
|
|
|
|
2014-09-06 16:17:32 +00:00
|
|
|
$scope.$on('ConfigSaved', function (event, arg) {
|
|
|
|
updateLocalConfig(arg.data);
|
|
|
|
|
|
|
|
$http.get(urlbase + '/config/sync').success(function (data) {
|
|
|
|
$scope.configInSync = data.configInSync;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-09-24 19:59:28 +00:00
|
|
|
var debouncedFuncs = {};
|
2014-07-29 09:54:00 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
function refreshFolder(folder) {
|
|
|
|
var key = "refreshFolder" + folder;
|
2014-09-24 19:59:28 +00:00
|
|
|
if (!debouncedFuncs[key]) {
|
|
|
|
debouncedFuncs[key] = debounce(function () {
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.get(urlbase + '/model?folder=' + encodeURIComponent(folder)).success(function (data) {
|
|
|
|
$scope.model[folder] = data;
|
|
|
|
console.log("refreshFolder", folder, data);
|
2014-09-24 19:59:28 +00:00
|
|
|
});
|
|
|
|
}, 1000, true);
|
2014-07-29 09:54:00 +00:00
|
|
|
}
|
2014-09-24 19:59:28 +00:00
|
|
|
debouncedFuncs[key]();
|
2014-01-09 09:31:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-06 16:17:32 +00:00
|
|
|
function updateLocalConfig(config) {
|
|
|
|
var hasConfig = !isEmptyObject($scope.config);
|
|
|
|
|
|
|
|
$scope.config = config;
|
|
|
|
$scope.config.Options.ListenStr = $scope.config.Options.ListenAddress.join(', ');
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.devices = $scope.config.Devices;
|
|
|
|
$scope.devices.forEach(function (deviceCfg) {
|
|
|
|
$scope.completion[deviceCfg.DeviceID] = {
|
2014-09-06 16:17:32 +00:00
|
|
|
_total: 100,
|
|
|
|
};
|
|
|
|
});
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.devices.sort(deviceCompare);
|
2014-09-06 16:17:32 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folders = folderMap($scope.config.Folders);
|
|
|
|
Object.keys($scope.folders).forEach(function (folder) {
|
|
|
|
refreshFolder(folder);
|
|
|
|
$scope.folders[folder].Devices.forEach(function (deviceCfg) {
|
|
|
|
refreshCompletion(deviceCfg.DeviceID, folder);
|
2014-09-06 16:17:32 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!hasConfig) {
|
|
|
|
$scope.$emit('ConfigLoaded');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 09:06:52 +00:00
|
|
|
function refreshSystem() {
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.get(urlbase + '/system').success(function (data) {
|
2014-07-29 09:06:52 +00:00
|
|
|
$scope.myID = data.myID;
|
2014-01-09 23:09:27 +00:00
|
|
|
$scope.system = data;
|
2014-07-29 09:54:00 +00:00
|
|
|
console.log("refreshSystem", data);
|
2014-04-09 21:00:23 +00:00
|
|
|
});
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
function refreshCompletion(device, folder) {
|
|
|
|
if (device === $scope.myID) {
|
2014-09-18 18:05:05 +00:00
|
|
|
return;
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
var key = "refreshCompletion" + device + folder;
|
2014-09-24 19:59:28 +00:00
|
|
|
if (!debouncedFuncs[key]) {
|
|
|
|
debouncedFuncs[key] = debounce(function () {
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.get(urlbase + '/completion?device=' + device + '&folder=' + encodeURIComponent(folder)).success(function (data) {
|
|
|
|
if (!$scope.completion[device]) {
|
|
|
|
$scope.completion[device] = {};
|
2014-09-24 19:59:28 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.completion[device][folder] = data.completion;
|
2014-09-24 19:59:28 +00:00
|
|
|
|
|
|
|
var tot = 0,
|
|
|
|
cnt = 0;
|
2014-09-28 11:00:38 +00:00
|
|
|
for (var cmp in $scope.completion[device]) {
|
2014-09-24 19:59:28 +00:00
|
|
|
if (cmp === "_total") {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
tot += $scope.completion[device][cmp];
|
2014-09-24 19:59:28 +00:00
|
|
|
cnt += 1;
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.completion[device]._total = tot / cnt;
|
2014-09-24 19:59:28 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
console.log("refreshCompletion", device, folder, $scope.completion[device]);
|
2014-09-24 19:59:28 +00:00
|
|
|
});
|
|
|
|
}, 1000, true);
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
2014-09-24 19:59:28 +00:00
|
|
|
debouncedFuncs[key]();
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshConnectionStats() {
|
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-09-18 18:05:05 +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-07-29 09:54:00 +00:00
|
|
|
console.log("refreshConnections", data);
|
2014-01-05 22:54:57 +00:00
|
|
|
});
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshErrors() {
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.get(urlbase + '/errors').success(function (data) {
|
2014-09-18 10:49:59 +00:00
|
|
|
$scope.errors = data.errors;
|
2014-07-29 09:54:00 +00:00
|
|
|
console.log("refreshErrors", data);
|
2014-02-12 22:18:41 +00:00
|
|
|
});
|
2014-07-29 09:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function refreshConfig() {
|
|
|
|
$http.get(urlbase + '/config').success(function (data) {
|
2014-09-06 16:17:32 +00:00
|
|
|
updateLocalConfig(data);
|
2014-07-29 09:54:00 +00:00
|
|
|
console.log("refreshConfig", data);
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$http.get(urlbase + '/config/sync').success(function (data) {
|
|
|
|
$scope.configInSync = data.configInSync;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
var refreshDeviceStats = debounce(function () {
|
|
|
|
$http.get(urlbase + "/stats/device").success(function (data) {
|
2014-08-22 19:35:22 +00:00
|
|
|
$scope.stats = data;
|
2014-09-28 11:00:38 +00:00
|
|
|
for (var device in $scope.stats) {
|
|
|
|
$scope.stats[device].LastSeen = new Date($scope.stats[device].LastSeen);
|
|
|
|
$scope.stats[device].LastSeenDays = (new Date() - $scope.stats[device].LastSeen) / 1000 / 86400;
|
2014-09-14 21:16:15 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
console.log("refreshDeviceStats", data);
|
2014-08-22 19:35:22 +00:00
|
|
|
});
|
2014-09-24 19:59:28 +00:00
|
|
|
}, 500);
|
2014-08-22 19:35:22 +00:00
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
$scope.init = function () {
|
2014-07-29 09:06:52 +00:00
|
|
|
refreshSystem();
|
|
|
|
refreshConfig();
|
|
|
|
refreshConnectionStats();
|
2014-09-28 11:00:38 +00:00
|
|
|
refreshDeviceStats();
|
2014-07-29 09:06:52 +00:00
|
|
|
|
|
|
|
$http.get(urlbase + '/version').success(function (data) {
|
2014-09-18 10:52:45 +00:00
|
|
|
$scope.version = data.version;
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$http.get(urlbase + '/report').success(function (data) {
|
|
|
|
$scope.reportData = data;
|
|
|
|
});
|
|
|
|
|
|
|
|
$http.get(urlbase + '/upgrade').success(function (data) {
|
|
|
|
$scope.upgradeInfo = data;
|
|
|
|
}).error(function () {
|
2014-09-30 22:01:32 +00:00
|
|
|
$scope.upgradeInfo = null;
|
2014-07-29 09:06:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.refresh = function () {
|
|
|
|
refreshSystem();
|
|
|
|
refreshConnectionStats();
|
|
|
|
refreshErrors();
|
2014-01-05 22:54:57 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folderStatus = function (folder) {
|
|
|
|
if (typeof $scope.model[folder] === 'undefined') {
|
2014-07-26 20:30:29 +00:00
|
|
|
return 'unknown';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
if ($scope.model[folder].invalid !== '') {
|
2014-07-26 20:30:29 +00:00
|
|
|
return 'stopped';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
return '' + $scope.model[folder].state;
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-04-14 07:58:17 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folderClass = function (folder) {
|
|
|
|
if (typeof $scope.model[folder] === 'undefined') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'info';
|
2014-04-14 07:58:17 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
if ($scope.model[folder].invalid !== '') {
|
2014-05-20 17:36:37 +00:00
|
|
|
return 'danger';
|
2014-04-27 19:53:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
var state = '' + $scope.model[folder].state;
|
2014-04-14 07:58:17 +00:00
|
|
|
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-07-31 08:53:54 +00:00
|
|
|
if (state == 'scanning') {
|
|
|
|
return 'primary';
|
|
|
|
}
|
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-09-28 11:00:38 +00:00
|
|
|
$scope.syncPercentage = function (folder) {
|
|
|
|
if (typeof $scope.model[folder] === 'undefined') {
|
2014-04-09 21:00:23 +00:00
|
|
|
return 100;
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
if ($scope.model[folder].globalBytes === 0) {
|
2014-04-09 21:00:23 +00:00
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
var pct = 100 * $scope.model[folder].inSyncBytes / $scope.model[folder].globalBytes;
|
2014-05-20 17:36:37 +00:00
|
|
|
return Math.floor(pct);
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deviceIcon = function (deviceCfg) {
|
|
|
|
if ($scope.connections[deviceCfg.DeviceID]) {
|
|
|
|
if ($scope.completion[deviceCfg.DeviceID] && $scope.completion[deviceCfg.DeviceID]._total === 100) {
|
2014-02-13 11:41:37 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deviceClass = function (deviceCfg) {
|
|
|
|
if ($scope.connections[deviceCfg.DeviceID]) {
|
|
|
|
if ($scope.completion[deviceCfg.DeviceID] && $scope.completion[deviceCfg.DeviceID]._total === 100) {
|
2014-02-13 11:41:37 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deviceAddr = function (deviceCfg) {
|
|
|
|
var conn = $scope.connections[deviceCfg.DeviceID];
|
2014-02-01 19:23:19 +00:00
|
|
|
if (conn) {
|
|
|
|
return conn.Address;
|
|
|
|
}
|
2014-04-09 21:00:23 +00:00
|
|
|
return '?';
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deviceCompletion = function (deviceCfg) {
|
|
|
|
var conn = $scope.connections[deviceCfg.DeviceID];
|
2014-02-13 11:41:37 +00:00
|
|
|
if (conn) {
|
|
|
|
return conn.Completion + '%';
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.findDevice = function (deviceID) {
|
|
|
|
var matches = $scope.devices.filter(function (n) {
|
|
|
|
return n.DeviceID == deviceID;
|
2014-09-18 18:05:05 +00:00
|
|
|
});
|
2014-05-20 17:36:37 +00:00
|
|
|
if (matches.length != 1) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return matches[0];
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deviceName = function (deviceCfg) {
|
|
|
|
if (typeof deviceCfg === 'undefined') {
|
2014-05-21 19:07:37 +00:00
|
|
|
return "";
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
if (deviceCfg.Name) {
|
|
|
|
return deviceCfg.Name;
|
2014-02-05 21:49:26 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
return deviceCfg.DeviceID.substr(0, 6);
|
2014-02-05 21:49:26 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.thisDeviceName = function () {
|
|
|
|
var device = $scope.thisDevice();
|
|
|
|
if (typeof device === 'undefined') {
|
|
|
|
return "(unknown device)";
|
2014-05-16 16:42:22 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
if (device.Name) {
|
|
|
|
return device.Name;
|
2014-05-16 16:42:22 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
return device.DeviceID.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);
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.tmpOptions.DeviceName = $scope.thisDevice().Name;
|
2014-09-27 15:00:20 +00:00
|
|
|
$scope.tmpOptions.AutoUpgradeEnabled = ($scope.tmpOptions.AutoUpgradeIntervalH > 0);
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.tmpGUI = angular.copy($scope.config.GUI);
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#settings').modal();
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
$scope.saveConfig = function () {
|
2014-06-07 02:00:46 +00:00
|
|
|
var cfg = JSON.stringify($scope.config);
|
2014-09-18 18:05:05 +00:00
|
|
|
var opts = {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
};
|
2014-06-07 02:00:46 +00:00
|
|
|
$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) ||
|
2014-09-18 18:05:05 +00:00
|
|
|
!angular.equals($scope.config.GUI, $scope.tmpGUI);
|
2014-06-17 21:22:19 +00:00
|
|
|
if (changed) {
|
|
|
|
// Check if usage reporting has been enabled or disabled
|
|
|
|
if ($scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted <= 0) {
|
|
|
|
$scope.tmpOptions.URAccepted = 1000;
|
2014-09-18 18:05:05 +00:00
|
|
|
} else if (!$scope.tmpOptions.UREnabled && $scope.tmpOptions.URAccepted > 0) {
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.tmpOptions.URAccepted = -1;
|
|
|
|
}
|
|
|
|
|
2014-09-27 15:00:20 +00:00
|
|
|
// Check if auto-upgrade has been enabled or disabled
|
|
|
|
if ($scope.tmpOptions.AutoUpgradeEnabled) {
|
|
|
|
$scope.tmpOptions.AutoUpgradeIntervalH = $scope.tmpOptions.AutoUpgradeIntervalH || 12;
|
|
|
|
} else {
|
|
|
|
$scope.tmpOptions.AutoUpgradeIntervalH = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-17 21:22:19 +00:00
|
|
|
// Check if protocol will need to be changed on restart
|
2014-09-18 18:05:05 +00:00
|
|
|
if ($scope.config.GUI.UseTLS !== $scope.tmpGUI.UseTLS) {
|
2014-05-28 15:26:38 +00:00
|
|
|
$scope.protocolChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply new settings locally
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.thisDevice().Name = $scope.tmpOptions.DeviceName;
|
2014-06-17 21:22:19 +00:00
|
|
|
$scope.config.Options = angular.copy($scope.tmpOptions);
|
|
|
|
$scope.config.GUI = angular.copy($scope.tmpGUI);
|
2014-09-18 18:05:05 +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-08-10 22:28:04 +00:00
|
|
|
$('#restarting').modal();
|
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
|
2014-09-18 18:05:05 +00:00
|
|
|
if ($scope.protocolChanged) {
|
2014-05-28 15:26:38 +00:00
|
|
|
var protocol = 'http';
|
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
if ($scope.config.GUI.UseTLS) {
|
|
|
|
protocol = 'https';
|
2014-05-28 15:26:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
setTimeout(function () {
|
2014-05-28 15:26:38 +00:00
|
|
|
window.location.protocol = protocol;
|
2014-09-14 22:18:05 +00:00
|
|
|
}, 2500);
|
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-07-14 08:45:29 +00:00
|
|
|
$scope.upgrade = function () {
|
2014-08-06 12:41:46 +00:00
|
|
|
restarting = true;
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#upgrading').modal();
|
2014-07-14 08:45:29 +00:00
|
|
|
$http.post(urlbase + '/upgrade').success(function () {
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#restarting').modal();
|
2014-08-06 12:41:46 +00:00
|
|
|
$('#upgrading').modal('hide');
|
2014-07-14 08:45:29 +00:00
|
|
|
}).error(function () {
|
2014-08-06 12:41:46 +00:00
|
|
|
$('#upgrading').modal('hide');
|
2014-07-14 08:45:29 +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-08-10 22:28:04 +00:00
|
|
|
$('#shutdown').modal();
|
2014-05-20 17:36:37 +00:00
|
|
|
});
|
|
|
|
$scope.configInSync = true;
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.editDevice = function (deviceCfg) {
|
|
|
|
$scope.currentDevice = $.extend({}, deviceCfg);
|
2014-02-01 19:23:19 +00:00
|
|
|
$scope.editingExisting = true;
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.editingSelf = (deviceCfg.DeviceID == $scope.myID);
|
|
|
|
$scope.currentDevice.AddressesStr = deviceCfg.Addresses.join(', ');
|
|
|
|
$scope.deviceEditor.$setPristine();
|
|
|
|
$('#editDevice').modal();
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.idDevice = function () {
|
2014-05-21 18:06:14 +00:00
|
|
|
$('#idqr').modal('show');
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.addDevice = function () {
|
2014-10-15 20:02:57 +00:00
|
|
|
$http.get(urlbase + '/discovery')
|
|
|
|
.success(function (registry) {
|
|
|
|
$scope.discovery = registry;
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
$scope.currentDevice = {
|
|
|
|
AddressesStr: 'dynamic',
|
|
|
|
Compression: true,
|
|
|
|
Introducer: false
|
|
|
|
};
|
|
|
|
$scope.editingExisting = false;
|
|
|
|
$scope.editingSelf = false;
|
|
|
|
$scope.deviceEditor.$setPristine();
|
|
|
|
$('#editDevice').modal();
|
|
|
|
});
|
2014-02-01 19:23:19 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deleteDevice = function () {
|
|
|
|
$('#editDevice').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-09-28 11:00:38 +00:00
|
|
|
$scope.devices = $scope.devices.filter(function (n) {
|
|
|
|
return n.DeviceID !== $scope.currentDevice.DeviceID;
|
2014-04-09 21:00:23 +00:00
|
|
|
});
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.config.Devices = $scope.devices;
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
for (var id in $scope.folders) {
|
|
|
|
$scope.folders[id].Devices = $scope.folders[id].Devices.filter(function (n) {
|
|
|
|
return n.DeviceID !== $scope.currentDevice.DeviceID;
|
2014-04-09 21:00:23 +00:00
|
|
|
});
|
|
|
|
}
|
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
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.saveDevice = function () {
|
|
|
|
var deviceCfg, done, i;
|
2014-02-10 19:54:37 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$('#editDevice').modal('hide');
|
|
|
|
deviceCfg = $scope.currentDevice;
|
|
|
|
deviceCfg.Addresses = deviceCfg.AddressesStr.split(',').map(function (x) {
|
2014-09-18 18:05:05 +00:00
|
|
|
return x.trim();
|
|
|
|
});
|
2014-02-01 19:23:19 +00:00
|
|
|
|
2014-02-10 19:54:37 +00:00
|
|
|
done = false;
|
2014-09-28 11:00:38 +00:00
|
|
|
for (i = 0; i < $scope.devices.length; i++) {
|
|
|
|
if ($scope.devices[i].DeviceID === deviceCfg.DeviceID) {
|
|
|
|
$scope.devices[i] = deviceCfg;
|
2014-02-01 19:23:19 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-10 19:54:37 +00:00
|
|
|
}
|
2014-02-01 19:23:19 +00:00
|
|
|
|
|
|
|
if (!done) {
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.devices.push(deviceCfg);
|
2014-02-01 19:23:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.devices.sort(deviceCompare);
|
|
|
|
$scope.config.Devices = $scope.devices;
|
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-09-28 11:00:38 +00:00
|
|
|
$scope.otherDevices = function () {
|
|
|
|
return $scope.devices.filter(function (n) {
|
|
|
|
return n.DeviceID !== $scope.myID;
|
2014-04-09 21:00:23 +00:00
|
|
|
});
|
2014-02-10 19:54:37 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.thisDevice = function () {
|
2014-02-10 19:54:37 +00:00
|
|
|
var i, n;
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
for (i = 0; i < $scope.devices.length; i++) {
|
|
|
|
n = $scope.devices[i];
|
|
|
|
if (n.DeviceID === $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-09-28 11:00:38 +00:00
|
|
|
$scope.allDevices = function () {
|
|
|
|
var devices = $scope.otherDevices();
|
|
|
|
devices.push($scope.thisDevice());
|
|
|
|
return devices;
|
2014-05-20 17:36:37 +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;
|
2014-04-30 20:02:34 +00:00
|
|
|
$http.post(urlbase + '/error/clear');
|
2014-02-12 22:18:41 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.friendlyDevices = function (str) {
|
|
|
|
for (var i = 0; i < $scope.devices.length; i++) {
|
|
|
|
var cfg = $scope.devices[i];
|
|
|
|
str = str.replace(cfg.DeviceID, $scope.deviceName(cfg));
|
2014-02-12 22:18:41 +00:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folderList = function () {
|
|
|
|
return folderList($scope.folders);
|
2014-05-28 15:26:38 +00:00
|
|
|
};
|
2014-05-14 10:55:00 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.editFolder = function (deviceCfg) {
|
|
|
|
$scope.currentFolder = angular.copy(deviceCfg);
|
|
|
|
$scope.currentFolder.selectedDevices = {};
|
|
|
|
$scope.currentFolder.Devices.forEach(function (n) {
|
|
|
|
$scope.currentFolder.selectedDevices[n.DeviceID] = true;
|
2014-04-09 21:00:23 +00:00
|
|
|
});
|
2014-09-28 11:00:38 +00:00
|
|
|
if ($scope.currentFolder.Versioning && $scope.currentFolder.Versioning.Type === "simple") {
|
|
|
|
$scope.currentFolder.simpleFileVersioning = true;
|
|
|
|
$scope.currentFolder.FileVersioningSelector = "simple";
|
|
|
|
$scope.currentFolder.simpleKeep = +$scope.currentFolder.Versioning.Params.keep;
|
|
|
|
} else if ($scope.currentFolder.Versioning && $scope.currentFolder.Versioning.Type === "staggered") {
|
|
|
|
$scope.currentFolder.staggeredFileVersioning = true;
|
|
|
|
$scope.currentFolder.FileVersioningSelector = "staggered";
|
|
|
|
$scope.currentFolder.staggeredMaxAge = Math.floor(+$scope.currentFolder.Versioning.Params.maxAge / 86400);
|
|
|
|
$scope.currentFolder.staggeredCleanInterval = +$scope.currentFolder.Versioning.Params.cleanInterval;
|
|
|
|
$scope.currentFolder.staggeredVersionsPath = $scope.currentFolder.Versioning.Params.versionsPath;
|
2014-08-21 22:41:17 +00:00
|
|
|
} else {
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.currentFolder.FileVersioningSelector = "none";
|
2014-05-25 18:49:08 +00:00
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.currentFolder.simpleKeep = $scope.currentFolder.simpleKeep || 5;
|
|
|
|
$scope.currentFolder.staggeredCleanInterval = $scope.currentFolder.staggeredCleanInterval || 3600;
|
|
|
|
$scope.currentFolder.staggeredVersionsPath = $scope.currentFolder.staggeredVersionsPath || "";
|
2014-08-22 16:16:05 +00:00
|
|
|
|
2014-08-31 19:44:06 +00:00
|
|
|
// staggeredMaxAge can validly be zero, which we should not replace
|
|
|
|
// with the default value of 365. So only set the default if it's
|
|
|
|
// actually undefined.
|
2014-09-28 11:00:38 +00:00
|
|
|
if (typeof $scope.currentFolder.staggeredMaxAge === 'undefined') {
|
|
|
|
$scope.currentFolder.staggeredMaxAge = 365;
|
2014-08-31 19:44:06 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editingExisting = true;
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folderEditor.$setPristine();
|
|
|
|
$('#editFolder').modal();
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.addFolder = function () {
|
|
|
|
$scope.currentFolder = {
|
|
|
|
selectedDevices: {}
|
2014-09-18 18:05:05 +00:00
|
|
|
};
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.currentFolder.RescanIntervalS = 60;
|
|
|
|
$scope.currentFolder.FileVersioningSelector = "none";
|
|
|
|
$scope.currentFolder.simpleKeep = 5;
|
|
|
|
$scope.currentFolder.staggeredMaxAge = 365;
|
|
|
|
$scope.currentFolder.staggeredCleanInterval = 3600;
|
|
|
|
$scope.currentFolder.staggeredVersionsPath = "";
|
2014-04-09 21:00:23 +00:00
|
|
|
$scope.editingExisting = false;
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folderEditor.$setPristine();
|
|
|
|
$('#editFolder').modal();
|
2014-04-09 21:00:23 +00:00
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.saveFolder = function () {
|
|
|
|
var folderCfg, done, i;
|
|
|
|
|
|
|
|
$('#editFolder').modal('hide');
|
|
|
|
folderCfg = $scope.currentFolder;
|
|
|
|
folderCfg.Devices = [];
|
|
|
|
folderCfg.selectedDevices[$scope.myID] = true;
|
|
|
|
for (var deviceID in folderCfg.selectedDevices) {
|
|
|
|
if (folderCfg.selectedDevices[deviceID] === true) {
|
|
|
|
folderCfg.Devices.push({
|
|
|
|
DeviceID: deviceID
|
2014-09-18 18:05:05 +00:00
|
|
|
});
|
2014-04-09 21:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
delete folderCfg.selectedDevices;
|
2014-04-09 21:00:23 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
if (folderCfg.FileVersioningSelector === "simple") {
|
|
|
|
folderCfg.Versioning = {
|
2014-05-25 18:49:08 +00:00
|
|
|
'Type': 'simple',
|
|
|
|
'Params': {
|
2014-09-28 11:00:38 +00:00
|
|
|
'keep': '' + folderCfg.simpleKeep,
|
2014-05-25 18:49:08 +00:00
|
|
|
}
|
|
|
|
};
|
2014-09-28 11:00:38 +00:00
|
|
|
delete folderCfg.simpleFileVersioning;
|
|
|
|
delete folderCfg.simpleKeep;
|
|
|
|
} else if (folderCfg.FileVersioningSelector === "staggered") {
|
|
|
|
folderCfg.Versioning = {
|
2014-08-21 22:41:17 +00:00
|
|
|
'Type': 'staggered',
|
|
|
|
'Params': {
|
2014-09-28 11:00:38 +00:00
|
|
|
'maxAge': '' + (folderCfg.staggeredMaxAge * 86400),
|
|
|
|
'cleanInterval': '' + folderCfg.staggeredCleanInterval,
|
|
|
|
'versionsPath': '' + folderCfg.staggeredVersionsPath,
|
2014-08-21 22:41:17 +00:00
|
|
|
}
|
|
|
|
};
|
2014-09-28 11:00:38 +00:00
|
|
|
delete folderCfg.staggeredFileVersioning;
|
|
|
|
delete folderCfg.staggeredMaxAge;
|
|
|
|
delete folderCfg.staggeredCleanInterval;
|
|
|
|
delete folderCfg.staggeredVersionsPath;
|
2014-08-22 16:16:05 +00:00
|
|
|
|
2014-05-25 18:49:08 +00:00
|
|
|
} else {
|
2014-09-28 11:00:38 +00:00
|
|
|
delete folderCfg.Versioning;
|
2014-05-25 18:49:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.folders[folderCfg.ID] = folderCfg;
|
|
|
|
$scope.config.Folders = folderList($scope.folders);
|
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-09-28 11:00:38 +00:00
|
|
|
$scope.sharesFolder = function (folderCfg) {
|
2014-05-24 19:13:35 +00:00
|
|
|
var names = [];
|
2014-09-28 11:00:38 +00:00
|
|
|
folderCfg.Devices.forEach(function (device) {
|
|
|
|
names.push($scope.deviceName($scope.findDevice(device.DeviceID)));
|
2014-05-24 19:13:35 +00:00
|
|
|
});
|
|
|
|
names.sort();
|
|
|
|
return names.join(", ");
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.deleteFolder = function () {
|
|
|
|
$('#editFolder').modal('hide');
|
2014-04-09 21:00:23 +00:00
|
|
|
if (!$scope.editingExisting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
delete $scope.folders[$scope.currentFolder.ID];
|
|
|
|
$scope.config.Folders = folderList($scope.folders);
|
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-09-19 20:02:53 +00:00
|
|
|
$scope.editIgnores = function () {
|
|
|
|
if (!$scope.editingExisting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#editIgnoresButton').attr('disabled', 'disabled');
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.get(urlbase + '/ignores?folder=' + encodeURIComponent($scope.currentFolder.ID))
|
2014-09-19 20:02:53 +00:00
|
|
|
.success(function (data) {
|
2014-09-22 12:04:20 +00:00
|
|
|
data.ignore = data.ignore || [];
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$('#editFolder').modal('hide');
|
2014-09-19 20:02:53 +00:00
|
|
|
var textArea = $('#editIgnores textarea');
|
|
|
|
|
|
|
|
textArea.val(data.ignore.join('\n'));
|
|
|
|
|
|
|
|
$('#editIgnores').modal()
|
|
|
|
.on('hidden.bs.modal', function () {
|
2014-09-28 11:00:38 +00:00
|
|
|
$('#editFolder').modal();
|
2014-09-19 20:02:53 +00:00
|
|
|
})
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
textArea.focus();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
$('#editIgnoresButton').removeAttr('disabled');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.saveIgnores = function () {
|
|
|
|
if (!$scope.editingExisting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.post(urlbase + '/ignores?folder=' + encodeURIComponent($scope.currentFolder.ID), {
|
2014-09-19 20:02:53 +00:00
|
|
|
ignore: $('#editIgnores textarea').val().split('\n')
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-04 20:00:55 +00:00
|
|
|
$scope.setAPIKey = function (cfg) {
|
|
|
|
cfg.APIKey = randomString(30, 32);
|
|
|
|
};
|
|
|
|
|
2014-09-08 22:52:31 +00:00
|
|
|
$scope.showURPreview = function () {
|
|
|
|
$('#settings').modal('hide');
|
|
|
|
$('#urPreview').modal().on('hidden.bs.modal', function () {
|
|
|
|
$('#settings').modal();
|
|
|
|
});
|
2014-09-18 18:05:05 +00:00
|
|
|
};
|
2014-09-08 22:52:31 +00:00
|
|
|
|
2014-06-11 18:04:23 +00:00
|
|
|
$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-09-28 11:00:38 +00:00
|
|
|
$scope.showNeed = function (folder) {
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.neededLoaded = false;
|
2014-08-10 22:28:04 +00:00
|
|
|
$('#needed').modal();
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.get(urlbase + "/need?folder=" + encodeURIComponent(folder)).success(function (data) {
|
2014-06-14 08:58:36 +00:00
|
|
|
$scope.needed = data;
|
|
|
|
$scope.neededLoaded = true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.needAction = function (file) {
|
|
|
|
var fDelete = 4096;
|
|
|
|
var fDirectory = 16384;
|
|
|
|
|
2014-09-18 18:05:05 +00:00
|
|
|
if ((file.Flags & (fDelete + fDirectory)) === fDelete + fDirectory) {
|
2014-06-14 08:58:36 +00:00
|
|
|
return 'rmdir';
|
|
|
|
} else if ((file.Flags & fDelete) === fDelete) {
|
|
|
|
return 'rm';
|
|
|
|
} else if ((file.Flags & fDirectory) === fDirectory) {
|
|
|
|
return 'touch';
|
|
|
|
} else {
|
|
|
|
return 'sync';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.override = function (folder) {
|
|
|
|
$http.post(urlbase + "/model/override?folder=" + encodeURIComponent(folder));
|
2014-06-16 08:47:02 +00:00
|
|
|
};
|
|
|
|
|
2014-07-07 10:58:56 +00:00
|
|
|
$scope.about = function () {
|
|
|
|
$('#about').modal('show');
|
|
|
|
};
|
|
|
|
|
2014-08-03 19:47:02 +00:00
|
|
|
$scope.showReportPreview = function () {
|
|
|
|
$scope.reportPreview = true;
|
|
|
|
};
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
$scope.rescanFolder = function (folder) {
|
|
|
|
$http.post(urlbase + "/scan?folder=" + encodeURIComponent(folder));
|
2014-08-15 10:48:36 +00:00
|
|
|
};
|
|
|
|
|
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-09-28 11:00:38 +00:00
|
|
|
function deviceCompare(a, b) {
|
2014-05-14 10:55:00 +00:00
|
|
|
if (typeof a.Name !== 'undefined' && typeof b.Name !== 'undefined') {
|
|
|
|
if (a.Name < b.Name)
|
|
|
|
return -1;
|
|
|
|
return a.Name > b.Name;
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
if (a.DeviceID < b.DeviceID) {
|
2014-05-14 10:55:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
return a.DeviceID > b.DeviceID;
|
2014-05-14 10:55:00 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
function folderCompare(a, b) {
|
2014-09-03 16:41:45 +00:00
|
|
|
if (a.ID < b.ID) {
|
2014-05-14 10:55:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-09-03 16:41:45 +00:00
|
|
|
return a.ID > b.ID;
|
2014-05-14 10:55:00 +00:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
function folderMap(l) {
|
2014-05-14 10:55:00 +00:00
|
|
|
var m = {};
|
|
|
|
l.forEach(function (r) {
|
|
|
|
m[r.ID] = r;
|
|
|
|
});
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
function folderList(m) {
|
2014-05-14 10:55:00 +00:00
|
|
|
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
|
|
|
}
|
2014-09-28 11:00:38 +00:00
|
|
|
l.sort(folderCompare);
|
2014-05-14 10:55:00 +00:00
|
|
|
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-09-18 18:05:05 +00:00
|
|
|
function randomString(len, bits) {
|
2014-06-04 20:00:55 +00:00
|
|
|
bits = bits || 36;
|
2014-09-18 18:05:05 +00:00
|
|
|
var outStr = "",
|
|
|
|
newStr;
|
|
|
|
while (outStr.length < len) {
|
2014-06-04 20:00:55 +00:00
|
|
|
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-07-29 09:06:52 +00:00
|
|
|
function isEmptyObject(obj) {
|
|
|
|
var name;
|
|
|
|
for (name in obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-24 19:59:28 +00:00
|
|
|
function debounce(func, wait) {
|
|
|
|
var timeout, args, context, timestamp, result, again;
|
|
|
|
|
|
|
|
var later = function () {
|
|
|
|
var last = Date.now() - timestamp;
|
|
|
|
if (last < wait) {
|
|
|
|
timeout = setTimeout(later, wait - last);
|
|
|
|
} else {
|
|
|
|
timeout = null;
|
|
|
|
if (again) {
|
|
|
|
again = false;
|
|
|
|
result = func.apply(context, args);
|
|
|
|
context = args = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return function () {
|
|
|
|
context = this;
|
|
|
|
args = arguments;
|
|
|
|
timestamp = Date.now();
|
|
|
|
var callNow = !timeout;
|
|
|
|
if (!timeout) {
|
|
|
|
timeout = setTimeout(later, wait);
|
|
|
|
result = func.apply(context, args);
|
|
|
|
context = args = null;
|
|
|
|
} else {
|
|
|
|
again = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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('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-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;
|
|
|
|
}
|
2014-09-18 18:05:05 +00:00
|
|
|
return parts[parts.length - 1];
|
2014-06-14 08:58:36 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
syncthing.directive('uniqueFolder', function () {
|
2014-05-14 10:55:00 +00:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
2014-09-18 18:05:05 +00:00
|
|
|
link: function (scope, elm, attrs, ctrl) {
|
|
|
|
ctrl.$parsers.unshift(function (viewValue) {
|
2014-05-14 10:55:00 +00:00
|
|
|
if (scope.editingExisting) {
|
|
|
|
// we shouldn't validate
|
2014-09-28 11:00:38 +00:00
|
|
|
ctrl.$setValidity('uniqueFolder', true);
|
|
|
|
} else if (scope.folders[viewValue]) {
|
|
|
|
// the folder exists already
|
|
|
|
ctrl.$setValidity('uniqueFolder', false);
|
2014-05-14 10:55:00 +00:00
|
|
|
} else {
|
2014-09-28 11:00:38 +00:00
|
|
|
// the folder is unique
|
|
|
|
ctrl.$setValidity('uniqueFolder', true);
|
2014-05-14 10:55:00 +00:00
|
|
|
}
|
|
|
|
return viewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-05-28 03:16:11 +00:00
|
|
|
|
2014-09-28 11:00:38 +00:00
|
|
|
syncthing.directive('validDeviceid', function ($http) {
|
2014-05-28 03:16:11 +00:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
2014-09-18 18:05:05 +00:00
|
|
|
link: function (scope, elm, attrs, ctrl) {
|
|
|
|
ctrl.$parsers.unshift(function (viewValue) {
|
2014-05-28 03:16:11 +00:00
|
|
|
if (scope.editingExisting) {
|
|
|
|
// we shouldn't validate
|
2014-09-28 11:00:38 +00:00
|
|
|
ctrl.$setValidity('validDeviceid', true);
|
2014-05-28 03:16:11 +00:00
|
|
|
} else {
|
2014-09-28 11:00:38 +00:00
|
|
|
$http.get(urlbase + '/deviceid?id=' + viewValue).success(function (resp) {
|
2014-07-18 08:00:02 +00:00
|
|
|
if (resp.error) {
|
2014-09-28 11:00:38 +00:00
|
|
|
ctrl.$setValidity('validDeviceid', false);
|
2014-07-18 08:00:02 +00:00
|
|
|
} else {
|
2014-09-28 11:00:38 +00:00
|
|
|
ctrl.$setValidity('validDeviceid', true);
|
2014-07-18 08:00:02 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-28 03:16:11 +00:00
|
|
|
}
|
|
|
|
return viewValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2014-07-14 12:14:26 +00:00
|
|
|
|
|
|
|
syncthing.directive('modal', function () {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'modal.html',
|
|
|
|
replace: true,
|
|
|
|
transclude: true,
|
|
|
|
scope: {
|
|
|
|
title: '@',
|
|
|
|
status: '@',
|
|
|
|
icon: '@',
|
|
|
|
close: '@',
|
|
|
|
large: '@',
|
|
|
|
},
|
2014-09-18 18:05:05 +00:00
|
|
|
};
|
2014-07-14 12:14:26 +00:00
|
|
|
});
|