/templates/library/common/browse_library.mako

https://bitbucket.org/cistrome/cistrome-harvard/ · Mako · 619 lines · 573 code · 38 blank · 8 comment · 18 complexity · f3190a0dfcac682441982f9af1b3e89f MD5 · raw file

  1. <%namespace file="/message.mako" import="render_msg" />
  2. <%namespace file="/library/common/library_item_info.mako" import="render_library_item_info" />
  3. <%namespace file="/library/common/common.mako" import="render_actions_on_multiple_items" />
  4. <%namespace file="/library/common/common.mako" import="render_compression_types_help" />
  5. <%namespace file="/library/common/common.mako" import="common_javascripts" />
  6. <%!
  7. def inherit(context):
  8. if context.get('use_panels'):
  9. return '/webapps/galaxy/base_panels.mako'
  10. else:
  11. return '/base.mako'
  12. %>
  13. <%inherit file="${inherit(context)}"/>
  14. <%def name="init()">
  15. <%
  16. self.has_left_panel=False
  17. self.has_right_panel=False
  18. self.message_box_visible=False
  19. self.active_view="user"
  20. self.overlay_visible=False
  21. self.has_accessible_datasets = False
  22. %>
  23. </%def>
  24. ##
  25. ## Override methods from base.mako and base_panels.mako
  26. ##
  27. <%def name="center_panel()">
  28. <div style="overflow: auto; height: 100%;">
  29. <div class="page-container" style="padding: 10px;">
  30. ${render_content()}
  31. </div>
  32. </div>
  33. </%def>
  34. ## Render the grid's basic elements. Each of these elements can be subclassed.
  35. <%def name="body()">
  36. ${render_content()}
  37. </%def>
  38. <%def name="title()">Browse data library</%def>
  39. <%def name="stylesheets()">
  40. ${parent.stylesheets()}
  41. ${h.css( "library" )}
  42. </%def>
  43. <%def name="javascripts()">
  44. ${parent.javascripts()}
  45. ${h.js("jstorage")}
  46. ${common_javascripts()}
  47. ${self.grid_javascripts()}
  48. </%def>
  49. <%def name="grid_javascripts()">
  50. <script type="text/javascript">
  51. var init_libraries = function() {
  52. var storage_id = "library-expand-state-${trans.security.encode_id(library.id)}";
  53. var restore_folder_state = function() {
  54. var state = $.jStorage.get(storage_id);
  55. if (state) {
  56. for (var id in state) {
  57. if (state[id] === true) {
  58. var row = $("#" + id),
  59. index = row.parent().children().index(row);
  60. row.addClass("expanded").show();
  61. row.siblings().filter("tr[parent='" + index + "']").show();
  62. }
  63. }
  64. }
  65. };
  66. var save_folder_state = function() {
  67. var state = {};
  68. $("tr.folderRow").each( function() {
  69. var folder = $(this);
  70. state[folder.attr("id")] = folder.hasClass("expanded");
  71. });
  72. $.jStorage.set(storage_id, state);
  73. };
  74. $("#library-grid").each(function() {
  75. var child_of_parent_cache = {};
  76. // Recursively fill in children and descendents of each row
  77. var process_row = function(q, parents) {
  78. // Find my index
  79. var parent = q.parent(),
  80. this_level = child_of_parent_cache[parent] || (child_of_parent_cache[parent] = parent.children());
  81. var index = this_level.index(q);
  82. // Find my immediate children
  83. var children = $(par_child_dict[index]);
  84. // Recursively handle them
  85. var descendents = children;
  86. children.each( function() {
  87. child_descendents = process_row( $(this), parents.add(q) );
  88. descendents = descendents.add(child_descendents);
  89. });
  90. // Set up expand / hide link
  91. var expand_fn = function() {
  92. if ( q.hasClass("expanded") ) {
  93. descendents.hide();
  94. descendents.removeClass("expanded");
  95. q.removeClass("expanded");
  96. } else {
  97. children.show();
  98. q.addClass("expanded");
  99. }
  100. save_folder_state();
  101. };
  102. $("." + q.attr("id") + "-click").click(expand_fn);
  103. // Check/uncheck boxes in subfolders.
  104. q.children("td").children("input[type=checkbox]").click( function() {
  105. if ( $(this).is(":checked") ) {
  106. descendents.find("input[type=checkbox]").attr("checked", true);
  107. } else {
  108. descendents.find("input[type=checkbox]").attr("checked", false);
  109. // If you uncheck a lower level checkbox, uncheck the boxes above it
  110. // (since deselecting a child means the parent is not fully selected any more).
  111. parents.children("td").children("input[type=checkbox]").attr("checked", false);
  112. }
  113. });
  114. // return descendents for use by parent
  115. return descendents;
  116. }
  117. // Initialize dict[parent_id] = rows_which_have_that_parent_id_as_parent_attr
  118. var par_child_dict = {},
  119. no_parent = [];
  120. $(this).find("tbody tr").each( function() {
  121. if ( $(this).attr("parent")) {
  122. var parent = $(this).attr("parent");
  123. if (par_child_dict[parent] !== undefined) {
  124. par_child_dict[parent].push(this);
  125. } else {
  126. par_child_dict[parent] = [this];
  127. }
  128. } else {
  129. no_parent.push(this);
  130. }
  131. });
  132. $(no_parent).each( function() {
  133. descendents = process_row( $(this), $([]) );
  134. descendents.hide();
  135. });
  136. });
  137. restore_folder_state();
  138. };
  139. $(function() {
  140. init_libraries();
  141. });
  142. // Looks for changes in dataset state using an async request. Keeps
  143. // calling itself (via setTimeout) until all datasets are in a terminal
  144. // state.
  145. var updater = function ( tracked_datasets ) {
  146. // Check if there are any items left to track
  147. var empty = true;
  148. for ( i in tracked_datasets ) {
  149. empty = false;
  150. break;
  151. }
  152. if ( ! empty ) {
  153. setTimeout( function() { updater_callback( tracked_datasets ) }, 3000 );
  154. }
  155. };
  156. var updater_callback = function ( tracked_datasets ) {
  157. // Build request data
  158. var ids = []
  159. var states = []
  160. $.each( tracked_datasets, function ( id, state ) {
  161. ids.push( id );
  162. states.push( state );
  163. });
  164. // Make ajax call
  165. $.ajax( {
  166. type: "POST",
  167. url: "${h.url_for( controller='library_common', action='library_item_updates' )}",
  168. dataType: "json",
  169. data: { ids: ids.join( "," ), states: states.join( "," ) },
  170. success : function ( data ) {
  171. $.each( data, function( id, val ) {
  172. // Replace HTML
  173. var cell = $("#libraryItem-" + id).find("#libraryItemInfo");
  174. cell.html( val.html );
  175. // If new state was terminal, stop tracking
  176. if (( val.state == "ok") || ( val.state == "error") || ( val.state == "empty") || ( val.state == "deleted" ) || ( val.state == "discarded" )) {
  177. delete tracked_datasets[ parseInt(id) ];
  178. } else {
  179. tracked_datasets[ parseInt(id) ] = val.state;
  180. }
  181. });
  182. updater( tracked_datasets );
  183. },
  184. error: function() {
  185. // Just retry, like the old method, should try to be smarter
  186. updater( tracked_datasets );
  187. }
  188. });
  189. };
  190. </script>
  191. </%def>
  192. <%def name="render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, parent, row_counter, tracked_datasets, show_deleted=False, simple=False )">
  193. <%
  194. ## The received ldda must always be a LibraryDatasetDatasetAssociation object. The object id passed to methods
  195. ## from the drop down menu should be the ldda id to prevent id collision ( which could happen when displaying
  196. ## children, which are always lddas ). We also need to make sure we're displaying the latest version of this
  197. ## library_dataset, so we display the attributes from the ldda.
  198. from galaxy.web.controllers.library_common import branch_deleted
  199. is_admin = trans.user_is_admin() and cntrller == 'library_admin'
  200. if ldda.user:
  201. uploaded_by = ldda.user.email
  202. else:
  203. uploaded_by = 'anonymous'
  204. if ldda == library_dataset.library_dataset_dataset_association:
  205. current_version = True
  206. if is_admin:
  207. can_modify = can_manage = True
  208. elif cntrller in [ 'library', 'requests' ]:
  209. can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library_dataset )
  210. can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library_dataset )
  211. else:
  212. can_modify = can_manage = False
  213. else:
  214. current_version = False
  215. if current_version and ldda.state not in ( 'ok', 'error', 'empty', 'deleted', 'discarded' ):
  216. tracked_datasets[ldda.id] = ldda.state
  217. info_association, inherited = ldda.get_info_association( restrict=True )
  218. form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
  219. %>
  220. %if current_version and ( not ldda.library_dataset.deleted or show_deleted ):
  221. <tr class="datasetRow"
  222. %if parent is not None:
  223. parent="${parent}"
  224. %endif
  225. id="libraryItem-${ldda.id}">
  226. <td style="padding-left: ${pad+20}px;">
  227. <input style="float: left;" type="checkbox" name="ldda_ids" id="${trans.security.encode_id( ldda.id )}" value="${trans.security.encode_id( ldda.id )}"
  228. %if selected:
  229. checked="checked"
  230. %endif
  231. />
  232. %if simple:
  233. <label for="${trans.security.encode_id( ldda.id )}">${ldda.name}</label>
  234. %else:
  235. <div style="float: left; margin-left: 1px;" class="menubutton split popup" id="dataset-${ldda.id}-popup">
  236. <a class="view-info" href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">
  237. %if ldda.library_dataset.deleted:
  238. <div class="libraryItem-error">${ldda.name}</div>
  239. %else:
  240. ${ldda.name}
  241. %endif
  242. </a>
  243. </div>
  244. %if not library.deleted:
  245. <div popupmenu="dataset-${ldda.id}-popup">
  246. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify:
  247. <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
  248. <a class="action-button" href="${h.url_for( controller='library_common', action='move_library_item', cntrller=cntrller, item_type='ldda', item_id=trans.security.encode_id( ldda.id ), source_library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Move this dataset</a>
  249. %else:
  250. <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">View information</a>
  251. %endif
  252. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify and not info_association:
  253. <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
  254. %endif
  255. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify and info_association:
  256. <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
  257. <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
  258. %endif
  259. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_manage:
  260. %if not trans.app.security_agent.dataset_is_public( ldda.dataset ):
  261. <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='ldda', id=trans.security.encode_id( ldda.dataset.id ), use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
  262. %endif
  263. <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
  264. %endif
  265. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify:
  266. <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), replace_id=trans.security.encode_id( library_dataset.id ), show_deleted=show_deleted )}">Upload a new version of this dataset</a>
  267. %endif
  268. %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ldda.has_data:
  269. <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Import this dataset into selected histories</a>
  270. <a class="action-button" href="${h.url_for( controller='library_common', action='download_dataset_from_folder', cntrller=cntrller, id=trans.security.encode_id( ldda.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels )}">Download this dataset</a>
  271. %endif
  272. %if can_modify:
  273. %if not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.deleted:
  274. <a class="action-button" confirm="Click OK to delete dataset '${ldda.name}'." href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library_dataset.id ), item_type='library_dataset', show_deleted=show_deleted )}">Delete this dataset</a>
  275. %elif not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.purged and ldda.library_dataset.deleted:
  276. <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library_dataset.id ), item_type='library_dataset', show_deleted=show_deleted )}">Undelete this dataset</a>
  277. %endif
  278. %endif
  279. </div>
  280. %endif
  281. %endif
  282. </td>
  283. % if not simple:
  284. <td id="libraryItemInfo">${render_library_item_info( ldda )}</td>
  285. <td>${uploaded_by}</td>
  286. % endif
  287. <td>${ldda.create_time.strftime( "%Y-%m-%d" )}</td>
  288. <td>${ldda.get_size( nice_size=True )}</td>
  289. </tr>
  290. <%
  291. my_row = row_counter.count
  292. row_counter.increment()
  293. %>
  294. %endif
  295. </%def>
  296. <%def name="render_folder( cntrller, folder, folder_pad, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=False, parent=None, row_counter=None, root_folder=False, simple=False )">
  297. <%
  298. from galaxy.web.controllers.library_common import active_folders, active_folders_and_library_datasets, activatable_folders_and_library_datasets, branch_deleted
  299. is_admin = trans.user_is_admin() and cntrller == 'library_admin'
  300. has_accessible_library_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, folder, trans.user, current_user_roles, search_downward=False )
  301. if root_folder:
  302. pad = folder_pad
  303. expander = h.url_for("/static/images/silk/resultset_bottom.png")
  304. folder_img = h.url_for("/static/images/silk/folder_page.png")
  305. else:
  306. pad = folder_pad + 20
  307. expander = h.url_for("/static/images/silk/resultset_next.png")
  308. folder_img = h.url_for("/static/images/silk/folder.png")
  309. if created_ldda_ids:
  310. created_ldda_ids = util.listify( created_ldda_ids )
  311. if str( folder.id ) in hidden_folder_ids:
  312. return ""
  313. my_row = None
  314. if is_admin:
  315. can_add = can_modify = can_manage = True
  316. elif cntrller in [ 'library' ]:
  317. can_access, folder_ids = trans.app.security_agent.check_folder_contents( trans.user, current_user_roles, folder )
  318. if not can_access:
  319. can_show, folder_ids = \
  320. trans.app.security_agent.show_library_item( trans.user,
  321. current_user_roles,
  322. folder,
  323. [ trans.app.security_agent.permitted_actions.LIBRARY_ADD,
  324. trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
  325. trans.app.security_agent.permitted_actions.LIBRARY_MANAGE ] )
  326. if not can_show:
  327. return ""
  328. can_add = trans.app.security_agent.can_add_library_item( current_user_roles, folder )
  329. can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, folder )
  330. can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, folder )
  331. else:
  332. can_add = can_modify = can_manage = False
  333. form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
  334. info_association, inherited = folder.get_info_association( restrict=True )
  335. %>
  336. %if not root_folder and ( not folder.deleted or show_deleted ):
  337. <% encoded_id = trans.security.encode_id( folder.id ) %>
  338. <tr id="folder-${encoded_id}" class="folderRow libraryOrFolderRow"
  339. %if parent is not None:
  340. parent="${parent}"
  341. style="display: none;"
  342. %endif
  343. >
  344. <td style="padding-left: ${folder_pad}px;">
  345. <input type="checkbox" class="folderCheckbox"/>
  346. <span class="expandLink folder-${encoded_id}-click">
  347. <div style="float: left; margin-left: 2px;" class="menubutton split popup" id="folder_img-${folder.id}-popup">
  348. <a class="folder-${encoded_id}-click" href="javascript:void(0);">
  349. <span class="rowIcon"></span>
  350. %if folder.deleted:
  351. <div class="libraryItem-error">${folder.name}</div>
  352. %else:
  353. ${folder.name}
  354. %endif
  355. </a>
  356. </div>
  357. </span>
  358. %if not library.deleted:
  359. <div popupmenu="folder_img-${folder.id}-popup">
  360. %if not branch_deleted( folder ) and can_add:
  361. <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add datasets</a>
  362. <a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add sub-folder</a>
  363. %endif
  364. %if not branch_deleted( folder ):
  365. %if has_accessible_library_datasets:
  366. <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Select datasets for import into selected histories</a>
  367. %endif
  368. %if can_modify:
  369. <a class="action-button" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
  370. <a class="action-button" href="${h.url_for( controller='library_common', action='move_library_item', cntrller=cntrller, item_type='folder', item_id=trans.security.encode_id( folder.id ), source_library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Move this folder</a>
  371. %else:
  372. <a class="action-button" class="view-info" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">View information</a>
  373. %endif
  374. %endif
  375. %if not branch_deleted( folder ) and can_modify and not info_association:
  376. <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
  377. %endif
  378. %if not branch_deleted( folder ) and can_modify and info_association:
  379. <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
  380. <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
  381. %endif
  382. %if not branch_deleted( folder ) and can_manage:
  383. %if not trans.app.security_agent.folder_is_public( folder ):
  384. <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='folder', id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
  385. %endif
  386. <a class="action-button" href="${h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
  387. %endif
  388. %if can_modify:
  389. %if not library.deleted and not folder.deleted:
  390. <a class="action-button" confirm="Click OK to delete the folder '${folder.name}.'" href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Delete this folder</a>
  391. %elif not library.deleted and folder.deleted and not folder.purged:
  392. <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Undelete this folder</a>
  393. %endif
  394. %endif
  395. </div>
  396. %endif
  397. <td>
  398. %if folder.description:
  399. ${folder.description}
  400. %endif
  401. <td colspan="3"></td>
  402. </tr>
  403. <%
  404. my_row = row_counter.count
  405. row_counter.increment()
  406. %>
  407. %endif
  408. <%
  409. if show_deleted:
  410. sub_folders, library_datasets = activatable_folders_and_library_datasets( trans, folder )
  411. else:
  412. sub_folders, library_datasets = active_folders_and_library_datasets( trans, folder )
  413. %>
  414. %if is_admin:
  415. %for sub_folder in sub_folders:
  416. ${render_folder( cntrller, sub_folder, pad, created_ldda_ids, library, [], tracked_datasets, show_deleted=show_deleted, parent=my_row, row_counter=row_counter, root_folder=False )}
  417. %endfor
  418. %for library_dataset in library_datasets:
  419. <%
  420. ldda = library_dataset.library_dataset_dataset_association
  421. if ldda:
  422. # There should always be an ldda, but some users running their own instances have reported that
  423. # some of their LibraryDatasets have no associated lddas
  424. selected = created_ldda_ids and str( ldda.id ) in created_ldda_ids
  425. %>
  426. %if ldda:
  427. ${render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, my_row, row_counter, tracked_datasets, show_deleted=show_deleted )}
  428. %endif
  429. %endfor
  430. %else:
  431. %for sub_folder in sub_folders:
  432. ${render_folder( cntrller, sub_folder, pad, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=show_deleted, parent=my_row, row_counter=row_counter, root_folder=False, simple=simple )}
  433. %endfor
  434. %for library_dataset in library_datasets:
  435. <%
  436. ldda = library_dataset.library_dataset_dataset_association
  437. if ldda:
  438. # There should always be an ldda, but some users running their own instances have reported that
  439. # some of their LibraryDatasets have no associated lddas
  440. can_access = trans.app.security_agent.can_access_dataset( current_user_roles, ldda.dataset )
  441. selected = created_ldda_ids and str( ldda.id ) in created_ldda_ids
  442. else:
  443. can_access = False
  444. %>
  445. %if can_access:
  446. ${render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, my_row, row_counter, tracked_datasets, show_deleted=show_deleted, simple=simple )}
  447. %endif
  448. %endfor
  449. %endif
  450. </%def>
  451. <%def name="render_content(simple=False)">
  452. <%
  453. from galaxy import util
  454. from galaxy.web.controllers.library_common import branch_deleted
  455. from time import strftime
  456. is_admin = trans.user_is_admin() and cntrller == 'library_admin'
  457. if is_admin:
  458. can_add = can_modify = can_manage = True
  459. elif cntrller in [ 'library', 'requests' ]:
  460. can_add = trans.app.security_agent.can_add_library_item( current_user_roles, library )
  461. can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library )
  462. can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library )
  463. else:
  464. can_add = can_modify = can_manage = False
  465. info_association, inherited = library.get_info_association()
  466. form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
  467. self.has_accessible_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, library.root_folder, trans.user, current_user_roles )
  468. root_folder_has_accessible_library_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, library.root_folder, trans.user, current_user_roles, search_downward=False )
  469. has_accessible_folders = is_admin or trans.app.security_agent.has_accessible_folders( trans, library.root_folder, trans.user, current_user_roles )
  470. tracked_datasets = {}
  471. class RowCounter( object ):
  472. def __init__( self ):
  473. self.count = 0
  474. def increment( self ):
  475. self.count += 1
  476. def __str__( self ):
  477. return str( self.count )
  478. %>
  479. <h2>Data Library &ldquo;${library.name}&rdquo;</h2>
  480. <ul class="manage-table-actions">
  481. %if not library.deleted and ( is_admin or can_add ):
  482. <li><a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add datasets</a></li>
  483. <li><a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( library.root_folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add folder</a></li>
  484. %endif
  485. %if ( ( not library.deleted ) and ( can_modify or can_manage ) ) or ( can_modify and not library.purged ) or ( library.purged ):
  486. <li><a class="action-button" id="library-${library.id}-popup" class="menubutton">Library Actions</a></li>
  487. <div popupmenu="library-${library.id}-popup">
  488. %if not library.deleted:
  489. %if can_modify:
  490. <a class="action-button" href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
  491. <a class="action-button" confirm="Click OK to delete the library named '${library.name}'." href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Delete this data library</a>
  492. %if show_deleted:
  493. <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=False )}">Hide deleted items</a>
  494. %else:
  495. <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=True )}">Show deleted items</a>
  496. %endif
  497. %endif
  498. %if can_modify and not library.info_association:
  499. <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
  500. %endif
  501. %if can_modify and info_association:
  502. <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
  503. <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
  504. %endif
  505. %if can_manage:
  506. %if not trans.app.security_agent.library_is_public( library, contents=True ):
  507. <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='library', id=trans.security.encode_id( library.id ), contents=True, use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
  508. %endif
  509. <a class="action-button" href="${h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
  510. %endif
  511. %if root_folder_has_accessible_library_datasets:
  512. <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Select datasets for import into selected histories</a>
  513. %endif
  514. %elif can_modify and not library.purged:
  515. <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library', use_panels=use_panels )}">Undelete this data library</a>
  516. %elif library.purged:
  517. <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">This data library has been purged</a>
  518. %endif
  519. </div>
  520. %endif
  521. </ul>
  522. %if message:
  523. ${render_msg( message, status )}
  524. %endif
  525. %if library.synopsis not in [ '', 'None', None ]:
  526. <div class="libraryItemBody">
  527. ${library.synopsis}
  528. </div>
  529. %endif
  530. %if self.has_accessible_datasets:
  531. <form name="act_on_multiple_datasets" action="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}" onSubmit="javascript:return checkForm();" method="post">
  532. %endif
  533. %if has_accessible_folders:
  534. <table cellspacing="0" cellpadding="0" border="0" width="100%" class="grid" id="library-grid">
  535. <thead>
  536. <tr class="libraryTitle">
  537. <th>
  538. %if self.has_accessible_datasets:
  539. <input type="checkbox" id="checkAll" name=select_all_datasets_checkbox value="true" onclick='checkAllFields(1);'/><input type="hidden" name=select_all_datasets_checkbox value="true"/>
  540. %endif
  541. Name
  542. </th>
  543. % if not simple:
  544. <th>Message</th>
  545. <th>Uploaded By</th>
  546. % endif
  547. <th>Date</th>
  548. <th>File Size</th>
  549. </tr>
  550. </thead>
  551. <% row_counter = RowCounter() %>
  552. %if cntrller in [ 'library', 'requests' ]:
  553. ${self.render_folder( 'library', library.root_folder, 0, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=show_deleted, parent=None, row_counter=row_counter, root_folder=True, simple=simple )}
  554. %if not library.deleted and self.has_accessible_datasets and not simple:
  555. ${render_actions_on_multiple_items()}
  556. %endif
  557. %elif ( trans.user_is_admin() and cntrller in [ 'library_admin', 'requests_admin' ] ):
  558. ${self.render_folder( 'library_admin', library.root_folder, 0, created_ldda_ids, library, [], tracked_datasets, show_deleted=show_deleted, parent=None, row_counter=row_counter, root_folder=True )}
  559. %if not library.deleted and not show_deleted and self.has_accessible_datasets:
  560. ${render_actions_on_multiple_items()}
  561. %endif
  562. %endif
  563. </table>
  564. %endif
  565. %if self.has_accessible_datasets:
  566. </form>
  567. %endif
  568. %if tracked_datasets:
  569. <script type="text/javascript">
  570. // Updater
  571. updater({${ ",".join( [ '"%s" : "%s"' % ( k, v ) for k, v in tracked_datasets.iteritems() ] ) }});
  572. </script>
  573. <!-- running: do not change this comment, used by TwillTestCase.library_wait -->
  574. %endif
  575. %if self.has_accessible_datasets and not simple:
  576. ${render_compression_types_help( comptypes )}
  577. %endif
  578. %if not has_accessible_folders:
  579. The data library '${library.name}' does not contain any datasets that you can access.
  580. %endif
  581. </%def>