Utils.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. define([ "require", "utils/Globals", "pnotify", "utils/Messages", "utils/Enums", "moment", "moment-timezone", "pnotify.buttons", "pnotify.confirm" ], function(require, Globals, pnotify, Messages, Enums, moment) {
  2. "use strict";
  3. var Utils = {}, prevNetworkErrorTime = 0;
  4. Utils.generatePopover = function(options) {
  5. if (options.el) {
  6. var defaultObj = {
  7. placement: "auto bottom",
  8. html: !0,
  9. animation: !1,
  10. container: "body",
  11. sanitize: !1
  12. };
  13. return (options.viewFixedPopover || options.contentClass) && (defaultObj.template = '<div class="popover ' + (options.viewFixedPopover ? "fixed-popover" : "") + ' fade bottom"><div class="arrow"></div><h3 class="popover-title"></h3><div class="' + (options.contentClass ? options.contentClass : "") + ' popover-content"></div></div>'),
  14. options.el.popover(_.extend(defaultObj, options.popoverOptions));
  15. }
  16. }, Utils.getNumberSuffix = function(options) {
  17. if (options && options.number) {
  18. var n = options.number, s = [ "th", "st", "nd", "rd" ], v = n % 100, suffix = s[(v - 20) % 10] || s[v] || s[0];
  19. return n + (options.sup ? "<sup>" + suffix + "</sup>" : suffix);
  20. }
  21. }, Utils.generateUUID = function() {
  22. var d = new Date().getTime();
  23. window.performance && "function" == typeof window.performance.now && (d += performance.now());
  24. var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
  25. var r = (d + 16 * Math.random()) % 16 | 0;
  26. return d = Math.floor(d / 16), ("x" == c ? r : 3 & r | 8).toString(16);
  27. });
  28. return uuid;
  29. }, Utils.getBaseUrl = function(url, noPop) {
  30. var path = url.replace(/\/[\w-]+.(jsp|html)|\/+$/gi, ""), splitPath = path.split("/");
  31. return noPop !== !0 && splitPath && "n" === splitPath[splitPath.length - 1] ? (splitPath.pop(),
  32. splitPath.join("/")) : path;
  33. }, Utils.getEntityIconPath = function(options) {
  34. function getImgPath(imageName) {
  35. return iconBasePath + (Enums.entityStateReadOnly[status] ? "disabled/" + imageName : imageName);
  36. }
  37. function getDefaultImgPath() {
  38. return entityData.isProcess ? Enums.entityStateReadOnly[status] ? iconBasePath + "disabled/process.png" : iconBasePath + "process.png" : Enums.entityStateReadOnly[status] ? iconBasePath + "disabled/table.png" : iconBasePath + "table.png";
  39. }
  40. var serviceType, status, typeName, entityData = options && options.entityData, iconBasePath = Utils.getBaseUrl(window.location.pathname, !0) + Globals.entityImgPath;
  41. if (entityData && (typeName = entityData.typeName, serviceType = entityData && entityData.serviceType,
  42. status = entityData && entityData.status), entityData) {
  43. if (options.errorUrl) {
  44. var isErrorInTypeName = !(!options.errorUrl || !options.errorUrl.match("entity-icon/" + typeName + ".png|disabled/" + typeName + ".png"));
  45. if (serviceType && isErrorInTypeName) {
  46. var imageName = serviceType + ".png";
  47. return getImgPath(imageName);
  48. }
  49. return getDefaultImgPath();
  50. }
  51. if (entityData.typeName) {
  52. var imageName = entityData.typeName + ".png";
  53. return getImgPath(imageName);
  54. }
  55. return getDefaultImgPath();
  56. }
  57. }, pnotify.prototype.options.styling = "fontawesome";
  58. var notify = function(options) {
  59. return new pnotify(_.extend({
  60. icon: !0,
  61. hide: !0,
  62. delay: 3e3,
  63. remove: !0,
  64. buttons: {
  65. classes: {
  66. closer: "fa fa-times",
  67. pin_up: "fa fa-pause",
  68. pin_down: "fa fa-play"
  69. }
  70. }
  71. }, options));
  72. };
  73. return Utils.notifyInfo = function(options) {
  74. notify({
  75. type: "info",
  76. text: (options.html ? options.content : _.escape(options.content)) || "Info message."
  77. });
  78. }, Utils.notifyWarn = function(options) {
  79. notify({
  80. type: "notice",
  81. text: (options.html ? options.content : _.escape(options.content)) || "Info message."
  82. });
  83. }, Utils.notifyError = function(options) {
  84. notify({
  85. type: "error",
  86. text: (options.html ? options.content : _.escape(options.content)) || "Error occurred."
  87. });
  88. }, Utils.notifySuccess = function(options) {
  89. notify({
  90. type: "success",
  91. text: (options.html ? options.content : _.escape(options.content)) || "Error occurred."
  92. });
  93. }, Utils.notifyConfirm = function(options) {
  94. var modal = {};
  95. if (options && options.modal) {
  96. var myStack = {
  97. dir1: "down",
  98. dir2: "right",
  99. push: "top",
  100. modal: !0
  101. };
  102. modal.addclass = "stack-modal " + (options.modalClass ? modalClass : "width-500"),
  103. modal.stack = myStack;
  104. }
  105. notify(_.extend({
  106. title: "Confirmation",
  107. hide: !1,
  108. confirm: {
  109. confirm: !0,
  110. buttons: [ {
  111. text: options.cancelText || "Cancel",
  112. addClass: "btn-action btn-md cancel",
  113. click: function(notice) {
  114. options.cancel(notice), notice.remove();
  115. }
  116. }, {
  117. text: options.okText || "Ok",
  118. addClass: "btn-atlas btn-md ok",
  119. click: function(notice) {
  120. options.ok && options.ok($.extend({}, notice, {
  121. hideButtonLoader: function() {
  122. notice.container.find("button.ok").hideButtonLoader();
  123. },
  124. showButtonLoader: function() {
  125. notice.container.find("button.ok").showButtonLoader();
  126. }
  127. })), options.okShowLoader && notice.container.find("button.ok").showButtonLoader(),
  128. options.okCloses !== !1 && notice.remove();
  129. }
  130. } ]
  131. },
  132. buttons: {
  133. closer: !1,
  134. sticker: !1
  135. },
  136. history: {
  137. history: !1
  138. }
  139. }, modal, options)).get().on("pnotify.confirm", function() {
  140. options.ok && options.ok();
  141. }).on("pnotify.cancel", function() {
  142. options.cancel && options.cancel();
  143. });
  144. }, Utils.defaultErrorHandler = function(model, error, options) {
  145. var skipDefaultError = null, defaultErrorMessage = null, isHtml = null;
  146. options && (skipDefaultError = options.skipDefaultError, defaultErrorMessage = options.defaultErrorMessage,
  147. isHtml = options.isHtml);
  148. var redirectToLoginPage = function() {
  149. Utils.localStorage.setValue("last_ui_load", "v2"), window.location = "login.jsp";
  150. };
  151. if (error && error.status) if (401 == error.status) redirectToLoginPage(); else if (419 == error.status) redirectToLoginPage(); else if (403 == error.status) Utils.serverErrorHandler(error, "You are not authorized"); else if ("0" == error.status && "abort" != error.statusText) {
  152. var diffTime = new Date().getTime() - prevNetworkErrorTime;
  153. diffTime > 3e3 && (prevNetworkErrorTime = new Date().getTime(), Utils.notifyError({
  154. content: "Network Connection Failure : It seems you are not connected to the internet. Please check your internet connection and try again"
  155. }));
  156. } else skipDefaultError !== !0 && Utils.serverErrorHandler(error, defaultErrorMessage, isHtml); else skipDefaultError !== !0 && Utils.serverErrorHandler(error, defaultErrorMessage);
  157. }, Utils.serverErrorHandler = function(response, defaultErrorMessage, isHtml) {
  158. var responseJSON = response ? response.responseJSON : response, message = defaultErrorMessage ? defaultErrorMessage : Messages.defaultErrorMessage;
  159. response && responseJSON && (message = responseJSON.errorMessage || responseJSON.message || responseJSON.error || message);
  160. var existingError = $(".ui-pnotify-container.alert-danger .ui-pnotify-text").text();
  161. existingError !== message && Utils.notifyError({
  162. html: isHtml,
  163. content: message
  164. });
  165. }, Utils.cookie = {
  166. setValue: function(cname, cvalue) {
  167. document.cookie = cname + "=" + cvalue + "; ";
  168. },
  169. getValue: function(findString) {
  170. for (var ca = document.cookie.split(";"), i = 0; i < ca.length; i++) {
  171. for (var c = ca[i]; " " == c.charAt(0); ) c = c.substring(1);
  172. if (0 == c.indexOf(name)) return c.substring(name.length, c.length);
  173. }
  174. return "";
  175. }
  176. }, Utils.localStorage = function() {
  177. this.setValue = function() {
  178. localStorage.setItem(arguments[0], arguments[1]);
  179. }, this.getValue = function(key, value) {
  180. var keyValue = localStorage.getItem(key);
  181. return keyValue && "undefined" != keyValue || void 0 == value ? "" === keyValue || "undefined" === keyValue || "null" === keyValue ? null : keyValue : this.setLocalStorage(key, value);
  182. }, this.removeValue = function() {
  183. localStorage.removeItem(arguments[0]);
  184. }, "undefined" == typeof Storage && (_.extend(this, Utils.cookie), console.log("Sorry! No Web Storage support"));
  185. }, Utils.localStorage = new Utils.localStorage(), Utils.setUrl = function(options) {
  186. if (options) {
  187. if (options.mergeBrowserUrl) {
  188. var param = Utils.getUrlState.getQueryParams();
  189. param && (options.urlParams = $.extend(param, options.urlParams));
  190. }
  191. if (options.urlParams) {
  192. var urlParams = "?";
  193. _.each(options.urlParams, function(value, key, obj) {
  194. value && (value = encodeURIComponent(String(value)), urlParams += key + "=" + value + "&");
  195. }), urlParams = urlParams.slice(0, -1), options.url += urlParams;
  196. }
  197. if (options.updateTabState) {
  198. var urlUpdate = {
  199. stateChanged: !0
  200. };
  201. Utils.getUrlState.isTagTab(options.url) ? urlUpdate.tagUrl = options.url : Utils.getUrlState.isSearchTab(options.url) ? urlUpdate.searchUrl = options.url : Utils.getUrlState.isGlossaryTab(options.url) ? urlUpdate.glossaryUrl = options.url : Utils.getUrlState.isBMDetailPage(options.url) ? (urlUpdate.bmDetailPageUrl = options.url,
  202. urlUpdate.administratorUrl = options.url) : Utils.getUrlState.isAdministratorTab(options.url) ? urlUpdate.administratorUrl = options.url : Utils.getUrlState.isDebugMetricsTab(options.url) && (urlUpdate.debugMetricsUrl = options.url),
  203. $.extend(Globals.saveApplicationState.tabState, urlUpdate);
  204. }
  205. Backbone.history.navigate(options.url, {
  206. trigger: void 0 == options.trigger || options.trigger
  207. });
  208. }
  209. }, Utils.getUrlState = {
  210. getQueryUrl: function(url) {
  211. var hashValue = window.location.hash;
  212. return url && (hashValue = url), {
  213. firstValue: hashValue.split("/")[1],
  214. hash: hashValue,
  215. queyParams: hashValue.split("?"),
  216. lastValue: hashValue.split("/")[hashValue.split("/").length - 1]
  217. };
  218. },
  219. checkTabUrl: function(options) {
  220. var url = options && options.url, matchString = options && options.matchString, quey = this.getQueryUrl(url);
  221. return quey.firstValue == matchString || quey.queyParams[0] == "#!/" + matchString;
  222. },
  223. isInitial: function() {
  224. return void 0 == this.getQueryUrl().firstValue;
  225. },
  226. isTagTab: function(url) {
  227. return this.checkTabUrl({
  228. url: url,
  229. matchString: "tag"
  230. });
  231. },
  232. isSearchTab: function(url) {
  233. return this.checkTabUrl({
  234. url: url,
  235. matchString: "search"
  236. });
  237. },
  238. isAdministratorTab: function(url) {
  239. return this.checkTabUrl({
  240. url: url,
  241. matchString: "administrator"
  242. });
  243. },
  244. isBMDetailPage: function(url) {
  245. var quey = this.getQueryUrl(url);
  246. return quey.hash.indexOf("businessMetadata") > -1;
  247. },
  248. isDebugMetricsTab: function(url) {
  249. return this.checkTabUrl({
  250. url: url,
  251. matchString: "debugMetrics"
  252. });
  253. },
  254. isGlossaryTab: function(url) {
  255. return this.checkTabUrl({
  256. url: url,
  257. matchString: "glossary"
  258. });
  259. },
  260. isDetailPage: function(url) {
  261. return this.checkTabUrl({
  262. url: url,
  263. matchString: "detailPage"
  264. });
  265. },
  266. getLastValue: function() {
  267. return this.getQueryUrl().lastValue;
  268. },
  269. getFirstValue: function() {
  270. return this.getQueryUrl().firstValue;
  271. },
  272. getQueryParams: function(url) {
  273. var qs = this.getQueryUrl(url).queyParams[1];
  274. if ("string" == typeof qs) {
  275. qs = qs.split("+").join(" ");
  276. for (var tokens, params = {}, re = /[?&]?([^=]+)=([^&]*)/g; tokens = re.exec(qs); ) params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  277. return params;
  278. }
  279. },
  280. getKeyValue: function(key) {
  281. var paramsObj = this.getQueryParams();
  282. if (!key.length) return paramsObj[key];
  283. var values = [];
  284. _.each(key, function(objKey) {
  285. var obj = {};
  286. return obj[objKey] = paramsObj[objKey], values.push(obj), values;
  287. });
  288. }
  289. }, Utils.getName = function() {
  290. return Utils.extractKeyValueFromEntity.apply(this, arguments).name;
  291. }, Utils.getNameWithProperties = function() {
  292. return Utils.extractKeyValueFromEntity.apply(this, arguments);
  293. }, Utils.extractKeyValueFromEntity = function() {
  294. var collectionJSON = arguments[0], priorityAttribute = arguments[1], skipAttribute = arguments[2], returnObj = {
  295. name: "-",
  296. found: !0,
  297. key: null
  298. };
  299. if (collectionJSON) {
  300. if (collectionJSON.attributes && collectionJSON.attributes[priorityAttribute]) return returnObj.name = _.escape(collectionJSON.attributes[priorityAttribute]),
  301. returnObj.key = priorityAttribute, returnObj;
  302. if (collectionJSON[priorityAttribute]) return returnObj.name = _.escape(collectionJSON[priorityAttribute]),
  303. returnObj.key = priorityAttribute, returnObj;
  304. if (collectionJSON.attributes) {
  305. if (collectionJSON.attributes.name) return returnObj.name = _.escape(collectionJSON.attributes.name),
  306. returnObj.key = "name", returnObj;
  307. if (collectionJSON.attributes.displayName) return returnObj.name = _.escape(collectionJSON.attributes.displayName),
  308. returnObj.key = "displayName", returnObj;
  309. if (collectionJSON.attributes.qualifiedName) return returnObj.name = _.escape(collectionJSON.attributes.qualifiedName),
  310. returnObj.key = "qualifiedName", returnObj;
  311. if (collectionJSON.attributes.displayText) return returnObj.name = _.escape(collectionJSON.attributes.displayText),
  312. returnObj.key = "displayText", returnObj;
  313. if (collectionJSON.attributes.guid) return returnObj.name = _.escape(collectionJSON.attributes.guid),
  314. returnObj.key = "guid", returnObj;
  315. if (collectionJSON.attributes.id) return _.isObject(collectionJSON.attributes.id) ? collectionJSON.id.id && (returnObj.name = _.escape(collectionJSON.attributes.id.id)) : returnObj.name = _.escape(collectionJSON.attributes.id),
  316. returnObj.key = "id", returnObj;
  317. }
  318. if (collectionJSON.name) return returnObj.name = _.escape(collectionJSON.name),
  319. returnObj.key = "name", returnObj;
  320. if (collectionJSON.displayName) return returnObj.name = _.escape(collectionJSON.displayName),
  321. returnObj.key = "displayName", returnObj;
  322. if (collectionJSON.qualifiedName) return returnObj.name = _.escape(collectionJSON.qualifiedName),
  323. returnObj.key = "qualifiedName", returnObj;
  324. if (collectionJSON.displayText) return returnObj.name = _.escape(collectionJSON.displayText),
  325. returnObj.key = "displayText", returnObj;
  326. if (collectionJSON.guid) return returnObj.name = _.escape(collectionJSON.guid),
  327. returnObj.key = "guid", returnObj;
  328. if (collectionJSON.id) return _.isObject(collectionJSON.id) ? collectionJSON.id.id && (returnObj.name = _.escape(collectionJSON.id.id)) : returnObj.name = _.escape(collectionJSON.id),
  329. returnObj.key = "id", returnObj;
  330. }
  331. return returnObj.found = !1, skipAttribute && returnObj.key == skipAttribute ? {
  332. name: "-",
  333. found: !0,
  334. key: null
  335. } : returnObj;
  336. }, Utils.backButtonClick = function() {
  337. var queryParams = Utils.getUrlState.getQueryParams(), urlPath = "searchUrl";
  338. queryParams && queryParams.from && ("classification" == queryParams.from ? urlPath = "tagUrl" : "glossary" == queryParams.from ? urlPath = "glossaryUrl" : "bm" == queryParams.from && (urlPath = "administratorUrl")),
  339. Utils.setUrl({
  340. url: Globals.saveApplicationState.tabState[urlPath],
  341. mergeBrowserUrl: !1,
  342. trigger: !0,
  343. updateTabState: !0
  344. });
  345. }, Utils.showTitleLoader = function(loaderEl, titleBoxEl) {
  346. loaderEl.css ? loaderEl.css({
  347. display: "block",
  348. position: "relative",
  349. height: "85px",
  350. marginTop: "85px",
  351. marginLeft: "50%",
  352. left: "0%"
  353. }) : null, titleBoxEl.hide ? titleBoxEl.hide() : null;
  354. }, Utils.hideTitleLoader = function(loaderEl, titleBoxEl) {
  355. loaderEl.hide ? loaderEl.hide() : null, titleBoxEl.fadeIn ? titleBoxEl.fadeIn() : null;
  356. }, Utils.findAndMergeRefEntity = function(options) {
  357. var attributeObject = options.attributeObject, referredEntities = options.referredEntities, mergeObject = function(obj) {
  358. obj && (obj.attributes ? Utils.findAndMergeRefEntity({
  359. attributeObject: obj.attributes,
  360. referredEntities: referredEntities
  361. }) : referredEntities[obj.guid] && _.extend(obj, referredEntities[obj.guid]));
  362. };
  363. attributeObject && referredEntities && _.each(attributeObject, function(obj, key) {
  364. _.isObject(obj) && (_.isArray(obj) ? _.each(obj, function(value) {
  365. mergeObject(value);
  366. }) : mergeObject(obj));
  367. });
  368. }, Utils.findAndMergeRelationShipEntity = function(options) {
  369. var attributeObject = options.attributeObject, relationshipAttributes = options.relationshipAttributes;
  370. _.each(attributeObject, function(val, key) {
  371. if (relationshipAttributes && relationshipAttributes[key]) {
  372. var relationShipVal = relationshipAttributes[key];
  373. _.isObject(val) && (_.isArray(val) ? _.each(val, function(attr) {
  374. if (attr && void 0 === attr.attributes) {
  375. var entityFound = _.find(relationShipVal, {
  376. guid: attr.guid
  377. });
  378. entityFound && (attr.attributes = _.omit(entityFound, "typeName", "guid", "entityStatus"),
  379. attr.status = entityFound.entityStatus);
  380. }
  381. }) : relationShipVal && void 0 === val.attributes && (val.attributes = _.omit(relationShipVal, "typeName", "guid", "entityStatus"),
  382. val.status = relationShipVal.entityStatus));
  383. }
  384. });
  385. }, Utils.getNestedSuperTypes = function(options) {
  386. var data = options.data, collection = options.collection, superTypes = [], getData = function(data, collection) {
  387. data && (superTypes = superTypes.concat(data.superTypes), data.superTypes && data.superTypes.length && _.each(data.superTypes, function(superTypeName) {
  388. if (collection.fullCollection) var collectionData = collection.fullCollection.findWhere({
  389. name: superTypeName
  390. }).toJSON(); else var collectionData = collection.findWhere({
  391. name: superTypeName
  392. }).toJSON();
  393. getData(collectionData, collection);
  394. }));
  395. };
  396. return getData(data, collection), _.uniq(superTypes);
  397. }, Utils.getNestedSuperTypeObj = function(options) {
  398. var mainData = options.data, collection = options.collection, attrMerge = options.attrMerge, seperateRelatioshipAttr = options.seperateRelatioshipAttr || !1, mergeRelationAttributes = options.mergeRelationAttributes || !seperateRelatioshipAttr;
  399. if (mergeRelationAttributes && seperateRelatioshipAttr) throw "Both mergeRelationAttributes & seperateRelatioshipAttr cannot be true!";
  400. var attributeDefs = {};
  401. attrMerge && !seperateRelatioshipAttr ? attributeDefs = [] : options.attrMerge && seperateRelatioshipAttr && (attributeDefs = {
  402. attributeDefs: [],
  403. relationshipAttributeDefs: []
  404. });
  405. var getRelationshipAttributeDef = function(data) {
  406. return _.filter(data.relationshipAttributeDefs, function(obj, key) {
  407. return obj;
  408. });
  409. }, getData = function(data, collection) {
  410. options.attrMerge ? seperateRelatioshipAttr ? (attributeDefs.attributeDefs = attributeDefs.attributeDefs.concat(data.attributeDefs),
  411. attributeDefs.relationshipAttributeDefs = attributeDefs.relationshipAttributeDefs.concat(getRelationshipAttributeDef(data))) : (attributeDefs = attributeDefs.concat(data.attributeDefs),
  412. mergeRelationAttributes && (attributeDefs = attributeDefs.concat(getRelationshipAttributeDef(data)))) : attributeDefs[data.name] ? attributeDefs[data.name] = _.toArrayifObject(attributeDefs[data.name]).concat(data.attributeDefs) : seperateRelatioshipAttr ? attributeDefs[data.name] = {
  413. attributeDefs: data.attributeDefs,
  414. relationshipAttributeDefs: data.relationshipAttributeDefs
  415. } : (attributeDefs[data.name] = data.attributeDefs, mergeRelationAttributes && (attributeDefs[data.name] = _.toArrayifObject(attributeDefs[data.name]).concat(getRelationshipAttributeDef(data)))),
  416. data.superTypes && data.superTypes.length && _.each(data.superTypes, function(superTypeName) {
  417. if (collection.fullCollection) var collectionData = collection.fullCollection.findWhere({
  418. name: superTypeName
  419. }); else var collectionData = collection.findWhere({
  420. name: superTypeName
  421. });
  422. return collectionData = collectionData && collectionData.toJSON ? collectionData.toJSON() : collectionData,
  423. collectionData ? getData(collectionData, collection) : void 0;
  424. });
  425. };
  426. return getData(mainData, collection), attrMerge && (attributeDefs = seperateRelatioshipAttr ? {
  427. attributeDefs: _.uniq(_.sortBy(attributeDefs.attributeDefs, "name"), !0, function(obj) {
  428. return obj.name;
  429. }),
  430. relationshipAttributeDefs: _.uniq(_.sortBy(attributeDefs.relationshipAttributeDefs, "name"), !0, function(obj) {
  431. return obj.name + obj.relationshipTypeName;
  432. })
  433. } : _.uniq(_.sortBy(attributeDefs, "name"), !0, function(obj) {
  434. return obj.relationshipTypeName ? obj.name + obj.relationshipTypeName : obj.name;
  435. })), attributeDefs;
  436. }, Utils.getProfileTabType = function(profileData, skipData) {
  437. var parseData = profileData.distributionData;
  438. _.isString(parseData) && (parseData = JSON.parse(parseData));
  439. var createData = function(type) {
  440. var orderValue = [], sort = !1;
  441. if ("date" === type) {
  442. var dateObj = {};
  443. return _.keys(parseData).map(function(key) {
  444. var splitValue = key.split(":");
  445. dateObj[splitValue[0]] || (dateObj[splitValue[0]] = {
  446. value: splitValue[0],
  447. monthlyCounts: {},
  448. totalCount: 0
  449. }), dateObj[splitValue[0]] && "count" == splitValue[1] && (dateObj[splitValue[0]].count = parseData[key]),
  450. dateObj[splitValue[0]] && "count" !== splitValue[1] && (dateObj[splitValue[0]].monthlyCounts[splitValue[1]] = parseData[key],
  451. dateObj[splitValue[0]].count || (dateObj[splitValue[0]].totalCount += parseData[key]));
  452. }), _.toArray(dateObj).map(function(obj) {
  453. return !obj.count && obj.totalCount && (obj.count = obj.totalCount), obj;
  454. });
  455. }
  456. var data = [];
  457. return profileData.distributionKeyOrder ? orderValue = profileData.distributionKeyOrder : (sort = !0,
  458. orderValue = _.keys(parseData)), _.each(orderValue, function(key) {
  459. parseData[key] && data.push({
  460. value: key,
  461. count: parseData[key]
  462. });
  463. }), sort && (data = _.sortBy(data, function(o) {
  464. return o.value.toLowerCase();
  465. })), data;
  466. };
  467. if (profileData && profileData.distributionType) {
  468. if ("count-frequency" === profileData.distributionType) return {
  469. type: "string",
  470. label: Enums.profileTabType[profileData.distributionType],
  471. actualObj: skipData ? null : createData("string"),
  472. xAxisLabel: "FREQUENCY",
  473. yAxisLabel: "COUNT"
  474. };
  475. if ("decile-frequency" === profileData.distributionType) return {
  476. label: Enums.profileTabType[profileData.distributionType],
  477. type: "numeric",
  478. xAxisLabel: "DECILE RANGE",
  479. actualObj: skipData ? null : createData("numeric"),
  480. yAxisLabel: "FREQUENCY"
  481. };
  482. if ("annual" === profileData.distributionType) return {
  483. label: Enums.profileTabType[profileData.distributionType],
  484. type: "date",
  485. xAxisLabel: "",
  486. actualObj: skipData ? null : createData("date"),
  487. yAxisLabel: "COUNT"
  488. };
  489. }
  490. }, Utils.isUrl = function(url) {
  491. var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  492. return regexp.test(url);
  493. }, Utils.JSONPrettyPrint = function(obj, getValue) {
  494. var replacer = function(match, pIndent, pKey, pVal, pEnd) {
  495. var key = "<span class=json-key>", val = "<span class=json-value>", str = "<span class=json-string>", r = pIndent || "";
  496. return pKey && (r = r + key + pKey.replace(/[": ]/g, "") + "</span>: "), pVal && (r = r + ('"' == pVal[0] ? str : val) + getValue(pVal) + "</span>"),
  497. r + (pEnd || "");
  498. }, jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/gm;
  499. return obj && _.isObject(obj) ? JSON.stringify(obj, null, 3).replace(/&/g, "&amp;").replace(/\\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(jsonLine, replacer) : {};
  500. }, $.fn.toggleAttribute = function(attributeName, firstString, secondString) {
  501. this.attr(attributeName) == firstString ? this.attr(attributeName, secondString) : this.attr(attributeName, firstString);
  502. }, Utils.millisecondsToTime = function(duration) {
  503. var milliseconds = parseInt(duration % 1e3 / 100), seconds = parseInt(duration / 1e3 % 60), minutes = parseInt(duration / 6e4 % 60), hours = parseInt(duration / 36e5 % 24);
  504. return hours = hours < 10 ? "0" + hours : hours, minutes = minutes < 10 ? "0" + minutes : minutes,
  505. seconds = seconds < 10 ? "0" + seconds : seconds, hours + ":" + minutes + ":" + seconds + "." + milliseconds;
  506. }, Utils.togglePropertyRelationshipTableEmptyValues = function(object) {
  507. var inputSelector = object.inputType, tableEl = object.tableEl;
  508. 1 == inputSelector.prop("checked") ? tableEl.removeClass("hide-empty-value") : tableEl.addClass("hide-empty-value");
  509. }, $.fn.showButtonLoader = function() {
  510. $(this).attr("disabled", "true").addClass("button-loader"), $(this).siblings("button.cancel").prop("disabled", !0);
  511. }, $.fn.hideButtonLoader = function() {
  512. $(this).removeClass("button-loader").removeAttr("disabled"), $(this).siblings("button.cancel").prop("disabled", !1);
  513. }, Utils.formatDate = function(options) {
  514. var dateValue = null, dateFormat = Globals.dateTimeFormat, isValidDate = !1;
  515. return options && options.date && (dateValue = options.date, "-" !== dateValue && (dateValue = parseInt(dateValue),
  516. _.isNaN(dateValue) && (dateValue = options.date), dateValue = moment(dateValue),
  517. dateValue._isValid && (isValidDate = !0, dateValue = dateValue.format(dateFormat)))),
  518. "-" !== dateValue && (isValidDate === !1 && options && options.defaultDate !== !1 && (dateValue = moment().format(dateFormat)),
  519. Globals.isTimezoneFormatEnabled && (!options || options && options.zone !== !1) && (dateValue += " (" + moment.tz(moment.tz.guess()).zoneAbbr() + ")")),
  520. dateValue;
  521. }, Utils;
  522. });