Adding sort code to the client
This commit is contained in:
parent
19e897ae3f
commit
18458b83c0
@ -52,7 +52,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
features := fixFeatures(request.Features)
|
features := fixFeatures(request.Features)
|
||||||
|
|
||||||
foundEntries := findRecords(entries, features, request.MinScore)
|
foundEntries := findRecords(entries, features, request.MinScore)
|
||||||
sorter := recordSorter{entries: foundEntries, key: request.SortKey, ascending: request.SortAscending}
|
sorter := recordSorter{entries: foundEntries, key: request.SortKey, ascending: request.SortAsc}
|
||||||
sorter.sort()
|
sorter.sort()
|
||||||
|
|
||||||
response := jsonQueryResponse{
|
response := jsonQueryResponse{
|
||||||
|
@ -96,13 +96,13 @@
|
|||||||
<table class="table table-striped table-condensed">
|
<table class="table table-striped table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th><a href="javascript:sortReviewsBy('name');">Name</a></th>
|
||||||
<th>Distance to user</th>
|
<th><a href="javascript:sortReviewsBy('distanceToUser');">Distance to user</a></th>
|
||||||
<th>Closest station</th>
|
<th><a href="javascript:sortReviewsBy('closestStn');">Closest station</a></th>
|
||||||
<th>Distance to station</th>
|
<th><a href="javascript:sortReviewsBy('distanceToStn');">Distance to station</a></th>
|
||||||
<th>Compatibility</th>
|
<th><a href="javascript:sortReviewsBy('compatibility');">Compatibility</a></th>
|
||||||
<th>Score</th>
|
<th><a href="javascript:sortReviewsBy('score');">Score</a></th>
|
||||||
<th>Access count</th>
|
<th><a href="javascript:sortReviewsBy('accessCount');">Access count</a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each records}}
|
{{#each records}}
|
||||||
|
@ -35,7 +35,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onReady(geo) {
|
function onReady(geo) {
|
||||||
_ctx = {geo: geo, query: {}};
|
_ctx = {
|
||||||
|
sortKey: 'score',
|
||||||
|
sortAsc: false,
|
||||||
|
query: {},
|
||||||
|
geo: geo
|
||||||
|
};
|
||||||
|
|
||||||
Handlebars.registerHelper('prettyFloat', function(precision, options) {
|
Handlebars.registerHelper('prettyFloat', function(precision, options) {
|
||||||
return parseFloat(options.fn(this)).toFixed(precision);
|
return parseFloat(options.fn(this)).toFixed(precision);
|
||||||
@ -55,12 +60,25 @@
|
|||||||
onSearch();
|
onSearch();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.sortReviewsBy = function(sortKey) {
|
||||||
|
if (sortKey === _ctx.sortKey) {
|
||||||
|
_ctx.sortAsc = !_ctx.sortAsc;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_ctx.sortKey = sortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSearch();
|
||||||
|
};
|
||||||
|
|
||||||
onSearch();
|
onSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSearch() {
|
function onSearch() {
|
||||||
_ctx.query = {
|
_ctx.query = {
|
||||||
features: _ctx.query.features || {},
|
features: _ctx.query.features || {},
|
||||||
|
sortKey: _ctx.sortKey,
|
||||||
|
sortAsc: _ctx.sortAsc,
|
||||||
profile: getProfile(),
|
profile: getProfile(),
|
||||||
walkingDist: parseFloat($('#walkingDist').val()),
|
walkingDist: parseFloat($('#walkingDist').val()),
|
||||||
minScore: parseFloat($('#minScore').val()),
|
minScore: parseFloat($('#minScore').val()),
|
||||||
|
2
types.go
2
types.go
@ -43,7 +43,7 @@ type jsonQueryRequest struct {
|
|||||||
MaxResults int `json:"maxResults"`
|
MaxResults int `json:"maxResults"`
|
||||||
MinScore float64 `json:"minScore"`
|
MinScore float64 `json:"minScore"`
|
||||||
Profile featureMap `json:"profile"`
|
Profile featureMap `json:"profile"`
|
||||||
SortAscending bool `json:"SortAscending"`
|
SortAsc bool `json:"sortAsc"`
|
||||||
SortKey string `json:"sortKey"`
|
SortKey string `json:"sortKey"`
|
||||||
WalkingDist float64 `json:"walkingDist"`
|
WalkingDist float64 `json:"walkingDist"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user