AdminAuditTableLayoutView.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. define([ "require", "backbone", "hbs!tmpl/audit/AdminAuditTableLayoutView_tmpl", "collection/VEntityList", "utils/Utils", "utils/UrlLinks", "utils/CommonViewFunction", "utils/Enums", "moment" ], function(require, Backbone, AdminAuditTableLayoutView_tmpl, VEntityList, Utils, UrlLinks, CommonViewFunction, Enums, moment) {
  2. "use strict";
  3. var AdminAuditTableLayoutView = Backbone.Marionette.LayoutView.extend({
  4. _viewName: "AdminAuditTableLayoutView",
  5. template: AdminAuditTableLayoutView_tmpl,
  6. regions: {
  7. RAuditTableLayoutView: "#r_adminAuditTableLayoutView",
  8. RQueryBuilderAdmin: "#r_attributeQueryBuilderAdmin"
  9. },
  10. ui: {
  11. adminPurgedEntityClick: "[data-id='adminPurgedEntity']",
  12. adminAuditEntityDetails: "[data-id='adminAuditEntityDetails']",
  13. attrFilter: "[data-id='adminAttrFilter']",
  14. adminRegion: "[data-id='adminRegion']",
  15. attrApply: "[data-id='attrApply']",
  16. showDefault: "[data-id='showDefault']",
  17. attrClose: "[data-id='attrClose']"
  18. },
  19. events: function() {
  20. var events = {}, that = this;
  21. return events["click " + this.ui.adminPurgedEntityClick] = "onClickAdminPurgedEntity",
  22. events["click " + this.ui.adminAuditEntityDetails] = "showAdminAuditEntity", events["click " + this.ui.attrFilter] = function(e) {
  23. this.ui.attrFilter.find(".fa-angle-right").toggleClass("fa-angle-down"), this.$(".attributeResultContainer").addClass("overlay"),
  24. this.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide"),
  25. this.onClickAttrFilter();
  26. }, events["click " + this.ui.attrClose] = function(e) {
  27. that.closeAttributeModel();
  28. }, events["click " + this.ui.attrApply] = function(e) {
  29. that.okAttrFilterButton(e);
  30. }, events;
  31. },
  32. initialize: function(options) {
  33. _.extend(this, _.pick(options, "searchTableFilters", "entityDefCollection", "enumDefCollection")),
  34. this.entityCollection = new VEntityList(), this.limit = 25, this.offset = 0, this.entityCollection.url = UrlLinks.adminApiUrl(),
  35. this.entityCollection.modelAttrName = "events", this.commonTableOptions = {
  36. collection: this.entityCollection,
  37. includePagination: !1,
  38. includeAtlasPagination: !0,
  39. includeFooterRecords: !1,
  40. includeColumnManager: !0,
  41. includeOrderAbleColumns: !1,
  42. includeSizeAbleColumns: !1,
  43. includeTableLoader: !0,
  44. includeAtlasPageSize: !0,
  45. includeAtlasTableSorting: !0,
  46. columnOpts: {
  47. opts: {
  48. initialColumnsVisible: null,
  49. saveState: !1
  50. },
  51. visibilityControlOpts: {
  52. buttonTemplate: _.template("<button class='btn btn-action btn-sm pull-right'>Columns&nbsp<i class='fa fa-caret-down'></i></button>")
  53. },
  54. el: this.ui.colManager
  55. },
  56. atlasPaginationOpts: {
  57. limit: this.limit,
  58. offset: this.offset,
  59. fetchCollection: this.getAdminCollection.bind(this)
  60. },
  61. gridOpts: {
  62. emptyText: "No Record found!",
  63. className: "table table-hover backgrid table-quickMenu colSort"
  64. },
  65. filterOpts: {},
  66. paginatorOpts: {}
  67. }, this.isFilters = null, this.adminAuditEntityData = {};
  68. },
  69. onRender: function() {
  70. this.ui.adminRegion.hide(), this.getAdminCollection(), this.entityCollection.comparator = function(model) {
  71. return -model.get("timestamp");
  72. }, this.renderTableLayoutView();
  73. },
  74. onShow: function() {
  75. this.$(".fontLoader").show(), this.$(".tableOverlay").show();
  76. },
  77. bindEvents: function() {},
  78. closeAttributeModel: function() {
  79. var that = this;
  80. that.$(".attributeResultContainer").removeClass("overlay"), that.ui.attrFilter.find(".fa-angle-right").toggleClass("fa-angle-down"),
  81. that.$(".attribute-filter-container, .attr-filter-overlay").toggleClass("hide");
  82. },
  83. onClickAttrFilter: function() {
  84. var that = this;
  85. this.ui.adminRegion.show(), require([ "views/search/QueryBuilderView" ], function(QueryBuilderView) {
  86. that.RQueryBuilderAdmin.show(new QueryBuilderView({
  87. adminAttrFilters: !0,
  88. searchTableFilters: that.searchTableFilters,
  89. entityDefCollection: that.entityDefCollection,
  90. enumDefCollection: that.enumDefCollection
  91. }));
  92. });
  93. },
  94. okAttrFilterButton: function(options) {
  95. var that = this, isFilterValidate = !0, queryBuilderRef = that.RQueryBuilderAdmin.currentView.ui.builder;
  96. if (queryBuilderRef.data("queryBuilder")) {
  97. var queryBuilder = queryBuilderRef.queryBuilder("getRules");
  98. queryBuilder ? (that.ruleUrl = that.searchTableFilters.adminAttrFilters = CommonViewFunction.attributeFilter.generateUrl({
  99. value: queryBuilder,
  100. formatedDateToLong: !0
  101. }), that.isFilters = queryBuilder.rules.length ? queryBuilder.rules : null) : isFilterValidate = !1;
  102. }
  103. isFilterValidate && (that.closeAttributeModel(), that.defaultPagination(), that.getAdminCollection());
  104. },
  105. getAdminCollection: function(option) {
  106. var that = this, auditFilters = CommonViewFunction.attributeFilter.generateAPIObj(that.ruleUrl);
  107. $.extend(that.entityCollection.queryParams, {
  108. auditFilters: that.isFilters ? auditFilters : null,
  109. limit: that.entityCollection.queryParams.limit || that.limit,
  110. offset: that.entityCollection.queryParams.offset || that.offset,
  111. sortBy: "startTime",
  112. sortOrder: "DESCENDING"
  113. });
  114. var apiObj = {
  115. sort: !1,
  116. data: _.pick(that.entityCollection.queryParams, "auditFilters", "limit", "offset", "sortBy", "sortOrder"),
  117. success: function(dataOrCollection, response) {
  118. that.entityCollection.state.pageSize = that.entityCollection.queryParams.limit || 25,
  119. that.entityCollection.fullCollection.reset(dataOrCollection, option);
  120. },
  121. complete: function() {
  122. that.$(".fontLoader").hide(), that.$(".tableOverlay").hide(), that.$(".auditTable").show();
  123. },
  124. reset: !0
  125. };
  126. this.entityCollection.getAdminData(apiObj);
  127. },
  128. renderTableLayoutView: function() {
  129. var that = this;
  130. this.ui.showDefault.hide(), require([ "utils/TableLayout" ], function(TableLayout) {
  131. var cols = new Backgrid.Columns(that.getAuditTableColumns());
  132. that.RAuditTableLayoutView.show(new TableLayout(_.extend({}, that.commonTableOptions, {
  133. columns: cols
  134. })));
  135. });
  136. },
  137. createTableWithValues: function(tableDetails, isAdminAudit) {
  138. var attrTable = CommonViewFunction.propertyTable({
  139. scope: this,
  140. getValue: function(val, key) {
  141. return key && key.toLowerCase().indexOf("time") > 0 ? Utils.formatDate({
  142. date: val
  143. }) : val;
  144. },
  145. valueObject: tableDetails,
  146. guidHyperLink: !isAdminAudit
  147. });
  148. return attrTable;
  149. },
  150. getAuditTableColumns: function() {
  151. var that = this;
  152. return this.entityCollection.constructor.getTableCols({
  153. result: {
  154. label: "",
  155. cell: "html",
  156. editable: !1,
  157. sortable: !1,
  158. cell: Backgrid.ExpandableCell,
  159. fixWidth: "20",
  160. accordion: !1,
  161. alwaysVisible: !0,
  162. renderable: !0,
  163. isExpandVisible: function(el, model) {
  164. return !Enums.serverAudits[model.get("operation")];
  165. },
  166. expand: function(el, model) {
  167. var operation = model.get("operation"), results = model.get("result") || null, adminText = "No records found", adminTypDetails = null, auditData = {
  168. operation: operation,
  169. model: model,
  170. results: results,
  171. adminText: adminText,
  172. adminTypDetails: adminTypDetails
  173. };
  174. if (el.attr("colspan", "8"), results) {
  175. adminText = "PURGE" == operation ? that.displayPurgeAndImportAudits(auditData) : "EXPORT" == operation || "IMPORT" == operation ? that.displayExportAudits(auditData) : that.displayCreateUpdateAudits(auditData);
  176. }
  177. $(el).append($("<div>").html(adminText));
  178. }
  179. },
  180. userName: {
  181. label: "Users",
  182. cell: "html",
  183. renderable: !0,
  184. editable: !1
  185. },
  186. operation: {
  187. label: "Operation",
  188. cell: "String",
  189. renderable: !0,
  190. editable: !1
  191. },
  192. clientId: {
  193. label: "Client ID",
  194. cell: "String",
  195. renderable: !0,
  196. editable: !1
  197. },
  198. resultCount: {
  199. label: "Result Count",
  200. cell: "String",
  201. renderable: !0,
  202. editable: !1,
  203. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  204. fromRaw: function(rawValue, model) {
  205. return Enums.serverAudits[model.get("operation")] ? "N/A" : rawValue;
  206. }
  207. })
  208. },
  209. startTime: {
  210. label: "Start Time",
  211. cell: "html",
  212. renderable: !0,
  213. editable: !1,
  214. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  215. fromRaw: function(rawValue, model) {
  216. return Utils.formatDate({
  217. date: rawValue
  218. });
  219. }
  220. })
  221. },
  222. endTime: {
  223. label: "End Time",
  224. cell: "html",
  225. renderable: !0,
  226. editable: !1,
  227. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  228. fromRaw: function(rawValue, model) {
  229. return Utils.formatDate({
  230. date: rawValue
  231. });
  232. }
  233. })
  234. },
  235. duration: {
  236. label: "Duration",
  237. cell: "html",
  238. renderable: !1,
  239. editable: !1,
  240. sortable: !1,
  241. formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
  242. fromRaw: function(rawValue, model) {
  243. var startTime = model.get("startTime") ? parseInt(model.get("startTime")) : null, endTime = model.get("endTime") ? parseInt(model.get("endTime")) : null;
  244. if (_.isNumber(startTime) && _.isNumber(endTime)) {
  245. var duration = moment.duration(moment(endTime).diff(moment(startTime)));
  246. return Utils.millisecondsToTime(duration);
  247. }
  248. return "N/A";
  249. }
  250. })
  251. }
  252. }, this.entityCollection);
  253. },
  254. defaultPagination: function() {
  255. $.extend(this.entityCollection.queryParams, {
  256. limit: this.limit,
  257. offset: this.offset
  258. }), this.renderTableLayoutView();
  259. },
  260. showAdminAuditEntity: function(e) {
  261. var typeDefObj = this.adminAuditEntityData[e.target.dataset.auditentityid], typeDetails = this.createTableWithValues(typeDefObj, !0), view = '<table class="table admin-audit-details bold-key" ><tbody >' + typeDetails + "</tbody></table>", modalData = {
  262. title: Enums.category[typeDefObj.category] + " Type Details: " + typeDefObj.name,
  263. htmlContent: view,
  264. mainClass: "modal-full-screen",
  265. okCloses: !0,
  266. showFooter: !1,
  267. width: "40%"
  268. };
  269. this.showModal(modalData);
  270. },
  271. displayPurgeAndImportAudits: function(obj) {
  272. var adminValues = '<ul class="col-sm-6">', guids = null, adminTypDetails = Enums.category[obj.operation];
  273. return guids = "PURGE" == obj.operation ? obj.results ? obj.results.replace("[", "").replace("]", "").split(",") : guids : obj.model.get("params") ? obj.model.get("params").split(",") : guids,
  274. _.each(guids, function(adminGuid, index) {
  275. index % 5 == 0 && 0 != index && (adminValues += '</ul><ul class="col-sm-6">'), adminValues += '<li class="blue-link" data-id="adminPurgedEntity" data-operation=' + obj.operation + ">" + adminGuid.trim() + "</li>";
  276. }), adminValues += "</ul>", '<div class="row"><div class="attr-details"><h4 style="word-break: break-word;">' + adminTypDetails + "</h4>" + adminValues + "</div></div>";
  277. },
  278. displayExportAudits: function(obj) {
  279. var adminValues = "", adminTypDetails = "IMPORT" === obj.operation ? Enums.category[obj.operation] : Enums.category[obj.operation] + " And Options", resultData = obj.results ? JSON.parse(obj.results) : null, paramsData = obj.model && obj.model.get("params") && obj.model.get("params").length ? {
  280. params: [ obj.model.get("params") ]
  281. } : null;
  282. return resultData && (adminValues += this.showImportExportTable(resultData, obj.operation)),
  283. paramsData && (adminValues += this.showImportExportTable(paramsData)), adminValues = adminValues ? adminValues : obj.adminText,
  284. '<div class="row"><div class="attr-details"><h4 style="word-break: break-word;">' + adminTypDetails + "</h4>" + adminValues + "</div></div>";
  285. },
  286. showImportExportTable: function(obj, operations) {
  287. var that = this, view = '<ul class="col-sm-5 import-export"><table class="table admin-audit-details bold-key" ><tbody >';
  288. if (operations && "IMPORT" === operations) {
  289. var importKeys = Object.keys(obj);
  290. _.each(importKeys, function(key, index) {
  291. var newObj = {};
  292. newObj[key] = obj[key], index % 5 === 0 && 0 != index && (view += '</tbody></table></ul><ul class="col-sm-5 import-export"><table class="table admin-audit-details bold-key" ><tbody >'),
  293. view += that.createTableWithValues(newObj, !0);
  294. });
  295. } else view += this.createTableWithValues(obj, !0);
  296. return view += "</tbody></table></ul>";
  297. },
  298. displayCreateUpdateAudits: function(obj) {
  299. var that = this, resultData = JSON.parse(obj.results), typeName = obj.model ? obj.model.get("params").split(",") : null, typeContainer = "";
  300. _.each(typeName, function(name) {
  301. var typeData = resultData[name], adminValues = 1 == typeName.length ? '<ul class="col-sm-4">' : "<ul>", adminTypDetails = Enums.category[name] + " " + Enums.auditAction[obj.operation];
  302. typeContainer += '<div class="attr-type-container"><h4 style="word-break: break-word;">' + adminTypDetails + "</h4>",
  303. _.each(typeData, function(typeDefObj, index) {
  304. index % 5 == 0 && 0 != index && 1 == typeName.length && (adminValues += '</ul><ul class="col-sm-4">');
  305. var panelId = typeDefObj.name.split(" ").join("") + obj.model.get("startTime");
  306. that.adminAuditEntityData[panelId] = typeDefObj, adminValues += '<li class="blue-link" data-id="adminAuditEntityDetails" data-auditEntityId=' + panelId + ">" + typeDefObj.name + "</li>";
  307. }), adminValues += "</ul>", typeContainer += adminValues + "</div>";
  308. });
  309. var typeClass = 1 == typeName.length ? null : "admin-audit-details";
  310. return '<div class="row"><div class="attr-details ' + typeClass + '">' + typeContainer + "</div></div>";
  311. },
  312. onClickAdminPurgedEntity: function(e) {
  313. var that = this;
  314. require([ "views/audit/AuditTableLayoutView" ], function(AuditTableLayoutView) {
  315. var obj = {
  316. guid: $(e.target).text(),
  317. titleText: "PURGE" == e.target.dataset.operation ? "Purged Entity Details: " : "Import Details: "
  318. }, modalData = {
  319. title: obj.titleText + obj.guid,
  320. content: new AuditTableLayoutView(obj),
  321. mainClass: "modal-full-screen",
  322. okCloses: !0,
  323. showFooter: !1
  324. };
  325. that.showModal(modalData);
  326. });
  327. },
  328. showModal: function(modalObj, title) {
  329. require([ "modules/Modal" ], function(Modal) {
  330. var modal = new Modal(modalObj).open();
  331. modal.on("closeModal", function() {
  332. $(".modal").css({
  333. "padding-right": "0px !important"
  334. }), modal.trigger("cancel");
  335. }), modal.$el.on("click", "td a", function() {
  336. modal.trigger("cancel");
  337. });
  338. });
  339. }
  340. });
  341. return AdminAuditTableLayoutView;
  342. });