summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/templates/filterbox.html
diff options
context:
space:
mode:
authorChristian Klinger2016-07-15 14:18:29 +0200
committerChristian Klinger2016-07-15 14:19:27 +0200
commit6e73dfb95b22524322c2de7a09db04af462b50cc (patch)
tree7078ad789cf0ea6f2df3ab35f2d76e1f0486b425 /modules-available/statistics/templates/filterbox.html
parent[syslog] API: Write machineuuid to DB (diff)
downloadslx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.tar.gz
slx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.tar.xz
slx-admin-6e73dfb95b22524322c2de7a09db04af462b50cc.zip
Merging some refactoring + new filter functionality.
Diffstat (limited to 'modules-available/statistics/templates/filterbox.html')
-rw-r--r--modules-available/statistics/templates/filterbox.html249
1 files changed, 249 insertions, 0 deletions
diff --git a/modules-available/statistics/templates/filterbox.html b/modules-available/statistics/templates/filterbox.html
new file mode 100644
index 00000000..2e7928e9
--- /dev/null
+++ b/modules-available/statistics/templates/filterbox.html
@@ -0,0 +1,249 @@
+<div id="modal-add-filter" class="modal modal-sm fade" role="dialog" style="position:absolute; min-width:600px; min-height: 400px;margin:auto">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+ {{lang_add_filter}}
+ </div>
+ <form class="modal-body form-inline center">
+ <div class="form-group">
+ <select id="columnSelect" name="column" class="form-control col-4-xs"> </select>
+ </div>
+ <div class="form-group">
+ <select id="operatorSelect" name="operator" class="form-control col-4-xs"> </select>
+ </div>
+ <div class="form-group">
+ <input name="argument" id="argumentInput" class="form-control col-4-xs"> </input>
+ <select name="argument" id="argumentSelect" class="form-control col-4-xs"> </select>
+ </div>
+ <button type="button" class="btn btn-primary" onclick="addFilterFromForm()" >
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_add}}</button>
+ </form>
+ </div>
+</div>
+
+
+<div style="height:120px">
+ <!-- use GET here, to avoid the "resend form?" confirmation, and anyway this is stateless, so GET makes more sense -->
+ <form id="queryForm" method="GET" action="?do=Statistics" class="" role="form">
+ <input type="hidden" name="do" value="Statistics"/>
+ <label for="filters">{{lang_labelFilter}}</label>
+ <input type="text" name="filters" class="" id="filterInput"/>
+ <input type="hidden" name="sortColumn" id="sortColumn" value="{{sortColumn}}"/>
+ <input type="hidden" name="sortDirection" id="sortDirection" value="{{sortDirection}}"/>
+
+ <button type="button" class="btn btn-success" onclick="popupFilter(null)">
+ <span class="glyphicon glyphicon-plus"></span>
+ {{lang_add_filter}}</button>
+ <button class="btn btn-primary pull-right" type="submit" name="show" value="{{show}}">
+ <span class="glyphicon glyphicon-refresh"></span>
+ {{lang_refresh}}</button>
+ {{#showList}}
+ <button class="btn btn-secondary pull-right" type="submit" name="show" value="stat">
+ <span class="glyphicon glyphicon-stats"></span>
+ {{lang_showVisualization}}</button>
+ {{/showList}}
+ {{^showList}}
+ <button class="btn btn-secondary pull-right" type="submit" name="show" value="list">
+ <span class="glyphicon glyphicon-list"></span>
+ {{lang_showList}}</button>
+ {{/showList}}
+</form>
+<br/>
+<br/>
+</div>
+<script type="application/javascript"><!--
+
+var filterSelectize;
+
+var slxFilterNames = {
+ machineuuid: '{{lang_uuid}}',
+ macaddr: '{{lang_macAddr}}',
+ firstseen: '{{lang_firstSeen}}',
+ lastseen: '{{lang_lastSeen}}',
+ lastboot: '{{lang_lastBoot}}',
+ logintime: '{{lang_lastLogin}}',
+ realcores: '{{lang_cores}}',
+ systemmodel: '{{lang_model}}',
+ cpumodel: '{{lang_cpuModel}}',
+ hddgb: '{{lang_tmpGb}}',
+ gbram: '{{lang_gbRam}}',
+ kvmstate: '{{lang_kvmSupport}}',
+ badsectors: '{{lang_reallocatedSectors}}',
+ clientip: '{{lang_ip}}',
+ state: '{{lang_usageState}}',
+ location: '{{lang_location}}'
+};
+
+slxLocations = {{{locations}}};
+
+var slxFilterDel = '{{delimiter}}';
+
+
+document.addEventListener("DOMContentLoaded", function () {
+
+ /* some objects */
+ var $columnSelect = $('#columnSelect');
+ $modal = $('#modal-add-filter');
+ $queryForm = $('#queryForm');
+
+ var columns= {{{columns}}};
+
+ /* add options to column select */
+ for (var key in columns) {
+ $columnSelect.append($('<option>', {
+ value: key, text: (slxFilterNames[key] ? slxFilterNames[key] : key) }));
+ };
+
+
+ /* initialize selectize */
+ filterSelectize = $('#filterInput').selectize({
+ delimiter: slxFilterDel,
+ plugins: ['restore_on_backspace', 'remove_button'],
+ create: function(input) {
+ return {value: input, text: input}
+ },
+ onChange: function() {
+ // if (initComplete && !$('#filterInput').is(':focus')) {
+ // reload();
+ // }
+ }
+ })[0].selectize;
+ /* add query */
+ var str = "{{{query}}}";
+ var eExp = /^(\w+)\s*([=><!~]+)\s*(.*)$/;
+ str.split(slxFilterDel).forEach(function(v) {
+ var match = eExp.exec(v);
+ if (match && match.length === 4) {
+ addFilter(match[1], match[2], match[3]);
+ } else {
+ filterSelectize.addOption({value: v, text: v});
+ filterSelectize.addItem(v);
+ }
+ });
+
+ $('#columnSelect').on('change', function() {
+ $('#operatorSelect option').remove();
+ var col = $('#columnSelect').val();
+ var opS = $('#operatorSelect');
+ columns[col]['op'].sort(myOpSort);
+ columns[col]['op'].forEach(function (v) {
+ $(opS).append($('<option>', {
+ value: v, text: v
+ }));
+ });
+ /* also set the type of the input */
+ if (columns[col]['type'] == 'date') {
+ $('#argumentInput').datepicker({format : 'yyyy-mm-dd'});
+ $('#argumentSelect').hide();
+ } else if(columns[col]['type'] == 'enum') {
+ $('#argumentInput').hide();
+ $('#argumentSelect').show();
+ columns[col]['values'].forEach(function (v) {
+ var t = v;
+ if (col === 'location' && slxLocations['L' + v]) {
+ t = slxLocations['L' + v].pad + ' ' + slxLocations['L' + v].name;
+ }
+ $('#argumentSelect').append($('<option>', { value: v, text: t }));
+ });
+ } else {
+ $('#argumentInput').datepicker('remove');
+ $('#argumentSelect option').remove();
+ $('#argumentInput').show();
+ $('#argumentSelect').hide();
+ }
+ });
+
+ initButtons();
+
+}, false);
+
+
+function initButtons() {
+ ['gbram', 'hddgb', 'realcores', 'kvmstate', 'lastseen', 'clientip'].forEach(function (v) {
+ var $sortBtn = $('#sortButton-' + v);
+ var order = 'up'; /* default */
+ if ($('#sortColumn').val() == v) {
+ $sortBtn.addClass('btn-success');
+ order = $('#sortDirection').val() == 'ASC' ? 'up' : 'down';
+ }
+ $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
+ $sortBtn.attr('onclick', 'toggleButton(\'' + v + '\');');
+ });
+}
+
+function toggleButton(v) {
+ var $sortBtn = $('#sortButton-' + v);
+ var $col = $('#sortColumn');
+ var $dir = $('#sortDirection');
+ if ($col.val() == v) {
+ /* toggle direction */
+ var newDir = $dir.val() == 'ASC' ? 'DESC' : 'ASC';
+ $dir.val(newDir);
+ /* update button */
+ var order = newDir == 'ASC' ? 'up' : 'down';
+ $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
+ } else {
+ /* remove "btn-success" from current sorting */
+ $('#sortButton-'+v).removeClass('btn-success');
+ $sortBtn.addClass('btn-success');
+ $col.val(v);
+ $dir = 'ASC';
+ }
+ refresh();
+}
+
+function popupFilter(field) {
+ if (field != null) {
+ $('#columnSelect').val(field);
+ }
+ $('#columnSelect').change();
+ $modal.modal('show');
+}
+
+function addFilterFromForm() {
+ var argument1 = $('#argumentInput').val();
+ var argument2 = $('#argumentSelect').val();
+ var argument = argument1 == '' ? argument2 : argument1;
+ var col = $('#columnSelect').val();
+ var op = $('#operatorSelect').val();
+
+ addFilter(col, op, argument);
+ refresh(); // TODO: AJAX
+}
+
+function addFilter(col, op, argument) {
+ var filterValue = col + ' ' + op + ' ' + argument;
+ var filterText = filterValue;
+ var displayArgument = argument;
+ if (col === 'location' && slxLocations['L' + argument]) {
+ displayArgument = slxLocations['L' + argument].name;
+ }
+ if (slxFilterNames[col]) {
+ filterText = slxFilterNames[col] + ' ' + op + ' ' + displayArgument;
+ }
+ filterSelectize.addOption({value: filterValue, text: filterText});
+ filterSelectize.addItem(filterValue);
+}
+
+function toggleSort(field) {
+ $('#sort').val(field + ' ' + order);
+ refresh();
+}
+
+/* equal sign should always be first, the rest doesn't matter*/
+function myOpSort(a,b) {
+ if (a == '=') { return -1; }
+ else if (a == b) {return 0}
+ else { return 1;}
+
+}
+
+function refresh() {
+ console.log('refresh');
+ $queryForm.submit(); /* TODO: use AJAX */
+}
+// --></script>
+
+
+