nav.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.focusModel(app.views.tabledata);
  30. },
  31. setCluster: function(cluster)
  32. {
  33. Router.set();
  34. app.cluster(cluster);
  35. },
  36. set: function()
  37. {
  38. Breadcrumbs.render();
  39. }
  40. }
  41. var Breadcrumbs =
  42. {
  43. _selector_root:'#hbase-breadcrumbs',
  44. //renders breadcrumbs automaticall
  45. render:function(mutators)
  46. {
  47. root = $(Breadcrumbs._selector_root).html('');
  48. crumbs = ['/hbase'].concat(document.URL.split('/').splice(4));
  49. biglink = "";
  50. for(i=0;i<crumbs.length;i++)
  51. {
  52. biglink += crumbs[i] + '/'
  53. function clean_url(url)
  54. {
  55. replacers = {'/': '', '#': '', '_': ' ', '^[a-z]': function(a) { return a.toUpperCase(); }};
  56. keys = Object.keys(replacers);
  57. for(q=0;q<keys.length;q++)
  58. {
  59. url = url.replace(new RegExp(keys[q],'g'), replacers[keys[q]]);
  60. }
  61. return url;
  62. }
  63. if(crumbs[i]!="")
  64. root.append('<li><a href="' + biglink + '">' + clean_url(crumbs[i]) + '</a></li><li><a href="' + biglink + '">/</a></li>');
  65. }
  66. return root.find('li:last-child').remove();
  67. }
  68. }
  69. var Views =
  70. {
  71. render:function(view)
  72. {
  73. page = $('.hbase-page#hbase-page-' + view);
  74. if(!page)
  75. return false;
  76. $('.hbase-page.active').removeClass('active');
  77. page.addClass('active');
  78. return page;
  79. },
  80. displayError:function(error)
  81. {
  82. console.log(error);
  83. }
  84. }