DebugMetricsTableLayoutView.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. define([ "require", "backbone", "hbs!tmpl/site/DebugMetricsTableLayoutView_tmpl", "utils/UrlLinks", "collection/VEntityList", "utils/CommonViewFunction", "utils/Utils" ], function(require, Backbone, DebugMetricsTableLayoutViewTmpl, UrlLinks, VEntityList, CommonViewFunction, Utils) {
  2. "use strict";
  3. var DebugMetricsTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "DebugMetricsTableLayoutView",
  5. template: DebugMetricsTableLayoutViewTmpl,
  6. regions: {
  7. RDebugMetricsTableLayoutView: "#r_debugMetricsTableLayoutView"
  8. },
  9. ui: {
  10. refreshMetricsBtn: '[data-id="refreshMetricsBtn"]',
  11. metricsInfoBtn: '[data-id="metricsInfo"]'
  12. },
  13. events: function() {
  14. var events = {};
  15. return events["click " + this.ui.refreshMetricsBtn] = function(e) {
  16. this.currPage = 1, this.limit = 26, this.debugMetricsCollection.state.pageSize = 25,
  17. this.debugMetricsCollection.state.currentPage = 0, this.fetchMetricData();
  18. }, events["click " + this.ui.metricsInfoBtn] = "metricsInfo", events;
  19. },
  20. initialize: function(options) {
  21. _.extend(this, options);
  22. this.DATA_MAX_LENGTH = 25, this.debugMetricsCollection = new VEntityList(), this.debugMetricsCollection.url = UrlLinks.debugMetricsApiUrl(),
  23. this.debugMetricsCollection.modelAttrName = "data", this.commonTableOptions = {
  24. collection: this.debugMetricsCollection,
  25. includeFilter: !1,
  26. includePagination: !0,
  27. includeFooterRecords: !0,
  28. includePageSize: !0,
  29. includeGotoPage: !0,
  30. includeAtlasTableSorting: !0,
  31. includeTableLoader: !0,
  32. includeColumnManager: !1,
  33. gridOpts: {
  34. className: "table table-hover backgrid table-quickMenu",
  35. emptyText: "No records found!"
  36. },
  37. filterOpts: {},
  38. paginatorOpts: {}
  39. }, this.currPage = 1, this.limit = 26;
  40. },
  41. bindEvents: function() {
  42. },
  43. onRender: function() {
  44. this.bindEvents(), this.$(".debug-metrics-table").show(), this.fetchMetricData();
  45. },
  46. metricsInfo: function(e) {
  47. require([ "views/site/MetricsUIInfoView", "modules/Modal" ], function(MetricsUIInfoView, Modal) {
  48. var view = new MetricsUIInfoView(), modal = new Modal({
  49. title: "Debug Metrics",
  50. content: view,
  51. okCloses: !0,
  52. showFooter: !1,
  53. allowCancel: !1
  54. }).open();
  55. view.on("closeModal", function() {
  56. modal.trigger("cancel");
  57. });
  58. });
  59. },
  60. fetchMetricData: function(options) {
  61. var that = this;
  62. this.debugMetricsCollection.fetch({
  63. success: function(data) {
  64. var data = _.first(data.toJSON()), metricsDataKeys = data ? Object.keys(data) : null;
  65. that.debugMetricsCollection.fullCollection.reset(), _.each(metricsDataKeys.sort(), function(keyName) {
  66. that.debugMetricsCollection.fullCollection.add(data[keyName]);
  67. });
  68. },
  69. complete: function(data) {
  70. that.renderTableLayoutView();
  71. }
  72. });
  73. },
  74. renderTableLayoutView: function() {
  75. var that = this;
  76. require([ "utils/TableLayout" ], function(TableLayout) {
  77. var cols = new Backgrid.Columns(that.getAuditTableColumns());
  78. that.RDebugMetricsTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  79. columns: cols
  80. }))), that.debugMetricsCollection.models.length < that.limit || that.RDebugMetricsTableLayoutView.$el.find("table tr").last().hide();
  81. });
  82. },
  83. millisecondsToSeconds: function(rawValue) {
  84. return parseFloat(rawValue % 6e4 / 1e3).toFixed(3);
  85. },
  86. getAuditTableColumns: function() {
  87. var that = this;
  88. return this.debugMetricsCollection.constructor.getTableCols({
  89. name: {
  90. label: "Name",
  91. cell: "html",
  92. sortable: !0,
  93. editable: !1
  94. },
  95. numops: {
  96. label: "Count",
  97. cell: "html",
  98. toolTip: "Number of times the API has been hit since Atlas started",
  99. sortable: !0,
  100. editable: !1
  101. },
  102. minTime: {
  103. label: "Min Time (secs)",
  104. cell: "html",
  105. toolTip: "Minimum API execution time since Atlas started",
  106. sortable: !0,
  107. editable: !1,
  108. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  109. fromRaw: function(rawValue, model) {
  110. return that.millisecondsToSeconds(rawValue);
  111. }
  112. })
  113. },
  114. maxTime: {
  115. label: "Max Time (secs)",
  116. cell: "html",
  117. toolTip: "Maximum API execution time since Atlas started",
  118. sortable: !0,
  119. editable: !1,
  120. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  121. fromRaw: function(rawValue, model) {
  122. return that.millisecondsToSeconds(rawValue);
  123. }
  124. })
  125. },
  126. avgTime: {
  127. label: "Average Time (secs)",
  128. cell: "html",
  129. toolTip: "Average time taken to execute by an API within an interval of time",
  130. sortable: !0,
  131. editable: !1,
  132. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  133. fromRaw: function(rawValue, model) {
  134. return that.millisecondsToSeconds(rawValue);
  135. }
  136. })
  137. }
  138. }, this.debugMetricsCollection);
  139. }
  140. });
  141. return DebugMetricsTableLayoutView;
  142. });