1

Adding sort code to the client

This commit is contained in:
Alex Yatskov 2015-03-27 12:03:23 +09:00
parent 19e897ae3f
commit 18458b83c0
4 changed files with 36 additions and 18 deletions

View File

@ -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{

View File

@ -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}}

View File

@ -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()),

View File

@ -43,7 +43,7 @@ type jsonQueryRequest struct {
MaxResults int `json:"maxResults"`
MinScore float64 `json:"minScore"`
Profile featureMap `json:"profile"`
SortAscending bool `json:"SortAscending"`
SortAsc bool `json:"sortAsc"`
SortKey string `json:"sortKey"`
WalkingDist float64 `json:"walkingDist"`
}