Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ const app = express();

const allScans = [];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to avoid repetitions in the "recent" page.
I want to add one by one unique items on that page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the way to handle changes and features. We create an issue, discuss it and push it.
Hidding secret features in unrelated commits is not appropriate decision workflow and distracting for code review

function logScanned(uuid, fixture) {
function logScanned(uuid, allMatches) {
const now = new Date();
// TRICK: fixture tells if the the uuid was found in database or not
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
return;
}
const now = new Date();
if (!fixture) {
allScans.unshift({ time: now, status: 'missing', uuid });
allScans.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status);
if (allMatches.length > 1) {
allMatches.map((item, index) =>
allScans.unshift({
time: now,
fixture: allMatches[index].fixture ? allMatches[index].fixture : '',
status: allMatches[index].fixture ? '' : 'missing',
uuid,
double: true,
}));
return;
}
allScans.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status);
allScans.unshift({ time: now, fixture, uuid });
allScans.unshift({
time: now,
fixture: allMatches[0].fixture ? allMatches[0].fixture : '',
status: allMatches[0].fixture ? '' : 'missing',
uuid,
});
}

app.set('view engine', 'ejs');
Expand Down Expand Up @@ -65,7 +77,7 @@ app.get('/:uuid', (req, res) => {
});
return;
}
logScanned(req.params.uuid, matches[0].fixture);
logScanned(req.params.uuid, matches);
matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

off topic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps amateur questions, but why remove the hard URL and how else do we get a link to work?

.filter(item => item.uuid !== matches[0].uuid)
.splice(0, 3);
Expand Down
12 changes: 11 additions & 1 deletion views/recent.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
<h1>Recently scanned QR code</h1>
<article class="col-xs-12">
<ul class='recent-list'>
<% for(var i = 0; i <allScans.length; i++){%>
<% for(var i = 0; i <allScans.length; i++){ %>
<% if(allScans[i].fixture) { %>
<li>
<a href="/<%- allScans[i].uuid %>"><%- allScans[i].time.toTimeString() %> - <%- allScans[i].fixture %> </a> :<br/>
<%- allScans[i].uuid %>
<% if (allScans[i].double) { %>
<span style="color: red" >
Duplicate UUID!
</span>
<% } %>
</li>
<% } else { %>
<li>
Expand All @@ -17,6 +22,11 @@
:<br/>
<%- allScans[i].uuid %>
</span>
<% if (allScans[i].double) { %>
<span style="color: red" >
Duplicate UUID!
</span>
<% } %>
</li>
<%}%>
<%}%>
Expand Down