This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Group adress updated at
#1
Hi
As subject indicated iam wondering if it is possible to get a "tooltip" when holding mouse over objects in visu that grabs the updated at from group adress?
This is to indicate if the value is new or old?
Reply
#2
As I know only by Custom Javascript + .lp file.

Custom JS could lhave such code:
Code:
$(function(){
  const updatetimes = {};
  const marked = document.querySelectorAll(".when-updated");
  const gaMatcher = /wh\-([0-9]+)_([0-9]+)_([0-9]+)/i;
  const isDef = n => typeof n !== "undefined";
  const showDate = updatetime => new Date(updatetime * 1000).toString();

  marked.forEach(element => {
    let loaded = false;
   
    const [matching, a, b, c] = element.className.match(gaMatcher);
    if (!matching) return;
    const ga = `${a}/${b}/${c}`;

    if (typeof updatetimes[ga] === "undefined") updatetimes[ga] = 0;

    grp.listen(ga, (object, state) => {
      if (state === "value" && loaded) {
        updatetimes[ga] = Date.now()/1000;
        element.title = updatetimes[ga] ? showDate(updatetimes[ga]) : null;
      }
    }, true);
  });
 
  const updateUpdatetimes = data => {
      if (!data) return;
   
    const objects = JSON.parse(data);
   
    Object.keys(updatetimes).forEach(ga => {
      const found = objects.find(obj => obj.address === ga);
      if (found.updatetime > updatetimes[ga]) {
        updatetimes[ga] = found.updatetime;
        document.querySelectorAll(`.wh-${ga.split("/").join("_")}`).forEach(element => element.title = showDate(updatetimes[ga]))
      }
    });
   
    loaded = true;
  }
 
  // download current grp.all() from object.lp
  $.get("/user/objects.lp", data => updateUpdatetimes(data));
});

You need also /user/objects.lp file with such content:
Code:
<?
require("json")
require("genohm-scada")
require("apps")

objects = json.encode(grp.all())
print(objects)
?>

Then all controls on the visu which will have special classes e.g. "when-updated wh-1_1_1" (for 1/1/1 address) will have title with last updated info ().

This is only some scratch, for a startWink
Done is better than perfect
Reply


Forum Jump: