PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/assets/javascripts/pages/supervision.js

https://gitlab.com/exploitation.sm.eu/xucmgt
JavaScript | 170 lines | 138 code | 32 blank | 0 comment | 9 complexity | bea83075f8b20e3766997981fe36fa2d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, BSD-3-Clause, Apache-2.0
  1. $(function() {
  2. var supervision = {};
  3. supervision.container = "#all_queues";
  4. supervision.nbOfQueues = 0;
  5. supervision.lineNb = 0;
  6. supervision.queues = [];
  7. var drawOrUpdateDoNut = function(divid, counters, radius) {
  8. var dataSet = counters;
  9. var todisplay = {
  10. Lost : "Lost",
  11. Link : "Link"
  12. };
  13. dataSet = dataSet.filter(function(el) {
  14. return todisplay[el.statName];
  15. });
  16. var validData = dataSet.filter(function(el) {
  17. if (el.value >= 0)
  18. return el.value;
  19. });
  20. if (validData.length === 0)
  21. return;
  22. if (dataSet.length === 0)
  23. return;
  24. var getValues = function(d) {
  25. return d.value;
  26. };
  27. var arc = d3.svg.arc().outerRadius(radius - 10).innerRadius(60);
  28. var agentpie = d3.layout.pie().value(getValues);
  29. var color = d3.scale.ordinal().range([ "green", "red", "orange", "yellow" ]);
  30. var arcs = d3.select(divid).select("svg").select(".arcGrp").selectAll("path").data(agentpie(dataSet));
  31. arcs.enter().append("svg:path").attr("stroke", "white").attr("stroke-width", 0.5).attr("fill", function(d, i) {
  32. return color(i);
  33. }).attr("d", arc).each(function(d) {
  34. this._current = d.value;
  35. });
  36. arcs.transition().attr("stroke", "white").attr("stroke-width", 0.5).attr("fill", function(d, i) {
  37. return color(i);
  38. }).attr("d", arc).each(function(d) {
  39. this._current = d.value;
  40. });
  41. };
  42. var drawOrUpdateCenterLabel = function(divid, counters) {
  43. var wtclass = "normal";
  44. var todisplay = {
  45. WaitingCalls : "WaitingCalls"
  46. };
  47. var dataSet = counters.filter(function(el) {
  48. return todisplay[el.statName];
  49. });
  50. if (dataSet.length === 0)
  51. return;
  52. var getData = function(d) {
  53. return d.value;
  54. };
  55. var getClass = function(d) {
  56. if (d.value > 3)
  57. return "error";
  58. if (d.value > 1)
  59. return "warning";
  60. else
  61. return "normal";
  62. };
  63. var center_label = d3.select(divid).select("svg").select(".ctrGroup").selectAll("text").data(dataSet);
  64. center_label.enter().append("svg:text").attr("dy", ".35em").attr("class", wtclass)
  65. .attr("text-anchor", "middle").text(getData);
  66. center_label.transition().attr("dy", ".35em").attr("class", getClass).attr("text-anchor", "middle").text(
  67. getData);
  68. };
  69. var drawDoNuts = function(divid, counters) {
  70. var width = 200, height = 200, radius = Math.min(width, height) / 2;
  71. if (d3.select(divid).selectAll("svg").empty()) {
  72. var svg = d3.select(divid).append("svg:svg").attr("width", width).attr("height", height);
  73. svg.append("svg:g").attr("class", "arcGrp").attr("transform",
  74. "translate(" + (width / 2) + "," + (height / 2) + ")");
  75. svg.append("svg:g").attr("class", "ctrGroup").attr("transform",
  76. "translate(" + (width / 2) + "," + (height / 2) + ")");
  77. }
  78. drawOrUpdateDoNut(divid, counters, radius);
  79. drawOrUpdateCenterLabel(divid, counters);
  80. };
  81. var queueConfigHandler = function(queueConfig) {
  82. console.log("queue config Handler " + JSON.stringify(queueConfig));
  83. supervision.queues[supervision.nbOfQueues] = queueConfig.id;
  84. if (supervision.nbOfQueues % 3 === 0) {
  85. supervision.lineNb = supervision.lineNb + 1;
  86. createLine(supervision.lineNb);
  87. }
  88. supervision.nbOfQueues = supervision.nbOfQueues + 1;
  89. createQueue(supervision.lineNb, supervision.nbOfQueues, queueConfig);
  90. console.log(supervision.nbOfQueues + " " + (supervision.lineNb));
  91. getStats();
  92. };
  93. var queueStatisticsHandler = function(event) {
  94. var divid = "#queue_body" + event.queueId;
  95. drawDoNuts(divid, event.counters);
  96. };
  97. var createLine = function(lineNb) {
  98. $(supervision.container).append('<li class="list-group-item" id="li_queue' + lineNb + '"/>');
  99. $("#li_queue" + lineNb).append('<div class="row" id="row_queue' + lineNb + '">');
  100. };
  101. var createQueue = function(lineNb, queueNb, queue) {
  102. $("#row_queue" + lineNb).append('<div class="col-md-4" id="col_queue' + queueNb + '">');
  103. $("#col_queue" + queueNb).append('<div class="panel panel-info" id="panel_info' + queueNb + '">');
  104. $("#panel_info" + queueNb).append(
  105. '<div class="panel-heading">' + queue.displayName + ' (' + queue.number + ')' + '</div>');
  106. $("#panel_info" + queueNb).append('<div class="panel-body text-center" id="queue_body' + queue.id + '"/>');
  107. $("#panel_info" + queueNb).append('<div class="panel-footer"/>');
  108. };
  109. var getStats = function() {
  110. for (var i = 0; i < supervision.queues.length; i++) {
  111. Cti.getQueueStatistics(supervision.queues[i], 3600, 60);
  112. }
  113. };
  114. var initUi = function() {
  115. $(supervision.container).empty();
  116. setInterval(getStats, 5000);
  117. };
  118. var loggedOnHandler = function() {
  119. $('#xuc_logon_panel').hide();
  120. Cti.getConfig("queue");
  121. Cti.subscribeToQueueStats();
  122. };
  123. $('#xuc_sign_in').click(
  124. function(event) {
  125. initUi();
  126. var username = $('#xuc_username').val();
  127. var password = $('#xuc_password').val();
  128. var hostAndPort = $('#xuc_hostAndPort').val();
  129. var phoneNumber = 0;
  130. console.log("sign in " + username + " " + password + " to " + hostAndPort);
  131. var wsurl = "ws://" + hostAndPort + "/xuc/ctichannel?username=" + username + "&amp;agentNumber=" +
  132. phoneNumber + "&amp;password=" + password;
  133. Cti.setHandler(Cti.MessageType.QUEUECONFIG, queueConfigHandler);
  134. Cti.setHandler(Cti.MessageType.QUEUESTATISTICS, queueStatisticsHandler);
  135. Cti.setHandler(Cti.MessageType.LOGGEDON, loggedOnHandler);
  136. Cti.WebSocket.init(wsurl, username, 0);
  137. });
  138. });