nav.js 2.4 KB

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