xref: /openbmc/openbmc-tools/dbus-vis/info_panel.js (revision c403b03712808a0fa8deca1a90327dea67f8937e)
1*c403b037SSui Chen// This function accomplishes drag-and-drop gestures by attaching temporary onmouse{up,move} events to the document
2*c403b037SSui Chen// Only the header is draggable, the content is not
3*c403b037SSui Chenfunction DragElement(elt) {
4*c403b037SSui Chen  var x1=0, y1=0, x2=0, y2=0;
5*c403b037SSui Chen  let header = document.getElementById(elt.id + "_header");
6*c403b037SSui Chen  if (header == undefined) {
7*c403b037SSui Chen    return;
8*c403b037SSui Chen  }
9*c403b037SSui Chen  header.onmousedown = DragMouseDown;
10*c403b037SSui Chen
11*c403b037SSui Chen  function DragMouseDown(e) {
12*c403b037SSui Chen    e = e || window.event;
13*c403b037SSui Chen    e.preventDefault();
14*c403b037SSui Chen    // get the mouse cursor position at startup:
15*c403b037SSui Chen    x2 = e.clientX;
16*c403b037SSui Chen    y2 = e.clientY;
17*c403b037SSui Chen    document.onmouseup = MouseUp;
18*c403b037SSui Chen    // call a function whenever the cursor moves:
19*c403b037SSui Chen    document.onmousemove = MouseMove;
20*c403b037SSui Chen  }
21*c403b037SSui Chen
22*c403b037SSui Chen  function MouseMove(e) {
23*c403b037SSui Chen    e = e || window.event;
24*c403b037SSui Chen    e.preventDefault();
25*c403b037SSui Chen    x1 = x2 - e.clientX; y1 = y2 - e.clientY;
26*c403b037SSui Chen    x2 = e.clientX; y2 = e.clientY;
27*c403b037SSui Chen    elt.style.top = (elt.offsetTop - y1) + "px";
28*c403b037SSui Chen    elt.style.left= (elt.offsetLeft- x1) + "px";
29*c403b037SSui Chen  }
30*c403b037SSui Chen
31*c403b037SSui Chen  function MouseUp() {
32*c403b037SSui Chen    document.onmouseup = null;
33*c403b037SSui Chen    document.onmousemove = null;
34*c403b037SSui Chen  }
35*c403b037SSui Chen}
36*c403b037SSui Chen
37*c403b037SSui Chenfunction GetTotalCount(titles_and_intervals) {
38*c403b037SSui Chen  let ret = 0;
39*c403b037SSui Chen  titles_and_intervals.forEach((ti) => {
40*c403b037SSui Chen    ret += ti[1].length;
41*c403b037SSui Chen  });
42*c403b037SSui Chen  return ret;
43*c403b037SSui Chen}
44*c403b037SSui Chen
45*c403b037SSui Chenvar g_info_panel_table = undefined;
46*c403b037SSui Chen
47*c403b037SSui Chen// 6 rows
48*c403b037SSui Chen// Serial, Sender, Dest, Path, Iface, Member
49*c403b037SSui Chenfunction AddOneRowToTable(t, content) {
50*c403b037SSui Chen  let tr = document.createElement("tr");
51*c403b037SSui Chen  let td = document.createElement("td");
52*c403b037SSui Chen  td.colSpan = 6;
53*c403b037SSui Chen  t.appendChild(tr);
54*c403b037SSui Chen  tr.appendChild(td);
55*c403b037SSui Chen  td.innerText = content;
56*c403b037SSui Chen}
57*c403b037SSui Chen
58*c403b037SSui Chenfunction AddDBusRowHeaderToTable(t) {
59*c403b037SSui Chen  const headers = [ "Serial", "Sender", "Destination", "Path", "Iface", "Member" ];
60*c403b037SSui Chen  let tr = document.createElement("tr");
61*c403b037SSui Chen  headers.forEach((h) => {
62*c403b037SSui Chen    let td = document.createElement("td");
63*c403b037SSui Chen    td.innerText = h;
64*c403b037SSui Chen    td.style.backgroundColor = "#888";
65*c403b037SSui Chen    tr.appendChild(td);
66*c403b037SSui Chen  });
67*c403b037SSui Chen  t.appendChild(tr);
68*c403b037SSui Chen}
69*c403b037SSui Chen
70*c403b037SSui Chenfunction AddDBusMessageToTable(t, m) {
71*c403b037SSui Chen  const minfo = m[2];
72*c403b037SSui Chen  const cols = [
73*c403b037SSui Chen    minfo[2], // serial
74*c403b037SSui Chen    minfo[3], // sender
75*c403b037SSui Chen    minfo[4], // destination
76*c403b037SSui Chen    minfo[5], // path
77*c403b037SSui Chen    minfo[6], // iface
78*c403b037SSui Chen    minfo[7], // member
79*c403b037SSui Chen  ];
80*c403b037SSui Chen  let tr = document.createElement("tr");
81*c403b037SSui Chen  cols.forEach((c) => {
82*c403b037SSui Chen    let td = document.createElement("td");
83*c403b037SSui Chen    td.innerText = c;
84*c403b037SSui Chen    td.onclick = () => {
85*c403b037SSui Chen      console.log(m);
86*c403b037SSui Chen    };
87*c403b037SSui Chen    tr.appendChild(td);
88*c403b037SSui Chen  });
89*c403b037SSui Chen  t.appendChild(tr);
90*c403b037SSui Chen}
91*c403b037SSui Chen
92*c403b037SSui Chenfunction UpdateHighlightedMessagesInfoPanel() {
93*c403b037SSui Chen  const MAX_ENTRIES_SHOWN = 10000; // Show a maximum of this many
94*c403b037SSui Chen  const ti_dbus = dbus_timeline_view.HighlightedMessages();
95*c403b037SSui Chen  const ti_ipmi = ipmi_timeline_view.HighlightedMessages();
96*c403b037SSui Chen
97*c403b037SSui Chen  if (g_info_panel_table != undefined) {
98*c403b037SSui Chen    g_info_panel_table.remove(); // Remove from DOM tree
99*c403b037SSui Chen  }
100*c403b037SSui Chen
101*c403b037SSui Chen  g_info_panel_table = document.createElement("table");
102*c403b037SSui Chen
103*c403b037SSui Chen  const p = document.getElementById("highlighted_messages");
104*c403b037SSui Chen  p.style.display = "block";
105*c403b037SSui Chen
106*c403b037SSui Chen  const x = document.getElementById("highlighted_messages_content");
107*c403b037SSui Chen  x.appendChild(g_info_panel_table);
108*c403b037SSui Chen
109*c403b037SSui Chen  let nshown = 0;
110*c403b037SSui Chen  const count_dbus = GetTotalCount(ti_dbus);
111*c403b037SSui Chen  if (count_dbus > 0) {
112*c403b037SSui Chen    AddOneRowToTable(g_info_panel_table, count_dbus + " DBus messages");
113*c403b037SSui Chen    AddDBusRowHeaderToTable(g_info_panel_table);
114*c403b037SSui Chen    for (let i=0; i<ti_dbus.length; i++) {
115*c403b037SSui Chen      const title_and_msgs = ti_dbus[i];
116*c403b037SSui Chen      // Title
117*c403b037SSui Chen      AddOneRowToTable(g_info_panel_table, title_and_msgs[0]);
118*c403b037SSui Chen      for (let j=0; j<title_and_msgs[1].length; j++) {
119*c403b037SSui Chen        nshown ++;
120*c403b037SSui Chen        if (nshown > MAX_ENTRIES_SHOWN) break;
121*c403b037SSui Chen        AddDBusMessageToTable(g_info_panel_table, title_and_msgs[1][j]);
122*c403b037SSui Chen        // Messages
123*c403b037SSui Chen      }
124*c403b037SSui Chen    }
125*c403b037SSui Chen  }
126*c403b037SSui Chen  const count_ipmi = GetTotalCount(ti_ipmi);
127*c403b037SSui Chen  if (count_ipmi > 0) {
128*c403b037SSui Chen    AddOneRowToTable(g_info_panel_table, count_ipmi + " IPMI messages");
129*c403b037SSui Chen  }
130*c403b037SSui Chen  if (nshown > MAX_ENTRIES_SHOWN) {
131*c403b037SSui Chen    AddOneRowToTable(g_info_panel_table, "Showing only " + MAX_ENTRIES_SHOWN + " entries");
132*c403b037SSui Chen  }
133*c403b037SSui Chen}