Skip to content

Commit

Permalink
client pages: render identicons on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
skylenet committed Aug 27, 2024
1 parent 74b1c7c commit 3e434a5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 85 deletions.
2 changes: 0 additions & 2 deletions cmd/dora-explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ func startFrontend(webserver *http.Server) {
router.HandleFunc("/validator/{idxOrPubKey}", handlers.Validator).Methods("GET")
router.HandleFunc("/validator/{index}/slots", handlers.ValidatorSlots).Methods("GET")

router.HandleFunc("/identicon", handlers.Identicon).Methods("GET")

if utils.Config.Frontend.Pprof {
// add pprof handler
router.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
Expand Down
2 changes: 0 additions & 2 deletions handlers/clients_cl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func buildCLPeerMapData() *models.ClientCLPageDataPeerMap {
ID: peerID,
Label: client.GetName(),
Group: "internal",
Image: fmt.Sprintf("/identicon?key=%s", peerID),
Shape: "circularImage",
}
nodes[peerID] = &node
Expand All @@ -90,7 +89,6 @@ func buildCLPeerMapData() *models.ClientCLPageDataPeerMap {
ID: peer.PeerID,
Label: fmt.Sprintf("%s...%s", peer.PeerID[0:5], peer.PeerID[len(peer.PeerID)-5:]),
Group: "external",
Image: fmt.Sprintf("/identicon?key=%s", peer.PeerID),
Shape: "circularImage",
}
nodes[peer.PeerID] = &node
Expand Down
2 changes: 0 additions & 2 deletions handlers/clients_el.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func buildELPeerMapData() *models.ClientELPageDataPeerMap {
ID: peerID,
Label: client.GetName(),
Group: "internal",
Image: fmt.Sprintf("/identicon?key=%s", peerID),
Shape: "circularImage",
}
nodes[peerID] = &node
Expand Down Expand Up @@ -121,7 +120,6 @@ func buildELPeerMapData() *models.ClientELPageDataPeerMap {
ID: peerID,
Label: fmt.Sprintf("%s...%s", peerID[0:5], peerID[len(peerID)-5:]),
Group: "external",
Image: fmt.Sprintf("/identicon?key=%s", peerID),
Shape: "circularImage",
}
nodes[peerID] = &node
Expand Down
46 changes: 0 additions & 46 deletions handlers/identicon.go

This file was deleted.

4 changes: 2 additions & 2 deletions static/css/clients.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Client peers table
.client-node-icon {
border-radius:50%;
border:1px solid #0f0f0f;
background-color: #fafafa;
background-color: #111111;
margin-right: 10px;
height: 25px;
width: 25px;
Expand All @@ -20,7 +20,7 @@ Client peers table
height: 25px;
border-radius: 50%;
border: 2px solid #0f0f0f;
background-color: #fafafa;
background-color: #111111;
margin-right: 10px;
}

Expand Down
7 changes: 6 additions & 1 deletion static/js/cytoscape-network-aux.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ $_network.create = function (container, data){
classes: "bottom-center",
}
);
svgIdenticon = jdenticon.toSvg(data.nodes[i].id, 80);
// Add style to nodes
stylesheet.selector('#' + data.nodes[i].id).css({
'background-image': '/identicon?key=' + data.nodes[i].id
'shape': 'circle',
'background-image': 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svgIdenticon),
'background-fit': 'cover',
'background-opacity': 1,
'background-color': '#111111',
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions static/js/vendor/jdenticon-3.3.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 13 additions & 14 deletions templates/clients/clients_cl.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,16 @@ <h2 class="accordion-header">
<tr>
<td>{{ $client.Index }}</td>
<td>
<img src="/identicon?key={{ $client.PeerID }}"
alt="{{ $client.PeerID }}"
class="client-node-icon"/>
<span
id="clientRow-{{ $client.Name }}"
style="cursor:pointer;"
onclick="$_network.isolateNode(cy, '{{ $client.PeerID}}');
$('.collapse.peerInfo').collapse('hide');
$('#peerInfo-{{ $client.PeerID }}').collapse('show');
">
<a href="#name={{ $client.Name }}">{{ $client.Name }}</a>
</span>
<svg class="client-node-icon" data-jdenticon-value="{{ $client.PeerID }}"></svg>
<span
id="clientRow-{{ $client.Name }}"
style="cursor:pointer;"
onclick="$_network.isolateNode(cy, '{{ $client.PeerID}}');
$('.collapse.peerInfo').collapse('hide');
$('#peerInfo-{{ $client.PeerID }}').collapse('show');
">
<a href="#name={{ $client.Name }}">{{ $client.Name }}</a>
</span>
</td>
<td style="font-size: 0.8rem; vertical-align: middle;">
<span style="width:30px;display: inline-block;" class="text-success" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Inbound Peers">
Expand Down Expand Up @@ -122,7 +120,7 @@ <h2 class="accordion-header">
{{ range $j, $peer := $client.Peers }}
{{if eq "inbound" $peer.Direction}}
<div style="padding-left: 20px; padding-top:3px">
<img src="/identicon?key={{ $peer.ID }}" class="peer-table-icon {{ $peer.State }}" alt="{{ $peer.State }}"/>
<svg class="peer-table-icon {{ $peer.State }}" data-jdenticon-value="{{ $peer.ID }}"></svg>
<code data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $peer.ID }}">
{{ $peer.Alias }}
{{ if eq $peer.Type "internal" }}
Expand All @@ -139,7 +137,7 @@ <h2 class="accordion-header">
{{ range $j, $peer := $client.Peers }}
{{if eq "outbound" $peer.Direction}}
<div style="padding-left: 20px; padding-top:3px">
<img src="/identicon?key={{ $peer.ID }}" class="peer-table-icon {{ $peer.State }}" alt="{{ $peer.State }}"/>
<svg class="peer-table-icon {{ $peer.State }}" data-jdenticon-value="{{ $peer.ID }}"></svg>
<code data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $peer.ID }}">
{{ $peer.Alias }}
{{ if eq $peer.Type "internal" }}
Expand Down Expand Up @@ -179,6 +177,7 @@ <h2 class="accordion-header">
{{ end }}

