-
Notifications
You must be signed in to change notification settings - Fork 3
Log items that share the same UUID #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
9790b58
f19fcc8
4aea460
e4bb3c8
b6dc388
93da255
cae791d
5b37912
6f7a97f
1c1d78a
d04c2cf
9d8e1c8
12229de
3cd5020
d33e8d9
9b0b9a6
e773185
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,28 +6,26 @@ const { loadDatabase, searchDatabase } = require('./googleSpreadsheet'); | |
|
|
||
| const app = express(); | ||
|
|
||
| const allScans = []; | ||
| const allScans = new Map(); | ||
|
|
||
| function logScanned(uuid, matches) { | ||
| let allMatches = matches; | ||
| const now = new Date(); | ||
| function addRecentlyScanned(uuid, item, nbFound = 0) { | ||
| // TRICK: only record uuids | ||
| 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; | ||
| } | ||
| allScans.map(item => item.status = (item.uuid === uuid) ? 'fixed' : item.status); | ||
| if (allMatches.length > 1) { | ||
| allMatches = allMatches.splice(0, 1); | ||
| allMatches[0].double = true; | ||
|
|
||
| const duplicatedItem = item; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if item is a reference or a copy.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is creating any copy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to recheck that, but if that is a reference, then I need the local variable
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really useful reply |
||
| duplicatedItem.time = new Date(); | ||
| duplicatedItem.duplicated = nbFound > 1; | ||
|
|
||
| if (nbFound === 0) { | ||
| duplicatedItem.fixture = ''; | ||
| duplicatedItem.uuid = uuid; | ||
| duplicatedItem.status = 'missing'; | ||
| } | ||
| allScans.unshift({ | ||
| time: now, | ||
| fixture: allMatches[0].fixture ? allMatches[0].fixture : '', | ||
| status: allMatches[0].fixture ? '' : 'missing', | ||
| uuid, | ||
| double: allMatches[0].double, | ||
| link: allMatches[0].cellRef, | ||
| }); | ||
|
|
||
| allScans.set(uuid, duplicatedItem); | ||
| } | ||
|
|
||
| app.set('view engine', 'ejs'); | ||
|
|
@@ -67,17 +65,17 @@ app.get('/:uuid', (req, res) => { | |
| loadDatabase((allItems) => { | ||
| const matches = searchDatabase(req.params, allItems); | ||
| if (matches.length === 0) { | ||
| logScanned(req.params.uuid, [{ fixture: null }]); | ||
| addRecentlyScanned(req.params.uuid, {}); | ||
| res.status(404).render('notFound', { | ||
| item: '', | ||
| id: req.params.uuid, | ||
| }); | ||
| return; | ||
| } | ||
| logScanned(req.params.uuid, matches); | ||
| if (matches.length >= 1) { | ||
| if (matches.length > 1) { | ||
| console.log(`Too much matches for uuid ${req.params.uuid} length = ${matches.length}`); | ||
| } | ||
| addRecentlyScanned(req.params.uuid, matches[0], matches.length); | ||
| matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems) | ||
|
||
| .filter(item => item.uuid !== matches[0].uuid) | ||
| .splice(0, 3); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,21 @@ | |
| <h1>Recently scanned QR codes</h1> | ||
| <article class="col-xs-12"> | ||
| <ul class='recent-list'> | ||
| <% for (var i = 0; i < allScans.length; i++) { %> | ||
| <% for (let item of allScans.values()) { %> | ||
| <li> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mpsido nice! Are there other areas in the code where this rewrite should be applied?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everywhere there is a for loop ;) if you don't care about the index then you can use for..in or for..of.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean do it. |
||
| <%- allScans[i].time.toTimeString() %> - | ||
| <% if (allScans[i].fixture) { %> | ||
| <%- allScans[i].fixture %> | ||
| <%- item.time.toTimeString() %> - | ||
| <% if (item.fixture) { %> | ||
| <%- item.fixture %> | ||
| <% } else { %> | ||
| ??? | ||
| <% } %> | ||
| : <br/> | ||
| <a href="/<%- allScans[i].uuid %>"><%- allScans[i].uuid %></a> | ||
| <% if (!allScans[i].fixture) { %> | ||
| <a href="<%- allScans[i].link %>" style="color: <%- allScans[i].status === 'fixed' ? 'orange' : 'red' %>">Missing Details!</a> | ||
| <a href="/<%- item.uuid %>"><%- item.uuid %></a> | ||
| <% if (!item.fixture) { %> | ||
| <a href="<%- item.link %>" style="color: <%- item.status === 'fixed' ? 'orange' : 'red' %>">Missing Details!</a> | ||
| <% } %> | ||
| <% if (allScans[i].double) { %> | ||
| <a href="<%- allScans[i].link %>" style="color: red">Duplicate UUID!</a> | ||
| <% if (item.duplicated) { %> | ||
| <a href="<%- item.link %>" style="color: red">Duplicate UUID!</a> | ||
| <% } %> | ||
| </li> | ||
| <% } %> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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