<commit_before>
/***
 * Here is the 'clients' part
 * It is available on the global clients view
 */

/***
 * First we map some burp status with some style
 */
var __status = {
	'client crashed': 'danger',
	'server crashed': 'danger',
	'running': 'info',
};

/***
 * _clients: function that retrieve up-to-date informations from the burp server
 * JSON format:
 * {
 *   "results": [
 *     {
 *       "last": "2014-05-12 19:40:02",
 *       "name": "client1",
 *       "state": "idle"
 *     },
 *     {
 *       "last": "never",
 *       "name": "client2",
 *       "state": "idle"
 *     }
 *   ]
 * }
 *  The JSON is then parsed into a table
 */

/*
var _clients_table = $('#table-clients').DataTable( {
	ajax: '{{ url_for("clients_json", server=server) }}',
	columns: [
*/
var _clients_table = $('#table-clients').dataTable( {
	ajax: {
		url: '{{ url_for("clients_json", server=server) }}',
		dataSrc: 'results'
	},
	destroy: true,
	rowCallback: function( row, data ) {
		if (__status[data.state] != undefined) {
			row.className += ' '+__status[data.state];
		}
		row.className += ' clickable';
	},
	columns: [
		{ data: null, render: function ( data, type, row ) {
				return '<a href="{{ url_for("client", server=server) }}?name='+data.name+'" style="color: inherit; text-decoration: inherit;">'+data.name+'</a>';
			}
		},
		{ data: 'state' },
		{ data: 'last' }
	]
});
var first = true;

var _clients = function() {
	url = '{{ url_for("clients_json", server=server) }}';
	$.getJSON(url, function(data) {
		if (!data.results) {
			if (data.notif) {
				$.each(data.notif, function(i, n) {
					notif(n[0], n[1]);
				});
			}
			return;
		}
		if (first) {
			first = false;
		} else {
			_clients_table.api().ajax.reload( null, false );
		}
	});
};<commit_msg>refactoring of the datatable making one less ajax call<commit_after>
/***
 * Here is the 'clients' part
 * It is available on the global clients view
 */

/***
 * First we map some burp status with some style
 */
var __status = {
	'client crashed': 'danger',
	'server crashed': 'danger',
	'running': 'info',
};

/***
 * Show the row as warning if there are no backups
 */
var __date = {
	'never': 'warning',
};

/***
 * _clients: function that retrieve up-to-date informations from the burp server
 * JSON format:
 * {
 *   "results": [
 *     {
 *       "last": "2014-05-12 19:40:02",
 *       "name": "client1",
 *       "state": "idle"
 *     },
 *     {
 *       "last": "never",
 *       "name": "client2",
 *       "state": "idle"
 *     }
 *   ]
 * }
 *  The JSON is then parsed into a table
 */

var _clients_table = $('#table-clients').dataTable( {
	ajax: {
		url: '{{ url_for("clients_json", server=server) }}',
		dataSrc: function (data) {
			if (!data.results) {
				if (data.notif) {
					$.each(data.notif, function(i, n) {
						notif(n[0], n[1]);
					});
				}
				return {};
			}
			return data.results;
		}
	},
	order: [[2, 'desc']],
	destroy: true,
	rowCallback: function( row, data ) {
		if (__status[data.state] != undefined) {
			row.className += ' '+__status[data.state];
		}
		if (__date[data.last] != undefined) {
			row.className += ' '+__date[data.last];
		}
		row.className += ' clickable';
	},
	columns: [
		{ data: null, render: function ( data, type, row ) {
				return '<a href="{{ url_for("client", server=server) }}?name='+data.name+'" style="color: inherit; text-decoration: inherit;">'+data.name+'</a>';
			}
		},
		{ data: 'state' },
		{ data: 'last' }
	]
});
var first = true;

var _clients = function() {
	if (first) {
		first = false;
	} else {
		_clients_table.api().ajax.reload( null, false );
	}
};
{'fraction_non_alphanumeric': 0.2021600664635835, 'fraction_numerical': 0.010246469122126834, 'mean_word_length': 2.9518599562363237, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4867180', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1318, 'n_words': 315}