{{ define "js" }}
<script src="/js/vendor/jdenticon-3.3.0.min.js"></script>
<script src="/js/vendor/cytoscape.min.js"></script>
<script src="/js/vendor/cytoscape-layout-base.js"></script>
<script src="/js/vendor/cytoscape-cose-base.js"></script>
Expand Down
27 changes: 13 additions & 14 deletions templates/clients/clients_el.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,16 @@ <h2 class="accordion-header">
<tr>
<td>{{ $client.Index }}</td>
<td>
<img src="/identicon?key={{ $client.PeerID }}"
alt="{{ $client.PeerID }}"
class="client-node-icon"/>
<span
id="clientRow-{{ $client.Name }}"
style="cursor:pointer;"
onclick="$_network.isolateNode(cy, '{{ $client.PeerID}}');
$('.collapse.peerInfo').collapse('hide');
$('#peerInfo-{{ $client.PeerID }}').collapse('show');
">
<a href="#name={{ $client.Name }}">{{ $client.Name }}</a>
</span>
<svg class="client-node-icon" data-jdenticon-value="{{ $client.PeerID }}"></svg>
<span
id="clientRow-{{ $client.Name }}"
style="cursor:pointer;"
onclick="$_network.isolateNode(cy, '{{ $client.PeerID}}');
$('.collapse.peerInfo').collapse('hide');
$('#peerInfo-{{ $client.PeerID }}').collapse('show');
">
<a href="#name={{ $client.Name }}">{{ $client.Name }}</a>
</span>
</td>
<td style="font-size: 0.8rem; vertical-align: middle;">
<span style="width:30px;display: inline-block;" class="text-success" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Inbound Peers">
Expand Down Expand Up @@ -150,7 +148,7 @@ <h2 class="accordion-header">
{{ range $j, $peer := $client.Peers }}
{{if eq "inbound" $peer.Direction}}
<div style="padding-left: 20px; padding-top:3px">
<img src="/identicon?key={{ $peer.ID }}" class="peer-table-icon" title="{{ $peer.State }}"/>
<svg class="peer-table-icon {{ $peer.State }}" data-jdenticon-value="{{ $peer.ID }}"></svg>
<code data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $peer.ID }}">
{{ $peer.Alias }}
{{ if eq $peer.Type "internal" }}
Expand All @@ -167,7 +165,7 @@ <h2 class="accordion-header">
{{ range $j, $peer := $client.Peers }}
{{if eq "outbound" $peer.Direction}}
<div style="padding-left: 20px; padding-top:3px">
<img src="/identicon?key={{ $peer.ID }}" class="peer-table-icon {{ $peer.State }}" alt="{{ $peer.State }}"/>
<svg class="peer-table-icon {{ $peer.State }}" data-jdenticon-value="{{ $peer.ID }}"></svg>
<code data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $peer.ID }}">
{{ $peer.Alias }}
{{ if eq $peer.Type "internal" }}
Expand Down Expand Up @@ -207,6 +205,7 @@ <h2 class="accordion-header">
{{ end }}

{{ define "js" }}
<script src="/js/vendor/jdenticon-3.3.0.min.js"></script>
<script src="/js/vendor/cytoscape.min.js"></script>
<script src="/js/vendor/cytoscape-layout-base.js"></script>
<script src="/js/vendor/cytoscape-cose-base.js"></script>
Expand Down
Loading

0 comments on commit 3e434a5

Please sign in to comment.