Skip to content

Commit 5ee9d79

Browse files
author
Doug Wright
committed
CHANGED: /recent merges the successful scan and not found into 1 single list
1 parent 4db666a commit 5ee9d79

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

app.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,22 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet');
66

77
const app = express();
88

9-
const recentScans = {
10-
assigned: [],
11-
unassigned: [],
12-
};
13-
9+
const allScans = [];
1410

1511
function logScanned(uuid, fixture) {
1612
// TRICK: fixture tells if the the uuid was found in database or not
17-
1813
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
1914
return;
2015
}
2116
const now = new Date();
2217
if (!fixture) {
23-
recentScans.unassigned.unshift({ time: now, status: 'missing', uuid });
18+
allScans.unshift({ time: now, status: 'missing', uuid });
2419
return;
2520
}
26-
recentScans.unassigned.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status);
27-
recentScans.assigned.unshift({ time: now, fixture, uuid });
21+
allScans.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status);
22+
allScans.unshift({ time: now, fixture, uuid });
2823
}
2924

30-
3125
app.set('view engine', 'ejs');
3226

3327
app.use(express.static(`${__dirname}/public`));
@@ -57,7 +51,7 @@ app.get('/qrlist', (req, res) => {
5751
});
5852

5953
app.get('/recent', (req, res) => {
60-
res.render('recent', { data: recentScans });
54+
res.render('recent', { allScans });
6155
});
6256

6357
app.get('/:uuid', (req, res) => {

views/recent.ejs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
<div class="resultContainer col-xs-12">
33
<h1>Recently scanned QR code</h1>
44
<article class="col-xs-12">
5-
<h2>Not Found</h2>
65
<ul class='recent-list'>
7-
<% for(var i = 0; i<data.unassigned.length; i++){%>
8-
<li>
9-
<a href="/<%- data.unassigned[i].uuid %>"><%- data.unassigned[i].time.toTimeString() %> - <%- data.unassigned[i].status %> </a> :<br/>
10-
<%- data.unassigned[i].uuid %>
11-
</li>
12-
<%}%>
13-
</ul>
14-
</article>
15-
<article class="col-xs-12">
16-
<h2>Recent Item</h2>
17-
<ul class='recent-list'>
18-
<% for(var i = 0; i<data.assigned.length; i++){%>
19-
<li>
20-
<a href="/<%- data.assigned[i].uuid %>"><%- data.assigned[i].time.toTimeString() %> - <%- data.assigned[i].fixture %> </a>: <br/>
21-
<%- data.assigned[i].uuid %>
22-
</li>
6+
<% for(var i = 0; i <allScans.length; i++){%>
7+
<% if(allScans[i].fixture) { %>
8+
<li>
9+
<a href="/<%- allScans[i].uuid %>"><%- allScans[i].time.toTimeString() %> - <%- allScans[i].fixture %> </a> :<br/>
10+
<%- allScans[i].uuid %>
11+
</li>
12+
<% } else { %>
13+
<li>
14+
<a href="/<%- allScans[i].uuid %>"><%- allScans[i].time.toTimeString() %>
15+
</a>
16+
<span style="color:<%- allScans[i].status==='fixed'?'orange':'red'%>" >
17+
:<br/>
18+
<%- allScans[i].uuid %>
19+
</span>
20+
</li>
21+
<%}%>
2322
<%}%>
2423
</ul>
2524
</article>

0 commit comments

Comments
 (0)