From 9f63feef30289d694bd121ac46549b8bea5b2842 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 13 Feb 2014 12:41:37 +0100 Subject: [PATCH] Add peer node sync status in GUI (fixes #46) --- gui/app.js | 40 +++++++++++++++++++++++++++------------- gui/index.html | 30 ++++++++++++++---------------- model.go | 20 ++++++++++++++++++++ 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/gui/app.js b/gui/app.js index 7cab3a084..fbf0a19fa 100644 --- a/gui/app.js +++ b/gui/app.js @@ -138,25 +138,27 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) { }); }; - $scope.nodeIcon = function (nodeCfg) { - if ($scope.connections[nodeCfg.NodeID]) { - return 'ok'; - } - - return 'minus'; - }; - $scope.nodeStatus = function (nodeCfg) { - if ($scope.connections[nodeCfg.NodeID]) { - return 'Connected'; + var conn = $scope.connections[nodeCfg.NodeID]; + if (conn) { + if (conn.Completion === 100) { + return 'In Sync'; + } else { + return 'Syncing (' + conn.Completion + '%)'; + } } return 'Disconnected'; }; $scope.nodeIcon = function (nodeCfg) { - if ($scope.connections[nodeCfg.NodeID]) { - return 'ok'; + var conn = $scope.connections[nodeCfg.NodeID]; + if (conn) { + if (conn.Completion === 100) { + return 'ok'; + } else { + return 'refresh'; + } } return 'minus'; @@ -165,7 +167,11 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) { $scope.nodeClass = function (nodeCfg) { var conn = $scope.connections[nodeCfg.NodeID]; if (conn) { - return 'success'; + if (conn.Completion === 100) { + return 'success'; + } else { + return 'primary'; + } } return 'info'; @@ -179,6 +185,14 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http) { return '(unknown address)'; }; + $scope.nodeCompletion = function (nodeCfg) { + var conn = $scope.connections[nodeCfg.NodeID]; + if (conn) { + return conn.Completion + '%'; + } + return ''; + }; + $scope.nodeVer = function (nodeCfg) { if (nodeCfg.NodeID === $scope.myID) { return $scope.version; diff --git a/gui/index.html b/gui/index.html index 350d8c459..8621fc9b2 100644 --- a/gui/index.html +++ b/gui/index.html @@ -67,31 +67,31 @@ thead tr th { - + This node - + {{nodeName(nodeCfg)}} {{version}} (this node) - + {{inbps | metric}}bps - + {{outbps | metric}}bps - + - + {{nodeStatus(nodeCfg)}} @@ -99,12 +99,8 @@ thead tr th { {{nodeName(nodeCfg)}} - - {{nodeVer(nodeCfg)}} - - - {{nodeAddr(nodeCfg)}} - + {{nodeVer(nodeCfg)}} + {{nodeAddr(nodeCfg)}} {{connections[nodeCfg.NodeID].inbps | metric}}bps @@ -167,10 +163,12 @@ thead tr th {
-

System

-
-

{{system.sys | binary}}B RAM allocated, {{system.alloc | binary}}B in use

-

{{system.cpuPercent | alwaysNumber | natural:1}}% CPU, {{system.goroutines | alwaysNumber}} goroutines

+ +
+
+

{{system.sys | binary}}B RAM allocated, {{system.alloc | binary}}B in use

+

{{system.cpuPercent | alwaysNumber | natural:1}}% CPU, {{system.goroutines | alwaysNumber}} goroutines

+
diff --git a/model.go b/model.go index 059200eb8..80af8252b 100644 --- a/model.go +++ b/model.go @@ -158,6 +158,7 @@ type ConnectionInfo struct { Address string ClientID string ClientVersion string + Completion int } // ConnectionStats returns a map with connection statistics for each connected node. @@ -166,7 +167,14 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo { RemoteAddr() net.Addr } + m.gmut.RLock() m.pmut.RLock() + m.rmut.RLock() + + var tot int + for _, f := range m.global { + tot += f.Size() + } var res = make(map[string]ConnectionInfo) for node, conn := range m.protoConn { @@ -178,10 +186,22 @@ func (m *Model) ConnectionStats() map[string]ConnectionInfo { if nc, ok := m.rawConn[node].(remoteAddrer); ok { ci.Address = nc.RemoteAddr().String() } + + var have int + for _, f := range m.remote[node] { + if f.Equals(m.global[f.Name]) { + have += f.Size() + } + } + + ci.Completion = 100 * have / tot + res[node] = ci } + m.rmut.RUnlock() m.pmut.RUnlock() + m.gmut.RUnlock() return res }