Router.js 17 KB

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