Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zipkin-web: sort order fix #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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