Favorite.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. define([ "require", "backbone", "hbs!tmpl/site/Statistics_tmpl", "hbs!tmpl/site/Statistics_Notification_table_tmpl", "hbs!tmpl/site/entity_tmpl", "modules/Modal", "models/VCommon", "utils/UrlLinks", "collection/VTagList", "utils/CommonViewFunction", "utils/Enums", "moment", "utils/Utils", "moment-timezone" ], function(require, Backbone, StatTmpl, StatsNotiTable, EntityTable, Modal, VCommon, UrlLinks, VTagList, CommonViewFunction, Enums, moment, Utils) {
  2. "use strict";
  3. Backbone.Marionette.LayoutView.extend({
  4. template: StatTmpl,
  5. regions: {
  6. RSaveSearchBasic: "[data-id='r_saveSearchBasic']",
  7. RSaveSearchAdvance: "[data-id='r_saveSearchAdvance']"
  8. },
  9. ui: {},
  10. events: function() {},
  11. initialize: function(options) {
  12. _.extend(this, options);
  13. var that = this, modal = new Modal({
  14. title: "统计信息",
  15. content: this,
  16. okCloses: !0,
  17. okText: "Close",
  18. showFooter: !0,
  19. allowCancel: !1,
  20. width: "60%",
  21. headerButtons: [ {
  22. title: "Refresh Data",
  23. btnClass: "fa fa-refresh",
  24. onClick: function() {
  25. modal.$el.find(".header-button .fa-refresh").tooltip("hide").prop("disabled", !0).addClass("fa-spin"),
  26. that.fetchMetricData({
  27. update: !0
  28. });
  29. }
  30. } ]
  31. }).open();
  32. modal.on("closeModal", function() {
  33. modal.trigger("cancel");
  34. }), this.modal = modal;
  35. },
  36. bindEvents: function() {},
  37. fetchMetricData: function(options) {
  38. that.RSaveSearchBasic.show(new SaveSearchView(_.extend(obj, {
  39. isBasic: !0,
  40. collection: saveSearchBaiscCollection.fullCollection
  41. }))), that.RSaveSearchAdvance.show(new SaveSearchView(_.extend(obj, {
  42. isBasic: !1,
  43. collection: saveSearchAdvanceCollection.fullCollection
  44. })));
  45. },
  46. onRender: function() {
  47. this.fetchMetricData();
  48. },
  49. genrateStatusData: function(stateObject) {
  50. var stats = {};
  51. return _.each(stateObject, function(val, key) {
  52. var keys = key.split(":"), key = keys[0], subKey = keys[1];
  53. stats[key] ? stats[key][subKey] = val : (stats[key] = {}, stats[key][subKey] = val);
  54. }), stats;
  55. },
  56. renderEntities: function(options) {
  57. var that = this, data = options.data, entityData = data.entity, activeEntities = entityData.entityActive || {}, deletedEntities = entityData.entityDeleted || {}, stats = {}, activeEntityCount = 0, deletedEntityCount = 0, createEntityData = function(opt) {
  58. var entityData = opt.entityData, type = opt.type;
  59. _.each(entityData, function(val, key) {
  60. var intVal = _.isUndefined(val) ? 0 : val;
  61. "active" == type ? activeEntityCount += intVal : deletedEntityCount += intVal, intVal = _.numberFormatWithComma(intVal),
  62. stats[key] ? stats[key][type] = intVal : (stats[key] = {}, stats[key][type] = intVal);
  63. });
  64. };
  65. createEntityData({
  66. entityData: activeEntities,
  67. type: "active"
  68. }), createEntityData({
  69. entityData: deletedEntities,
  70. type: "deleted"
  71. }), _.isEmpty(stats) || (that.ui.entityCard.html(EntityTable({
  72. data: _.pick(stats, _.keys(stats).sort())
  73. })), that.$('[data-id="activeEntity"]').html(" (" + _.numberFormatWithComma(activeEntityCount) + ")"),
  74. that.$('[data-id="deletedEntity"]').html(" (" + _.numberFormatWithComma(deletedEntityCount) + ")"),
  75. that.ui.entityHeader.html(" (" + _.numberFormatWithComma(data.general.entityCount) + ")"));
  76. },
  77. renderStats: function(options) {
  78. var that = this, data = this.genrateStatusData(options.valueObject), generalData = options.dataObject, createTable = function(obj) {
  79. var tableBody = "", enums = obj.enums, data = obj.data;
  80. return _.each(data, function(value, key, list) {
  81. tableBody += "<tr><td>" + key + '</td><td class="">' + that.getValue({
  82. value: value,
  83. type: enums[key]
  84. }) + "</td></tr>";
  85. }), tableBody;
  86. };
  87. if (data.Notification) {
  88. var tableCol = [ {
  89. label: "Total <br> (from " + that.getValue({
  90. value: data.Server.startTimeStamp,
  91. type: Enums.stats.Server.startTimeStamp
  92. }) + ")",
  93. key: "total"
  94. }, {
  95. label: "Current Hour <br> (from " + that.getValue({
  96. value: data.Notification.currentHourStartTime,
  97. type: Enums.stats.Notification.currentHourStartTime
  98. }) + ")",
  99. key: "currentHour"
  100. }, {
  101. label: "Previous Hour",
  102. key: "previousHour"
  103. }, {
  104. label: "Current Day <br> (from " + that.getValue({
  105. value: data.Notification.currentDayStartTime,
  106. type: Enums.stats.Notification.currentDayStartTime
  107. }) + ")",
  108. key: "currentDay"
  109. }, {
  110. label: "Previous Day",
  111. key: "previousDay"
  112. } ], tableHeader = [ "count", "AvgTime", "EntityCreates", "EntityUpdates", "EntityDeletes", "Failed" ];
  113. that.ui.notificationCard.html(StatsNotiTable({
  114. enums: Enums.stats.Notification,
  115. data: data.Notification,
  116. tableHeader: tableHeader,
  117. tableCol: tableCol,
  118. getTmplValue: function(argument, args) {
  119. var pickValueFrom = argument.key.concat(args);
  120. "total" == argument.key && "EntityCreates" == args ? pickValueFrom = "totalCreates" : "total" == argument.key && "EntityUpdates" == args ? pickValueFrom = "totalUpdates" : "total" == argument.key && "EntityDeletes" == args ? pickValueFrom = "totalDeletes" : "count" == args && (pickValueFrom = argument.key);
  121. var returnVal = data.Notification[pickValueFrom];
  122. return returnVal ? _.numberFormatWithComma(returnVal) : 0;
  123. }
  124. })), that.ui.notificationSmallCard.html(createTable({
  125. enums: Enums.stats.Notification,
  126. data: _.pick(data.Notification, "lastMessageProcessedTime", "offsetCurrent", "offsetStart")
  127. }));
  128. }
  129. data.Server && that.ui.serverCard.html(createTable({
  130. enums: _.extend(Enums.stats.Server, Enums.stats.ConnectionStatus, Enums.stats.generalData),
  131. data: _.extend(_.pick(data.Server, "startTimeStamp", "activeTimeStamp", "upTime", "statusBackendStore", "statusIndexStore"), _.pick(generalData, "collectionTime"))
  132. }));
  133. },
  134. getValue: function(options) {
  135. var value = options.value, type = options.type;
  136. return "time" == type ? Utils.millisecondsToTime(value) : "day" == type ? moment.tz(value, moment.tz.guess()).format("MM/DD/YYYY h:mm A z") : "number" == type ? _.numberFormatWithComma(value) : "millisecond" == type ? _.numberFormatWithComma(value) + " millisecond/s" : "status-html" == type ? '<span class="connection-status ' + value + '"></span>' : value;
  137. }
  138. });
  139. return StatisticsView;
  140. });