nav.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. var Router =
  17. {
  18. go: function(page)
  19. {
  20. if(!Views.render(page))
  21. return history.back();
  22. return page;
  23. },
  24. setTable: function(cluster, table)
  25. {
  26. Router.setCluster(cluster);
  27. app.pageTitle(cluster + ' / ' + table);
  28. app.views.tabledata.name(table);
  29. app.views.tabledata.name(table);
  30. app.focusModel(app.views.tabledata);
  31. },
  32. setCluster: function(cluster)
  33. {
  34. Router.set();
  35. app.cluster(cluster);
  36. },
  37. set: function()
  38. {
  39. Breadcrumbs.render();
  40. }
  41. }
  42. var Breadcrumbs =
  43. {
  44. _selector_root:'#hbase-breadcrumbs',
  45. //renders breadcrumbs automaticall
  46. render:function(mutators)
  47. {
  48. root = $(Breadcrumbs._selector_root).html('');
  49. crumbs = ['/hbase'].concat(document.URL.split('/').splice(4));
  50. biglink = "";
  51. for(i=0;i<crumbs.length;i++)
  52. {
  53. biglink += crumbs[i] + '/'
  54. function clean_url(url)
  55. {
  56. replacers = {'/': '', '#': '', '_': ' ', '^[a-z]': function(a) { return a.toUpperCase(); }};
  57. keys = Object.keys(replacers);
  58. for(q=0;q<keys.length;q++)
  59. {
  60. url = url.replace(new RegExp(keys[q],'g'), replacers[keys[q]]);
  61. }
  62. return url;
  63. }
  64. if(crumbs[i]!="")
  65. root.append('<li><a href="' + biglink + '">' + clean_url(crumbs[i]) + '</a></li><li><a href="' + biglink + '">/</a></li>');
  66. }
  67. return root.find('li:last-child').remove();
  68. }
  69. }
  70. var Views =
  71. {
  72. render:function(view)
  73. {
  74. page = $('.hbase-page#hbase-page-' + view);
  75. if(!page)
  76. return false;
  77. $('.hbase-page.active').removeClass('active');
  78. page.addClass('active');
  79. return page;
  80. },
  81. displayError:function(error)
  82. {
  83. console.log(error);
  84. }
  85. }