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