Permalink
Browse files

Bug 1020348 - Added new signature-based report with a simple data tab…

…. r=peterbe
  • Loading branch information...
1 parent 0c900b5 commit 141a5459f7812a468c254ef71d2a52441d1cc303 @adngdb adngdb committed Jun 22, 2014
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,10 +1,11 @@
{% macro pagination(report, current_url, current_page, tab = None) %}
+{% set separator = not current_url.endswith('?') and '&' or '' %}
<div class="pagination">
<span class="totalItems">{{ report.total_count }}</span> Results
{% if report.total_pages > 1 %}
&hellip;
{% if current_page > 1 %}
- <a href="{{ current_url }}&amp;page={{ current_page - 1 }}{{ tab }}">&larr; Prev</a>
+ <a href="{{ current_url }}{{ separator }}page={{ current_page - 1 }}{{ tab }}">&larr; Prev</a>
{% endif %}
{% for page in range(1, report.total_pages + 1) %}
{% if page == current_page %}
@@ -15,16 +16,16 @@
{% elif current_page > 6 and page == 3 %}
&hellip;
{% elif page > (current_page - 3) and page < (current_page + 3) %}
- <a href="{{ current_url }}&amp;page={{ page }}{{ tab }}">{{ page }}</a>
+ <a href="{{ current_url }}{{ separator }}page={{ page }}{{ tab }}">{{ page }}</a>
{% elif page == (report.total_pages - 3) %}
&hellip;
{% endif %}
{% else %}
- <a href="{{ current_url }}&amp;page={{ page }}{{ tab }}">{{ page }}</a>
+ <a href="{{ current_url }}{{ separator }}page={{ page }}{{ tab }}">{{ page }}</a>
{% endif %}
{% endfor %}
{% if report.total_pages > current_page %}
- <a href="{{ current_url }}&amp;page={{ current_page + 1 }}{{ tab }}">Next &rarr;</a>
+ <a href="{{ current_url }}{{ separator }}page={{ current_page + 1 }}{{ tab }}">Next &rarr;</a>
{% endif %}
{% endif %}
</div>
@@ -182,6 +182,57 @@
return dates;
}
},
+ search: {
+ parseQueryString: function (queryString) {
+ var params = {};
+ var queries;
+ var temp;
+ var i;
+ var len;
+
+ // Split into key/value pairs
+ queries = queryString.split("&");
+ len = queries.length;
+
+ if (len === 1 && queries[0] === '') {
+ return false;
+ }
+
+ // Convert the array of strings into an object
+ for (i = 0; i < len; i++) {
+ temp = queries[i].split('=');
+ var key = temp[0];
+ var value = decodeURIComponent(temp[1]);
+ value = value.replace(/\+/g, ' ');
+
+ if (params[key] && Array.isArray(params[key])) {
+ params[key].push(value);
+ }
+ else if (params[key]) {
+ params[key] = [params[key], value];
+ }
+ else {
+ params[key] = value;
+ }
+ }
+
+ return params;
+ },
+ getFilteredParams: function (params) {
+ if ('page' in params) {
+ delete params.page;
+ }
+
+ // Remove all private parameters (beginning with a _).
+ for (var p in params) {
+ if (p.charAt(0) === '_') {
+ delete params[p];
+ }
+ }
+
+ return params;
+ }
+ },
dateSupported: function() {
var inputElem = document.createElement("input");
inputElem.setAttribute("type", "date");
@@ -20,6 +20,7 @@
'%s.api' % PROJECT_MODULE,
'%s.manage' % PROJECT_MODULE,
'%s.supersearch' % PROJECT_MODULE,
+ '%s.signature' % PROJECT_MODULE,
'jingo_offline_compressor',
'%s.auth' % PROJECT_MODULE,
'%s.tokens' % PROJECT_MODULE,
@@ -0,0 +1,48 @@
+.tabs {
+ margin: 0.3em 1em 1em 0;
+ padding: 0;
+ a:link,
+ a:visited {
+ display: inline-block;
+ background-color: #e0e0e0;
+ color: #333;
+ margin-right: .2em;
+ padding: .3em .8em;
+ text-decoration: none;
+ text-align: center;
+ border-radius: 6px;
+ }
+ a:hover {
+ background-color: #B6D3E2;
+ }
+ a.selected {
+ background-color: #2e5d74;
+ color: #fff;
+ }
+ li {
+ display: inline;
+ }
+}
+
+/* By default, hide all panels except the loading one. */
+.panel {
+ display: none;
+}
+#loading-panel {
+ display: block;
+}
+
+.toggle-filters {
+ float: right;
+}
+.toggle-filters:before {
+ content: url('../../img/3rdparty/silk/arrow_top.png');
+ display: inline-block;
+ height: 16px;
+ padding: 5px;
+ vertical-align: middle;
+ width: 16px;
+}
+.toggle-filters.show:before {
+ content: url('../../img/3rdparty/silk/arrow_bottom.png');
+}
@@ -0,0 +1,201 @@
+/* global socorro:true, $:true */
+
+$(function () {
+ 'use strict';
+
+ // parameters
+ var form = $('#search-form form');
+ var fieldsURL = form.data('fields-url');
+ var tabsElt = $('.tabs');
+
+ var pageNum = 1; // the page number as passed in the URL
+
+ var initializedTabs = {};
+ var tabsLoadFunctions = {};
+
+ function loadTab(tabName) {
+ if (!initializedTabs[tabName]) {
+ initializedTabs[tabName] = true;
+ tabsLoadFunctions[tabName]();
+ }
+ }
+
+ function showTab(tabName) {
+ $('.selected', tabsElt).removeClass('selected');
+ $('.' + tabName, tabsElt).addClass('selected');
+
+ loadTab(tabName);
+
+ // Hide all panels.
+ $('.panel').hide();
+ // Then show the one for our tab.
+ $('#' + tabName + '-panel').show();
+ }
+
+ function loadInitialTab() {
+ var currentTab = window.location.hash.substring(1);
+
+ if (!currentTab) {
+ currentTab = 'reports'; // the default tab
+ }
+
+ showTab(currentTab);
+ }
+
+ function startSearchForm(callback) {
+ var queryString = window.location.search.substring(1);
+ var initialParams = socorro.search.parseQueryString(queryString);
+ if (initialParams) {
+ if (initialParams.page) {
+ pageNum = initialParams.page;
+ }
+
+ initialParams = socorro.search.getFilteredParams(initialParams);
+ form.dynamicForm(fieldsURL, initialParams, '#search-params-fieldset', function () {
+ // When the form has finished loading, we get sanitized parameters
+ // from it and show the results. This will avoid strange behaviors
+ // that can be caused by manually set parameters, for example.
+ callback();
+ });
+ }
+ else {
+ // No initial params, just load the form and let the user play with it.
+ form.dynamicForm(fieldsURL, {}, '#search-params-fieldset');
+ callback();
+ }
+
+ form.hide();
+ }
+
+ function addLoaderToElt(elt) {
+ elt.append($('<div>', {class: 'loader'}));
+ }
+
+ function handleError(contentElt, jqXHR, textStatus, errorThrown) {
+ var errorContent = $('<div>', {class: 'error'});
+
+ try {
+ var errorDetails = $(jqXHR.responseText); // This might fail
+ var errorTitle = 'Oops, an error occured';
+ var errorMsg = 'Please fix the following issues: ';
+
+ errorContent.append($('<h3>', {text: errorTitle}));
+ errorContent.append($('<p>', {text: errorMsg}));
+ errorContent.append(errorDetails);
+ }
+ catch (e) {
+ // If an exception occurs, that means jQuery wasn't able
+ // to understand the status of the HTTP response. It is
+ // probably a 500 error. We thus show a different error.
+ var errorTitle = 'An unexpected error occured :(';
+ var errorMsg = 'We have been automatically informed of that error, and are working on a solution. ';
+ var errorDetails = textStatus + ' - ' + errorThrown;
+
+ errorContent.append($('<h3>', {text: errorTitle}));
+ errorContent.append($('<p>', {text: errorMsg}));
+ errorContent.append($('<p>', {text: errorDetails}));
+ }
+
+ contentElt.empty().append(errorContent);
+ }
+
+ function bindEvents() {
+ $('.new-line').click(function (e) {
+ e.preventDefault();
+ form.dynamicForm('newLine');
+ });
+
+ $('button[type=submit]', form).click(function (e) {
+ e.preventDefault();
+ var params = form.dynamicForm('getParams');
+ var queryString = '?' + $.param(params, true);
+ window.location.search = queryString;
+ });
+
+ // Change tab using navigation links.
+ $('a', tabsElt).click(function (e) {
+ showTab($(this).data('tab-name'));
+ });
+
+ // Show or hide filters.
+ $('.toggle-filters').click(function (e) {
+ e.preventDefault();
+
+ var elt = $(this);
+ form.toggle();
+ elt.toggleClass('show');
+ if (elt.hasClass('show')) {
+ elt.html('Show');
+ }
+ else {
+ elt.html('Hide');
+ }
+ });
+ }
+
+ tabsLoadFunctions.reports = function () {
+ // Initialize the reports tab, bind all events and start loading
+ // default data.
+ var reportsPanel = $('#reports-panel');
+ var contentElt = $('.content', reportsPanel);
+ var columnsInput = $('input[name=_columns_fake]', reportsPanel);
+
+ var dataUrl = reportsPanel.data('source-url');
+
+ function prepareResultsQueryString(params) {
+ var i;
+ var len;
+
+ var columns = columnsInput.select2('data');
+ if (columns) {
+ params._columns = [];
+ for (i = 0, len = columns.length; i < len; i++) {
+ params._columns[i] = columns[i].id;
+ }
+ }
+
+ // Add the page number.
+ params.page = pageNum;
+
+ var queryString = $.param(params, true);
+ return '?' + queryString;
+ }
+
+ function showReports() {
+ // Remove previous results and show loader.
+ contentElt.empty();
+ addLoaderToElt(contentElt);
+
+ var params = form.dynamicForm('getParams');
+ var url = dataUrl + prepareResultsQueryString(params);
+
+ $.ajax({
+ url: url,
+ success: function(data) {
+ contentElt.empty().append($(data));
+ $('.tablesorter').tablesorter();
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ handleError(contentElt, jqXHR, textStatus, errorThrown);
+ },
+ dataType: 'HTML'
+ });
+ }
+
+ $('submit', reportsPanel).click(function (e) {
+ e.preventDefault();
+ showReports();
+ });
+
+ showReports();
+ };
+
+ tabsLoadFunctions.aggregations = function () {
+ var aggregationsPanel = $('#aggregations-panel');
+ var contentElt = $('.content', aggregationsPanel);
+ };
+
+ // Finally start the damn thing.
+ bindEvents();
+ startSearchForm(loadInitialTab);
+});
Oops, something went wrong.

0 comments on commit 141a545

Please sign in to comment.