-
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 7 commits
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 |
|---|---|---|
|
|
@@ -8,29 +8,25 @@ const app = express(); | |
|
|
||
| const allScans = []; | ||
|
|
||
| function logScanned(uuid, allMatches) { | ||
| function logScanned(uuid, matches) { | ||
| let allMatches = matches; | ||
|
||
| const now = new Date(); | ||
| // TRICK: fixture tells if the the uuid was found in database or not | ||
| // 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.map((item, index) => | ||
| allScans.unshift({ | ||
| time: now, | ||
| fixture: allMatches[index].fixture ? allMatches[index].fixture : '', | ||
| status: allMatches[index].fixture ? '' : 'missing', | ||
| uuid, | ||
| double: true, | ||
| })); | ||
| return; | ||
| allMatches = allMatches.splice(0, 1); | ||
| allMatches[0].double = true; | ||
| } | ||
| 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, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -44,9 +40,10 @@ app.get(['/favicon.ico', '/robots.txt'], (req, res) => { | |
|
|
||
| app.get('/search', (req, res) => { | ||
| loadDatabase((allItems) => { | ||
| console.log(allItems); | ||
| res.render('search', { | ||
| matches: searchDatabase(req.query, allItems) | ||
| .sort((a, b) => (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)), | ||
| matches: searchDatabase(req.query, allItems).sort((a, b) => | ||
| (a.floor === b.floor ? 0 : +(a.floor > b.floor) || -1)), | ||
| }); | ||
|
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. this is noise, refrain from doing cosmetic changes.
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. you may understand why if you try the git blame command |
||
| }); | ||
| }); | ||
|
|
@@ -70,7 +67,7 @@ app.get('/:uuid', (req, res) => { | |
| loadDatabase((allItems) => { | ||
| const matches = searchDatabase(req.params, allItems); | ||
| if (matches.length === 0) { | ||
| logScanned(req.params.uuid); | ||
| logScanned(req.params.uuid, [{ fixture: null }]); | ||
| res.status(404).render('notFound', { | ||
| item: '', | ||
| id: req.params.uuid, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| const google = require('googleapis'); | ||
| const keys = require('./config/keys'); | ||
|
|
||
| function rowToObject(val, lab) { | ||
| function rowToObject(val, lab, index) { | ||
| const o = {}; | ||
| for (let i = 0; i < lab.length; i += 1) { | ||
| o[lab[i]] = val[i]; | ||
| } | ||
| o.cellRef = 'https://docs.google.com/spreadsheets/d/1QHKa3vUpht7zRl_LEzl3BlUbolz3ZiL8yKHzdBL42dY/edit#gid=0&range=A' + index + ':T' + index; | ||
| return o; | ||
|
||
| } | ||
|
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 a good practice to mix refactoring and altering behaviour ( i.e. deleting cellRef)
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. and now the template for |
||
|
|
||
|
|
@@ -20,8 +21,8 @@ function loadDatabase(callback) { | |
| console.log(`The API returned an error: ${err}`); | ||
| return; | ||
| } | ||
| return callback(response.values.map(row => | ||
| rowToObject(row, response.values[0])).splice(1)); | ||
| return callback(response.values.map((row, index) => | ||
| rowToObject(row, response.values[0], index + 1)).splice(1)); | ||
| }); | ||
|
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. introducing redundant local variable is not recommended. It can be a symptom of poor function breakdown
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 actually meant to break into two steps for better readability,
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. Extracting local variable is usually bad design.
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 understand what "Extracting subfunction" means.
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.
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,25 @@ | ||
| <% include ./partials/header %> | ||
| <div class="resultContainer col-xs-12"> | ||
| <h1>Recently scanned QR code</h1> | ||
| <article class="col-xs-12"> | ||
| <ul class='recent-list'> | ||
| <% 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> | ||
| <h1>Recently scanned QR codes</h1> | ||
| <article class="col-xs-12"> | ||
| <ul class='recent-list'> | ||
| <% for (var i = 0; i < allScans.length; i++) { %> | ||
| <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 %> | ||
| <% } else { %> | ||
| <li> | ||
| <a href="/<%- allScans[i].uuid %>"><%- allScans[i].time.toTimeString() %> | ||
| </a> | ||
| <span style="color:<%- allScans[i].status==='fixed'?'orange':'red'%>" > | ||
| :<br/> | ||
| <%- allScans[i].uuid %> | ||
| </span> | ||
| <% if (allScans[i].double) { %> | ||
| <span style="color: red" > | ||
| Duplicate UUID! | ||
| </span> | ||
| <% } %> | ||
| </li> | ||
| <%}%> | ||
| <%}%> | ||
| </ul> | ||
| </article> | ||
| </div> | ||
| ??? | ||
| <% } %> | ||
| : <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> | ||
|
||
| <% } %> | ||
| <% if (allScans[i].double) { %> | ||
| <a href="<%- allScans[i].link %>" style="color: red">Duplicate UUID!</a> | ||
| <% } %> | ||
| </li> | ||
| <% } %> | ||
| </ul> | ||
| </article> | ||
| <% include ./partials/footer %> | ||
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