Skip to content

Commit 5a4dee1

Browse files
author
Doug Wright
authored
Merge pull request #45 from coderbunker/simplerObj
remove complex object handling from templates
2 parents 4ba9062 + 4ed4b6e commit 5a4dee1

4 files changed

Lines changed: 43 additions & 47 deletions

File tree

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ app.get('/:uuid', (req, res) => {
6666
return;
6767
}
6868
logScanned(req.params.uuid, matches[0].fixture);
69-
matches.similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
69+
matches[0].similarItems = searchDatabase({ fixture: matches[0].fixture }, allItems)
7070
.filter(item => item.uuid !== matches[0].uuid)
7171
.splice(0, 3);
72-
res.render('item', { matches });
72+
res.render('item', matches[0]);
7373
});
7474
});
7575

views/partials/itemCards.ejs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
<ul class="searchResultList">
2-
<% for(var i = 0; i < matches.length; i++){ %>
3-
<li>
4-
<div class="col-xs-12">
5-
<span> <a href="/search?floor=<%- matches[i].floor %>"> <%- matches[i].floor.toLowerCase() %> </a></span> >
6-
<span> <a href="/search?floor=<%- matches[i].floor %>&room=<%- matches[i].room %>"> <%- matches[i].room.toLowerCase() %> </a></span> >
7-
<span> <a href="/search?floor=<%- matches[i].floor %>&room=<%- matches[i].room %>&location=<%- matches[i].location %>"> <%- matches[i].location.toLowerCase() %> </a></span> >
8-
<span> <a href="/search?fixture=<%- matches[i].fixture %>"> <%- matches[i].fixture.toLowerCase() %> </a></span>
9-
</div>
10-
<div class="well col-xs-12">
11-
<div class="col-xs-2">
12-
<% if (matches[i].picture === undefined || matches[i].picture === '') { %>
13-
<img class="itemImg" src="noImg.png" />
14-
<% }else{ %>
15-
<img class="itemImg" src=" <%- matches[i].picture %> " />
16-
<%}%>
17-
</div>
18-
<div class="itemTitle col-xs-8">
19-
<h4> <a href="/<%- matches[i].uuid %>"> <%- matches[i].fixture.toUpperCase().bold() %> </a> </h4>
20-
<span> <%- matches[i].model.toLowerCase().italics() %> </span>
21-
</div>
22-
<div class="itemImg col-xs-2">
23-
<% if (matches[i].status === 'broken') { %>
24-
<span class="glyphicon glyphicon-wrench" title="Status: <%- matches[i].status %>" alt="<%- matches[i].status %>" style="color:red"></span>
25-
<%}%>
26-
</div>
27-
</div>
28-
</li>
29-
<% } %>
30-
</ul>
1+
<div class="col-xs-12">
2+
<span> <a href="/search?floor=<%- floor %>"> <%- floor.toLowerCase() %> </a></span> >
3+
<span> <a href="/search?floor=<%- floor %>&room=<%- room %>"> <%- room.toLowerCase() %> </a></span> >
4+
<span> <a href="/search?floor=<%- floor %>&room=<%- room %>&location=<%- location %>"> <%- location.toLowerCase() %> </a></span> >
5+
<span> <a href="/search?fixture=<%- fixture %>"> <%- fixture.toLowerCase() %> </a></span>
6+
</div>
7+
<div class="well col-xs-12">
8+
<div class="col-xs-2">
9+
<% if (picture === undefined || picture === '') { %>
10+
<img class="itemImg" src="noImg.png" />
11+
<% }else{ %>
12+
<img class="itemImg" src=" <%- picture %> " />
13+
<%}%>
14+
</div>
15+
<div class="itemTitle col-xs-8">
16+
<h4> <a href="/<%- uuid %>"> <%- fixture.toUpperCase().bold() %> </a> </h4>
17+
<span> <%- model.toLowerCase().italics() %> </span>
18+
</div>
19+
<div class="itemImg col-xs-2">
20+
<% if (status === 'broken') { %>
21+
<span class="glyphicon glyphicon-wrench" title="Status: <%- status %>" alt="<%- status %>" style="color:red"></span>
22+
<%}%>
23+
</div>
24+
</div>

views/partials/itemImgInfo.ejs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
<% if (matches[0].HOWTO) { %>
1+
<% if (HOWTO) { %>
22
<article class="well col-xs-12">
33
<h2>How To</h2>
44
<div>
5-
<%- matches[0].HOWTO %>
5+
<%- HOWTO %>
66
</div>
77
</article>
88
<%}%>
9-
<% if (matches[0].Troubleshooting) { %>
9+
<% if (Troubleshooting) { %>
1010
<article class="well col-xs-12">
1111
<h2>Need Help</h2>
1212
<div>
13-
<%- matches[0].Troubleshooting %>
13+
<%- Troubleshooting %>
1414
</div>
1515
</article>
1616
<% } %>
17-
<% if ( matches.similarItems ) { %>
17+
<% if ( similarItems.length > 0 ) { %>
1818
<article class="well col-xs-12">
1919
<h2>Similar Items</h2>
2020
<div>
21-
<% for(var i = 0; i < matches.similarItems.length; i++){ %>
21+
<% for(var i = 0; i < similarItems.length; i++){ %>
2222
<div class='miniSearchItem col-xs-4'>
23-
<% if (matches.similarItems[i].picture === undefined || matches.similarItems[i].picture === '') { %>
24-
<a href="/<%- matches.similarItems[i].uuid %>"> <img class="miniItemImg" src="noImg.png" /> </a>
23+
<% if (similarItems[i].picture === undefined || similarItems[i].picture === '') { %>
24+
<a href="/<%- similarItems[i].uuid %>"> <img class="miniItemImg" src="noImg.png" /> </a>
2525
<% }else{ %>
26-
<a href="/<%- matches.similarItems[i].uuid %>"> <img class="miniItemImg" src=" <%- matches.similarItems[i].picture %> " /> </a>
26+
<a href="/<%- similarItems[i].uuid %>"> <img class="miniItemImg" src=" <%- similarItems[i].picture %> " /> </a>
2727
<%}%>
2828
</div>
2929
<% } %>
@@ -32,11 +32,11 @@
3232
<%}%>
3333
<article class="well col-xs-12">
3434
<h2>Details</h2>
35-
<%- matches[0].details %>
35+
<%- details %>
3636
<ul>
37-
<li>model: <%- matches[0].model %></li>
38-
<li>serial: <%- matches[0].serial %></li>
39-
<li>owner: <%- matches[0].owner %></li>
40-
<li>UUID: <%- matches[0].uuid %></li>
37+
<li>model: <%- model %></li>
38+
<li>serial: <%- serial %></li>
39+
<li>owner: <%- owner %></li>
40+
<li>UUID: <%- uuid %></li>
4141
</ul>
4242
</article>

views/search.ejs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<% include ./partials/header %>
22
<div class="resultContainer col-xs-12">
3-
<% include ./partials/itemCards %>
3+
<% matches.forEach(function(el) { %>
4+
<%- include('./partials/itemCards', el); %>
5+
<% }) %>
46
</div>
57
<% include ./partials/footer %>

0 commit comments

Comments
 (0)