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)
|
||||
|
||||
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()
|
||||
|
||||
response := jsonQueryResponse{
|
||||
|
@ -96,13 +96,13 @@
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Distance to user</th>
|
||||
<th>Closest station</th>
|
||||
<th>Distance to station</th>
|
||||
<th>Compatibility</th>
|
||||
<th>Score</th>
|
||||
<th>Access count</th>
|
||||
<th><a href="javascript:sortReviewsBy('name');">Name</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('distanceToUser');">Distance to user</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('closestStn');">Closest station</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('distanceToStn');">Distance to station</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('compatibility');">Compatibility</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('score');">Score</a></th>
|
||||
<th><a href="javascript:sortReviewsBy('accessCount');">Access count</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{{#each records}}
|
||||
|
@ -35,7 +35,12 @@
|
||||
}
|
||||
|
||||
function onReady(geo) {
|
||||
_ctx = {geo: geo, query: {}};
|
||||
_ctx = {
|
||||
sortKey: 'score',
|
||||
sortAsc: false,
|
||||
query: {},
|
||||
geo: geo
|
||||
};
|
||||
|
||||
Handlebars.registerHelper('prettyFloat', function(precision, options) {
|
||||
return parseFloat(options.fn(this)).toFixed(precision);
|
||||
@ -55,12 +60,25 @@
|
||||
onSearch();
|
||||
};
|
||||
|
||||
window.sortReviewsBy = function(sortKey) {
|
||||
if (sortKey === _ctx.sortKey) {
|
||||
_ctx.sortAsc = !_ctx.sortAsc;
|
||||
}
|
||||
else {
|
||||
_ctx.sortKey = sortKey;
|
||||
}
|
||||
|
||||
onSearch();
|
||||
};
|
||||
|
||||
onSearch();
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
_ctx.query = {
|
||||
features: _ctx.query.features || {},
|
||||
sortKey: _ctx.sortKey,
|
||||
sortAsc: _ctx.sortAsc,
|
||||
profile: getProfile(),
|
||||
walkingDist: parseFloat($('#walkingDist').val()),
|
||||
minScore: parseFloat($('#minScore').val()),
|
||||
|
18
types.go
18
types.go
@ -37,15 +37,15 @@ type jsonGeoData struct {
|
||||
}
|
||||
|
||||
type jsonQueryRequest struct {
|
||||
Features featureMap `json:"features"`
|
||||
Geo *jsonGeoData `json:"geo"`
|
||||
HintSteps int `json:"hintSteps"`
|
||||
MaxResults int `json:"maxResults"`
|
||||
MinScore float64 `json:"minScore"`
|
||||
Profile featureMap `json:"profile"`
|
||||
SortAscending bool `json:"SortAscending"`
|
||||
SortKey string `json:"sortKey"`
|
||||
WalkingDist float64 `json:"walkingDist"`
|
||||
Features featureMap `json:"features"`
|
||||
Geo *jsonGeoData `json:"geo"`
|
||||
HintSteps int `json:"hintSteps"`
|
||||
MaxResults int `json:"maxResults"`
|
||||
MinScore float64 `json:"minScore"`
|
||||
Profile featureMap `json:"profile"`
|
||||
SortAsc bool `json:"sortAsc"`
|
||||
SortKey string `json:"sortKey"`
|
||||
WalkingDist float64 `json:"walkingDist"`
|
||||
}
|
||||
|
||||
type jsonColumn struct {
|
||||
|
Loading…
Reference in New Issue
Block a user