Skip to content

Commit f0d3921

Browse files
author
Peter Pratscher
committed
Fix some minor frontend issues
1 parent d6b39af commit f0d3921

File tree

11 files changed

+169
-286
lines changed

11 files changed

+169
-286
lines changed

handlers/index.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package handlers
1818

1919
import (
20-
"coda-explorer/db"
2120
"coda-explorer/services"
2221
"coda-explorer/templates"
2322
"coda-explorer/types"
@@ -47,16 +46,7 @@ func Index(w http.ResponseWriter, r *http.Request) {
4746
Version: version.Version,
4847
}
4948

50-
var stats []*types.Statistic
51-
err := db.DB.Select(&stats, "SELECT * FROM statistics WHERE value > 0 ORDER BY ts, indicator")
52-
if err != nil {
53-
logger.Errorf("error retrieving statistcs data for route %v: %v", r.URL.String(), err)
54-
http.Error(w, "Internal server error", 503)
55-
return
56-
}
57-
indexPageData.ChartData = stats
58-
59-
err = indexTemplate.ExecuteTemplate(w, "layout", data)
49+
err := indexTemplate.ExecuteTemplate(w, "layout", data)
6050

6151
if err != nil {
6252
logger.Errorf("error executing template for %v route: %v", r.URL.String(), err)

services/services.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func getIndexPageData() (*types.IndexPageData, error) {
115115
return nil, fmt.Errorf("error retrieving total staked data: %w", err)
116116
}
117117

118+
err = db.DB.Get(&data.Peers, "select peerscount from daemonstatus order by ts desc limit 1;")
119+
if err != nil {
120+
return nil, fmt.Errorf("error retrieving peerscount data: %w", err)
121+
}
122+
118123
return data, nil
119124
}
120125

static/img/Developers.svg

Lines changed: 65 additions & 0 deletions
Loading

static/js/layout.js

Lines changed: 3 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -30,194 +30,11 @@ function switchTheme(e) {
3030
}
3131
$('#toggleSwitch').on('change', switchTheme)
3232

33-
// typeahead
34-
$(document).ready(function() {
35-
$('[data-toggle="tooltip"]').tooltip()
36-
37-
var bhValidators = new Bloodhound({
38-
datumTokenizer: Bloodhound.tokenizers.whitespace,
39-
queryTokenizer: Bloodhound.tokenizers.whitespace,
40-
identify: function(obj) {
41-
return obj.index
42-
},
43-
remote: {
44-
url: '/search/validators/%QUERY',
45-
wildcard: '%QUERY'
46-
}
47-
})
48-
49-
var bhBlocks = new Bloodhound({
50-
datumTokenizer: Bloodhound.tokenizers.whitespace,
51-
queryTokenizer: Bloodhound.tokenizers.whitespace,
52-
identify: function(obj) {
53-
return obj.blockroot
54-
},
55-
remote: {
56-
url: '/search/blocks/%QUERY',
57-
wildcard: '%QUERY'
58-
}
59-
})
60-
61-
var bhGraffiti = new Bloodhound({
62-
datumTokenizer: Bloodhound.tokenizers.whitespace,
63-
queryTokenizer: Bloodhound.tokenizers.whitespace,
64-
identify: function(obj) {
65-
return obj.graffiti
66-
},
67-
remote: {
68-
url: '/search/graffiti/%QUERY',
69-
wildcard: '%QUERY'
70-
}
71-
})
72-
73-
var bhEpochs = new Bloodhound({
74-
datumTokenizer: Bloodhound.tokenizers.whitespace,
75-
queryTokenizer: Bloodhound.tokenizers.whitespace,
76-
identify: function(obj) {
77-
return obj.blockroot
78-
},
79-
remote: {
80-
url: '/search/epochs/%QUERY',
81-
wildcard: '%QUERY'
82-
}
83-
})
84-
85-
$('.typeahead').typeahead(
86-
{
87-
minLength: 1,
88-
highlight: true,
89-
hint: false,
90-
autoselect: false
91-
},
92-
{
93-
limit: 5,
94-
name: 'validators',
95-
source: bhValidators,
96-
display: 'pubkey',
97-
templates: {
98-
header: '<h3>Validators</h3>',
99-
suggestion: function(data) {
100-
return `<div>${data.index}: ${data.pubkey.substring(0, 16)}…</div>`
101-
}
102-
}
103-
},
104-
{
105-
limit: 5,
106-
name: 'blocks',
107-
source: bhBlocks,
108-
display: 'blockroot',
109-
templates: {
110-
header: '<h3>Blocks</h3>',
111-
suggestion: function(data) {
112-
return `<div>${data.slot}: ${data.blockroot.substring(0, 16)}…</div>`
113-
}
114-
}
115-
},
116-
{
117-
limit: 5,
118-
name: 'epochs',
119-
source: bhEpochs,
120-
display: 'epoch',
121-
templates: {
122-
header: '<h3>Epochs</h3>',
123-
suggestion: function(data) {
124-
return `<div>${data.epoch}</div>`
125-
}
126-
}
127-
},
128-
{
129-
limit: 5,
130-
name: 'graffiti',
131-
source: bhGraffiti,
132-
display: 'graffiti',
133-
templates: {
134-
header: '<h3>Graffiti</h3>',
135-
suggestion: function(data) {
136-
if (data.graffiti) {
137-
data.graffiti = data.graffiti.replace(/(^\")|(\"$)'/, '').trim()
138-
return `<div>${data.graffiti}</div>`
139-
} else {
140-
return `<div>${data.slot}<div>`
141-
}
142-
}
143-
}
144-
}
145-
)
146-
147-
$('.typeahead').on('focus', function(event) {
148-
if (event.target.value !== '') {
149-
$(this).trigger(
150-
$.Event('keydown', {
151-
keyCode: 40
152-
})
153-
)
154-
}
155-
})
156-
var searchIcon
157-
158-
// $('input.typeahead').on('blur', function(input) {
159-
// if (searchIcon)
160-
// $(this)
161-
// .parent()
162-
// .parent()
163-
// .append(searchIcon)
164-
// })
165-
166-
// $('input.typeahead').on('focus', function(input) {
167-
// if (searchIcon) searchIcon.detach()
168-
// })
169-
170-
$('.typeahead').on('input', function(input) {
171-
var siblings = $(this)
172-
.parent()
173-
.siblings()
174-
if (siblings && siblings.length) {
175-
searchIcon = siblings
176-
}
177-
if (searchIcon)
178-
if (input.target.value !== '') {
179-
searchIcon.detach()
180-
} else {
181-
$(this)
182-
.parent()
183-
.parent()
184-
.append(searchIcon)
185-
}
186-
187-
$('.tt-suggestion')
188-
.first()
189-
.addClass('tt-cursor')
190-
})
191-
192-
$('.tt-menu').on('mouseenter', function() {
193-
$('.tt-suggestion')
194-
.first()
195-
.removeClass('tt-cursor')
196-
})
197-
198-
$('.tt-menu').on('mouseleave', function() {
199-
$('.tt-suggestion')
200-
.first()
201-
.addClass('tt-cursor')
202-
})
203-
204-
$('.typeahead').on('typeahead:select', function(ev, sug) {
205-
if (sug.blockroot !== undefined) {
206-
window.location = '/block/' + sug.blockroot
207-
} else if (sug.index !== undefined) {
208-
window.location = '/validator/' + sug.index
209-
} else if (sug.epoch !== undefined) {
210-
window.location = '/epoch/' + sug.epoch
211-
} else {
212-
console.log('invalid typeahead-selection', sug)
213-
}
214-
})
215-
})
21633

21734
moment.locale((window.navigator.userLanguage || window.navigator.language).toLowerCase())
218-
$('[aria-ethereum-date]').each(function(item) {
219-
var dt = $(this).attr('aria-ethereum-date')
220-
var format = $(this).attr('aria-ethereum-date-format')
35+
$('[aria-local-date]').each(function(item) {
36+
var dt = $(this).attr('aria-local-date')
37+
var format = $(this).attr('aria-local-date-format')
22138

22239
if (!format) {
22340
format = 'L LTS'

templates/account.html

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,27 +196,25 @@ <h1 class="h4 mb-1 mb-md-0">
196196
<div class="col-md-10">{{.Nonce}}</div>
197197
</div>
198198
<div class="row border-bottom p-3">
199-
<div class="col-md-2">FirstSeen:</div>
200-
<div class="col-md-10">{{.FirstSeen.Format "02 Jan 2006 15:04:05 MST"}}</div>
199+
<div class="col-md-2">Added to Ledger:</div>
200+
<div class="col-md-10"><span aria-local-date="{{.FirstSeen.Unix}}">{{.FirstSeen}}</span></div>
201201
</div>
202202
<div class="row border-bottom p-3">
203-
<div class="col-md-2">LastSeen:</div>
204-
<div class="col-md-10">{{.LastSeen.Format "02 Jan 2006 15:04:05 MST"}}</div>
203+
<div class="col-md-2">Most Recent Activity:</div>
204+
<div class="col-md-10"><span aria-local-date="{{.LastSeen.Unix}}">{{.LastSeen}}</span> (<span aria-local-date="{{.LastSeen.Unix}}" aria-local-date-format="FROMNOW"></span>)</div>
205205
</div>
206206
<div class="row border-bottom p-3">
207207
<div class="col-md-2">Receipt Chain Hash:</div>
208208
<div class="col-md-10 text-monospace text-break">{{.ReceiptChainHash}}</div>
209209
</div>
210210
<div class="row border-bottom p-3">
211211
<div class="col-md-2">Delegate:</div>
212-
<div class="col-md-10 text-monospace text-break">
213-
<a href="/account/{{.Delegate}}">{{.Delegate}}</a>
214-
</div>
215-
</div>
216-
<div class="row border-bottom p-3">
217-
<div class="col-md-2">Voting For:</div>
218-
<div class="col-md-10 text-monospace text-break">
219-
<a href="/account/{{.VotingFor}}">{{.VotingFor}}</a>
212+
<div class="col-md-10 text-break">
213+
{{ if eq .Delegate .PublicKey}}
214+
<span>Not delegating</span>
215+
{{else}}
216+
<a class="text-monospace" href="/account/{{.Delegate}}">{{.Delegate}}</a>
217+
{{end}}
220218
</div>
221219
</div>
222220
<div class="row border-bottom p-3">
@@ -228,7 +226,7 @@ <h1 class="h4 mb-1 mb-md-0">
228226
<div class="col-md-10">{{.TxReceived}}</div>
229227
</div>
230228
<div class="row border-bottom p-3">
231-
<div class="col-md-2">Blocks Proposed:</div>
229+
<div class="col-md-2">Blocks Produced:</div>
232230
<div class="col-md-10">{{.BlocksProposed}}</div>
233231
</div>
234232
<div class="row p-3">
@@ -283,7 +281,7 @@ <h1 class="h4 mb-1 mb-md-0">
283281
<thead>
284282
<tr>
285283
<th>Job IDs</th>
286-
<th>Prover</th>
284+
<th>Snark Worker</th>
287285
<th>Fee</th>
288286
<th>Time</th>
289287
<th>Block</th>

templates/accounts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-user mr-2"></i>Accounts</h1>
5959
<table class="table table-sm" id="blocks">
6060
<thead>
6161
<tr>
62-
<th>Public Key</th>
62+
<th>Address</th>
6363
<th>Balance</th>
6464
<th>First Seen</th>
6565
<th>Last Seen</th>

templates/block.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ <h4 class="alert-heading"><i class="fas fa-exclamation-triangle mr-1"></i>Block
7878
</div>
7979
<div class="row border-bottom p-3">
8080
<div class="col-md-2">Time:</div>
81-
<div class="col-md-10">{{.Ts.Format "02 Jan 2006 15:04:05 MST"}}</div>
81+
<div class="col-md-10"><span aria-local-date="{{.Ts.Unix}}">{{.Ts}}</span></div>
8282
</div>
8383
<div class="row border-bottom p-3">
8484
<div class="col-md-2">Creator:</div>
85-
<div class="col-md-10">{{.Creator}}</div>
85+
<div class="col-md-10"><a href="/account/{{.Creator}}">{{.Creator}}</a></div>
8686
</div>
8787
<div class="row border-bottom p-3">
8888
<div class="col-md-2">State Hash:</div>
@@ -107,7 +107,7 @@ <h4 class="alert-heading"><i class="fas fa-exclamation-triangle mr-1"></i>Block
107107
<div class="col-md-10">{{.Coinbase}}</div>
108108
</div>
109109
<div class="row border-bottom p-3">
110-
<div class="col-md-2">Total Currency:</div>
110+
<div class="col-md-2">Coda Supply:</div>
111111
<div class="col-md-10">{{.TotalCurrency | intcomma}}</div>
112112
</div>
113113
<div class="row border-bottom p-3">

templates/funcs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func GetTemplateFuncs() template.FuncMap {
3434
"formatMilliSeconds": formatMilliSeconds,
3535
"formatPGIntArray": formatPGIntArray,
3636
"decodeBase58": decodeBase58,
37+
"joinHtml": joinHtml,
3738
}
3839

3940
gtf.ForceInject(fm)
@@ -60,3 +61,7 @@ func decodeBase58(encoded string) string {
6061
decoded, _ := base58.Decode(encoded)
6162
return string(decoded)
6263
}
64+
65+
func joinHtml(arg string, value []string) template.HTML {
66+
return template.HTML(strings.Join(value, arg))
67+
}

0 commit comments

Comments
 (0)