Browse Source

Merge remote-tracking branch 'syncthing/pr/1577'

* syncthing/pr/1577:
  Add uptime in webgui (fixes #1501)

Conflicts:
	cmd/syncthing/gui.go
	internal/auto/gui.files.go
Jakob Borg 10 years ago
parent
commit
207b43499c

+ 0 - 0
cmd/syncthing/.stfolder


+ 2 - 0
cmd/syncthing/gui.go

@@ -47,6 +47,7 @@ var (
 	configInSync = true
 	guiErrors    = []guiError{}
 	guiErrorsMut sync.Mutex
+	startTime    = time.Now()
 	eventSub     *events.BufferedSubscription
 )
 
@@ -519,6 +520,7 @@ func restGetSystem(w http.ResponseWriter, r *http.Request) {
 	cpuUsageLock.RUnlock()
 	res["cpuPercent"] = cpusum / float64(len(cpuUsagePercent)) / float64(runtime.NumCPU())
 	res["pathSeparator"] = string(filepath.Separator)
+	res["uptime"] = int(time.Since(startTime).Seconds())
 
 	w.Header().Set("Content-Type", "application/json; charset=utf-8")
 	json.NewEncoder(w).Encode(res)

+ 1 - 0
gui/assets/lang/lang-en.json

@@ -158,6 +158,7 @@
    "Upgrade To {%version%}": "Upgrade To {{version}}",
    "Upgrading": "Upgrading",
    "Upload Rate": "Upload Rate",
+   "Uptime": "Uptime",
    "Use HTTPS for GUI": "Use HTTPS for GUI",
    "Version": "Version",
    "Versions Path": "Versions Path",

+ 5 - 0
gui/index.html

@@ -320,6 +320,10 @@
                       </span>
                     </td>
                   </tr>
+                  <tr>
+                    <th><span class="glyphicon glyphicon-time"></span>&emsp;<span translate>Uptime</span></th>
+                    <td class="text-right">{{system.uptime | duration:"m"}}</td>
+                  </tr>
                   <tr>
                     <th><span class="glyphicon glyphicon-tag"></span>&emsp;<span translate>Version</span></th>
                     <td class="text-right">{{version}}</td>
@@ -1038,6 +1042,7 @@
   <script src="scripts/syncthing/core/filters/alwaysNumberFilter.js"></script>
   <script src="scripts/syncthing/core/filters/basenameFilter.js"></script>
   <script src="scripts/syncthing/core/filters/binaryFilter.js"></script>
+  <script src="scripts/syncthing/core/filters/durationFilter.js"></script>
   <script src="scripts/syncthing/core/filters/naturalFilter.js"></script>
   <script src="scripts/syncthing/core/services/localeService.js"></script>
 

+ 1 - 1
gui/scripts/syncthing/core/controllers/syncthingController.js

@@ -1069,7 +1069,7 @@ angular.module('syncthing.core')
                         break;
                     }
                 }
-            };
+            }
 
             folders.sort();
             return folders;

+ 35 - 0
gui/scripts/syncthing/core/filters/durationFilter.js

@@ -0,0 +1,35 @@
+/** convert amount of seconds to string format "d h m s" without zero values
+ * precision must be one of 'd', 'h', 'm', 's'(default)
+ * Example:
+ * {{121020003|duration}}     --> 1400d 16h 40m 3s
+ * {{121020003|duration:"m"}} --> 1400d 16h 40m
+ * {{121020003|duration:"h"}} --> 1400d 16h
+ * {{1|duration:"h"}}         --> <1h
+**/
+angular.module('syncthing.core')
+    .filter('duration', function () {
+        'use strict';
+
+        var SECONDS_IN = {"d": 86400, "h": 3600, "m": 60,  "s": 1};
+        return function (input, precision) {
+            var result = "";
+            if (!precision) {
+                precision = "s";
+            }
+            input = parseInt(input, 10);
+            for (var k in SECONDS_IN) {
+                var t = (input/SECONDS_IN[k] | 0); // Math.floor
+
+                if (t > 0) {
+                    result += " " + t + k; 
+                }
+
+                if (precision == k) {
+                    return result ? result : "<1" + k; 
+                } else {
+                    input %= SECONDS_IN[k];
+                }
+            }
+            return "[Error: incorrect usage, precision must be one of " + Object.keys(SECONDS_IN) + "]";
+        };
+    });

File diff suppressed because it is too large
+ 2 - 2
internal/auto/gui.files.go


Some files were not shown because too many files changed in this diff