Router.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. define([ "jquery", "underscore", "backbone", "App", "utils/Globals", "utils/Utils", "utils/UrlLinks", "utils/Enums", "collection/VGlossaryList" ], function($, _, Backbone, App, Globals, Utils, UrlLinks, Enums, VGlossaryList) {
  2. var AppRouter = Backbone.Router.extend({
  3. routes: {
  4. "": "defaultAction",
  5. "!/search": "renderDefaultSearchLayoutView",
  6. "!/search/searchResult": function() {
  7. this.renderDefaultSearchLayoutView({
  8. fromSearchResultView: !0
  9. });
  10. },
  11. "!/tag": "renderTagLayoutView",
  12. "!/tag/tagAttribute/(*name)": "renderTagLayoutView",
  13. "!/glossary": "renderGlossaryLayoutView",
  14. "!/glossary/:id": "renderGlossaryLayoutView",
  15. "!/detailPage/:id": "detailPage",
  16. "!/administrator": "administrator",
  17. "!/administrator/businessMetadata/:id": "businessMetadataDetailPage",
  18. "!/debugMetrics": "debugMetrics",
  19. "*actions": "defaultAction"
  20. },
  21. initialize: function(options) {
  22. _.extend(this, _.pick(options, "entityDefCollection", "typeHeaders", "enumDefCollection", "classificationDefCollection", "metricCollection", "classificationAndMetricEvent", "businessMetadataDefCollection")),
  23. this.showRegions(), this.bindCommonEvents(), this.listenTo(this, "route", this.postRouteExecute, this),
  24. this.searchVent = new Backbone.Wreqr.EventAggregator(), this.categoryEvent = new Backbone.Wreqr.EventAggregator(),
  25. this.glossaryCollection = new VGlossaryList([], {
  26. comparator: function(item) {
  27. return item.get("name");
  28. }
  29. }), this.preFetchedCollectionLists = {
  30. entityDefCollection: this.entityDefCollection,
  31. typeHeaders: this.typeHeaders,
  32. enumDefCollection: this.enumDefCollection,
  33. classificationDefCollection: this.classificationDefCollection,
  34. glossaryCollection: this.glossaryCollection,
  35. metricCollection: this.metricCollection,
  36. classificationAndMetricEvent: this.classificationAndMetricEvent,
  37. businessMetadataDefCollection: this.businessMetadataDefCollection
  38. }, this.ventObj = {
  39. searchVent: this.searchVent,
  40. categoryEvent: this.categoryEvent
  41. }, this.sharedObj = {
  42. searchTableColumns: {},
  43. glossary: {
  44. selectedItem: {}
  45. },
  46. searchTableFilters: {
  47. tagFilters: {},
  48. entityFilters: {}
  49. }
  50. };
  51. },
  52. bindCommonEvents: function() {
  53. var that = this;
  54. $("body").on("click", "a.show-stat", function() {
  55. require([ "views/site/Statistics" ], function(Statistics) {
  56. new Statistics(_.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj));
  57. });
  58. }), $("body").on("click", "li.aboutAtlas", function() {
  59. require([ "views/site/AboutAtlas" ], function(AboutAtlas) {
  60. new AboutAtlas();
  61. });
  62. }), $("body").on("click", "a.show-classification", function() {
  63. Utils.setUrl({
  64. url: "!/tag",
  65. mergeBrowserUrl: !1,
  66. trigger: !0,
  67. updateTabState: !0
  68. });
  69. }), $("body").on("click", "a.show-glossary", function() {
  70. Utils.setUrl({
  71. url: "!/glossary",
  72. mergeBrowserUrl: !1,
  73. trigger: !0,
  74. updateTabState: !0
  75. });
  76. });
  77. },
  78. showRegions: function() {},
  79. renderViewIfNotExists: function(options) {
  80. var view = options.view, render = options.render, viewName = options.viewName, manualRender = options.manualRender;
  81. view.currentView ? manualRender && viewName ? viewName === view.currentView._viewName ? options.manualRender(options) : render && view.show(options.render(options)) : manualRender && options.manualRender(options) : render && view.show(options.render(options));
  82. },
  83. execute: function(callback, args) {
  84. this.preRouteExecute(), callback && callback.apply(this, args), this.postRouteExecute();
  85. },
  86. preRouteExecute: function() {
  87. $("body").removeClass("global-search-active"), $(".tooltip").tooltip("hide");
  88. },
  89. postRouteExecute: function(name, args) {},
  90. getHeaderOptions: function(Header, options) {
  91. var that = this;
  92. return {
  93. view: App.rHeader,
  94. manualRender: function() {
  95. this.view.currentView.manualRender(options);
  96. },
  97. render: function() {
  98. return new Header(_.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj, options));
  99. }
  100. };
  101. },
  102. detailPage: function(id) {
  103. var that = this;
  104. id && require([ "views/site/Header", "views/detail_page/DetailPageLayoutView", "views/site/SideNavLayoutView" ], function(Header, DetailPageLayoutView, SideNavLayoutView) {
  105. var paramObj = Utils.getUrlState.getQueryParams(), options = _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  106. that.renderViewIfNotExists(that.getHeaderOptions(Header)), that.renderViewIfNotExists({
  107. view: App.rSideNav,
  108. manualRender: function() {
  109. this.view.currentView.manualRender(options);
  110. },
  111. render: function() {
  112. return new SideNavLayoutView(options);
  113. }
  114. });
  115. var dOptions = _.extend({
  116. id: id,
  117. value: paramObj
  118. }, options);
  119. that.renderViewIfNotExists({
  120. view: App.rContent,
  121. viewName: "DetailPageLayoutView",
  122. manualRender: function() {
  123. this.view.currentView.manualRender(dOptions);
  124. },
  125. render: function() {
  126. return new DetailPageLayoutView(dOptions);
  127. }
  128. });
  129. });
  130. },
  131. renderTagLayoutView: function(tagName) {
  132. var that = this;
  133. require([ "views/site/Header", "views/tag/TagContainerLayoutView", "views/site/SideNavLayoutView" ], function(Header, TagContainerLayoutView, SideNavLayoutView) {
  134. var paramObj = Utils.getUrlState.getQueryParams();
  135. that.renderViewIfNotExists(that.getHeaderOptions(Header));
  136. var options = _.extend({
  137. tag: tagName,
  138. value: paramObj
  139. }, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  140. that.renderViewIfNotExists({
  141. view: App.rSideNav,
  142. manualRender: function() {
  143. this.view.currentView.manualRender(options);
  144. },
  145. render: function() {
  146. return new SideNavLayoutView(options);
  147. }
  148. }), App.rContent.show(new TagContainerLayoutView(options));
  149. });
  150. },
  151. renderGlossaryLayoutView: function(id) {
  152. var that = this;
  153. require([ "views/site/Header", "views/glossary/GlossaryContainerLayoutView", "views/search/SearchDefaultLayoutView", "views/site/SideNavLayoutView" ], function(Header, GlossaryContainerLayoutView, SearchDefaultLayoutView, SideNavLayoutView) {
  154. var paramObj = Utils.getUrlState.getQueryParams();
  155. if (void 0 === paramObj) return void that.defaultAction();
  156. that.renderViewIfNotExists(that.getHeaderOptions(Header));
  157. var options = _.extend({
  158. guid: id,
  159. value: paramObj
  160. }, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  161. that.renderViewIfNotExists({
  162. view: App.rSideNav,
  163. manualRender: function() {
  164. this.view.currentView.manualRender(options);
  165. },
  166. render: function() {
  167. return new SideNavLayoutView(options);
  168. }
  169. }), "glossary" !== paramObj.gType ? that.renderViewIfNotExists({
  170. view: App.rContent,
  171. viewName: "GlossaryContainerLayoutView",
  172. manualRender: function() {
  173. this.view.currentView.manualRender(options);
  174. },
  175. render: function() {
  176. return new GlossaryContainerLayoutView(options);
  177. }
  178. }) : (options.value = "", options.initialView = !0, that.renderViewIfNotExists(that.getHeaderOptions(Header, {
  179. fromDefaultSearch: !0
  180. })), App.rContent.show(new SearchDefaultLayoutView(options)));
  181. });
  182. },
  183. renderDefaultSearchLayoutView: function(opt) {
  184. var that = this;
  185. require([ "views/site/Header", "views/search/SearchDefaultLayoutView", "views/site/SideNavLayoutView", "collection/VTagList" ], function(Header, SearchDefaultLayoutView, SideNavLayoutView, VTagList) {
  186. function renderSearchView() {
  187. var isinitialView = !0, tempParam = _.extend({}, paramObj);
  188. paramObj && (isinitialView = 0 === (paramObj.type || ("true" == paramObj.dslChecked ? "" : paramObj.tag || paramObj.term) || (paramObj.query ? paramObj.query.trim() : "")).length);
  189. var options = _.extend({
  190. value: paramObj,
  191. initialView: isinitialView,
  192. fromDefaultSearch: !opt || opt && !opt.fromSearchResultView,
  193. fromSearchResultView: opt && opt.fromSearchResultView || !1,
  194. fromCustomFilterView: opt && opt.fromCustomFilterView || !1,
  195. isTypeTagNotExists: paramObj && (paramObj.type != tempParam.type || tempParam.tag != paramObj.tag)
  196. }, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  197. that.renderViewIfNotExists(that.getHeaderOptions(Header, {
  198. fromDefaultSearch: options.fromDefaultSearch
  199. })), that.renderViewIfNotExists({
  200. view: App.rSideNav,
  201. manualRender: function() {
  202. this.view.currentView.manualRender(options);
  203. },
  204. render: function() {
  205. return new SideNavLayoutView(options);
  206. }
  207. }), that.renderViewIfNotExists({
  208. view: App.rContent,
  209. viewName: "SearchDefaultlLayoutView",
  210. manualRender: function() {
  211. this.view.currentView.manualRender(options);
  212. },
  213. render: function() {
  214. return new SearchDefaultLayoutView(options);
  215. }
  216. });
  217. }
  218. var paramObj = Utils.getUrlState.getQueryParams();
  219. if (tag = new VTagList(), paramObj && void 0 === (paramObj.type || paramObj.tag || paramObj.term || paramObj.query || paramObj.udKeys || paramObj.udLabels) && Utils.setUrl({
  220. url: "#!/search",
  221. mergeBrowserUrl: !1,
  222. trigger: !0,
  223. updateTabState: !0
  224. }), "search" !== Utils.getUrlState.getQueryUrl().lastValue && Utils.getUrlState.isAdministratorTab() === !1 && (paramObj = _.omit(paramObj, [ "tabActive", "ns", "nsa" ]),
  225. Utils.setUrl({
  226. url: "#!/search/searchResult",
  227. urlParams: paramObj,
  228. mergeBrowserUrl: !1,
  229. trigger: !1,
  230. updateTabState: !0
  231. })), paramObj) if (paramObj.type || paramObj.entityFilters && (paramObj.entityFilters = null),
  232. paramObj.tag) {
  233. var tagValidate = paramObj.tag, isTagPresent = !1;
  234. tagValidate.indexOf("*") == -1 ? (classificationDefCollection.fullCollection.each(function(model) {
  235. var name = Utils.getName(model.toJSON(), "name");
  236. "CLASSIFICATION" == model.get("category") && tagValidate && name === tagValidate && (isTagPresent = !0);
  237. }), _.each(Enums.addOnClassification, function(classificationName) {
  238. classificationName === tagValidate && (isTagPresent = !0);
  239. }), isTagPresent ? renderSearchView() : (tag.url = UrlLinks.classificationDefApiUrl(tagValidate),
  240. tag.fetch({
  241. success: function(tagCollection) {
  242. isTagPresent = !0;
  243. },
  244. cust_error: function(model, response) {
  245. paramObj.tag = null;
  246. },
  247. complete: function() {
  248. renderSearchView.call();
  249. }
  250. }))) : renderSearchView();
  251. } else paramObj.tagFilters && (paramObj.tagFilters = null), renderSearchView(); else renderSearchView();
  252. });
  253. },
  254. administrator: function() {
  255. var that = this;
  256. require([ "views/site/Header", "views/site/SideNavLayoutView", "views/administrator/AdministratorLayoutView" ], function(Header, SideNavLayoutView, AdministratorLayoutView) {
  257. var paramObj = Utils.getUrlState.getQueryParams(), options = _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  258. that.renderViewIfNotExists(that.getHeaderOptions(Header)), that.renderViewIfNotExists({
  259. view: App.rSideNav,
  260. manualRender: function() {
  261. this.view.currentView.manualRender(options);
  262. },
  263. render: function() {
  264. return new SideNavLayoutView(options);
  265. }
  266. }), App.rContent.show(new AdministratorLayoutView(_.extend({
  267. value: paramObj,
  268. guid: null
  269. }, options)));
  270. });
  271. },
  272. debugMetrics: function() {
  273. var that = this;
  274. require([ "views/site/Header", "views/site/SideNavLayoutView", "views/dev_debug/DebugMetricsLayoutView" ], function(Header, SideNavLayoutView, DebugMetricsLayoutView) {
  275. var options = (Utils.getUrlState.getQueryParams(), _.extend({}, that.preFetchedCollectionLists, that.sharedObj, that.ventObj));
  276. that.renderViewIfNotExists(that.getHeaderOptions(Header)), that.renderViewIfNotExists({
  277. view: App.rSideNav,
  278. manualRender: function() {
  279. this.view.currentView.manualRender(options);
  280. },
  281. render: function() {
  282. return new SideNavLayoutView(options);
  283. }
  284. }), App.rContent.show(new DebugMetricsLayoutView(options));
  285. });
  286. },
  287. businessMetadataDetailPage: function(guid) {
  288. var that = this;
  289. require([ "views/site/Header", "views/site/SideNavLayoutView", "views/business_metadata/BusinessMetadataContainerLayoutView" ], function(Header, SideNavLayoutView, BusinessMetadataContainerLayoutView) {
  290. var paramObj = Utils.getUrlState.getQueryParams(), options = _.extend({
  291. guid: guid,
  292. value: paramObj
  293. }, that.preFetchedCollectionLists, that.sharedObj, that.ventObj);
  294. that.renderViewIfNotExists(that.getHeaderOptions(Header)), that.renderViewIfNotExists({
  295. view: App.rSideNav,
  296. manualRender: function() {
  297. this.view.currentView.manualRender(options);
  298. },
  299. render: function() {
  300. return new SideNavLayoutView(options);
  301. }
  302. }), App.rContent.show(new BusinessMetadataContainerLayoutView(options));
  303. });
  304. },
  305. defaultAction: function(actions) {
  306. Utils.setUrl({
  307. url: "#!/search",
  308. mergeBrowserUrl: !1,
  309. trigger: !0,
  310. updateTabState: !0
  311. }), console.log("No route:", actions);
  312. }
  313. });
  314. return AppRouter;
  315. });