Skip to content

Commit

Permalink
Related documents are now working
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 11, 2015
1 parent b3d448a commit 957bc4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions app/views/documentation_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ <h2>Table of Contents</h2>
<div class="col-xs-12 related-documents">
<h2>Related Forge Documents</h2>
<ul>
<li><a href="#">Document Link</a></li>
<li><a href="#">Document Link</a></li>
<li><a href="#">Document Link</a></li>
<li><a href="#">Document Link</a></li>
<li ng-repeat="relatedDoc in doc.relatedDocs">
<a ui-sref="documentation_detail({docId: relatedDoc.id})">{{relatedDoc.title}}</a>
</li>
</ul>
</div><!-- /.related-documents -->

Expand Down
13 changes: 12 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,22 @@ app.get('/api/docs', function(req, res) {
});

app.get('/api/docs/:docsId', function (req,res) {
var item = findById(allDocs(),req.params.docsId);
var docs = allDocs();
var item = findById(docs,req.params.docsId);
if (!item) {
res.status(404);
res.end();
} else {
//Add related docs
item.relatedDocs = [];
while (item.relatedDocs.length < 5 && docs.length != 0) {
var idx = Math.floor(Math.random() * docs.length);
var elem = docs[idx];
if (elem.type === item.type && elem.id != item.id) {
item.relatedDocs.push({id: elem.id, title: elem.title});
}
docs.splice(idx, 1);
}
res.json(item);
}
});
Expand Down

0 comments on commit 957bc4c

Please sign in to comment.