dbWindow.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * TraCINg-Server - Gathering and visualizing cyber incidents on the world
  3. *
  4. * Copyright 2013 Matthias Gazzari, Annemarie Mattmann, André Wolski
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /*
  19. * database window part
  20. */
  21. // TODO: was sinnvolles für hier überlegen
  22. function requestAttackUpdate() {
  23. requestAttacks();
  24. }
  25. // get incidents
  26. function requestAttacks() {
  27. if (!$('#getIncidents').hasClass("disabled")) {
  28. // reset progress bar
  29. $('.bar').css('width', 0);
  30. // reset map and table
  31. refreshMap();
  32. // show "Loading..." on "Get Incidents" button and disable button
  33. $('#getIncidents').text('Loading Data');
  34. $('#getIncidents').addClass("disabled");
  35. // enable control buttons
  36. enableRequestControl();
  37. var attackFilter = filter.getFilter();
  38. // get date from datepicker
  39. attackFilter["start"] = $("#jrange").jrange("getStartDate");
  40. attackFilter["end"] = $("#jrange").jrange("getEndDate");
  41. if(currentView === VIEWS.TABLE){
  42. attackFilter["page"] = 1;
  43. attackFilter["perpage"] = 10;
  44. console.log("filter: ", attackFilter);
  45. currentTableFilter = attackFilter;
  46. socket.emit("requestAttacksForTable", attackFilter);
  47. } else {
  48. attackFilter["page"] = "all";
  49. console.log("filter: ", attackFilter);
  50. socket.emit("requestAttacks", attackFilter);
  51. }
  52. /*var settings = $("#attackTable").dataTable().fnSettings();
  53. settings.oFeatures.bServerSide = true;
  54. console.log(settings);
  55. $("#attackTable").dataTable()._fnAjaxUpdateDraw({
  56. recordsTotal: 300,
  57. recordsFiltered: 300,
  58. data: []
  59. }, settings);*/
  60. }
  61. }
  62. /* control buttons */
  63. // onclick control buttons methods
  64. $(function () {
  65. // stop showing data and enable a new request
  66. $('#stopButton').click(function (e) {
  67. if (!$(this).hasClass("disabled"))
  68. world.finishLoading(false);
  69. });
  70. // start/pause showing data from the database (toggles)
  71. $('#playButton').click(function (e) {
  72. // only change the button state if data is actually requested
  73. if (!$(this).hasClass("disabled")) {
  74. if ($('#playButton i').hasClass('icon-play')) {
  75. world.restartTimer();
  76. $('#playButton i').addClass('icon-pause');
  77. $('#playButton i').removeClass('icon-play');
  78. }
  79. else if ($('#playButton i').hasClass('icon-pause')) {
  80. world.stopTimer();
  81. $('#playButton i').addClass('icon-play');
  82. $('#playButton i').removeClass('icon-pause');
  83. }
  84. }
  85. });
  86. // lengthen the intervals in which new data from the database is shown
  87. $('#slowerButton').click(function (e) {
  88. if (!$(this).hasClass("disabled"))
  89. world.changeTimer(500);
  90. });
  91. // shorten the intervals in which new data from the database is shown
  92. $('#fasterButton').click(function (e) {
  93. if (!$(this).hasClass("disabled"))
  94. world.changeTimer(-500);
  95. });
  96. // immediately show the data from the database
  97. $('#showAllButton').click(function (e) {
  98. if (!$(this).hasClass("disabled"))
  99. world.resetTimer();
  100. });
  101. });
  102. // enable database request loading control buttons
  103. function enableRequestControl() {
  104. $('#stopButton').removeClass('disabled');
  105. $('#playButton').removeClass('disabled');
  106. $('#slowerButton').removeClass('disabled');
  107. $('#fasterButton').removeClass('disabled');
  108. $('#showAllButton').removeClass('disabled');
  109. }
  110. // disable database request loading control buttons
  111. function disableRequestControl() {
  112. $('#stopButton').addClass('disabled');
  113. $('#playButton').addClass('disabled');
  114. $('#slowerButton').addClass('disabled');
  115. $('#fasterButton').addClass('disabled');
  116. $('#showAllButton').addClass('disabled');
  117. }
  118. /*
  119. * database window gui functionality
  120. */
  121. $(function(){
  122. $("#jrange").jrange();
  123. });
  124. // based on http://stackoverflow.com/questions/13313867/custom-button-dissapearing-from-jquery-datepicker
  125. function addPanelSelectButton(obj) {
  126. setTimeout(function() {
  127. var buttonPane = $(obj).datepicker("widget").find(".ui-datepicker-buttonpane");
  128. var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-primary ui-corner-all" type="button">Select</button>');
  129. btn.unbind("click").bind("click", function() {
  130. setTimeout(function() {$('#hideTable').html('');}, 300);
  131. // write current year and month into text field on close, remember them for next time
  132. var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
  133. var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
  134. $(obj).datepicker('option', 'defaultDate', new Date(year, month));
  135. $(obj).datepicker('setDate', new Date(year, month));
  136. // set current (changed) ID for the request
  137. currentRequestID = "inputDateNoDay";
  138. });
  139. if (buttonPane.has('#customClearButton').length==0)
  140. btn.appendTo(buttonPane);
  141. }, 1);
  142. }