lib/sensu-dashboard/public/js/functions.js in sensu-dashboard-0.9.1 vs lib/sensu-dashboard/public/js/functions.js in sensu-dashboard-0.9.3
- old
+ new
@@ -196,12 +196,46 @@
m_clients = new Array();
$('table#clients > tbody').empty();
+ // iterate through the filters
+ grouped_filters = {};
+ for (var i in selected_filters) {
+ var current_filter = selected_filters[i];
+
+ // store client filters in the grouped filters array
+ if (current_filter['type'] == 'client') {
+ grouped_filters['client'] || (grouped_filters['client'] = []);
+ for (var j in current_filter['value']) {
+ grouped_filters['client'].push(current_filter['value'][j]);
+ }
+ }
+
+ // store subscription filters in the grouped filters array
+ if (current_filter['type'] == 'subscription') {
+ grouped_filters['subscription'] || (grouped_filters['subscription'] = []);
+ for (var j in current_filter['value']) {
+ grouped_filters['subscription'].push(current_filter['value'][j]);
+ }
+ }
+ }
+
+ // iterate through each node
for (var clientkey in data) {
var client = data[clientkey];
+
+ // skip node if client filters exist and the client is not in the filter
+ if ((Object.size(grouped_filters['client']) > 0) && ($.inArray(client['name'], grouped_filters['client']) == -1)) {
+ continue;
+ }
+
+ // skip node if subscription filters exist and the subscription is not in the filter
+ if ((Object.size(grouped_filters['subscription']) > 0) && ($.inArray(client['name'], grouped_filters['subscription']) == -1)) {
+ continue;
+ }
+
client['subscriptions'] = client['subscriptions'].join(', ');
m_clients.push(client);
}
$('#clientTemplate').tmpl(m_clients).prependTo('table#clients > tbody');
@@ -225,68 +259,70 @@
function fetchStashes() {
$.ajax({
type: 'GET',
url: '/stashes.json',
success: function(data, textStatus, xhr) {
- $.ajax({
- type: 'POST',
- url: '/stashes.json',
- data: JSON.stringify(data),
- success: function(stash_data, textStatus, xhr) {
- stashes = new Array();
- for (var stash in stash_data) {
- stash_keys = new Array();
- stash_values = new Array();
- for (var stash_value in stash_data[stash]) {
- stash_keys.push(stash_value);
- stash_values.push({
- name: stash_value,
- value: stash_data[stash][stash_value]
+ if (data.legnth > 0) {
+ $.ajax({
+ type: 'POST',
+ url: '/stashes.json',
+ data: JSON.stringify(data),
+ success: function(stash_data, textStatus, xhr) {
+ stashes = new Array();
+ for (var stash in stash_data) {
+ stash_keys = new Array();
+ stash_values = new Array();
+ for (var stash_value in stash_data[stash]) {
+ stash_keys.push(stash_value);
+ stash_values.push({
+ name: stash_value,
+ value: stash_data[stash][stash_value]
+ });
+ }
+ stashes.push({
+ identifier: SHA1(stash),
+ name: stash,
+ keys: stash_keys.join(', '),
+ values: stash_values
});
}
- stashes.push({
- identifier: SHA1(stash),
- name: stash,
- keys: stash_keys.join(', '),
- values: stash_values
- });
- }
- $('table#events > tbody').empty();
- $('#stashTemplate').tmpl(stashes).appendTo('table#events > tbody');
- $('tbody > tr').click(function() {
- $('div#event_details_modal').empty();
- var row = $(this).parent().children().index($(this));
- $('#stashDetailsTemplate').tmpl(stashes[row]).appendTo('div#event_details_modal');
- $('div#delete_stash').click(function() {
- $('div#delete_stash > img').attr("src", "/img/loading_circle.gif");
- $.ajax({
- type: 'DELETE',
- url: '/stash/'+stashes[row]['name']+'.json',
- success: function(data, textStatus, xhr) {
- $("#lean_overlay").fadeOut(200);
- $("#event_details_modal").css({'display':'none'});
- fetchStashes();
- },
- error: function(xhr, textStatus, errorThrown) {
- $('div#delete_stash > img').attr("src", "/img/cross.png");
- console.log('XHR: ' + xhr);
- console.log('textStatus: ' + textStatus);
- console.log('errorThrown: ' + errorThrown);
- alert('Error deleting stash');
- }
+ $('table#events > tbody').empty();
+ $('#stashTemplate').tmpl(stashes).appendTo('table#events > tbody');
+ $('tbody > tr').click(function() {
+ $('div#event_details_modal').empty();
+ var row = $(this).parent().children().index($(this));
+ $('#stashDetailsTemplate').tmpl(stashes[row]).appendTo('div#event_details_modal');
+ $('div#delete_stash').click(function() {
+ $('div#delete_stash > img').attr("src", "/img/loading_circle.gif");
+ $.ajax({
+ type: 'DELETE',
+ url: '/stash/'+stashes[row]['name']+'.json',
+ success: function(data, textStatus, xhr) {
+ $("#lean_overlay").fadeOut(200);
+ $("#event_details_modal").css({'display':'none'});
+ fetchStashes();
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ $('div#delete_stash > img').attr("src", "/img/cross.png");
+ console.log('XHR: ' + xhr);
+ console.log('textStatus: ' + textStatus);
+ console.log('errorThrown: ' + errorThrown);
+ alert('Error deleting stash');
+ }
+ });
});
});
- });
- $('tr[rel*=leanModal]').leanModal({ top : 50, bottom : 50 });
- },
- error: function(xhr, textStatus, errorThrown) {
- console.log('XHR: ' + xhr);
- console.log('textStatus: ' + textStatus);
- console.log('errorThrown: ' + errorThrown);
- alert('Error retrieving stashes');
- }
- });
+ $('tr[rel*=leanModal]').leanModal({ top : 50, bottom : 50 });
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ console.log('XHR: ' + xhr);
+ console.log('textStatus: ' + textStatus);
+ console.log('errorThrown: ' + errorThrown);
+ alert('Error retrieving stashes');
+ }
+ });
+ }
},
error: function(xhr, textStatus, errorThrown) {
console.log('XHR: ' + xhr);
console.log('textStatus: ' + textStatus);
console.log('errorThrown: ' + errorThrown);
@@ -296,32 +332,14 @@
}
/* trigger when page is ready */
$(document).ready(function() {
- $("input[type=text]").autoSuggest("http://" + location.hostname + ":" + location.port + "/autocomplete.json", {
- startText: "Enter keywords to filter by",
- selectedItemProp: "name",
- searchObjProps: "name",
- selectionAdded: function(elem) {
- fetchEvents();
- },
- selectionRemoved: function(elem) {
- elem.fadeTo("fast", 0, function() { elem.remove(); });
- fetchEvents();
- }
- });
-
$(document).keyup(function(e) {
if (e.keyCode == 27) { // esc
$("#lean_overlay").fadeOut(200);
$("#event_details_modal").css({'display':'none'});
}
- });
-
- $('#filter_unknown_checks').change(function() {
- filter_unknown_checks = !filter_unknown_checks;
- fetchEvents();
});
// TODO: fix clipboard support
/*$('div#event_details_modal > div.event_detail_group > div.copy').click(function() {
var currentVal = $(this).parent().find('div.event_detail').children().last().text();