Skip to content
Snippets Groups Projects
Commit a212fe6b authored by matograine's avatar matograine
Browse files

Merge branch 'hugo-version'

parents 47ab0086 c7c4be22
No related branches found
No related tags found
1 merge request!1Draft: add version column
...@@ -14,7 +14,8 @@ let is_path = function (to_test, endpoint) { ...@@ -14,7 +14,8 @@ let is_path = function (to_test, endpoint) {
class BMAEndpoint{ class BMAEndpoint{
constructor(raw_endpoint) { constructor(raw_endpoint, pubkey) {
this.pubkey = pubkey
let infos = raw_endpoint.split(" "); let infos = raw_endpoint.split(" ");
this.type = this.get_endpoint_type(infos); this.type = this.get_endpoint_type(infos);
...@@ -33,6 +34,7 @@ class BMAEndpoint{ ...@@ -33,6 +34,7 @@ class BMAEndpoint{
// TODO manage IPv4/v6 // TODO manage IPv4/v6
this.has_url = this.create_root_url(); this.has_url = this.create_root_url();
this.is_member();
} }
get_endpoint_type(raw_endpoint_array) { get_endpoint_type(raw_endpoint_array) {
...@@ -162,8 +164,27 @@ class BMAEndpoint{ ...@@ -162,8 +164,27 @@ class BMAEndpoint{
this.row = document.createElement('tr') this.row = document.createElement('tr')
fields.forEach(field => { fields.forEach(field => {
let cell = document.createElement('td') let cell = document.createElement('td')
cell.innerText = (this[field] == undefined) ? '' : this[field] cell.innerText = (this[field] == undefined) ? 'ø' : this[field]
this.row.appendChild(cell) this.row.appendChild(cell)
}); });
} }
get_version = async function() {
return fetch(this.url_protocol + this.url_root + '/node/summary/')
.then(response => response.json())
.then(data => this.version = data.duniter.version)
.catch(error => { this.version = "ø" })
}
is_member = async function() {
let url = this.url_protocol + this.url_root + '/wot/identity-of/' + this.pubkey
console.log(url)
return fetch(url)
.then(response => response.json())
.then(data => {
this.member = (data.pubkey ? 'Oui' : 'Non')
})
.catch(error => { this.member = "ø" })
}
} }
\ No newline at end of file
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
<th>Bloc</th> <th>Bloc</th>
<th>Type</th> <th>Type</th>
<th>Rapidité (ms)</th> <th>Rapidité (ms)</th>
<th>version</th>
<th>Membre</th>
</tr> </tr>
</thead> </thead>
</table> </table>
......
class DuniterNodes class DuniterNodes
{ {
constructor (peers) { constructor (peers) {
this.fields = ['url_root', 'head_block', 'type', 'speed'] this.fields = ['url_root', 'head_block', 'type', 'speed', 'version', 'member']
this.ep_body = document.createElement('tbody') this.ep_body = document.createElement('tbody')
this.draw() this.draw()
...@@ -21,7 +21,7 @@ class DuniterNodes ...@@ -21,7 +21,7 @@ class DuniterNodes
peers.forEach(peer => { peers.forEach(peer => {
let endpoints = peer.endpoints; let endpoints = peer.endpoints;
endpoints.forEach(endpoint => { endpoints.forEach(endpoint => {
let ep = new BMAEndpoint(endpoint) let ep = new BMAEndpoint(endpoint, peer.pubkey)
if (ep.has_url) { if (ep.has_url) {
this.endpoints.push(ep) this.endpoints.push(ep)
} }
...@@ -38,6 +38,7 @@ class DuniterNodes ...@@ -38,6 +38,7 @@ class DuniterNodes
ep.draw_row(fields) ep.draw_row(fields)
this.insert(ep) this.insert(ep)
}) })
ep.get_version()
}) })
} }
...@@ -100,6 +101,7 @@ class DuniterNodes ...@@ -100,6 +101,7 @@ class DuniterNodes
let rows = this.ep_body.childNodes let rows = this.ep_body.childNodes
rows.forEach(row => { rows.forEach(row => {
let cells = row.childNodes let cells = row.childNodes
switch (cells[1].innerText) { switch (cells[1].innerText) {
case consensus_block: case consensus_block:
cells[1].setAttribute('class', 'consensus') cells[1].setAttribute('class', 'consensus')
...@@ -107,13 +109,22 @@ class DuniterNodes ...@@ -107,13 +109,22 @@ class DuniterNodes
case 'undefined': case 'undefined':
cells[1].setAttribute('class', 'unreachable') cells[1].setAttribute('class', 'unreachable')
break break
case '': case 'ø':
cells[1].setAttribute('class', 'unreachable') cells[1].setAttribute('class', 'unreachable')
break break
default: default:
cells[1].setAttribute('class', 'desynchronized') cells[1].setAttribute('class', 'desynchronized')
break break
} }
switch(cells[5].innerText) {
case 'Oui':
cells[5].setAttribute('class', 'consensus')
break
case 'Non':
cells[5].setAttribute('class', 'desynchronized')
break
}
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment