Bläddra i källkod

Merge pull request #1464 from henrywhitaker3/v2-develop

Updated speedtest homepage item
causefx 5 år sedan
förälder
incheckning
e5bd21a17d
2 ändrade filer med 79 tillägg och 13 borttagningar
  1. 20 3
      api/homepage/speedtest.php
  2. 59 10
      js/functions.js

+ 20 - 3
api/homepage/speedtest.php

@@ -81,11 +81,28 @@ trait SpeedTestHomepageItem
 			$response = Requests::get($dataUrl);
 			if ($response->success) {
 				$json = json_decode($response->body, true);
+
 				$api['data'] = [
 					'current' => $json['data'],
-					'average' => $json['average'],
-					'max' => $json['max'],
 				];
+
+				$keys = [
+					'average',
+					'max',
+					'maximum',
+					'minimum'
+				];
+
+				foreach ($keys as $key) {
+					if (array_key_exists($key, $json)) {
+						if ($key == 'max') {
+							$api['data']['maximum'] = $json[$key];
+						} else {
+							$api['data'][$key] = $json[$key];
+						}
+					}
+				}
+
 				$api['options'] = [
 					'title' => $this->config['speedtestHeader'],
 					'titleToggle' => $this->config['speedtestHeaderToggle'],
@@ -103,4 +120,4 @@ trait SpeedTestHomepageItem
 		$this->setAPIResponse('success', null, 200, $api);
 		return $api;
 	}
-}
+}

+ 59 - 10
js/functions.js

@@ -7605,7 +7605,8 @@ function buildSpeedtest(array){
     `;
     var current = array.data.current;
     var average = array.data.average;
-    var max = array.data.max;
+    var maximum = array.data.maximum;
+    var minimum = array.data.minimum;
     var options = array.options;
   
     html += `
@@ -7632,16 +7633,32 @@ function buildSpeedtest(array){
                         <div class="text-truncate">
                             <h3 class="d-inline">`+parseFloat(current.ping).toFixed(1)+`</h3>
                             <p class="d-inline ml-1 text-white">ms (current)</p>
-                        </div>
+                        </div>`;
+    if(average != undefined) {
+        html += `
                         <div class="text-truncate text-muted">
                             <h5 class="d-inline">`+parseFloat(average.ping).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">ms (average)</p>
                         </div>
+        `;
+    }
+    if(maximum != undefined) {
+        html += `
                         <div class="text-truncate text-muted">
-                            <h5 class="d-inline">`+parseFloat(max.ping).toFixed(1)+`</h5>
+                            <h5 class="d-inline">`+parseFloat(maximum.ping).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">ms (maximum)</p>
                         </div>
-                    </div>
+        `;
+    }
+    if(minimum != undefined) {
+        html += `
+                        <div class="text-truncate text-muted">
+                            <h5 class="d-inline">`+parseFloat(minimum.ping).toFixed(1)+`</h5>
+                            <p class="d-inline ml-1">ms (minimum)</p>
+                        </div>
+        `;
+    }
+    html += `       </div>
                 </div>
             </div>
             <div class="my-2 col-lg-4 col-md-4 col-sm-12">
@@ -7654,16 +7671,32 @@ function buildSpeedtest(array){
                         <div class="text-truncate">
                             <h3 class="d-inline">`+parseFloat(current.download).toFixed(1)+`</h3>
                             <p class="d-inline ml-1 text-white">Mbit/s (current)</p>
-                        </div>
+                        </div>`;
+    if(average != undefined) {
+            html += `
                         <div class="text-truncate text-muted">
                             <h5 class="d-inline">`+parseFloat(average.download).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">Mbit/s (average)</p>
                         </div>
+            `;
+        }
+    if(maximum != undefined) {
+        html += `
                         <div class="text-truncate text-muted">
-                            <h5 class="d-inline">`+parseFloat(max.download).toFixed(1)+`</h5>
+                            <h5 class="d-inline">`+parseFloat(maximum.download).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">Mbit/s (maximum)</p>
                         </div>
-                    </div>
+        `;
+    }
+    if(minimum != undefined) {
+        html += `
+                        <div class="text-truncate text-muted">
+                            <h5 class="d-inline">`+parseFloat(minimum.download).toFixed(1)+`</h5>
+                            <p class="d-inline ml-1">Mbit/s (minimum)</p>
+                        </div>
+        `;
+    }
+    html += `       </div>
                 </div>
             </div>
             <div class="my-2 col-lg-4 col-md-4 col-sm-12">
@@ -7676,16 +7709,32 @@ function buildSpeedtest(array){
                         <div class="text-truncate">
                             <h3 class="d-inline">`+parseFloat(current.upload).toFixed(1)+`</h3>
                             <p class="d-inline ml-1 text-white">Mbit/s (current)</p>
-                        </div>
+                        </div>`;
+    if(average != undefined) {
+            html += `
                         <div class="text-truncate text-muted">
                             <h5 class="d-inline">`+parseFloat(average.upload).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">Mbit/s (average)</p>
                         </div>
+            `;
+        }
+    if(maximum != undefined) {
+        html += `
                         <div class="text-truncate text-muted">
-                            <h5 class="d-inline">`+parseFloat(max.upload).toFixed(1)+`</h5>
+                            <h5 class="d-inline">`+parseFloat(maximum.upload).toFixed(1)+`</h5>
                             <p class="d-inline ml-1">Mbit/s (maximum)</p>
                         </div>
-                    </div>
+        `;
+    }
+    if(minimum != undefined) {
+        html += `
+                        <div class="text-truncate text-muted">
+                            <h5 class="d-inline">`+parseFloat(minimum.upload).toFixed(1)+`</h5>
+                            <p class="d-inline ml-1">Mbit/s (minimum)</p>
+                        </div>
+        `;
+    }
+    html += `       </div>
                 </div>
             </div>
         </div>