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

Add static query linking #51

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
73 changes: 65 additions & 8 deletions zipkin-web/app/assets/javascripts/application-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Zipkin.Application.Index = (function() {
/* Data retrieved for a particular query */
var traceData;

var useQueryParams = false;
var searchQuery = "";

var filter_submit;

/* Makes ajax call to get and populate the service names field */
var fetchServiceNames = function() {
$.ajax({
Expand Down Expand Up @@ -100,6 +105,44 @@ Zipkin.Application.Index = (function() {

spanSelector.change();
$(".filter-submit button").removeAttr('disabled');

if (useQueryParams) {
/* Push any query params to the form and submit if they exist */
var selectSelector = function(name) { return 'select[name=' + name + ']'; };
var inputSelector = function(name) { return 'input[name=' + name + ']'; };

var formFields = {
"service_name" : selectSelector('service_name'),
"span_name" : selectSelector('span_name'),
"end_date" : inputSelector('end_date'),
"end_time" : inputSelector('end_time'),
"limit" : inputSelector('limit'),
"time_annotation" : inputSelector('time_annotation'),
"annotation_key" : inputSelector('annotation_key'),
"annotation_value" : inputSelector('annotation_value')
};
var any = false;
$.each(useQueryParams, function(i, pair) {
var k = pair[0]
, v = pair[1]
;
if (k === "adjust_clock_skew") {
if (v == "true") {
Zipkin.Base.enableClockSkewBtn();
} else if (v == "false") {
Zipkin.Base.disableClockSkewBtn();
}
} else if (k in formFields) {
var selector = formFields[k];
$(selector).val(v);
any = true;
}
});
if (any) {
filter_submit();
}
useQueryParams = false;
}
},
error: function(xhr, status, error) {
$('#help-msg').hide();
Expand All @@ -110,13 +153,6 @@ Zipkin.Application.Index = (function() {
};

var initialize = function() {
Zipkin.Base.initialize();

fetchServiceNames();

/* Populate span selector after a service has been selected */
$('#service_name').change(serviceNameChange);

/**
* Helper functions for trace query results
*/
Expand Down Expand Up @@ -282,7 +318,7 @@ Zipkin.Application.Index = (function() {
$(".service-tags").on("click", "li span.service-tag-close", labelRemove);

/* Search for traces */
var filter_submit = function(adjust_clock_skew) {
filter_submit = function(adjust_clock_skew) {

// Show some loading stuff while we wait for the query
$('#help-msg').hide();
Expand Down Expand Up @@ -371,6 +407,10 @@ Zipkin.Application.Index = (function() {
updateFilterTotalCount(data.length);
updateFilterDuration(minStartTime, maxStartTime);

/* Shove the query string into the static link */
searchQuery = this.url.split("?")[1];
$("#static-search-link").attr("href", root_url + "?" + searchQuery).show();

$(".infobar").show();
$(".service-tag-list").show();
},
Expand Down Expand Up @@ -450,6 +490,23 @@ Zipkin.Application.Index = (function() {
refreshQueryResults(content);
});
});

$(document).on("click", "li.trace", function(e) {
history.pushState({}, "Zipkin", root_url + "?" + searchQuery);
});

Zipkin.Base.initialize();

var params = Zipkin.Util.queryParams();
if (params.length > 0) {
useQueryParams = params;
}

fetchServiceNames();

/* Populate span selector after a service has been selected */
$('#service_name').change(serviceNameChange);

};

return {
Expand Down
17 changes: 17 additions & 0 deletions zipkin-web/app/assets/javascripts/zipkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ Zipkin.Util = (function(Zipkin) {
}
};

/**
* Parses the page query params and stuffs them into an object
*/
var queryParams = function() {
var arr = [];
var str = location.search.substring(1);
str = decodeURIComponent(str);
$.each(str.split("&"), function(i, pair) {
var index = pair.indexOf("=");
if (index !== -1) {
arr.push([pair.substring(0, index), pair.substring(index+1)]);
}
});
return arr;
};

/**
* Convenience method for using Hogan templates. If we have already
* fetched the template, initiate the callback. Otherwise, fetch it
Expand Down Expand Up @@ -86,6 +102,7 @@ Zipkin.Util = (function(Zipkin) {
shallowCopy: shallowCopy,
defaultDictPush: defaultDictPush,
defaultDictGet: defaultDictGet,
queryParams: queryParams,
templatize: templatize,
TEMPLATES: TEMPLATES
};
Expand Down
1 change: 1 addition & 0 deletions zipkin-web/app/views/traces/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<div class="sidebar-block filter-block-contents filter-submit">
<button class="btn primary" disabled>Submit</button>
<a data-toggle="modal" href="#lookup-help-modal" class="btn"><i class="icon-info-sign"></i></a>
<a id="static-search-link" class="hide pull-right">link</a>
</div>
</form>

Expand Down