Skip to content

Commit f55be3c

Browse files
author
Doug Wright
authored
Merge pull request #29 from coderbunker/scanList
Scan list
2 parents 906f7bd + 5cd7a9c commit f55be3c

4 files changed

Lines changed: 47 additions & 45 deletions

File tree

app.js

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

77
const app = express();
88

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

14-
const date = new Date();
15-
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
16-
const hour = date.getHours();
17-
const dayOfWeek = date.getDay();
18-
const week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
19-
const scanTime = week[dayOfWeek] + ' ' + hour + ':' + minutes;
11+
function logScanned(uuid, fixture) {
12+
// TRICK: fixture tells if the the uuid was found in database or not
13+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
14+
return;
15+
}
16+
const now = new Date();
17+
if (!fixture) {
18+
allScans.unshift({ time: now, status: 'missing', uuid });
19+
return;
20+
}
21+
allScans.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status);
22+
allScans.unshift({ time: now, fixture, uuid });
23+
}
2024

2125
app.set('view engine', 'ejs');
2226

@@ -47,21 +51,21 @@ app.get('/qrlist', (req, res) => {
4751
});
4852

4953
app.get('/recent', (req, res) => {
50-
res.render('recent', { data: recentScans });
54+
res.render('recent', { allScans });
5155
});
5256

5357
app.get('/:uuid', (req, res) => {
5458
loadDatabase((allItems) => {
5559
const matches = searchDatabase(req.params, allItems);
5660
if (matches.length === 0) {
57-
recentScans.unassigned.push([scanTime, req.params.uuid]);
61+
logScanned(req.params.uuid);
5862
res.render('notFound', {
5963
item: '',
6064
id: req.params.uuid,
6165
});
6266
return;
6367
}
64-
recentScans.assigned.push([scanTime, matches[0].fixture, req.params.uuid]);
68+
logScanned(req.params.uuid, matches[0].fixture);
6569
matches.similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
6670
.filter(item => item.uuid !== matches[0].uuid)
6771
.splice(0, 3);

public/main.css

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
position: relative;
1111
}
1212

13-
1413
.recent-list {
1514
list-style-type: none;
16-
padding-bottom: 5px;
17-
}
18-
15+
padding-left: 0;
16+
}
17+
.recent-list li {
18+
padding-bottom: 5px;
19+
}
1920

2021
#appTitle {
2122
color: white;
@@ -94,7 +95,3 @@ article {
9495
padding-top: 1em;
9596
padding-bottom: 1em;
9697
}
97-
98-
/*@media print {
99-
font-size: 0.2em;
100-
}*/

views/notFound.ejs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<% include ./partials/header %>
22

3-
<div class="notFound">
4-
<img src="/emoji.png" alt="">
5-
<p>Sorry, item with the id <strong><%= id %></strong> not found</p>
3+
<div class="col-xs-12">
4+
<img class="col-xs-12" src="/emoji.png" alt="">
5+
<p>Sorry, item not found with the id:</p>
6+
<p>
7+
<strong><%= id %></strong>
8+
</p>
69
</div>
7-
10+
811
<% include ./partials/footer %>

views/recent.ejs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
<% include ./partials/header %>
2-
32
<div class="resultContainer col-xs-12">
43
<h1>Recently scanned QR code</h1>
54
<article class="col-xs-12">
6-
<h2>Not Found</h2>
7-
8-
<% for(var i = 0; i<data.unassigned.length; i++){%>
9-
<li class="recent-list">
10-
<a href="<%- data.unassigned[i][1] %>"><%- data.unassigned[i][0] %></a>
11-
<br />
12-
<%- data.unassigned[i][1] %>
13-
</li>
14-
<%}%>
15-
16-
</article>
17-
<article class="col-xs-12">
18-
<h2>Recent Item</h2>
19-
<% for(var i = 0; i<data.assigned.length; i++){%>
20-
<li class="recent-list">
21-
<a href="/<%- data.assigned[i][2] %>"><%- data.assigned[i][0] %> <%- data.assigned[i][1] %></a><br />
22-
<%- data.assigned[i][2] %> <br />
23-
</a>
24-
</li>
5+
<ul class='recent-list'>
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+
<%}%>
2522
<%}%>
23+
</ul>
2624
</article>
2725
</div>
2826
<% include ./partials/footer %>

0 commit comments

Comments
 (0)