Various improvements
This commit is contained in:
parent
142e163510
commit
c2997ff3a1
36
server.go
36
server.go
@ -81,6 +81,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
item := jsonRecord{
|
||||
Name: value.name,
|
||||
Url: value.url,
|
||||
Score: value.score,
|
||||
DistanceToUser: value.distanceToUser,
|
||||
DistanceToStn: value.distanceToStn,
|
||||
@ -205,27 +206,26 @@ func accessReview(rw http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
reviewRow := db.QueryRow("SELECT url FROM reviews WHERE id = (?) LIMIT 1", request.Id)
|
||||
|
||||
var reply jsonAccessReply
|
||||
if err := reviewRow.Scan(&reply.Url); err == nil {
|
||||
reply.Url = "http://www.tripadvisor.com" + reply.Url
|
||||
reply.Success = true
|
||||
}
|
||||
|
||||
if reply.Success {
|
||||
_, err := db.Exec("UPDATE reviews SET accessCount = accessCount + 1 WHERE id = (?)", request.Id)
|
||||
reviewsResult, err := db.Exec("UPDATE reviews SET accessCount = accessCount + 1 WHERE id = (?)", request.Id)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if len(request.Profile) > 0 {
|
||||
result, err := db.Exec("INSERT INTO history(date, reviewId) VALUES(NOW(), ?)", request.Id)
|
||||
rowsAffected, err := reviewsResult.RowsAffected()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
insertId, err := result.LastInsertId()
|
||||
if rowsAffected == 0 || len(request.Profile) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
historyResult, err := db.Exec("INSERT INTO history(date, reviewId) VALUES(NOW(), ?)", request.Id)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
insertId, err := historyResult.LastInsertId()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -236,16 +236,6 @@ func accessReview(rw http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
js, err := json.Marshal(reply)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
rw.Write(js)
|
||||
}
|
||||
|
||||
func staticPath() (string, error) {
|
||||
if len(os.Args) > 1 {
|
||||
|
@ -106,12 +106,12 @@
|
||||
</thead>
|
||||
{{#each records}}
|
||||
<tr>
|
||||
<td><a href="javascript:accessReview({{id}});">{{name}}</a></td>
|
||||
<td>{{distanceToUser}} km</td>
|
||||
<td><a href="{{url}}" target="_blank" onclick="javascript:accessReview({{id}});">{{name}}</a></td>
|
||||
<td>{{#prettyFloat 2}}{{distanceToUser}}{{/prettyFloat}} km</td>
|
||||
<td>{{closestStn}}</td>
|
||||
<td>{{distanceToStn}} km</td>
|
||||
<td>{{distanceToStn}} m</td>
|
||||
<td>{{accessCount}}</td>
|
||||
<td>{{score}}</td>
|
||||
<td>{{#prettyFloat 4}}{{score}}{{/prettyFloat}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
|
@ -35,10 +35,11 @@
|
||||
}
|
||||
|
||||
function onReady(geo) {
|
||||
_ctx = {
|
||||
geo: geo,
|
||||
query: {}
|
||||
};
|
||||
_ctx = {geo: geo, query: {}};
|
||||
|
||||
Handlebars.registerHelper('prettyFloat', function(precision, options) {
|
||||
return parseFloat(options.fn(this)).toFixed(precision);
|
||||
});
|
||||
|
||||
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
|
||||
$('#profileDlg').on('hidden.bs.modal', onSearch);
|
||||
@ -50,11 +51,8 @@
|
||||
});
|
||||
|
||||
window.accessReview = function(id) {
|
||||
$.post('/access', JSON.stringify({id: id, profile: getProfile()}), function(results) {
|
||||
if (results.success) {
|
||||
location.replace(results.url);
|
||||
}
|
||||
}, 'json');
|
||||
$.post('/access', JSON.stringify({id: id, profile: getProfile()}));
|
||||
onSearch();
|
||||
};
|
||||
|
||||
onSearch();
|
||||
@ -130,21 +128,18 @@
|
||||
}
|
||||
|
||||
_ctx.grapher.setColumns(columns);
|
||||
outputMatches(results.records, results.count);
|
||||
}
|
||||
|
||||
function outputMatches(records, count) {
|
||||
var searchResultCnt = String(records.length);
|
||||
if (records.length < count) {
|
||||
searchResultCnt += ' of ' + count;
|
||||
var searchResultCnt = String(results.records.length);
|
||||
if (results.records.length < results.count) {
|
||||
searchResultCnt += ' of ' + results.count;
|
||||
}
|
||||
$('#resultCount').text(searchResultCnt);
|
||||
|
||||
var template = Handlebars.compile($('#template').html());
|
||||
$('#records').empty();
|
||||
$('#records').append(template({records: records}));
|
||||
$('#records').append(template({records: results.records}));
|
||||
|
||||
if (records.length === 0) {
|
||||
if (results.records.length === 0) {
|
||||
$('#resultPanel').slideUp();
|
||||
}
|
||||
else {
|
||||
|
6
types.go
6
types.go
@ -29,11 +29,6 @@ type jsonAccessRequest struct {
|
||||
Profile featureMap `json:"profile"`
|
||||
}
|
||||
|
||||
type jsonAccessReply struct {
|
||||
Success bool `json:"success"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type jsonGeoData struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
@ -69,6 +64,7 @@ type jsonRecord struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Score float64 `json:"score"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type jsonQueryResponse struct {
|
||||
|
Loading…
Reference in New Issue
Block a user