Adding indirection to review accesses
This commit is contained in:
parent
68b1b85b2a
commit
7f65091035
@ -81,7 +81,7 @@
|
|||||||
{{#each results}}
|
{{#each results}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{id}}</td>
|
<td>{{id}}</td>
|
||||||
<td><a href="{{url}}">{{name}}</a></td>
|
<td><a href="javascript:accessReview({{id}});">{{name}}</a></td>
|
||||||
<th>{{distanceToUser}} km</th>
|
<th>{{distanceToUser}} km</th>
|
||||||
<th>{{closestStn}}</th>
|
<th>{{closestStn}}</th>
|
||||||
<th>{{distanceToStn}} km</th>
|
<th>{{distanceToStn}} km</th>
|
||||||
|
@ -33,6 +33,14 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function accessReview(id) {
|
||||||
|
$.getJSON('/access', {id: id}, function(results) {
|
||||||
|
if (results.success) {
|
||||||
|
location.replace(results.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onReady(geo) {
|
function onReady(geo) {
|
||||||
_ctx = {
|
_ctx = {
|
||||||
geo: geo,
|
geo: geo,
|
||||||
@ -41,6 +49,8 @@
|
|||||||
|
|
||||||
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
|
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
|
||||||
|
|
||||||
|
window.accessReview = accessReview;
|
||||||
|
|
||||||
onSearch();
|
onSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ function findRecords(data, features, minScore) {
|
|||||||
walkMatches(data, features, minScore, function(record, score) {
|
walkMatches(data, features, minScore, function(record, score) {
|
||||||
results.push({
|
results.push({
|
||||||
name: record.name,
|
name: record.name,
|
||||||
url: 'http://www.tripadvisor.com' + record.relativeUrl,
|
|
||||||
score: score,
|
score: score,
|
||||||
distanceToUser: record.distanceToUser / 1000.0,
|
distanceToUser: record.distanceToUser / 1000.0,
|
||||||
distanceToStn: record.distanceToStn / 1000.0,
|
distanceToStn: record.distanceToStn / 1000.0,
|
||||||
@ -146,7 +145,6 @@ function getRecords(context, callback) {
|
|||||||
return {
|
return {
|
||||||
name: row.name,
|
name: row.name,
|
||||||
id: row.id,
|
id: row.id,
|
||||||
relativeUrl: row.url,
|
|
||||||
closestStn: row.closestStn,
|
closestStn: row.closestStn,
|
||||||
distanceToStn: row.distanceToStn,
|
distanceToStn: row.distanceToStn,
|
||||||
geo: {
|
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) {
|
function runQuery(query, callback) {
|
||||||
sanitizeQuery(query);
|
sanitizeQuery(query);
|
||||||
|
|
||||||
@ -291,5 +309,6 @@ module.exports = {
|
|||||||
loadDb: loadDb,
|
loadDb: loadDb,
|
||||||
runQuery: runQuery,
|
runQuery: runQuery,
|
||||||
getCategories: getCategories,
|
getCategories: getCategories,
|
||||||
addCategory: addCategory
|
addCategory: addCategory,
|
||||||
|
accessReview: accessReview
|
||||||
};
|
};
|
||||||
|
@ -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.use(express.static(path.join(__dirname, '..', staticFiles)));
|
||||||
app.listen(port);
|
app.listen(port);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user