ProfileTableLayoutView.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. define([ "require", "backbone", "hbs!tmpl/profile/ProfileTableLayoutView_tmpl", "collection/VProfileList", "utils/Utils", "utils/Messages", "utils/Globals", "moment", "utils/UrlLinks", "collection/VCommonList", "collection/VEntityList", "d3", "sparkline" ], function(require, Backbone, ProfileTableLayoutViewTmpl, VProfileList, Utils, Messages, Globals, moment, UrlLinks, VCommonList, VEntityList, d3, sparkline) {
  2. "use strict";
  3. var ProfileTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "ProfileTableLayoutView",
  5. template: ProfileTableLayoutViewTmpl,
  6. regions: {
  7. RProfileTableLayoutView: "#r_profileTableLayoutView"
  8. },
  9. ui: {},
  10. events: function() {
  11. var events = {};
  12. return events["click " + this.ui.addTag] = "checkedValue", events;
  13. },
  14. initialize: function(options) {
  15. _.extend(this, _.pick(options, "profileData", "guid", "entityDetail"));
  16. this.profileCollection = new VCommonList([], {
  17. comparator: function(item) {
  18. return item.get("position") || 999;
  19. }
  20. }), this.bindEvents();
  21. },
  22. onRender: function() {
  23. this.fetchEntity();
  24. },
  25. fetchEntity: function(argument) {
  26. var that = this;
  27. this.collection = new VEntityList([], {}), this.collection.url = UrlLinks.entitiesApiUrl({
  28. guid: this.guid,
  29. minExtInfo: !1
  30. }), this.collection.fetch({
  31. success: function(response) {
  32. that.entityObject = that.collection.first().toJSON();
  33. var collectionJSON = that.entityObject.entity;
  34. that.entityDetail = collectionJSON.attributes, Utils.findAndMergeRefEntity({
  35. attributeObject: collectionJSON.attributes,
  36. referredEntities: that.entityObject.referredEntities
  37. }), Utils.findAndMergeRefEntity({
  38. attributeObject: collectionJSON.relationshipAttributes,
  39. referredEntities: that.entityObject.referredEntities
  40. });
  41. var columns = collectionJSON.relationshipAttributes.columns || collectionJSON.attributes.columns, db = collectionJSON.relationshipAttributes.db || collectionJSON.attributes.db;
  42. if (that.renderTableLayoutView(), that.entityDetail) {
  43. that.guid && that.entityDetail.name && that.$(".table_name .graphval").html('<b><a href="#!/detailPage/' + that.guid + '">' + that.entityDetail.name + "</a></b>"),
  44. db && that.$(".db_name .graphval").html('<b><a href="#!/detailPage/' + db.guid + '?profile=true">' + Utils.getName(db) + "</a></b>");
  45. var profileData = that.entityDetail.profileData;
  46. profileData && profileData.attributes && profileData.attributes.rowCount && that.$(".rowValue .graphval").html("<b>" + d3.format("2s")(profileData.attributes.rowCount).replace("G", "B") + "</b>"),
  47. that.$(".table_created .graphval").html("<b>" + (that.entityDetail.createTime ? moment(that.entityDetail.createTime).format("LL") : "--") + "</b>");
  48. }
  49. _.each(columns, function(obj) {
  50. if (obj.attributes && obj.attributes.profileData) {
  51. var profileObj = Utils.getProfileTabType(obj.attributes.profileData.attributes, !0), changeValueObj = {};
  52. profileObj && profileObj.type && ("numeric" === profileObj.type && (changeValueObj.averageLength = 0,
  53. changeValueObj.maxLength = 0), "string" === profileObj.type && (changeValueObj.minValue = 0,
  54. changeValueObj.maxValue = 0, changeValueObj.meanValue = 0, changeValueObj.medianValue = 0),
  55. "date" === profileObj.type && (changeValueObj.averageLength = 0, changeValueObj.maxLength = 0,
  56. changeValueObj.minValue = 0, changeValueObj.maxValue = 0, changeValueObj.meanValue = 0,
  57. changeValueObj.medianValue = 0)), that.profileCollection.fullCollection.add(_.extend({}, obj.attributes, obj.attributes.profileData.attributes, changeValueObj, {
  58. guid: obj.guid,
  59. position: obj.attributes ? obj.attributes.position : null
  60. }));
  61. }
  62. });
  63. },
  64. reset: !1
  65. });
  66. },
  67. bindEvents: function() {
  68. this.listenTo(this.profileCollection, "backgrid:refresh", function(model, checked) {
  69. this.renderGraphs();
  70. }, this);
  71. },
  72. renderTableLayoutView: function() {
  73. var that = this;
  74. require([ "utils/TableLayout" ], function(TableLayout) {
  75. var cols = new Backgrid.Columns(that.getAuditTableColumns());
  76. that.RProfileTableLayoutView.show(new TableLayout(_.extend({}, {
  77. columns: cols,
  78. collection: that.profileCollection,
  79. includeFilter: !1,
  80. includePagination: !0,
  81. includePageSize: !1,
  82. includeFooterRecords: !0,
  83. gridOpts: {
  84. className: "table table-hover backgrid table-quickMenu",
  85. emptyText: "No records found!"
  86. }
  87. }))), that.renderGraphs();
  88. });
  89. },
  90. renderGraphs: function() {
  91. this.$(".sparklines").sparkline("html", {
  92. enableTagOptions: !0
  93. }), this.$(".sparklines").bind("sparklineClick", function(ev) {
  94. var id = $(ev.target).data().guid;
  95. Utils.setUrl({
  96. url: "#!/detailPage/" + id,
  97. mergeBrowserUrl: !1,
  98. trigger: !0,
  99. urlParams: {
  100. tabActive: "profile"
  101. }
  102. });
  103. });
  104. },
  105. getAuditTableColumns: function() {
  106. return this.profileCollection.constructor.getTableCols({
  107. name: {
  108. label: "Name",
  109. cell: "Html",
  110. editable: !1,
  111. sortable: !0,
  112. sortType: "toggle",
  113. direction: "ascending",
  114. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  115. fromRaw: function(rawValue, model) {
  116. return '<div><a href="#!/detailPage/' + model.get("guid") + '?profile=true">' + rawValue + "</a></div>";
  117. }
  118. })
  119. },
  120. type: {
  121. label: "Type",
  122. cell: "String",
  123. editable: !1,
  124. sortable: !0,
  125. sortType: "toggle"
  126. },
  127. nonNullData: {
  128. label: "% NonNull",
  129. cell: "Html",
  130. editable: !1,
  131. sortable: !0,
  132. sortType: "toggle",
  133. width: "180",
  134. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  135. fromRaw: function(rawValue, model) {
  136. if (rawValue < 50) var barClass = rawValue > 30 && rawValue <= 50 ? "progress-bar-warning" : "progress-bar-danger"; else var barClass = "progress-bar-success";
  137. return '<div class="progress cstm_progress" title="' + rawValue + '%"><div class="progress-bar ' + barClass + ' cstm_success-bar progress-bar-striped" style="width:' + rawValue + '%">' + rawValue + "%</div></div>";
  138. }
  139. })
  140. },
  141. distributionDecile: {
  142. label: "Distribution",
  143. cell: "Html",
  144. editable: !1,
  145. sortable: !1,
  146. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  147. fromRaw: function(rawValue, model) {
  148. var sparkarray = [], distibutionObj = Utils.getProfileTabType(model.toJSON());
  149. return distibutionObj && _.each(distibutionObj.actualObj, function(obj) {
  150. sparkarray.push(obj.count);
  151. }), '<span data-guid="' + model.get("guid") + '" class="sparklines" sparkType="bar" sparkBarColor="#38BB9B" values="' + sparkarray.join(",") + '"></span>';
  152. }
  153. })
  154. },
  155. cardinality: {
  156. label: "Cardinality",
  157. cell: "Number",
  158. editable: !1,
  159. sortable: !0,
  160. sortType: "toggle"
  161. },
  162. minValue: {
  163. label: "Min",
  164. cell: "Number",
  165. editable: !1,
  166. sortable: !0,
  167. sortType: "toggle",
  168. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  169. fromRaw: function(rawValue, model) {
  170. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  171. return profileObj && "numeric" === profileObj.type ? rawValue : "-";
  172. }
  173. })
  174. },
  175. maxValue: {
  176. label: "Max",
  177. cell: "Number",
  178. editable: !1,
  179. sortable: !0,
  180. sortType: "toggle",
  181. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  182. fromRaw: function(rawValue, model) {
  183. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  184. return profileObj && "numeric" === profileObj.type ? rawValue : "-";
  185. }
  186. })
  187. },
  188. averageLength: {
  189. label: "Average Length",
  190. cell: "Number",
  191. editable: !1,
  192. sortable: !0,
  193. sortType: "toggle",
  194. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  195. fromRaw: function(rawValue, model) {
  196. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  197. return profileObj && "string" === profileObj.type ? rawValue : "-";
  198. }
  199. })
  200. },
  201. maxLength: {
  202. label: "Max Length",
  203. cell: "Number",
  204. editable: !1,
  205. sortable: !0,
  206. sortType: "toggle",
  207. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  208. fromRaw: function(rawValue, model) {
  209. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  210. return profileObj && "string" === profileObj.type ? rawValue : "-";
  211. }
  212. })
  213. },
  214. meanValue: {
  215. label: "Mean",
  216. cell: "Number",
  217. editable: !1,
  218. sortable: !0,
  219. sortType: "toggle",
  220. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  221. fromRaw: function(rawValue, model) {
  222. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  223. return profileObj && "numeric" === profileObj.type ? rawValue : "-";
  224. }
  225. })
  226. },
  227. medianValue: {
  228. label: "Median",
  229. cell: "Number",
  230. editable: !1,
  231. sortable: !0,
  232. sortType: "toggle",
  233. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  234. fromRaw: function(rawValue, model) {
  235. var profileObj = Utils.getProfileTabType(model.toJSON(), !0);
  236. return profileObj && "numeric" === profileObj.type ? rawValue : "-";
  237. }
  238. })
  239. }
  240. }, this.profileCollection);
  241. }
  242. });
  243. return ProfileTableLayoutView;
  244. });