databases.mako 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. <%!
  17. from desktop.views import commonheader, commonfooter
  18. from django.utils.translation import ugettext as _
  19. %>
  20. <%namespace name="actionbar" file="actionbar.mako" />
  21. <%namespace name="components" file="components.mako" />
  22. ${ commonheader(_('Databases'), 'metastore', user) | n,unicode }
  23. ${ components.menubar() }
  24. <div class="container-fluid" id="databases">
  25. <div class="row-fluid">
  26. % if has_write_access:
  27. <div class="span3">
  28. <div class="sidebar-nav card-small">
  29. <ul class="nav nav-list">
  30. <li class="nav-header">${_('actions')}</li>
  31. <li><a href="${ url('beeswax:create_database') }">${_('Create a new database')}</a></li>
  32. </ul>
  33. </div>
  34. </div>
  35. <div class="span9">
  36. %else:
  37. <div class="span12">
  38. % endif
  39. <div class="card card-small">
  40. <h1 class="card-heading simple">${ components.breadcrumbs(breadcrumbs) }</h1>
  41. <%actionbar:render>
  42. <%def name="search()">
  43. <input id="filterInput" type="text" class="input-xlarge search-query" placeholder="${_('Search for database name')}">
  44. </%def>
  45. <%def name="actions()">
  46. % if has_write_access:
  47. <button id="dropBtn" class="btn toolbarBtn" title="${_('Drop the selected databases')}" disabled="disabled"><i class="icon-trash"></i> ${_('Drop')}</button>
  48. % endif
  49. </%def>
  50. </%actionbar:render>
  51. <table class="table table-condensed datatables">
  52. <thead>
  53. <tr>
  54. <th width="1%"><div class="hueCheckbox selectAll" data-selectables="databaseCheck"></div></th>
  55. <th>${_('Database Name')}</th>
  56. </tr>
  57. </thead>
  58. <tbody>
  59. % for database in databases:
  60. <tr>
  61. <td data-row-selector-exclude="true" width="1%">
  62. <div class="hueCheckbox databaseCheck"
  63. data-view-url="${ url('metastore:show_tables', database=database) }"
  64. data-drop-name="${ database }"
  65. data-row-selector-exclude="true"></div>
  66. </td>
  67. <td>
  68. <a href="${ url('metastore:show_tables', database=database) }" data-row-selector="true">${ database }</a>
  69. </td>
  70. </tr>
  71. % endfor
  72. </tbody>
  73. </table>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div id="dropDatabase" class="modal hide fade">
  79. <form id="dropDatabaseForm" action="${ url('metastore:drop_database') }" method="POST">
  80. <div class="modal-header">
  81. <a href="#" class="close" data-dismiss="modal">&times;</a>
  82. <h3 id="dropDatabaseMessage">${_('Confirm action')}</h3>
  83. </div>
  84. <div class="modal-footer">
  85. <input type="button" class="btn" data-dismiss="modal" value="${_('Cancel')}" />
  86. <input type="submit" class="btn btn-danger" value="${_('Yes')}"/>
  87. </div>
  88. <div class="hide">
  89. <select name="database_selection" data-bind="options: availableDatabases, selectedOptions: chosenDatabases" size="5" multiple="true"></select>
  90. </div>
  91. </form>
  92. </div>
  93. <link rel="stylesheet" href="/metastore/static/css/metastore.css" type="text/css">
  94. <script src="/static/ext/js/knockout-min.js" type="text/javascript" charset="utf-8"></script>
  95. <script type="text/javascript" charset="utf-8">
  96. $(document).ready(function () {
  97. var viewModel = {
  98. availableDatabases: ko.observableArray(${ databases_json | n,unicode }),
  99. chosenDatabases: ko.observableArray([])
  100. };
  101. ko.applyBindings(viewModel);
  102. var databases = $(".datatables").dataTable({
  103. "sDom": "<'row'r>t<'row'<'span8'i><''p>>",
  104. "bPaginate": false,
  105. "bLengthChange": false,
  106. "bInfo": false,
  107. "bFilter": true,
  108. "aoColumns": [
  109. {"bSortable": false, "sWidth": "1%" },
  110. null
  111. ],
  112. "oLanguage": {
  113. "sEmptyTable": "${_('No data available')}",
  114. "sZeroRecords": "${_('No matching records')}",
  115. }
  116. });
  117. $("#filterInput").keyup(function () {
  118. databases.fnFilter($(this).val());
  119. });
  120. $("a[data-row-selector='true']").jHueRowSelector();
  121. $(".selectAll").click(function () {
  122. if ($(this).attr("checked")) {
  123. $(this).removeAttr("checked").removeClass("icon-ok");
  124. $("." + $(this).data("selectables")).removeClass("icon-ok").removeAttr("checked");
  125. }
  126. else {
  127. $(this).attr("checked", "checked").addClass("icon-ok");
  128. $("." + $(this).data("selectables")).addClass("icon-ok").attr("checked", "checked");
  129. }
  130. toggleActions();
  131. });
  132. $(".databaseCheck").click(function () {
  133. if ($(this).attr("checked")) {
  134. $(this).removeClass("icon-ok").removeAttr("checked");
  135. }
  136. else {
  137. $(this).addClass("icon-ok").attr("checked", "checked");
  138. }
  139. $(".selectAll").removeAttr("checked").removeClass("icon-ok");
  140. toggleActions();
  141. });
  142. function toggleActions() {
  143. $(".toolbarBtn").attr("disabled", "disabled");
  144. var selector = $(".hueCheckbox[checked='checked']");
  145. if (selector.length >= 1) {
  146. $("#dropBtn").removeAttr("disabled");
  147. }
  148. }
  149. $("#dropBtn").click(function () {
  150. $.getJSON("${ url('metastore:drop_database') }", function (data) {
  151. $("#dropDatabaseMessage").text(data.title);
  152. });
  153. viewModel.chosenDatabases.removeAll();
  154. $(".hueCheckbox[checked='checked']").each(function (index) {
  155. viewModel.chosenDatabases.push($(this).data("drop-name"));
  156. });
  157. $("#dropDatabase").modal("show");
  158. });
  159. });
  160. </script>
  161. ${ commonfooter(messages) | n,unicode }