nav.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. go: function(page) {
  18. if(!Views.render(page))
  19. return history.back();
  20. return page;
  21. },
  22. setTable: function(cluster, table) {
  23. Router.setCluster(cluster);
  24. app.pageTitle(cluster + ' / ' + table);
  25. app.views.tabledata.name(table);
  26. app.focusModel(app.views.tabledata);
  27. },
  28. setCluster: function(cluster) {
  29. Router.set();
  30. app.cluster(cluster);
  31. },
  32. set: function() {
  33. Breadcrumbs.render();
  34. }
  35. }
  36. var Breadcrumbs = {
  37. _selector_root:'#hbase-breadcrumbs',
  38. //renders breadcrumbs automaticall
  39. render:function(mutators) {
  40. root = $(Breadcrumbs._selector_root).html('');
  41. crumbs = ['/hbase'].concat(document.URL.split('/').splice(4));
  42. biglink = "";
  43. for(i=0;i<crumbs.length;i++) {
  44. biglink += crumbs[i] + '/'
  45. function clean_url(url) {
  46. replacers = {'/': '', '#': '', '_': ' ', '^[a-z]': function(a) { return a.toUpperCase(); }};
  47. keys = Object.keys(replacers);
  48. for(q=0;q<keys.length;q++) {
  49. url = url.replace(new RegExp(keys[q],'g'), replacers[keys[q]]);
  50. }
  51. return url;
  52. }
  53. if(crumbs[i]!="")
  54. root.append('<li><a href="' + biglink + '">' + clean_url(crumbs[i]) + '</a></li><li><a href="' + biglink + '">/</a></li>');
  55. }
  56. return root.find('li:last-child').remove();
  57. }
  58. }
  59. var Views = {
  60. render:function(view) {
  61. page = $('.hbase-page#hbase-page-' + view);
  62. if(!page)
  63. return false;
  64. $('.hbase-page.active').removeClass('active');
  65. page.addClass('active');
  66. return page;
  67. },
  68. displayError:function(error) {
  69. console.log(error);
  70. }
  71. }