You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/06/18 19:47:20 UTC

[GitHub] [trafficcontrol] shamrickus commented on a change in pull request #4746: Update TM UI for multiple interfaces

shamrickus commented on a change in pull request #4746:
URL: https://github.com/apache/trafficcontrol/pull/4746#discussion_r442463863



##########
File path: traffic_monitor/static/script.js
##########
@@ -147,51 +147,136 @@ function getEvents() {
  * the "Cache States" table with the results - replacing the current content.
 */
 function getCacheStates() {
+	function parseIPAvailable(server, ipField) {
+		return server.status.indexOf("ONLINE") !== 0 ? server[ipField] : "N/A";
+	}
+
+	function parseBandwidth(server) {
+		if (Object.prototype.hasOwnProperty.call(server, "bandwidth_kbps")) {
+			const kbps = (server.bandwidth_kbps / kilobitsInMegabit).toFixed(2);
+			const max = numberStrWithCommas((server.bandwidth_capacity_kbps / kilobitsInMegabit).toFixed(0));
+			return `${kbps} / ${max}`;
+		} else {
+			return "N/A";
+		}
+	}
+	function parseStatusClass(server, row) {
+		if (Object.prototype.hasOwnProperty.call(server, "status")) {
+			if (server.status.indexOf("ADMIN_DOWN") !== -1 || server.status.indexOf("OFFLINE") !== -1) {
+				row.classList.add("warning");
+			} else if (!server.combined_available && server.status.indexOf("ONLINE") !== 0) {
+				row.classList.add("error");
+			} else if (server.status.indexOf(" availableBandwidth") !== -1) {
+				row.classList.add("error");
+			}
+		}
+	}
+
 	ajax("/api/cache-statuses", function(r) {
 		const servers = new Map(Object.entries(JSON.parse(r)));
+
+		// Sort by key (server name) so order doesn't change 'randomly'
+		servers[Symbol.iterator] = function* () {
+			yield *[...this.entries()].sort((serverCoupleA, serverCoupleB) => {
+				return serverCoupleA[0] < serverCoupleB[0];
+			});
+		};

Review comment:
       You are correct, the object is resorted every time it is iterated.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org