1

Adding indirection to review accesses

This commit is contained in:
Alex Yatskov 2015-03-09 19:20:19 +09:00
parent 68b1b85b2a
commit 7f65091035
4 changed files with 39 additions and 4 deletions

View File

@ -81,7 +81,7 @@
{{#each results}}
<tr>
<td>{{id}}</td>
<td><a href="{{url}}">{{name}}</a></td>
<td><a href="javascript:accessReview({{id}});">{{name}}</a></td>
<th>{{distanceToUser}} km</th>
<th>{{closestStn}}</th>
<th>{{distanceToStn}} km</th>

View File

@ -33,6 +33,14 @@
});
}
function accessReview(id) {
$.getJSON('/access', {id: id}, function(results) {
if (results.success) {
location.replace(results.url);
}
});
}
function onReady(geo) {
_ctx = {
geo: geo,
@ -41,6 +49,8 @@
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
window.accessReview = accessReview;
onSearch();
}

View File

@ -68,7 +68,6 @@ function findRecords(data, features, minScore) {
walkMatches(data, features, minScore, function(record, score) {
results.push({
name: record.name,
url: 'http://www.tripadvisor.com' + record.relativeUrl,
score: score,
distanceToUser: record.distanceToUser / 1000.0,
distanceToStn: record.distanceToStn / 1000.0,
@ -146,7 +145,6 @@ function getRecords(context, callback) {
return {
name: row.name,
id: row.id,
relativeUrl: row.url,
closestStn: row.closestStn,
distanceToStn: row.distanceToStn,
geo: {
@ -246,6 +244,26 @@ function addCategory(query, callback) {
}
}
function accessReview(query, callback) {
pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) {
if (err) {
throw err;
}
console.log(query.id);
var results = {
success: rows.length > 0
};
if (results.success) {
results.url = 'http://www.tripadvisor.com' + rows[0].url;
}
callback(results);
});
}
function runQuery(query, callback) {
sanitizeQuery(query);
@ -291,5 +309,6 @@ module.exports = {
loadDb: loadDb,
runQuery: runQuery,
getCategories: getCategories,
addCategory: addCategory
addCategory: addCategory,
accessReview: accessReview
};

View File

@ -57,6 +57,12 @@ function main(staticFiles, port) {
});
});
app.use('/access', function(req, res) {
search.accessReview(req.query, function(results) {
res.json(results);
});
});
app.use(express.static(path.join(__dirname, '..', staticFiles)));
app.listen(port);
}