Skip to content

Commit

Permalink
zipkin-web: sort order fix
Browse files Browse the repository at this point in the history
- Sort query results correctly when doing additional searches
- Fix typo

Author: franklinhu
Pull Request: #16
URL: #16
  • Loading branch information
Franklin Hu committed Jun 11, 2012
1 parent 9e290b5 commit 3975e1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 15 additions & 9 deletions zipkin-web/app/assets/javascripts/application-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Zipkin.Application.Index = (function() {
var ORDER_DURATION_DESC = 0
, ORDER_DURATION_ASC = 1
, ORDER_TIMESTAMP_DESC = 2
, ORDER_TIMSTAMP_ASC = 3
, ORDER_TIMESTAMP_ASC = 3
;

var templatize = Zipkin.Util.templatize
Expand Down Expand Up @@ -141,6 +141,10 @@ Zipkin.Application.Index = (function() {
return services;
};

var getSortOrder = function() {
return $(".js-sort-order").val();
};

/* Filter the query results based on service tag list */
var filterQueryResults = function (services) {
if (!services) {
Expand All @@ -161,13 +165,16 @@ Zipkin.Application.Index = (function() {
});
};

var sortQueryResults = function(data, sortOrder) {
var sortQueryResults = function(data) {
/* Option index directly maps to the correct sort order */
var sortOrder = getSortOrder();

data.sort(function(a, b) {
if (sortOrder === ORDER_TIMSTAMP_ASC) {
if (sortOrder == ORDER_TIMESTAMP_ASC) {
return new Date(a.start_time) - new Date(b.start_time);
} else if (sortOrder === ORDER_TIMESTAMP_DESC) {
} else if (sortOrder == ORDER_TIMESTAMP_DESC) {
return new Date(b.start_time) - new Date(a.start_time);
} else if (sortOrder === ORDER_DURATION_ASC) {
} else if (sortOrder == ORDER_DURATION_ASC) {
return a.duration - b.duration;
} else {
/* ORDER_DURATION_DESC */
Expand Down Expand Up @@ -350,6 +357,8 @@ Zipkin.Application.Index = (function() {
});
traces = updateFilteredServices(traces);

sortQueryResults(traces);

templatize(TEMPLATES.QUERY, function(template) {
var context = { traces: traces };
var content = template.render(context);
Expand Down Expand Up @@ -431,12 +440,9 @@ Zipkin.Application.Index = (function() {
});

$(".js-sort-order").change(function (e) {
/* Option index directly maps to the correct sort order */
var sortOrder = e.target.selectedIndex;

var services = getFilteredServices();
var newData = updateFilteredServices(filterQueryResults(services));
sortQueryResults(newData, sortOrder);
sortQueryResults(newData);

templatize(TEMPLATES.QUERY, function(template) {
var context = { traces: newData };
Expand Down
8 changes: 4 additions & 4 deletions zipkin-web/app/views/traces/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@
<div class="pull-right">
<span class="selector">Sorted by:
<select class="sort-order js-sort-order">
<option selected value="duration-desc">Duration Desc</i></span>
<option value="duration-asc">Duration Asc</span>
<option value="timestamp-desc">Timestamp Desc</span>
<option value="timestamp-asc">Timestamp Asc</span>
<option selected value="0">Duration Desc</i></span>
<option value="1">Duration Asc</span>
<option value="2">Timestamp Desc</span>
<option value="3">Timestamp Asc</span>
</select>
</span>
</div>
Expand Down

0 comments on commit 3975e1c

Please sign in to comment.