comparison service/collector/static/state.js @ 1451:71684fc9c692

new index page table Ignore-this: 7668675a04bd5cc03cf4e1799c54d4d1 darcs-hash:5b546637d01f1fa70134c09470007ed1251d708c
author drewp <drewp@bigasterisk.com>
date Wed, 25 Sep 2019 17:27:35 -0700
parents
children 25b418e2659e
comparison
equal deleted inserted replaced
1450:ca96da46c73e 1451:71684fc9c692
1 import { LitElement, TemplateResult, html, css } from '/lib/lit-element/2.2.0/lit-element-custom.js';
2
3 class CollectorState extends LitElement {
4 static get properties() {
5 return {
6 latestState: { type: Object }
7 };
8 }
9 firstUpdated() {
10 this.latestState = {graphClients: {}};
11 this.refreshLoop();
12 }
13
14 refreshLoop() {
15 setTimeout(() => {
16 requestAnimationFrame(() => {
17 this.refresh();
18 });
19 }, 5000);
20 }
21
22 refresh() {
23 fetch('state')
24 .then((response) => {
25 return response.json();
26 })
27 .then((newState) => {
28 this.latestState = newState;
29 this.refreshLoop();
30 });
31 }
32
33 static get styles() {
34 return css`
35 :host {
36 display: inline-block;
37 border: 2px solid gray;
38 padding: 5px;
39 }`;
40 }
41
42 render() {
43 const sourcesTable = (clients) => {
44 const clientRow = (client) => {
45 const d = client.reconnectedPatchSource;
46 return html`
47 <tr>
48 <td><a href="/rdf/browse/?graph=${d.url}">[browse]</a> <a href="${d.url}">${d.url}</a></td>
49 <td>${d.fullGraphReceived}</td>
50 <td>${d.patchesReceived}</td>
51 <td>${d.time.open}</td>
52 <td>${d.time.fullGraph}</td>
53 <td>${d.time.latestPatch}</td>
54 </tr>
55 `;
56 };
57
58 return html`
59 <table>
60 <thead>
61 <tr>
62 <th>patch source</th>
63 <th>full graph recv</th>
64 <th>patches recv</th>
65 <th>time open</th>
66 <th>time fullGraph</th>
67 <th>time latest patch</th>
68 </tr>
69 </thead>
70 <tbody>
71 ${clients.map(clientRow)}
72 </tbody>
73 </table>
74 `;
75 };
76
77 const handlersTable = (handlers) => {
78 const handlerRow = (d) => {
79 return html`
80 <tr>
81 <td>${d.created}</td>
82 <td>${d.ageHours}</td>
83 <td><a href="/rdf/browse/?graph=/sse_collector/graph/${d.streamId}">${d.streamId}</a></td>
84 <td>${d.foafAgent}</td>
85 <td>${d.userAgent}</td>
86 </tr>
87 `;
88 };
89
90 return html`
91 <table>
92 <thead>
93 <tr>
94 <th>created</th>
95 <th>age hours</th>
96 <th>stream</th>
97 <th>foaf agent</th>
98 <th>user agent</th>
99 </tr>
100 </thead>
101 <tbody>
102 ${handlers.map(handlerRow)}
103 </tbody>
104 </table>
105 `;
106 };
107
108 if (!this.latestState) {
109 return 'loading...';
110 }
111 const d = this.latestState.graphClients;
112 return html`
113 <div>
114 <p>
115 Graph: ${d.statements.len} statements
116 </p>
117
118 <p>
119 Sources:
120 ${sourcesTable(d.clients)}
121 </p>
122
123 <p>
124 Listening clients:
125 ${handlersTable(d.sseHandlers)}
126 </p>
127 </div>`;
128 }
129 }
130 customElements.define('collector-state', CollectorState);