Skip to content

Commit

Permalink
Merge pull request #1882 from chaveiro/master
Browse files Browse the repository at this point in the history
Fix feeds late warning colors
  • Loading branch information
TrystanLea committed May 3, 2024
2 parents b61a6c9 + 60a02b1 commit 1c32f96
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
32 changes: 19 additions & 13 deletions Lib/responsive-linked-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ $(function() {


// Calculate and color updated time
function list_format_updated(time, interval = false) {
function list_format_updated(time, interval = 1) {
var fv = list_format_updated_obj(time, interval);
return "<span class='last-update' style='color:" + fv.color + ";'>" + fv.value + "</span>";
}
Expand All @@ -134,7 +134,7 @@ function list_format_color(color_code) {
return colours[color_code];
}

function list_format_updated_obj(time, interval = false) {
function list_format_updated_obj(time, interval = 1) {
var servertime = (new Date()).getTime() - app.timeServerLocalOffset;
time = new Date(time * 1000);
var update = time.getTime();
Expand All @@ -150,22 +150,28 @@ function list_format_updated_obj(time, interval = false) {
else if (secs.toFixed(0) == 0) updated = "now";
else if (day > 365 && delta > 0) updated = time.toLocaleDateString("en-GB",{year:"numeric", month:"short"});
else if (day > 31 && delta > 0) updated = time.toLocaleDateString("en-GB",{month:"short", day:"numeric"});
else if (day > 2) updated = day.toFixed(1) + " days";
else if (day > 2) updated = day.toFixed(0) + " days";
else if (hour > 2) updated = hour.toFixed(0) + " hrs";
else if (secs > 180) updated = mins.toFixed(0) + " mins";

if (interval == false ) {
interval = 10;
}

secs = Math.abs(secs);

var color_code = 5; // grey
if (delta < 0) color_code = 0; // blue
else if (secs < interval*3) color_code = 1; // green
else if (secs < interval*6) color_code = 2; // yellow
else if (secs < interval*12) color_code = 3; // orange
else if (secs < interval*24) color_code = 4; // red
var color_code = 5; // grey - Inactive

if (interval == 1) { // => Variable Interval Feeds
if (delta < 0) color_code = 0; // blue - Ahead of time!
else if (secs < 30) color_code = 1; // green - < 30s
else if (secs < 60) color_code = 2; // yellow - < 2 min
else if (secs < (60 * 60)) color_code = 3; // orange - < 1h
else if (secs < (3600*24*31)) color_code = 4; // red - < 1 month
}
else { // => Fixed Interval Feeds
if (delta < 0) color_code = 0; // blue - Ahead of time!
else if (secs < interval*3) color_code = 1; // green - < 3x interval
else if (secs < interval*6) color_code = 2; // yellow - < 6x interval
else if (secs < interval*12) color_code = 3; // orange - < 12x interval
else if (secs < (3600*24*31)) color_code = 4; // red - < 1 month
}

var color = list_format_color(color_code);

Expand Down
27 changes: 11 additions & 16 deletions Modules/feed/Views/feedlist_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,16 @@ function update_feed_list() {

// Color code for node is based on highest level of feeds
var node_color_code = 0;
var node_fv = false;
var node_fv = null;
var node_size = 0;

// 1. Generate the feed rows

for (var feed in nodes[node]) {
var feed = nodes[node][feed];
var feedid = feed.id;
// Sum the size of all feeds in this node
node_size += Number(feed.size);

var title_lines = [feed.name,
'-----------------------',
Expand Down Expand Up @@ -457,19 +459,10 @@ function update_feed_list() {

row_title = title_lines.join("\n");

var this_feed_interval = false;
if (feed.engine == 5) {
this_feed_interval = feed.interval;
}

// Get the format for the feed
var fv = list_format_updated_obj(feed.time,this_feed_interval);

// If not set, set the first feed as the node color code
if (node_fv==false) node_fv = fv;

// If the current feed has a higher color code, set it as the node color code
if (fv.color_code > node_color_code) {
var fv = list_format_updated_obj(feed.time,feed.interval);
if (feed.time != null && parseInt(feed.engine) !== 7 && fv.color_code > node_color_code) {
// If the current feed has a higher color code, set it as the node color code
node_color_code = fv.color_code;
node_fv = fv;
}
Expand Down Expand Up @@ -499,17 +492,19 @@ function update_feed_list() {
feed_section += ' <div class="node-feed-right pull-right">';
if (feed.unit==undefined) feed.unit = "";
feed_section += ' <div class="value text-center" data-col="C">'+list_format_value(feed.value)+' '+feed.unit+'</div>';
feed_section += ' <div class="time text-center" data-col="D">'+list_format_updated(feed.time,this_feed_interval)+'</div>';
feed_section += ' <div class="time text-center" data-col="D">'+list_format_updated(feed.time,feed.interval)+'</div>';
feed_section += ' </div>';
feed_section += '</div>';

// Sum the size of all feeds in this node
node_size += Number(feed.size);
}

feed_section += "</div>";

// 2. Generate the node row for the feeds above

// If not set, use default
if (node_fv==null) node_fv = list_format_updated_obj(0);

let node_row = "";
node_row += '<div class="node accordion" style="--status-color: '+ node_fv.color + '">';
node_row += ' <div class="node-info accordion-toggle thead'+(isCollapsed ? ' collapsed' : '')+'" data-toggle="collapse" data-target="#collapse'+counter+'">'
Expand Down

0 comments on commit 1c32f96

Please sign in to comment.