Utils.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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) {
  30. return url.replace(/\/[\w-]+.(jsp|html)|\/+$/gi, "");
  31. }, Utils.getEntityIconPath = function(options) {
  32. function getImgPath(imageName) {
  33. return iconBasePath + (Enums.entityStateReadOnly[status] ? "disabled/" + imageName : imageName);
  34. }
  35. function getDefaultImgPath() {
  36. return entityData.isProcess ? Enums.entityStateReadOnly[status] ? iconBasePath + "disabled/process.png" : iconBasePath + "process.png" : Enums.entityStateReadOnly[status] ? iconBasePath + "disabled/table.png" : iconBasePath + "table.png";
  37. }
  38. var serviceType, status, typeName, entityData = options && options.entityData, iconBasePath = Utils.getBaseUrl(window.location.pathname) + Globals.entityImgPath;
  39. if (entityData && (typeName = entityData.typeName, serviceType = entityData && entityData.serviceType,
  40. status = entityData && entityData.status), entityData) {
  41. if (options.errorUrl) {
  42. var isErrorInTypeName = !(!options.errorUrl || !options.errorUrl.match("entity-icon/" + typeName + ".png|disabled/" + typeName + ".png"));
  43. if (serviceType && isErrorInTypeName) {
  44. var imageName = serviceType + ".png";
  45. return getImgPath(imageName);
  46. }
  47. return getDefaultImgPath();
  48. }
  49. if (entityData.typeName) {
  50. var imageName = entityData.typeName + ".png";
  51. return getImgPath(imageName);
  52. }
  53. return getDefaultImgPath();
  54. }
  55. }, pnotify.prototype.options.styling = "fontawesome";
  56. var notify = function(options) {
  57. return new pnotify(_.extend({
  58. icon: !0,
  59. hide: !0,
  60. delay: 3e3,
  61. remove: !0,
  62. buttons: {
  63. classes: {
  64. closer: "fa fa-times",
  65. pin_up: "fa fa-pause",
  66. pin_down: "fa fa-play"
  67. }
  68. }
  69. }, options));
  70. };
  71. return Utils.notifyInfo = function(options) {
  72. notify({
  73. type: "info",
  74. text: (options.html ? options.content : _.escape(options.content)) || "Info message."
  75. });
  76. }, Utils.notifyWarn = function(options) {
  77. notify({
  78. type: "notice",
  79. text: (options.html ? options.content : _.escape(options.content)) || "Info message."
  80. });
  81. }, Utils.notifyError = function(options) {
  82. notify({
  83. type: "error",
  84. text: (options.html ? options.content : _.escape(options.content)) || "Error occurred."
  85. });
  86. }, Utils.notifySuccess = function(options) {
  87. notify({
  88. type: "success",
  89. text: (options.html ? options.content : _.escape(options.content)) || "Error occurred."
  90. });
  91. }, Utils.notifyConfirm = function(options) {
  92. var modal = {};
  93. if (options && options.modal) {
  94. var myStack = {
  95. dir1: "down",
  96. dir2: "right",
  97. push: "top",
  98. modal: !0
  99. };
  100. modal.addclass = "stack-modal " + (options.modalClass ? modalClass : "width-500"),
  101. modal.stack = myStack;
  102. }
  103. notify(_.extend({
  104. title: "确定",
  105. hide: !1,
  106. confirm: {
  107. confirm: !0,
  108. buttons: [ {
  109. text: options.cancelText || "取消",
  110. addClass: "btn-action btn-md cancel",
  111. click: function(notice) {
  112. options.cancel(notice), notice.remove();
  113. }
  114. }, {
  115. text: options.okText || "确认",
  116. addClass: "btn-atlas btn-md ok",
  117. click: function(notice) {
  118. options.ok && options.ok($.extend({}, notice, {
  119. hideButtonLoader: function() {
  120. notice.container.find("button.ok").hideButtonLoader();
  121. },
  122. showButtonLoader: function() {
  123. notice.container.find("button.ok").showButtonLoader();
  124. }
  125. })), options.okShowLoader && notice.container.find("button.ok").showButtonLoader(),
  126. options.okCloses !== !1 && notice.remove();
  127. }
  128. } ]
  129. },
  130. buttons: {
  131. closer: !1,
  132. sticker: !1
  133. },
  134. history: {
  135. history: !1
  136. }
  137. }, modal, options)).get().on("pnotify.confirm", function() {
  138. options.ok && options.ok();
  139. }).on("pnotify.cancel", function() {
  140. options.cancel && options.cancel();
  141. });
  142. }, Utils.defaultErrorHandler = function(model, error, options) {
  143. var skipDefaultError = null, defaultErrorMessage = null;
  144. options && (skipDefaultError = options.skipDefaultError, defaultErrorMessage = options.defaultErrorMessage);
  145. var redirectToLoginPage = function() {
  146. Utils.localStorage.setValue("last_ui_load", "v1"), window.location = "login.jsp";
  147. };
  148. 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) {
  149. var diffTime = new Date().getTime() - prevNetworkErrorTime;
  150. diffTime > 3e3 && (prevNetworkErrorTime = new Date().getTime(), Utils.notifyError({
  151. content: "网路连接失败。请检查您与服务器的连接。"
  152. }));
  153. } else skipDefaultError !== !0 && Utils.serverErrorHandler(error, defaultErrorMessage); else skipDefaultError !== !0 && Utils.serverErrorHandler(error, defaultErrorMessage);
  154. }, Utils.serverErrorHandler = function(response, defaultErrorMessage) {
  155. var responseJSON = response ? response.responseJSON : response, message = defaultErrorMessage ? defaultErrorMessage : Messages.defaultErrorMessage;
  156. response && responseJSON && (message = Utils.replaceToChinese(responseJSON.errorMessage) || responseJSON.message || responseJSON.error || message);
  157. var existingError = $(".ui-pnotify-container.alert-danger .ui-pnotify-text").text();
  158. existingError !== message && Utils.notifyError({
  159. content: Utils.regexDuplicate(message)
  160. });
  161. }, Utils.cookie = {
  162. setValue: function(cname, cvalue) {
  163. document.cookie = cname + "=" + cvalue + "; ";
  164. },
  165. getValue: function(findString) {
  166. for (var ca = document.cookie.split(";"), i = 0; i < ca.length; i++) {
  167. for (var c = ca[i]; " " == c.charAt(0); ) c = c.substring(1);
  168. if (0 == c.indexOf(name)) return c.substring(name.length, c.length);
  169. }
  170. return "";
  171. }
  172. }, Utils.localStorage = function() {
  173. this.setValue = function() {
  174. localStorage.setItem(arguments[0], arguments[1]);
  175. }, this.getValue = function(key, value) {
  176. var keyValue = localStorage.getItem(key);
  177. return keyValue && "undefined" != keyValue || void 0 == value ? "" === keyValue || "undefined" === keyValue || "null" === keyValue ? null : keyValue : this.setLocalStorage(key, value);
  178. }, this.removeValue = function() {
  179. localStorage.removeItem(arguments[0]);
  180. }, "undefined" == typeof Storage && (_.extend(this, Utils.cookie), console.log("Sorry! No Web Storage support"));
  181. }, Utils.localStorage = new Utils.localStorage(), Utils.setUrl = function(options) {
  182. if (options) {
  183. if (options.mergeBrowserUrl) {
  184. var param = Utils.getUrlState.getQueryParams();
  185. param && (options.urlParams = $.extend(param, options.urlParams));
  186. }
  187. if (options.urlParams) {
  188. var urlParams = "?";
  189. _.each(options.urlParams, function(value, key, obj) {
  190. value && (value = encodeURIComponent(String(value)), urlParams += key + "=" + value + "&");
  191. }), urlParams = urlParams.slice(0, -1), options.url += urlParams;
  192. }
  193. if (options.updateTabState) {
  194. var urlUpdate = {
  195. stateChanged: !0
  196. };
  197. 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.isAdministratorTab(options.url) ? urlUpdate.administratorUrl = options.url : Utils.getUrlState.isDebugMetricsTab(options.url) && (urlUpdate.debugMetricsUrl = options.url),
  198. $.extend(Globals.saveApplicationState.tabState, urlUpdate);
  199. }
  200. Backbone.history.navigate(options.url, {
  201. trigger: void 0 == options.trigger || options.trigger
  202. });
  203. }
  204. }, Utils.getUrlState = {
  205. getQueryUrl: function(url) {
  206. var hashValue = window.location.hash;
  207. return url && (hashValue = url), {
  208. firstValue: hashValue.split("/")[1],
  209. hash: hashValue,
  210. queyParams: hashValue.split("?"),
  211. lastValue: hashValue.split("/")[hashValue.split("/").length - 1]
  212. };
  213. },
  214. checkTabUrl: function(options) {
  215. var url = options && options.url, matchString = options && options.matchString, quey = this.getQueryUrl(url);
  216. return quey.firstValue == matchString || quey.queyParams[0] == "#!/" + matchString;
  217. },
  218. isInitial: function() {
  219. return void 0 == this.getQueryUrl().firstValue;
  220. },
  221. isTagTab: function(url) {
  222. return this.checkTabUrl({
  223. url: url,
  224. matchString: "tag"
  225. });
  226. },
  227. isBSDetail: function(url) {
  228. var quey = this.getQueryUrl(url);
  229. return quey.queyParams[0].indexOf("administrator/businessMetadata") > -1;
  230. },
  231. isSearchTab: function(url) {
  232. return this.checkTabUrl({
  233. url: url,
  234. matchString: "search"
  235. });
  236. },
  237. isAdministratorTab: function(url) {
  238. return this.checkTabUrl({
  239. url: url,
  240. matchString: "administrator"
  241. });
  242. },
  243. isDebugMetricsTab: function(url) {
  244. return this.checkTabUrl({
  245. url: url,
  246. matchString: "debugMetrics"
  247. });
  248. },
  249. isGlossaryTab: function(url) {
  250. return this.checkTabUrl({
  251. url: url,
  252. matchString: "glossary"
  253. });
  254. },
  255. isDetailPage: function(url) {
  256. return this.checkTabUrl({
  257. url: url,
  258. matchString: "detailPage"
  259. });
  260. },
  261. getLastValue: function() {
  262. return this.getQueryUrl().lastValue;
  263. },
  264. getFirstValue: function() {
  265. return this.getQueryUrl().firstValue;
  266. },
  267. getQueryParams: function(url) {
  268. var qs = this.getQueryUrl(url).queyParams[1];
  269. if ("string" == typeof qs) {
  270. qs = qs.split("+").join(" ");
  271. for (var tokens, params = {}, re = /[?&]?([^=]+)=([^&]*)/g; tokens = re.exec(qs); ) params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  272. return params;
  273. }
  274. },
  275. getKeyValue: function(key) {
  276. var paramsObj = this.getQueryParams();
  277. if (!key.length) return paramsObj[key];
  278. var values = [];
  279. _.each(key, function(objKey) {
  280. var obj = {};
  281. return obj[objKey] = paramsObj[objKey], values.push(obj), values;
  282. });
  283. }
  284. }, Utils.getName = function() {
  285. return Utils.extractKeyValueFromEntity.apply(this, arguments).name;
  286. }, Utils.getNameWithProperties = function() {
  287. return Utils.extractKeyValueFromEntity.apply(this, arguments);
  288. }, Utils.extractKeyValueFromEntity = function() {
  289. var collectionJSON = arguments[0], priorityAttribute = arguments[1], skipAttribute = arguments[2], returnObj = {
  290. name: "-",
  291. found: !0,
  292. key: null
  293. };
  294. if (collectionJSON) {
  295. if (collectionJSON.attributes && collectionJSON.attributes[priorityAttribute]) return returnObj.name = _.escape(collectionJSON.attributes[priorityAttribute]),
  296. returnObj.key = priorityAttribute, returnObj;
  297. if (collectionJSON[priorityAttribute]) return returnObj.name = _.escape(collectionJSON[priorityAttribute]),
  298. returnObj.key = priorityAttribute, returnObj;
  299. if (collectionJSON.attributes) {
  300. if (collectionJSON.attributes.name) return returnObj.name = _.escape(collectionJSON.attributes.name),
  301. returnObj.key = "name", returnObj;
  302. if (collectionJSON.attributes.displayName) return returnObj.name = _.escape(collectionJSON.attributes.displayName),
  303. returnObj.key = "displayName", returnObj;
  304. if (collectionJSON.attributes.qualifiedName) return returnObj.name = _.escape(collectionJSON.attributes.qualifiedName),
  305. returnObj.key = "qualifiedName", returnObj;
  306. if (collectionJSON.attributes.displayText) return returnObj.name = _.escape(collectionJSON.attributes.displayText),
  307. returnObj.key = "displayText", returnObj;
  308. if (collectionJSON.attributes.guid) return returnObj.name = _.escape(collectionJSON.attributes.guid),
  309. returnObj.key = "guid", returnObj;
  310. 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),
  311. returnObj.key = "id", returnObj;
  312. }
  313. if (collectionJSON.name) return returnObj.name = _.escape(collectionJSON.name),
  314. returnObj.key = "name", returnObj;
  315. if (collectionJSON.displayName) return returnObj.name = _.escape(collectionJSON.displayName),
  316. returnObj.key = "displayName", returnObj;
  317. if (collectionJSON.qualifiedName) return returnObj.name = _.escape(collectionJSON.qualifiedName),
  318. returnObj.key = "qualifiedName", returnObj;
  319. if (collectionJSON.displayText) return returnObj.name = _.escape(collectionJSON.displayText),
  320. returnObj.key = "displayText", returnObj;
  321. if (collectionJSON.guid) return returnObj.name = _.escape(collectionJSON.guid),
  322. returnObj.key = "guid", returnObj;
  323. if (collectionJSON.id) return _.isObject(collectionJSON.id) ? collectionJSON.id.id && (returnObj.name = _.escape(collectionJSON.id.id)) : returnObj.name = _.escape(collectionJSON.id),
  324. returnObj.key = "id", returnObj;
  325. }
  326. return returnObj.found = !1, skipAttribute && returnObj.key == skipAttribute ? {
  327. name: "-",
  328. found: !0,
  329. key: null
  330. } : returnObj;
  331. }, Utils.backButtonClick = function() {
  332. var queryParams = Utils.getUrlState.getQueryParams(), urlPath = "searchUrl";
  333. queryParams && queryParams.from && ("classification" == queryParams.from ? urlPath = "tagUrl" : "glossary" == queryParams.from ? urlPath = "glossaryUrl" : "bm" == queryParams.from && (urlPath = "administratorUrl")),
  334. Utils.setUrl({
  335. url: Globals.saveApplicationState.tabState[urlPath],
  336. mergeBrowserUrl: !1,
  337. trigger: !0,
  338. updateTabState: !0
  339. });
  340. }, Utils.showTitleLoader = function(loaderEl, titleBoxEl) {
  341. loaderEl.css ? loaderEl.css({
  342. display: "block",
  343. position: "relative",
  344. height: "85px",
  345. marginTop: "85px",
  346. marginLeft: "50%",
  347. left: "0%"
  348. }) : null, titleBoxEl.hide ? titleBoxEl.hide() : null;
  349. }, Utils.hideTitleLoader = function(loaderEl, titleBoxEl) {
  350. loaderEl.hide ? loaderEl.hide() : null, titleBoxEl.fadeIn ? titleBoxEl.fadeIn() : null;
  351. }, Utils.findAndMergeRefEntity = function(options) {
  352. var attributeObject = options.attributeObject, referredEntities = options.referredEntities, mergeObject = function(obj) {
  353. obj && (obj.attributes ? Utils.findAndMergeRefEntity({
  354. attributeObject: obj.attributes,
  355. referredEntities: referredEntities
  356. }) : referredEntities[obj.guid] && _.extend(obj, referredEntities[obj.guid]));
  357. };
  358. attributeObject && referredEntities && _.each(attributeObject, function(obj, key) {
  359. _.isObject(obj) && (_.isArray(obj) ? _.each(obj, function(value) {
  360. mergeObject(value);
  361. }) : mergeObject(obj));
  362. });
  363. }, Utils.findAndMergeRelationShipEntity = function(options) {
  364. var attributeObject = options.attributeObject, relationshipAttributes = options.relationshipAttributes;
  365. _.each(attributeObject, function(val, key) {
  366. if (relationshipAttributes && relationshipAttributes[key]) {
  367. var relationShipVal = relationshipAttributes[key];
  368. _.isObject(val) && (_.isArray(val) ? _.each(val, function(attr) {
  369. if (attr && void 0 === attr.attributes) {
  370. var entityFound = _.find(relationShipVal, {
  371. guid: attr.guid
  372. });
  373. entityFound && (attr.attributes = _.omit(entityFound, "typeName", "guid", "entityStatus"),
  374. attr.status = entityFound.entityStatus);
  375. }
  376. }) : relationShipVal && void 0 === val.attributes && (val.attributes = _.omit(relationShipVal, "typeName", "guid", "entityStatus"),
  377. val.status = relationShipVal.entityStatus));
  378. }
  379. });
  380. }, Utils.getNestedSuperTypes = function(options) {
  381. var data = options.data, collection = options.collection, superTypes = [], getData = function(data, collection) {
  382. data && (superTypes = superTypes.concat(data.superTypes), data.superTypes && data.superTypes.length && _.each(data.superTypes, function(superTypeName) {
  383. if (collection.fullCollection) var collectionData = collection.fullCollection.findWhere({
  384. name: superTypeName
  385. }).toJSON(); else var collectionData = collection.findWhere({
  386. name: superTypeName
  387. }).toJSON();
  388. getData(collectionData, collection);
  389. }));
  390. };
  391. return getData(data, collection), _.uniq(superTypes);
  392. }, Utils.getNestedSuperTypeObj = function(options) {
  393. var mainData = options.data, collection = options.collection, attrMerge = options.attrMerge, seperateRelatioshipAttr = options.seperateRelatioshipAttr || !1, mergeRelationAttributes = options.mergeRelationAttributes || !seperateRelatioshipAttr;
  394. if (mergeRelationAttributes && seperateRelatioshipAttr) throw "Both mergeRelationAttributes & seperateRelatioshipAttr cannot be true!";
  395. var attributeDefs = {};
  396. attrMerge && !seperateRelatioshipAttr ? attributeDefs = [] : options.attrMerge && seperateRelatioshipAttr && (attributeDefs = {
  397. attributeDefs: [],
  398. relationshipAttributeDefs: []
  399. });
  400. var getRelationshipAttributeDef = function(data) {
  401. return _.filter(data.relationshipAttributeDefs, function(obj, key) {
  402. return obj;
  403. });
  404. }, getData = function(data, collection) {
  405. options.attrMerge ? seperateRelatioshipAttr ? (attributeDefs.attributeDefs = attributeDefs.attributeDefs.concat(data.attributeDefs),
  406. attributeDefs.relationshipAttributeDefs = attributeDefs.relationshipAttributeDefs.concat(getRelationshipAttributeDef(data))) : (attributeDefs = attributeDefs.concat(data.attributeDefs),
  407. mergeRelationAttributes && (attributeDefs = attributeDefs.concat(getRelationshipAttributeDef(data)))) : attributeDefs[data.name] ? attributeDefs[data.name] = _.toArrayifObject(attributeDefs[data.name]).concat(data.attributeDefs) : seperateRelatioshipAttr ? attributeDefs[data.name] = {
  408. attributeDefs: data.attributeDefs,
  409. relationshipAttributeDefs: data.relationshipAttributeDefs
  410. } : (attributeDefs[data.name] = data.attributeDefs, mergeRelationAttributes && (attributeDefs[data.name] = _.toArrayifObject(attributeDefs[data.name]).concat(getRelationshipAttributeDef(data)))),
  411. data.superTypes && data.superTypes.length && _.each(data.superTypes, function(superTypeName) {
  412. if (collection.fullCollection) var collectionData = collection.fullCollection.findWhere({
  413. name: superTypeName
  414. }); else var collectionData = collection.findWhere({
  415. name: superTypeName
  416. });
  417. return collectionData = collectionData && collectionData.toJSON ? collectionData.toJSON() : collectionData,
  418. collectionData ? getData(collectionData, collection) : void 0;
  419. });
  420. };
  421. return getData(mainData, collection), attrMerge && (attributeDefs = seperateRelatioshipAttr ? {
  422. attributeDefs: _.uniq(_.sortBy(attributeDefs.attributeDefs, "name"), !0, function(obj) {
  423. return obj.name;
  424. }),
  425. relationshipAttributeDefs: _.uniq(_.sortBy(attributeDefs.relationshipAttributeDefs, "name"), !0, function(obj) {
  426. return obj.name + obj.relationshipTypeName;
  427. })
  428. } : _.uniq(_.sortBy(attributeDefs, "name"), !0, function(obj) {
  429. return obj.relationshipTypeName ? obj.name + obj.relationshipTypeName : obj.name;
  430. })), attributeDefs;
  431. }, Utils.getProfileTabType = function(profileData, skipData) {
  432. var parseData = profileData.distributionData;
  433. _.isString(parseData) && (parseData = JSON.parse(parseData));
  434. var createData = function(type) {
  435. var orderValue = [], sort = !1;
  436. if ("date" === type) {
  437. var dateObj = {};
  438. return _.keys(parseData).map(function(key) {
  439. var splitValue = key.split(":");
  440. dateObj[splitValue[0]] || (dateObj[splitValue[0]] = {
  441. value: splitValue[0],
  442. monthlyCounts: {},
  443. totalCount: 0
  444. }), dateObj[splitValue[0]] && "count" == splitValue[1] && (dateObj[splitValue[0]].count = parseData[key]),
  445. dateObj[splitValue[0]] && "count" !== splitValue[1] && (dateObj[splitValue[0]].monthlyCounts[splitValue[1]] = parseData[key],
  446. dateObj[splitValue[0]].count || (dateObj[splitValue[0]].totalCount += parseData[key]));
  447. }), _.toArray(dateObj).map(function(obj) {
  448. return !obj.count && obj.totalCount && (obj.count = obj.totalCount), obj;
  449. });
  450. }
  451. var data = [];
  452. return profileData.distributionKeyOrder ? orderValue = profileData.distributionKeyOrder : (sort = !0,
  453. orderValue = _.keys(parseData)), _.each(orderValue, function(key) {
  454. parseData[key] && data.push({
  455. value: key,
  456. count: parseData[key]
  457. });
  458. }), sort && (data = _.sortBy(data, function(o) {
  459. return o.value.toLowerCase();
  460. })), data;
  461. };
  462. if (profileData && profileData.distributionType) {
  463. if ("count-frequency" === profileData.distributionType) return {
  464. type: "string",
  465. label: Enums.profileTabType[profileData.distributionType],
  466. actualObj: skipData ? null : createData("string"),
  467. xAxisLabel: "FREQUENCY",
  468. yAxisLabel: "COUNT"
  469. };
  470. if ("decile-frequency" === profileData.distributionType) return {
  471. label: Enums.profileTabType[profileData.distributionType],
  472. type: "numeric",
  473. xAxisLabel: "DECILE RANGE",
  474. actualObj: skipData ? null : createData("numeric"),
  475. yAxisLabel: "FREQUENCY"
  476. };
  477. if ("annual" === profileData.distributionType) return {
  478. label: Enums.profileTabType[profileData.distributionType],
  479. type: "date",
  480. xAxisLabel: "",
  481. actualObj: skipData ? null : createData("date"),
  482. yAxisLabel: "COUNT"
  483. };
  484. }
  485. }, Utils.isUrl = function(url) {
  486. var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  487. return regexp.test(url);
  488. }, Utils.JSONPrettyPrint = function(obj, getValue) {
  489. var replacer = function(match, pIndent, pKey, pVal, pEnd) {
  490. var key = "<span class=json-key>", val = "<span class=json-value>", str = "<span class=json-string>", r = pIndent || "";
  491. return pKey && (r = r + key + pKey.replace(/[": ]/g, "") + "</span>: "), pVal && (r = r + ('"' == pVal[0] ? str : val) + getValue(pVal) + "</span>"),
  492. r + (pEnd || "");
  493. }, jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/gm;
  494. return obj && _.isObject(obj) ? JSON.stringify(obj, null, 3).replace(/&/g, "&amp;").replace(/\\"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(jsonLine, replacer) : {};
  495. }, $.fn.toggleAttribute = function(attributeName, firstString, secondString) {
  496. this.attr(attributeName) == firstString ? this.attr(attributeName, secondString) : this.attr(attributeName, firstString);
  497. }, Utils.millisecondsToTime = function(duration) {
  498. var milliseconds = parseInt(duration % 1e3 / 100), seconds = parseInt(duration / 1e3 % 60), minutes = parseInt(duration / 6e4 % 60), hours = parseInt(duration / 36e5 % 24);
  499. return hours = hours < 10 ? "0" + hours : hours, minutes = minutes < 10 ? "0" + minutes : minutes,
  500. seconds = seconds < 10 ? "0" + seconds : seconds, hours + ":" + minutes + ":" + seconds + "." + milliseconds;
  501. }, Utils.togglePropertyRelationshipTableEmptyValues = function(object) {
  502. var inputSelector = object.inputType, tableEl = object.tableEl;
  503. 1 == inputSelector.prop("checked") ? tableEl.removeClass("hide-empty-value") : tableEl.addClass("hide-empty-value");
  504. }, $.fn.showButtonLoader = function() {
  505. $(this).attr("disabled", "true").addClass("button-loader"), $(this).siblings("button.cancel").prop("disabled", !0);
  506. }, $.fn.hideButtonLoader = function() {
  507. $(this).removeClass("button-loader").removeAttr("disabled"), $(this).siblings("button.cancel").prop("disabled", !1);
  508. }, Utils.formatDate = function(options) {
  509. var dateValue = null, dateFormat = Globals.dateTimeFormat, isValidDate = !1;
  510. return options && options.date && (dateValue = options.date, "-" !== dateValue && (dateValue = parseInt(dateValue),
  511. _.isNaN(dateValue) && (dateValue = options.date), dateValue = moment(dateValue),
  512. dateValue._isValid && (isValidDate = !0, dateValue = dateValue.format(dateFormat)))),
  513. "-" !== dateValue && (isValidDate === !1 && options && options.defaultDate !== !1 && (dateValue = moment().format(dateFormat)),
  514. Globals.isTimezoneFormatEnabled && (!options || options && options.zone !== !1) && (dateValue += " (" + moment.tz(moment.tz.guess()).zoneAbbr() + ")")),
  515. dateValue;
  516. },Utils.toChinese=function (name){
  517. switch (name){
  518. case "columns": return "列";
  519. case "aliases": return "别名";
  520. case "comment": return "备注";
  521. case "createTime": return "创建时间";
  522. case "db": return "数据库";
  523. case "displayName": return "展示名称";
  524. case "isIncomplete": return "是否为未完成";
  525. case "lastAccessTime": return "上次访问时间";
  526. case "name": return "名称";
  527. case "owner":return "所有者";
  528. case "parameters": return "参数";
  529. case "partitionKeys": return "分区键";
  530. case "qualifiedName": return "限定符";
  531. case "replicatedFrom": return "复制自";
  532. case "replicatedTo": return "复制到";
  533. case "retention": return "留存";
  534. case "sd": return "物理存储";
  535. case "tableType": return "表类型";
  536. case "temporary": return "临时";
  537. case "typeName": return "类型名称";
  538. case "userDescription": return "用户描述";
  539. case "viewExpandedText": return "视图拓展文本";
  540. case "viewOriginalText": return "视图原始文本";
  541. case "type": return "类型";
  542. case "ddlQueries": return "数据定义语句";
  543. case "outputFromProcesses": return "表格输出过程";
  544. case "inputs": return "输入";
  545. case "outputs": return "输出";
  546. case "processExecutions": return "执行过程";
  547. case "inputToProcesses": return "输入过程";
  548. case "namespace": return "命名空间";
  549. case "table": return "表";
  550. case "meanings": return "含义";
  551. case "model": return "模型";
  552. case "pipeline": return "管道";
  553. case "schema": return "模式";
  554. case "position": return "位置";
  555. case "description": return "描述";
  556. case "path": return "路径";
  557. case "clusterName": return "数据块名称";
  558. case "extendedAttributes": return "扩展属性";
  559. case "fileSize": return "文件大小";
  560. case "group": return "组";
  561. case "isFile": return "是否为文件";
  562. case "isSymlink": return "是否为符号链接";
  563. case "modifiedTime": return "修改时间";
  564. case "nameServiceId": return "服务器序号";
  565. case "numberOfReplicas": return "副本编号";
  566. case "posixPermissions": return "接口访问权限";
  567. case "hiveDb": return "hive数据库";
  568. case "compressed": return "压缩";
  569. case "location": return "位置";
  570. case "numBuckets": return "桶编号";
  571. case "serdeInfo": return "序列化信息";
  572. case "storedAsSubDirectories": return "存储的子目录";
  573. case "bucketCols": return "桶的列名";
  574. case "inputFormat": return "输入格式";
  575. case "outputFormat": return "输出格式";
  576. case "sortCols": return "排序列名";
  577. case "execTime": return "执行时间";
  578. case "queryText": return "查询语句";
  579. case "serviceType": return "服务类型";
  580. case "userName": return "用户名";
  581. case "blockCacheEnabled": return "块缓存是否启用";
  582. case "bloomFilterType": return "布隆过滤器类型";
  583. case "cacheBloomsOnWrite": return "布隆缓存是否可编辑";
  584. case "cacheDataOnWrite": return "缓存数据是否可编辑";
  585. case "cacheIndexesOnWrite": return "缓存序号是否可编辑";
  586. case "compactionCompressionType": return "压实类型";
  587. case "compressionType": return "压缩类型";
  588. case "evictBlocksOnClose": return "驱逐区块关闭";
  589. case "isMobEnabled": return "是否开启中等对象(mob)特性";
  590. case "keepDeletedCells": return "是否保存已删除的单元格";
  591. case "maxVersions": return "最大版本数";
  592. case "minVersions": return "最小版本数";
  593. case "newVersionBehavior": return "是否可改变列族描述";
  594. case "prefetchBlocksOnOpen": return "是否开启预取块";
  595. case "ttl": return "电瓶信号";
  596. case "StoragePolicy": return "缓存方案";
  597. case "mobCompactPartitionPolicy": return "中等对象压缩分区技术";
  598. case "encryptionType": return "压缩类型";
  599. case "inMemoryCompactionPolicy": return "可记忆压缩技术";
  600. case "column_families": return "列族";
  601. case "durability": return "耐久性";
  602. case "isCompactionEnabled": return "是否开启压缩";
  603. case "isNormalizationEnabled": return "是否开启标准化";
  604. case "isReadOnly": return "是否只读";
  605. case "maxFileSize": return "最大文件大小";
  606. case "replicasPerRegion": return "每个区域副本";
  607. case "uri": return "统一资源标识符";
  608. case "endTime": return "结束时间";
  609. case "operationType": return "操作类型";
  610. case "queryGraph": return "查询图";
  611. case "queryId": return "查询序号";
  612. case "queryPlan": return "查询计划";
  613. case "recentQueries": return "最近操作语句";
  614. case "startTime": return "开始时间";
  615. case "hostName": return "主机名";
  616. case "__pendingTasks": return "待完成的任务";
  617. case "Glossary": return "术语表";
  618. case "Category": return "分类";
  619. case "Term": return "术语";
  620. default: return name;
  621. }
  622. }, Utils.regexDuplicate=function (txt){
  623. var regex=/Glossary term with qualifiedName (.*?) already exists/
  624. var match=regex.exec(txt);
  625. return match && match[1]?"存在相同名称和术语表的术语"+match[1]+",无法重复创建":txt
  626. },
  627. Utils.replaceToChinese = function(name) {
  628. return name
  629. .replace("Names must consist of a letter followed by a sequence of letter, number, space, or _ characters","名称必须由一个字母和一系列字母、数字、空格或_字符组成")
  630. .replace("invalid name for CLASSIFICATION.","分类的名称无效。")
  631. },
  632. Utils;
  633. });