listdir_components.mako 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. import datetime
  18. from django.template.defaultfilters import urlencode, stringformat, filesizeformat, date, time
  19. %>
  20. <%def name="list_table_chooser(files, path_enc, current_request_path)">
  21. ${_table(files, path_enc, current_request_path, 'chooser')}
  22. </%def>
  23. <%def name="list_table_browser(files, path_enc, current_request_path, cwd_set=True)">
  24. ${_table(files, path_enc, current_request_path, 'view', cwd_set)}
  25. </%def>
  26. <%def name="_table(files, path_enc, current_request_path, view, cwd_set=False)">
  27. <table data-filters="HtmlTable" class="fb-file-list selectable sortable" cellpadding="0" cellspacing="0">
  28. <thead>
  29. <tr>
  30. % if cwd_set:
  31. <th>Name</th>
  32. % else:
  33. <th>Path</th>
  34. % endif
  35. <th>Size</th>
  36. <th>User</th>
  37. <th>Group</th>
  38. <th>Permissions</th>
  39. <th colspan="2">Date</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. % for file in files:
  44. <%
  45. cls = ''
  46. if (file_filter == 'dir' and file['type'] != 'dir') or (file_filter != 'dir' and file['type'] == 'dir'):
  47. if (file_filter != 'any'):
  48. cls = ' not-selectable'
  49. if cwd_set:
  50. display_name = file['name']
  51. else:
  52. display_name = file['path']
  53. endif
  54. %>
  55. ## Since path is in unicode, Django and Mako handle url encoding and
  56. ## iri encoding correctly for us.
  57. <% path_enc = file['path'] %>
  58. <tr class="ccs-no_select fb-item-row ${cls}"
  59. data-filters="ContextMenu"
  60. data-context-menu-actions="[{'events':['contextmenu','click:relay(.fb-item-options)'],'menu':'ul.context-menu'}]"
  61. data-dblclick-delegate= "{'dblclick_loads':'a.fb-item'}" data-filedata="{'path':'${path_enc}','type':'${file['type']|u}'}">
  62. <td class="fb-name">
  63. <div class="fb-name-container">
  64. % if "dir" == file['type']:
  65. <a data-filters="FitText" class="fb-item fb-dir jframe_ignore" href="${url('filebrowser.views.'+view, path=path_enc)}?file_filter=${file_filter}">${display_name}</a>
  66. % else:
  67. <a data-filters="FitText" class="fb-item fb-file jframe_ignore" target="FileViewer" href="${url('filebrowser.views.'+view, path=path_enc)}?file_filter=${file_filter}">${display_name}</a>
  68. % endif
  69. % if ".." != file['name']:
  70. <ul class="fb-item-actions context-menu">
  71. % if "dir" == file['type']:
  72. <li class="fb-rmdir-container"><a class="fb-rmdir confirm_and_post" alt="Are you sure you want to remove this directory and its contents?" href="${url('filebrowser.views.rmdir')}?path=${path_enc}&next=${urlencode(current_request_path)}">Remove</a></li>
  73. <li class="fb-rmtree-container"><a class="fb-rmtree confirm_and_post fb-default-rm" alt="Are you sure you want to remove this directory and its contents?" href="${url('filebrowser.views.rmtree')}?path=${path_enc}&next=${urlencode(current_request_path)}">Remove</a></li>
  74. % else:
  75. <li><a class="fb-viewfile" href="${url('filebrowser.views.view', path=path_enc)}" target="FileViewer">View File</a></li>
  76. <li><a class="fb-editfile" href="${url('filebrowser.views.edit', path=path_enc)}" target="FileEditor">Edit File</a></li>
  77. <li class="fb-rm-container"><a class="fb-rm fb-default-rm confirm_and_post" alt="Are you sure you want to remove this file?" href="${url('filebrowser.views.remove')}?path=${path_enc}&next=${urlencode(current_request_path)}">Remove</a></li>
  78. % endif
  79. <li class="fb-rename-container"><a class="fb-rename" href="${url('filebrowser.views.rename')}?src_path=${path_enc}&next=${urlencode(current_request_path)}">Rename</a></li>
  80. <li class="fb-chown-container"><a class="fb-chown" href="${url('filebrowser.views.chown') }?path=${path_enc}&user=${file['stats']['user']}&group=${file['stats']['group']}&next=${urlencode(current_request_path)}">Change Owner / Group</a></li>
  81. <li class="fb-chmod-container"><a class="fb-chmod" href="${url('filebrowser.views.chmod')}?path=${path_enc}&mode=${stringformat(file['stats']['mode'], "o")}&next=${urlencode(current_request_path)}">Change Permissions</a></li>
  82. <%
  83. if "dir" == file['type']:
  84. cls = "fb-move-dir"
  85. else:
  86. cls = "fb-move-file"
  87. %>
  88. <li><a class="fb-move ${cls}" href="${url('filebrowser.views.move')}?src_path=${path_enc}&mode=${stringformat(file['stats']['mode'], "o")}&next=${urlencode(current_request_path)}">Move File</a></li>
  89. </ul>
  90. % endif
  91. </div>
  92. </td>
  93. <%
  94. if "dir" == file['type']:
  95. sortValue = 0;
  96. else:
  97. sortValue = file['stats']['size']
  98. %>
  99. <td class="fb-filesize">
  100. % if "dir" == file['type']:
  101. <span data-sort-number="${sortValue}">~</span>
  102. % else:
  103. <span data-sort-number="${sortValue}">${file['stats']['size']|filesizeformat}</span>
  104. % endif
  105. </td>
  106. <td class="fb-user">${file['stats']['user']}</td>
  107. <td class="fb-group">${file['stats']['group']}</td>
  108. <td class="fb-perm">${file['rwx']}</td>
  109. <td class="fb-date">${date(datetime.datetime.fromtimestamp(file['stats']['mtime']))} ${time(datetime.datetime.fromtimestamp(file['stats']['mtime']))}</td>
  110. <td class="fb-option-links">
  111. % if ".." != file['name']:
  112. <a class="fb-item-options">options</a>
  113. % endif
  114. </td>
  115. </tr>
  116. % endfor
  117. </tbody>
  118. </table>
  119. </%def>