commit/galaxy-central: martenson: data libraries: API improvements; add datasets from history to folder; folder contents sorting; progressive rendering; new error code; new API endpoint; js model comparators; Galaxy.currUser defensive programming;
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/166660f085a5/ Changeset: 166660f085a5 User: martenson Date: 2014-04-16 22:27:13 Summary: data libraries: API improvements; add datasets from history to folder; folder contents sorting; progressive rendering; new error code; new API endpoint; js model comparators; Galaxy.currUser defensive programming; Affected #: 14 files diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 lib/galaxy/exceptions/__init__.py --- a/lib/galaxy/exceptions/__init__.py +++ b/lib/galaxy/exceptions/__init__.py @@ -89,6 +89,10 @@ status_code = 403 err_code = error_codes.CONFIG_DOES_NOT_ALLOW +class InsufficientPermissionsException( MessageException ): + status_code = 403 + err_code = error_codes.INSUFFICIENT_PERMISSIONS + class ObjectNotFound( MessageException ): """ Accessed object was not found """ status_code = 404 diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 lib/galaxy/exceptions/error_codes.json --- a/lib/galaxy/exceptions/error_codes.json +++ b/lib/galaxy/exceptions/error_codes.json @@ -75,6 +75,11 @@ "message": "The configuration of this Galaxy instance does not allow that operation" }, { + "name": "INSUFFICIENT_PERMISSIONS", + "code": 403005, + "message": "You don't have proper permissions to perform the requested operation" + }, + { "name": "USER_OBJECT_NOT_FOUND", "code": 404001, "message": "No such object found." diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 lib/galaxy/webapps/galaxy/api/folder_contents.py --- a/lib/galaxy/webapps/galaxy/api/folder_contents.py +++ b/lib/galaxy/webapps/galaxy/api/folder_contents.py @@ -7,12 +7,12 @@ from galaxy.web import _future_expose_api_anonymous as expose_api_anonymous from sqlalchemy.orm.exc import MultipleResultsFound from sqlalchemy.orm.exc import NoResultFound -from galaxy.web.base.controller import BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems +from galaxy.web.base.controller import BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems, UsesHistoryDatasetAssociationMixin import logging log = logging.getLogger( __name__ ) -class FolderContentsController( BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems ): +class FolderContentsController( BaseAPIController, UsesLibraryMixin, UsesLibraryMixinItems, UsesHistoryDatasetAssociationMixin ): """ Class controls retrieval, creation and updating of folder contents. """ @@ -146,6 +146,55 @@ content_items.append( dataset ) return content_items + @expose_api + def create( self, trans, encoded_folder_id, payload, **kwd ): + """ + create( self, trans, library_id, payload, **kwd ) + * POST /api/folders/{encoded_id}/contents + create a new library file from an HDA + + :param payload: dictionary structure containing: + :type payload: dict + + * folder_id: the parent folder of the new item + * from_hda_id: (optional) the id of an accessible HDA to copy into the library + * ldda_message: (optional) the new message attribute of the LDDA created + * extended_metadata: (optional) dub-dictionary containing any extended + metadata to associate with the item + + :returns: a dictionary containing the id, name, and 'show' url of the new item + :rtype: dict + """ + class_name, encoded_folder_id_16 = self.__decode_library_content_id( trans, encoded_folder_id ) + from_hda_id, ldda_message = ( payload.pop( 'from_hda_id', None ), payload.pop( 'ldda_message', '' ) ) + if ldda_message: + ldda_message = util.sanitize_html.sanitize_html( ldda_message, 'utf-8' ) + rval = {} + try: + hda = self.get_dataset( trans, from_hda_id, check_ownership=True, check_accessible=True, check_state=True ) + folder = self.get_library_folder( trans, encoded_folder_id_16, check_accessible=True ) + + if not self.can_current_user_add_to_library_item( trans, folder ): + raise exceptions.InsufficientPermissionsException( 'You do not have proper permissions to add a dataset to a folder with id (%s)' % ( encoded_folder_id ) ) + + ldda = self.copy_hda_to_library_folder( trans, hda, folder, ldda_message=ldda_message ) + ldda_dict = ldda.to_dict() + rval = trans.security.encode_dict_ids( ldda_dict ) + + except Exception, exc: + if 'not accessible to the current user' in str( exc ): + raise exceptions.ItemAccessibilityException( 'You do not have access to the requested item' ) + else: + log.exception( exc ) + raise exceptions.InternalServerError( 'An unknown error ocurred. Please try again.' ) + return rval + + def __decode_library_content_id( self, trans, encoded_folder_id ): + if ( len( encoded_folder_id ) == 17 and encoded_folder_id.startswith( 'F' )): + return 'LibraryFolder', encoded_folder_id[1:] + else: + raise exceptions.MalformedId( 'Malformed folder id ( %s ) specified, unable to decode.' % str( encoded_folder_id ) ) + @web.expose_api def show( self, trans, id, library_id, **kwd ): """ @@ -154,15 +203,6 @@ raise exceptions.NotImplemented( 'Showing the library folder content is not implemented.' ) @web.expose_api - def create( self, trans, library_id, payload, **kwd ): - """ - POST /api/folders/{encoded_folder_id}/contents - Creates a new folder. This should be superseded by the - LibraryController. - """ - raise exceptions.NotImplemented( 'Creating the library folder content is not implemented.' ) - - @web.expose_api def update( self, trans, id, library_id, payload, **kwd ): """ PUT /api/folders/{encoded_folder_id}/contents diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 lib/galaxy/webapps/galaxy/buildapp.py --- a/lib/galaxy/webapps/galaxy/buildapp.py +++ b/lib/galaxy/webapps/galaxy/buildapp.py @@ -224,26 +224,9 @@ action='download', conditions=dict( method=[ "POST", "GET" ] ) ) - webapp.mapper.connect( 'create_folder', - '/api/folders/:encoded_parent_folder_id', - controller='folders', - action='create', - conditions=dict( method=[ "POST" ] ) ) - webapp.mapper.resource_with_deleted( 'library', 'libraries', path_prefix='/api' ) - webapp.mapper.resource( 'folder', - 'folders', - path_prefix='/api' ) - - webapp.mapper.resource( 'content', - 'contents', - controller='folder_contents', - name_prefix='folder_', - path_prefix='/api/folders/:folder_id', - parent_resources=dict( member_name='folder', collection_name='folders' ), - conditions=dict( method=[ "GET" ] ) ) webapp.mapper.resource( 'content', 'contents', @@ -257,6 +240,38 @@ path_prefix='/api/libraries/:library_id', parent_resources=dict( member_name='library', collection_name='libraries' ) ) + _add_item_extended_metadata_controller( webapp, + name_prefix="library_dataset_", + path_prefix='/api/libraries/:library_id/contents/:library_content_id' ) + + # ======================= + # ===== FOLDERS API ===== + # ======================= + + webapp.mapper.connect( 'add_history_datasets_to_library', + '/api/folders/:encoded_folder_id/contents', + controller='folder_contents', + action='create', + conditions=dict( method=[ "POST" ] ) ) + + webapp.mapper.connect( 'create_folder', + '/api/folders/:encoded_parent_folder_id', + controller='folders', + action='create', + conditions=dict( method=[ "POST" ] ) ) + + webapp.mapper.resource( 'folder', + 'folders', + path_prefix='/api' ) + + webapp.mapper.resource( 'content', + 'contents', + controller='folder_contents', + name_prefix='folder_', + path_prefix='/api/folders/:folder_id', + parent_resources=dict( member_name='folder', collection_name='folders' ), + conditions=dict( method=[ "GET" ] ) ) + webapp.mapper.resource( 'job', 'jobs', path_prefix='/api' ) @@ -268,12 +283,7 @@ controller="job_files", name_prefix="job_", path_prefix='/api/jobs/:job_id', - parent_resources=dict( member_name="job", collection_name="jobs") - ) - - _add_item_extended_metadata_controller( webapp, - name_prefix="library_dataset_", - path_prefix='/api/libraries/:library_id/contents/:library_content_id' ) + parent_resources=dict( member_name="job", collection_name="jobs" ) ) _add_item_extended_metadata_controller( webapp, name_prefix="history_dataset_", diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/mvc/library/library-folderlist-view.js --- a/static/scripts/mvc/library/library-folderlist-view.js +++ b/static/scripts/mvc/library/library-folderlist-view.js @@ -23,10 +23,13 @@ folderContainer: null, + sort: 'asc', + // event binding events: { - 'click #select-all-checkboxes' : 'selectAll', - 'click .dataset_row' : 'selectClickedRow' + 'click #select-all-checkboxes' : 'selectAll', + 'click .dataset_row' : 'selectClickedRow', + 'click .sort-folder-link' : 'sort_clicked' }, // initialize initialize : function(options){ @@ -34,12 +37,18 @@ this.options = _.defaults(this.options || {}, options); this.queue = jQuery.Deferred(); this.queue.resolve(); - + this.collection = new mod_library_model.Folder(); + this.listenTo(this.collection, 'add', this.addOne); + this.folderContainer = new mod_library_model.FolderContainer({id: this.options.id}); this.folderContainer.url = this.folderContainer.attributes.urlRoot + this.options.id + '/contents'; this.folderContainer.fetch({ - success: function (folderContainer) { - that.render(); + success: function (folder_container) { + that.render(); + + var items = folder_container.get('folder').models; + that.addAll(items); + }, error: function(){ mod_toastr.error('An error occured :('); @@ -54,13 +63,13 @@ // TODO move to server // prepare nice size strings - for (var i = 0; i < this.folderContainer.attributes.folder.models.length; i++) { - var model = this.folderContainer.attributes.folder.models[i]; - if (model.get('type') === 'file'){ - contains_file = true; - model.set('readable_size', this.size_to_string(model.get('file_size'))); - } - } + // for (var i = 0; i < this.collection.models.length; i++) { + // var model = this.collection.models[i]; + // if (model.get('type') === 'file'){ + // contains_file = true; + // model.set('readable_size', this.size_to_string(model.get('file_size'))); + // } + // } // TODO move to server // find the upper id in the full path @@ -73,16 +82,16 @@ } // TODO add template when folder is empty - this.$el.html(template({ path: this.folderContainer.attributes.metadata.full_path, id: this.options.id, upper_folder_id: upper_folder_id })); + this.$el.html(template({ path: this.folderContainer.attributes.metadata.full_path, id: this.options.id, upper_folder_id: upper_folder_id, order: this.sort})); // this.$el.html(template({ path: this.folderContainer.attributes.metadata.full_path, items: this.folderContainer.attributes.folder.models, id: this.options.id, upper_folder_id: upper_folder_id })); - if (this.folderContainer.attributes.folder.models.length > 0){ + if (this.collection.models.length > 0){ this.renderRows(); } // if (this.folderContainer.attributes.metadata.can_add_library_item === true){ - var metadata = this.folderContainer.attributes.metadata; - metadata.contains_file = contains_file; - Galaxy.libraries.folderToolbarView.configureElements(metadata); + var options = this.folderContainer.attributes.metadata; + options.contains_file = this.options.contains_file; + Galaxy.libraries.folderToolbarView.configureElements(options); // Galaxy.libraries.folderToolbarView.configureElements({ can_add_library_item: this.folderContainer.attributes.metadata.can_add_library_item, contains_file: contains_file }); // } @@ -93,92 +102,128 @@ }, renderRows: function(){ - for (var i = 0; i < this.folderContainer.attributes.folder.models.length; i++) { - var folder_item = this.folderContainer.attributes.folder.models[i]; + for (var i = 0; i < this.collection.models.length; i++) { + var folder_item = this.collection.models[i]; var rowView = new mod_library_folderrow_view.FolderRowView(folder_item); this.$el.find('#folder_list_body').append(rowView.el); } }, - // convert size to nice string - size_to_string : function (size){ - // identify unit - var unit = ""; - if (size >= 100000000000) { size = size / 100000000000; unit = "TB"; } else - if (size >= 100000000) { size = size / 100000000; unit = "GB"; } else - if (size >= 100000) { size = size / 100000; unit = "MB"; } else - if (size >= 100) { size = size / 100; unit = "KB"; } else - { size = size * 10; unit = "b"; } - // return formatted string - return (Math.round(size) / 10) + unit; + addAll:function(items){ + _.each(items.reverse(), function(item) { + Galaxy.libraries.folderListView.collection.add(item); + }); + }, + + addOne: function(model){ + if (model.get('type') === 'file'){ + this.options.contains_file = true; + model.set('readable_size', this.size_to_string(model.get('file_size'))); + } + var rowView = new mod_library_folderrow_view.FolderRowView(model); + this.$el.find('#folder_list_body').prepend(rowView.el); + }, + + sort_clicked : function(event){ + event.preventDefault(); + if (this.sort === 'asc'){ + this.sortFolder('name','desc'); + this.sort = 'desc'; + } else { + this.sortFolder('name','asc'); + this.sort = 'asc'; + } + this.render(); + }, + + /** Sorts the underlying collection according to the parameters received. + Currently supports only sorting by name. */ + sortFolder: function(sort_by, order){ + if (sort_by === 'name'){ + if (order === 'asc'){ + this.collection.sortByNameAsc(); + } else if (order === 'desc'){ + this.collection.sortByNameDesc(); + } + } + }, + + // convert size to nice string + size_to_string : function (size){ + // identify unit + var unit = ""; + if (size >= 100000000000) { size = size / 100000000000; unit = "TB"; } else + if (size >= 100000000) { size = size / 100000000; unit = "GB"; } else + if (size >= 100000) { size = size / 100000; unit = "MB"; } else + if (size >= 100) { size = size / 100; unit = "KB"; } else + { size = size * 10; unit = "b"; } + // return formatted string + return (Math.round(size) / 10) + unit; + }, + + // select all datasets + selectAll : function (event) { + var selected = event.target.checked; + that = this; + // Iterate each checkbox + $(':checkbox').each(function() { + this.checked = selected; + $row = $(this.parentElement.parentElement); + // Change color of selected/unselected + (selected) ? that.makeDarkRow($row) : that.makeWhiteRow($row); + }); + // Show the tools in menu + // this.checkTools(); + }, + + // Check checkbox on row itself or row checkbox click + selectClickedRow : function (event) { + var checkbox = ''; + var $row; + var source; + if (event.target.localName === 'input'){ + checkbox = event.target; + $row = $(event.target.parentElement.parentElement); + source = 'input'; + } else if (event.target.localName === 'td') { + checkbox = $("#" + event.target.parentElement.id).find(':checkbox')[0]; + $row = $(event.target.parentElement); + source = 'td'; + } + if (checkbox.checked){ + if (source==='td'){ + checkbox.checked = ''; + this.makeWhiteRow($row); + } else if (source==='input') { + this.makeDarkRow($row); + } + } else { + if (source==='td'){ + checkbox.checked = 'selected'; + this.makeDarkRow($row); + } else if (source==='input') { + this.makeWhiteRow($row); + } + } }, - // select all datasets - selectAll : function (event) { - var selected = event.target.checked; - that = this; - // Iterate each checkbox - $(':checkbox').each(function() { - this.checked = selected; - $row = $(this.parentElement.parentElement); - // Change color of selected/unselected - (selected) ? that.makeDarkRow($row) : that.makeWhiteRow($row); - }); - // Show the tools in menu - // this.checkTools(); - }, + makeDarkRow: function($row){ + $row.removeClass('light'); + $row.find('a').removeClass('light'); + $row.addClass('dark'); + $row.find('a').addClass('dark'); + $row.find('span').removeClass('fa-file-o'); + $row.find('span').addClass('fa-file'); + }, - // Check checkbox on row itself or row checkbox click - selectClickedRow : function (event) { - var checkbox = ''; - var $row; - var source; - if (event.target.localName === 'input'){ - checkbox = event.target; - $row = $(event.target.parentElement.parentElement); - source = 'input'; - } else if (event.target.localName === 'td') { - checkbox = $("#" + event.target.parentElement.id).find(':checkbox')[0]; - $row = $(event.target.parentElement); - source = 'td'; - } - - if (checkbox.checked){ - if (source==='td'){ - checkbox.checked = ''; - this.makeWhiteRow($row); - } else if (source==='input') { - this.makeDarkRow($row); - } - } else { - if (source==='td'){ - checkbox.checked = 'selected'; - this.makeDarkRow($row); - } else if (source==='input') { - this.makeWhiteRow($row); - } - } - // this.checkTools(); - }, - - makeDarkRow: function($row){ - $row.removeClass('light'); - $row.find('a').removeClass('light'); - $row.addClass('dark'); - $row.find('a').addClass('dark'); - $row.find('span').removeClass('fa-file-o'); - $row.find('span').addClass('fa-file'); - - }, - - makeWhiteRow: function($row){ - $row.removeClass('dark'); - $row.find('a').removeClass('dark'); - $row.addClass('light'); - $row.find('a').addClass('light'); - $row.find('span').addClass('fa-file-o'); - $row.find('span').removeClass('fa-file'); - }, + makeWhiteRow: function($row){ + $row.removeClass('dark'); + $row.find('a').removeClass('dark'); + $row.addClass('light'); + $row.find('a').addClass('light'); + $row.find('span').addClass('fa-file-o'); + $row.find('span').removeClass('fa-file'); + }, // MMMMMMMMMMMMMMMMMM // === TEMPLATES ==== @@ -205,20 +250,20 @@ tmpl_array.push(' <thead>'); tmpl_array.push(' <th class="button_heading"></th>'); tmpl_array.push(' <th style="text-align: center; width: 20px; "><input id="select-all-checkboxes" style="margin: 0;" type="checkbox"></th>'); - tmpl_array.push(' <th>name</th>'); + tmpl_array.push(' <th><a class="sort-folder-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>'); tmpl_array.push(' <th>data type</th>'); tmpl_array.push(' <th>size</th>'); tmpl_array.push(' <th>time updated (UTC)</th>'); tmpl_array.push(' </thead>'); tmpl_array.push(' <tbody id="folder_list_body">'); - tmpl_array.push(' <tr>'); - tmpl_array.push(' <td><a href="#<% if (upper_folder_id !== 0){ print("folders/" + upper_folder_id)} %>" title="Go to parent folder" class="btn_open_folder btn btn-default btn-xs">..<a></td>'); - tmpl_array.push(' <td></td>'); - tmpl_array.push(' <td></td>'); - tmpl_array.push(' <td></td>'); - tmpl_array.push(' <td></td>'); - tmpl_array.push(' <td></td>'); - tmpl_array.push(' </tr>'); + // tmpl_array.push(' <tr>'); + // tmpl_array.push(' <td><a href="#<% if (upper_folder_id !== 0){ print("folders/" + upper_folder_id)} %>" title="Go to parent folder" class="btn_open_folder btn btn-default btn-xs">..<a></td>'); + // tmpl_array.push(' <td></td>'); + // tmpl_array.push(' <td></td>'); + // tmpl_array.push(' <td></td>'); + // tmpl_array.push(' <td></td>'); + // tmpl_array.push(' <td></td>'); + // tmpl_array.push(' </tr>'); tmpl_array.push(' </tbody>'); tmpl_array.push('</table>'); diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/mvc/library/library-foldertoolbar-view.js --- a/static/scripts/mvc/library/library-foldertoolbar-view.js +++ b/static/scripts/mvc/library/library-foldertoolbar-view.js @@ -1,4 +1,3 @@ -// dependencies define([ "galaxy.masthead", "utils/utils", @@ -36,7 +35,10 @@ render: function(options){ this.options = _.extend(this.options, options); var toolbar_template = this.templateToolBar(); - var is_admin = Galaxy.currUser.isAdmin(); + var is_admin = false; + if (Galaxy.currUser){ + is_admin = Galaxy.currUser.isAdmin(); + } this.$el.html(toolbar_template({id: this.options.id, admin_user: is_admin})); }, @@ -87,9 +89,8 @@ success: function (folder) { self.modal.hide(); mod_toastr.success('Folder created'); - folder.set({'type' : 'folder'}) - Galaxy.libraries.folderListView.folderContainer.attributes.folder.add(folder); - Galaxy.libraries.folderListView.render({id: current_folder_id}); + folder.set({'type' : 'folder'}); + Galaxy.libraries.folderListView.collection.add(folder); }, error: function(){ mod_toastr.error('An error occured :('); @@ -163,8 +164,8 @@ dataset_ids.push(this.parentElement.parentElement.id); } }); - var progress_bar_tmpl = this.templateProgressBar(); - $(this.modal.elMain).find('.modal-body').html(progress_bar_tmpl({ history_name : history_name })); + var progress_bar_tmpl = this.templateImportIntoHistoryProgressBar(); + this.modal.$el.find('.modal-body').html(progress_bar_tmpl({ history_name : history_name })); // init the progress bar var progressStep = 100 / dataset_ids.length; @@ -254,15 +255,20 @@ title : 'Add datasets from history to ' + self.options.folder_name, body : template_modal({histories: self.histories.models}), buttons : { - 'Add' : function() {self.addFiles();}, + 'Add' : function() {self.addAllDatasetsFromHistory();}, 'Close' : function() {Galaxy.modal.hide();} } }); - self.fetchAndDisplayHistoryContents(self.histories.models[0].id); - $( "#dataset_add_bulk" ).change(function(event) { - self.fetchAndDisplayHistoryContents(event.target.value); - }); - + + // user should always have a history, even anonymous user + if (self.histories.models.length > 0){ + self.fetchAndDisplayHistoryContents(self.histories.models[0].id); + $( "#dataset_add_bulk" ).change(function(event) { + self.fetchAndDisplayHistoryContents(event.target.value); + }); + } else { + mod_toastr.error('Unable to retrieve histories. Please report this error.'); + } }); }, @@ -282,8 +288,54 @@ }); }, - addFiles: function(){ - alert('adding files'); + // add all selected datasets from history into current folder + addAllDatasetsFromHistory : function (){ + //disable the button to prevent multiple submission + this.modal.disableButton('Add'); + + var history_dataset_ids = []; + this.modal.$el.find('#selected_history_content').find(':checked').each(function(){ + var hid = $(this.parentElement).data('id'); + if (hid) { + history_dataset_ids.push(hid); + } + }); + var folder_name = this.options.folder_name; + var progress_bar_tmpl = this.templateAddingDatasetsProgressBar(); + this.modal.$el.find('.modal-body').html(progress_bar_tmpl({ folder_name : folder_name })); + + // init the progress bar + this.progressStep = 100 / history_dataset_ids.length; + this.progress = 0; + + // prepare the dataset items to be added + var hdas_to_add = []; + for (var i = history_dataset_ids.length - 1; i >= 0; i--) { + history_dataset_id = history_dataset_ids[i]; + var folder_item = new mod_library_model.Item(); + var self = this; + folder_item.url = '/api/folders/' + this.options.id + '/contents'; + folder_item.set({'from_hda_id':history_dataset_id}); + hdas_to_add.push(folder_item); + } + // call the recursive function to call ajax one after each other (request FIFO queue) + this.chainCallAddingHdas(hdas_to_add); + }, + + chainCallAddingHdas: function(hdas_set){ + var self = this; + this.added_hdas = new mod_library_model.Folder(); + var popped_item = hdas_set.pop(); + if (typeof popped_item === "undefined") { + mod_toastr.success('Selected datasets from history imported'); + this.modal.hide(); + return this.added_hdas; + } + var promise = $.when(popped_item.save({from_hda_id: popped_item.get('from_hda_id')})).done(function(a1){ + Galaxy.libraries.folderListView.collection.add(a1); + self.updateProgress(); + self.chainCallAddingHdas(hdas_set); + }); }, templateToolBar: function(){ @@ -345,7 +397,7 @@ return _.template(tmpl_array.join('')); }, - templateProgressBar : function (){ + templateImportIntoHistoryProgressBar : function (){ var tmpl_array = []; tmpl_array.push('<div class="import_text">'); @@ -361,6 +413,22 @@ return _.template(tmpl_array.join('')); }, + templateAddingDatasetsProgressBar : function (){ + var tmpl_array = []; + + tmpl_array.push('<div class="import_text">'); + tmpl_array.push('Adding selected datasets from history to library folder <b><%= _.escape(folder_name) %></b>'); + tmpl_array.push('</div>'); + tmpl_array.push('<div class="progress">'); + tmpl_array.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">'); + tmpl_array.push(' <span class="completion_span">0% Complete</span>'); + tmpl_array.push(' </div>'); + tmpl_array.push('</div>'); + tmpl_array.push(''); + + return _.template(tmpl_array.join('')); + }, + templateAddFilesInModal : function (){ var tmpl_array = []; diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/mvc/library/library-librarylist-view.js --- a/static/scripts/mvc/library/library-librarylist-view.js +++ b/static/scripts/mvc/library/library-librarylist-view.js @@ -1,4 +1,3 @@ -// dependencies define([ "galaxy.masthead", "mvc/base-mvc", @@ -13,7 +12,6 @@ mod_library_model, mod_library_libraryrow_view) { -// galaxy library view var LibraryListView = Backbone.View.extend({ el: '#libraries_element', @@ -23,6 +21,7 @@ modal: null, + // collection of {Item}s collection: null, // map of library model ids to library views = cache @@ -115,21 +114,10 @@ sortLibraries: function(sort_by, order){ if (sort_by === 'name'){ if (order === 'asc'){ - // this.collection.sort_order = 'asc'; - this.collection.comparator = function(libraryA, libraryB){ - if (libraryA.get('name').toLowerCase() > libraryB.get('name').toLowerCase()) {return 1;} // after - if (libraryB.get('name').toLowerCase() > libraryA.get('name').toLowerCase()) {return -1;} // before - return 0; // equal - }; + this.collection.sortByNameAsc(); } else if (order === 'desc'){ - // this.collection.sort_order = 'desc'; - this.collection.comparator = function(libraryA, libraryB){ - if (libraryA.get('name').toLowerCase() > libraryB.get('name').toLowerCase()) {return -1;} // before - if (libraryB.get('name').toLowerCase() > libraryA.get('name').toLowerCase()) {return 1;} // after - return 0; // equal - }; + this.collection.sortByNameDesc(); } - this.collection.sort(); } }, diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/mvc/library/library-librarytoolbar-view.js --- a/static/scripts/mvc/library/library-librarytoolbar-view.js +++ b/static/scripts/mvc/library/library-librarytoolbar-view.js @@ -1,4 +1,3 @@ -// dependencies define([ "galaxy.masthead", "utils/utils", @@ -23,10 +22,16 @@ render: function(){ var toolbar_template = this.templateToolBar(); - var is_admin = Galaxy.currUser.isAdmin(); - var is_anonym = Galaxy.currUser.isAnonymous(); + var is_admin = false; + var is_anonym = false; + if (Galaxy.currUser){ + is_admin = Galaxy.currUser.isAdmin(); + is_anonym = Galaxy.currUser.isAnonymous(); + } else { + is_anonym = true; + } this.$el.html(toolbar_template({admin_user: is_admin, anon_user: is_anonym})); - if (Galaxy.currUser.isAdmin() === true){ + if (is_admin){ this.$el.find('#include_deleted_chk')[0].checked = Galaxy.libraries.preferences.get('with_deleted'); } }, diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/mvc/library/library-model.js --- a/static/scripts/mvc/library/library-model.js +++ b/static/scripts/mvc/library/library-model.js @@ -1,13 +1,13 @@ -// dependencies define([], function() { - // LIBRARY +// ============================================================================ +// LIBRARY RELATED MODELS + var Library = Backbone.Model.extend({ urlRoot: '/api/libraries/', - /** based on show_deleted - * would this lib show in the list of lib's? - * @param {Boolean} show_deleted are we showing deleted libraries? + /** based on show_deleted would this lib show in the list of lib's? + * @param {Boolean} show_deleted are we including deleted libraries? */ isVisible : function(show_deleted){ var isVisible = true; @@ -18,12 +18,6 @@ } }); - // FOLDER AS MODEL - var FolderAsModel = Backbone.Model.extend({ - urlRoot: '/api/folders' - }); - - // LIBRARIES var Libraries = Backbone.Collection.extend({ url: '/api/libraries', @@ -38,31 +32,119 @@ }, /** Get every 'shown' library in this collection based on deleted filter - * @param {Boolean} show_deleted are we showing deleted libraries? + * @param {Boolean} show_deleted are we including deleted libraries? * @returns array of library models */ getVisible : function(show_deleted, filters){ filters = filters || []; - // always filter by show deleted first var filteredLibraries = new Libraries( this.filter( function( item ){ return item.isVisible(show_deleted); })); return filteredLibraries; + }, + + /** Sort collection by library name (ascending) and return the sorted + * collection + */ + sortByNameAsc: function(){ + this.comparator = function(libraryA, libraryB){ + if (libraryA.get('name').toLowerCase() > libraryB.get('name').toLowerCase()) { + return 1; // after + } + if (libraryB.get('name').toLowerCase() > libraryA.get('name').toLowerCase()) { + return -1; // before + } + return 0; // equal + }; + this.sort(); + return this; + }, + + /** Sort collection by library name (descending) and return the sorted + * collection + */ + sortByNameDesc: function(){ + this.comparator = function(libraryA, libraryB){ + if (libraryA.get('name').toLowerCase() > libraryB.get('name').toLowerCase()) { + return -1; // before + } + if (libraryB.get('name').toLowerCase() > libraryA.get('name').toLowerCase()) { + return 1; // after + } + return 0; // equal + }; + this.sort(); + return this; } + }); - // ITEM +// ============================================================================ +// FOLDER RELATED MODELS + var Item = Backbone.Model.extend({ urlRoot : '/api/libraries/datasets' }); - // FOLDER AS COLLECTION - var Folder = Backbone.Collection.extend({ - model: Item + var FolderAsModel = Backbone.Model.extend({ + urlRoot: '/api/folders' }); - // CONTAINER for folder contents (folders, items and metadata). + var Folder = Backbone.Collection.extend({ + model: Item, + + /** Sort collection by item name (ascending) and return the sorted + * collection. Folders go before datasets. + */ + sortByNameAsc: function(){ + this.comparator = function(itemA, itemB){ + if (itemA.get('type') === itemB.get('type')){ + if (itemA.get('name').toLowerCase() > itemB.get('name').toLowerCase()) { + return 1; // after + } + if (itemB.get('name').toLowerCase() > itemA.get('name').toLowerCase()) { + return -1; // before + } + return 0; // equal + } else { + if (itemA.get('type') === 'folder'){ + return -1; // folder is always before dataset + } else { + return 1; + } + } + }; + this.sort(); + return this; + }, + + /** Sort collection by item name (descending) and return the sorted + * collection. Folders go before datasets. + */ + sortByNameDesc: function(){ + this.comparator = function(itemA, itemB){ + if (itemA.get('type') === itemB.get('type')){ + if (itemA.get('name').toLowerCase() > itemB.get('name').toLowerCase()) { + return -1; // after + } + if (itemB.get('name').toLowerCase() > itemA.get('name').toLowerCase()) { + return 1; // before + } + return 0; // equal + } else { + if (itemA.get('type') === 'folder'){ + return -1; // folder is always before dataset + } else { + return 1; + } + } + }; + this.sort(); + return this; + } + }); + var FolderContainer = Backbone.Model.extend({ defaults : { folder : new Folder(), @@ -77,12 +159,15 @@ } }); - // HISTORY ITEM + +// ============================================================================ +// HISTORY RELATED MODELS +// TODO UNITE + var HistoryItem = Backbone.Model.extend({ urlRoot : '/api/histories/' }); - // HISTORY CONTENTS var HistoryContents = Backbone.Collection.extend({ urlRoot : '/api/histories/', initialize: function(options){ @@ -94,18 +179,15 @@ model : HistoryItem }); - // HISTORY var GalaxyHistory = Backbone.Model.extend({ urlRoot : '/api/histories/' }); - // HISTORIES var GalaxyHistories = Backbone.Collection.extend({ url : '/api/histories', model : GalaxyHistory }); -// return return { Library: Library, FolderAsModel : FolderAsModel, diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/packed/mvc/library/library-folderlist-view.js --- a/static/scripts/packed/mvc/library/library-folderlist-view.js +++ b/static/scripts/packed/mvc/library/library-folderlist-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-folderrow-view"],function(c,e,f,d,a){var b=Backbone.View.extend({el:"#folder_items_element",progress:0,progressStep:1,modal:null,folderContainer:null,events:{"click #select-all-checkboxes":"selectAll","click .dataset_row":"selectClickedRow"},initialize:function(g){var h=this;this.options=_.defaults(this.options||{},g);this.queue=jQuery.Deferred();this.queue.resolve();this.folderContainer=new d.FolderContainer({id:this.options.id});this.folderContainer.url=this.folderContainer.attributes.urlRoot+this.options.id+"/contents";this.folderContainer.fetch({success:function(i){h.render()},error:function(){f.error("An error occured :(")}})},render:function(h){this.options=_.defaults(this.options||{},h);var l=this.templateFolder();var m=false;for(var k=0;k<this.folderContainer.attributes.folder.models.length;k++){var g=this.folderContainer.attributes.folder.models[k];if(g.get("type")==="file"){m=true;g.set("readable_size",this.size_to_string(g.get("file_size")))}}var n=this.folderContainer.attributes.metadata.full_path;var o;if(n.length===1){o=0}else{o=n[n.length-2][0]}this.$el.html(l({path:this.folderContainer.attributes.metadata.full_path,id:this.options.id,upper_folder_id:o}));if(this.folderContainer.attributes.folder.models.length>0){this.renderRows()}var j=this.folderContainer.attributes.metadata;j.contains_file=m;Galaxy.libraries.folderToolbarView.configureElements(j);$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(){for(var j=0;j<this.folderContainer.attributes.folder.models.length;j++){var h=this.folderContainer.attributes.folder.models[j];var g=new a.FolderRowView(h);this.$el.find("#folder_list_body").append(g.el)}},size_to_string:function(g){var h="";if(g>=100000000000){g=g/100000000000;h="TB"}else{if(g>=100000000){g=g/100000000;h="GB"}else{if(g>=100000){g=g/100000;h="MB"}else{if(g>=100){g=g/100;h="KB"}else{g=g*10;h="b"}}}}return(Math.round(g)/10)+h},selectAll:function(h){var g=h.target.checked;that=this;$(":checkbox").each(function(){this.checked=g;$row=$(this.parentElement.parentElement);(g)?that.makeDarkRow($row):that.makeWhiteRow($row)})},selectClickedRow:function(h){var j="";var g;var i;if(h.target.localName==="input"){j=h.target;g=$(h.target.parentElement.parentElement);i="input"}else{if(h.target.localName==="td"){j=$("#"+h.target.parentElement.id).find(":checkbox")[0];g=$(h.target.parentElement);i="td"}}if(j.checked){if(i==="td"){j.checked="";this.makeWhiteRow(g)}else{if(i==="input"){this.makeDarkRow(g)}}}else{if(i==="td"){j.checked="selected";this.makeDarkRow(g)}else{if(i==="input"){this.makeWhiteRow(g)}}}},makeDarkRow:function(g){g.removeClass("light");g.find("a").removeClass("light");g.addClass("dark");g.find("a").addClass("dark");g.find("span").removeClass("fa-file-o");g.find("span").addClass("fa-file")},makeWhiteRow:function(g){g.removeClass("dark");g.find("a").removeClass("dark");g.addClass("light");g.find("a").addClass("light");g.find("span").addClass("fa-file-o");g.find("span").removeClass("fa-file")},templateFolder:function(){var g=[];g.push('<ol class="breadcrumb">');g.push(' <li><a title="Return to the list of libraries" href="#">Libraries</a></li>');g.push(" <% _.each(path, function(path_item) { %>");g.push(" <% if (path_item[0] != id) { %>");g.push(' <li><a title="Return to this folder" href="#/folders/<%- path_item[0] %>"><%- path_item[1] %></a></li> ');g.push("<% } else { %>");g.push(' <li class="active"><span title="You are in this folder"><%- path_item[1] %></span></li>');g.push(" <% } %>");g.push(" <% }); %>");g.push("</ol>");g.push('<table id="folder_table" class="grid table table-condensed">');g.push(" <thead>");g.push(' <th class="button_heading"></th>');g.push(' <th style="text-align: center; width: 20px; "><input id="select-all-checkboxes" style="margin: 0;" type="checkbox"></th>');g.push(" <th>name</th>");g.push(" <th>data type</th>");g.push(" <th>size</th>");g.push(" <th>time updated (UTC)</th>");g.push(" </thead>");g.push(' <tbody id="folder_list_body">');g.push(" <tr>");g.push(' <td><a href="#<% if (upper_folder_id !== 0){ print("folders/" + upper_folder_id)} %>" title="Go to parent folder" class="btn_open_folder btn btn-default btn-xs">..<a></td>');g.push(" <td></td>");g.push(" <td></td>");g.push(" <td></td>");g.push(" <td></td>");g.push(" <td></td>");g.push(" </tr>");g.push(" </tbody>");g.push("</table>");return _.template(g.join(""))}});return{FolderListView:b}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-folderrow-view"],function(c,e,f,d,a){var b=Backbone.View.extend({el:"#folder_items_element",progress:0,progressStep:1,modal:null,folderContainer:null,sort:"asc",events:{"click #select-all-checkboxes":"selectAll","click .dataset_row":"selectClickedRow","click .sort-folder-link":"sort_clicked"},initialize:function(g){var h=this;this.options=_.defaults(this.options||{},g);this.queue=jQuery.Deferred();this.queue.resolve();this.collection=new d.Folder();this.listenTo(this.collection,"add",this.addOne);this.folderContainer=new d.FolderContainer({id:this.options.id});this.folderContainer.url=this.folderContainer.attributes.urlRoot+this.options.id+"/contents";this.folderContainer.fetch({success:function(i){h.render();var j=i.get("folder").models;h.addAll(j)},error:function(){f.error("An error occured :(")}})},render:function(g){this.options=_.defaults(this.options||{},g);var h=this.templateFolder();var i=false;var j=this.folderContainer.attributes.metadata.full_path;var k;if(j.length===1){k=0}else{k=j[j.length-2][0]}this.$el.html(h({path:this.folderContainer.attributes.metadata.full_path,id:this.options.id,upper_folder_id:k,order:this.sort}));if(this.collection.models.length>0){this.renderRows()}var g=this.folderContainer.attributes.metadata;g.contains_file=this.options.contains_file;Galaxy.libraries.folderToolbarView.configureElements(g);$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(){for(var j=0;j<this.collection.models.length;j++){var h=this.collection.models[j];var g=new a.FolderRowView(h);this.$el.find("#folder_list_body").append(g.el)}},addAll:function(g){_.each(g.reverse(),function(h){Galaxy.libraries.folderListView.collection.add(h)})},addOne:function(h){if(h.get("type")==="file"){this.options.contains_file=true;h.set("readable_size",this.size_to_string(h.get("file_size")))}var g=new a.FolderRowView(h);this.$el.find("#folder_list_body").prepend(g.el)},sort_clicked:function(g){g.preventDefault();if(this.sort==="asc"){this.sortFolder("name","desc");this.sort="desc"}else{this.sortFolder("name","asc");this.sort="asc"}this.render()},sortFolder:function(h,g){if(h==="name"){if(g==="asc"){this.collection.sortByNameAsc()}else{if(g==="desc"){this.collection.sortByNameDesc()}}}},size_to_string:function(g){var h="";if(g>=100000000000){g=g/100000000000;h="TB"}else{if(g>=100000000){g=g/100000000;h="GB"}else{if(g>=100000){g=g/100000;h="MB"}else{if(g>=100){g=g/100;h="KB"}else{g=g*10;h="b"}}}}return(Math.round(g)/10)+h},selectAll:function(h){var g=h.target.checked;that=this;$(":checkbox").each(function(){this.checked=g;$row=$(this.parentElement.parentElement);(g)?that.makeDarkRow($row):that.makeWhiteRow($row)})},selectClickedRow:function(h){var j="";var g;var i;if(h.target.localName==="input"){j=h.target;g=$(h.target.parentElement.parentElement);i="input"}else{if(h.target.localName==="td"){j=$("#"+h.target.parentElement.id).find(":checkbox")[0];g=$(h.target.parentElement);i="td"}}if(j.checked){if(i==="td"){j.checked="";this.makeWhiteRow(g)}else{if(i==="input"){this.makeDarkRow(g)}}}else{if(i==="td"){j.checked="selected";this.makeDarkRow(g)}else{if(i==="input"){this.makeWhiteRow(g)}}}},makeDarkRow:function(g){g.removeClass("light");g.find("a").removeClass("light");g.addClass("dark");g.find("a").addClass("dark");g.find("span").removeClass("fa-file-o");g.find("span").addClass("fa-file")},makeWhiteRow:function(g){g.removeClass("dark");g.find("a").removeClass("dark");g.addClass("light");g.find("a").addClass("light");g.find("span").addClass("fa-file-o");g.find("span").removeClass("fa-file")},templateFolder:function(){var g=[];g.push('<ol class="breadcrumb">');g.push(' <li><a title="Return to the list of libraries" href="#">Libraries</a></li>');g.push(" <% _.each(path, function(path_item) { %>");g.push(" <% if (path_item[0] != id) { %>");g.push(' <li><a title="Return to this folder" href="#/folders/<%- path_item[0] %>"><%- path_item[1] %></a></li> ');g.push("<% } else { %>");g.push(' <li class="active"><span title="You are in this folder"><%- path_item[1] %></span></li>');g.push(" <% } %>");g.push(" <% }); %>");g.push("</ol>");g.push('<table id="folder_table" class="grid table table-condensed">');g.push(" <thead>");g.push(' <th class="button_heading"></th>');g.push(' <th style="text-align: center; width: 20px; "><input id="select-all-checkboxes" style="margin: 0;" type="checkbox"></th>');g.push(' <th><a class="sort-folder-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');g.push(" <th>data type</th>");g.push(" <th>size</th>");g.push(" <th>time updated (UTC)</th>");g.push(" </thead>");g.push(' <tbody id="folder_list_body">');g.push(" </tbody>");g.push("</table>");return _.template(g.join(""))}});return{FolderListView:b}}); \ No newline at end of file diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/packed/mvc/library/library-foldertoolbar-view.js --- a/static/scripts/packed/mvc/library/library-foldertoolbar-view.js +++ b/static/scripts/packed/mvc/library/library-foldertoolbar-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({el:"#center",events:{"click #toolbtn_create_folder":"createFolderFromModal","click #toolbtn_bulk_import":"modalBulkImport","click .toolbtn_add_files":"addFilesToFolderModal"},defaults:{can_add_library_item:false,contains_file:false},modal:null,histories:null,initialize:function(f){this.options=_.defaults(f||{},this.defaults);this.render()},render:function(f){this.options=_.extend(this.options,f);var h=this.templateToolBar();var g=Galaxy.currUser.isAdmin();this.$el.html(h({id:this.options.id,admin_user:g}))},configureElements:function(f){this.options=_.extend(this.options,f);if(this.options.can_add_library_item===true){$("#toolbtn_create_folder").show();$(".toolbtn_add_files").show()}if(this.options.contains_file===true){$("#toolbtn_bulk_import").show();$("#toolbtn_dl").show()}this.$el.find("[data-toggle]").tooltip()},createFolderFromModal:function(){event.preventDefault();event.stopPropagation();var f=this;var g=this.templateNewFolderInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Folder",body:g(),buttons:{Create:function(){f.create_new_folder_event()},Close:function(){Galaxy.modal.hide()}}})},create_new_folder_event:function(){var f=this.serialize_new_folder();if(this.validate_new_folder(f)){var h=new c.FolderAsModel();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];h.url=h.urlRoot+"/"+current_folder_id;var g=this;h.save(f,{success:function(i){g.modal.hide();e.success("Folder created");i.set({type:"folder"});Galaxy.libraries.folderListView.folderContainer.attributes.folder.add(i);Galaxy.libraries.folderListView.render({id:current_folder_id})},error:function(){e.error("An error occured :(")}})}else{e.error("Folder's name is missing")}return false},serialize_new_folder:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val()}},validate_new_folder:function(f){return f.name!==""},modalBulkImport:function(){var f=$("#folder_table").find(":checked");if(f.length===0){e.info("You have to select some datasets first")}else{this.refreshUserHistoriesList(function(g){var h=g.templateBulkImportInModal();g.modal=Galaxy.modal;g.modal.show({closing_events:true,title:"Import into History",body:h({histories:g.histories.models}),buttons:{Import:function(){g.importAllIntoHistory()},Close:function(){Galaxy.modal.hide()}}})})}},refreshUserHistoriesList:function(g){var f=this;this.histories=new c.GalaxyHistories();this.histories.fetch({success:function(){g(f)},error:function(){}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var h=$("select[name=dataset_import_bulk] option:selected").val();var m=$("select[name=dataset_import_bulk] option:selected").text();var o=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){o.push(this.parentElement.parentElement.id)}});var n=this.templateProgressBar();$(this.modal.elMain).find(".modal-body").html(n({history_name:m}));var j=100/o.length;this.initProgress(j);var f=[];for(var g=o.length-1;g>=0;g--){library_dataset_id=o[g];var k=new c.HistoryItem();var l=this;k.url=k.urlRoot+h+"/contents";k.content=library_dataset_id;k.source="library";f.push(k)}this.chainCall(f)},chainCall:function(g){var f=this;var h=g.pop();if(typeof h==="undefined"){e.success("All datasets imported");this.modal.hide();return}var i=$.when(h.save({content:h.content,source:h.source})).done(function(j){f.updateProgress();f.chainCall(g)})},initProgress:function(f){this.progress=0;this.progressStep=f},updateProgress:function(){this.progress+=this.progressStep;$(".progress-bar-import").width(Math.round(this.progress)+"%");txt_representation=Math.round(this.progress)+"% Complete";$(".completion_span").text(txt_representation)},download:function(f,j){var h=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){h.push(this.parentElement.parentElement.id)}});var g="/api/libraries/datasets/download/"+j;var i={ldda_ids:h};this.processDownload(g,i,"get")},processDownload:function(g,h,i){if(g&&h){h=typeof h=="string"?h:$.param(h);var f="";$.each(h.split("&"),function(){var j=this.split("=");f+='<input type="hidden" name="'+j[0]+'" value="'+j[1]+'" />'});$('<form action="'+g+'" method="'+(i||"post")+'">'+f+"</form>").appendTo("body").submit().remove();e.info("Your download will begin soon")}},addFilesToFolderModal:function(){this.refreshUserHistoriesList(function(f){f.modal=Galaxy.modal;var g=f.templateAddFilesInModal();f.modal.show({closing_events:true,title:"Add datasets from history to "+f.options.folder_name,body:g({histories:f.histories.models}),buttons:{Add:function(){f.addFiles()},Close:function(){Galaxy.modal.hide()}}});f.fetchAndDisplayHistoryContents(f.histories.models[0].id);$("#dataset_add_bulk").change(function(h){f.fetchAndDisplayHistoryContents(h.target.value)})})},fetchAndDisplayHistoryContents:function(h){var g=new c.HistoryContents({id:h});var f=this;g.fetch({success:function(j){var i=f.templateHistoryContents();e.success("history contents fetched");f.histories.get(h).set({contents:j});f.modal.$el.find("#selected_history_content").html(i({history_contents:j.models.reverse()}))},error:function(){e.error("history contents fetch failed")}})},addFiles:function(){alert("adding files")},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>');tmpl_array.push('<div id="library_folder_toolbar" >');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Create New Folder" id="toolbtn_create_folder" class="primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-folder"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Add Datasets to Current Folder" id="toolbtn_add_files" class="toolbtn_add_files primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-file"></span></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Import selected datasets into history" id="toolbtn_bulk_import" class="primary-button" style="margin-left: 0.5em; display:none;" type="button"><span class="fa fa-book"></span> to history</button>');tmpl_array.push(' <div id="toolbtn_dl" class="btn-group" style="margin-left: 0.5em; display:none; ">');tmpl_array.push(' <button title="Download selected datasets" id="drop_toggle" type="button" class="primary-button dropdown-toggle" data-toggle="dropdown">');tmpl_array.push(' <span class="fa fa-download"></span> download <span class="caret"></span>');tmpl_array.push(" </button>");tmpl_array.push(' <ul class="dropdown-menu" role="menu">');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tgz">.tar.gz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tbz">.tar.bz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/zip">.zip</a></li>');tmpl_array.push(" </ul>");tmpl_array.push(" </div>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="folder_items_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_folder_modal">');tmpl_array.push("<form>");tmpl_array.push('<input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push('<input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push("</form>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateBulkImportInModal:function(){var f=[];f.push('<span id="history_modal_combo_bulk" style="width:90%; margin-left: 1em; margin-right: 1em; ">');f.push("Select history: ");f.push('<select id="dataset_import_bulk" name="dataset_import_bulk" style="width:50%; margin-bottom: 1em; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</span>");return _.template(f.join(""))},templateProgressBar:function(){var f=[];f.push('<div class="import_text">');f.push("Importing selected datasets to history <b><%= _.escape(history_name) %></b>");f.push("</div>");f.push('<div class="progress">');f.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">');f.push(' <span class="completion_span">0% Complete</span>');f.push(" </div>");f.push("</div>");f.push("");return _.template(f.join(""))},templateAddFilesInModal:function(){var f=[];f.push('<div id="add_files_modal">');f.push('<div id="history_modal_combo_bulk">');f.push("Select history: ");f.push('<select id="dataset_add_bulk" name="dataset_add_bulk" style="width:66%; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</div>");f.push('<div id="selected_history_content">');f.push("</div>");f.push("</div>");return _.template(f.join(""))},templateHistoryContents:function(){var f=[];f.push("Choose the datasets to import:");f.push("<ul>");f.push(" <% _.each(history_contents, function(history_item) { %>");f.push(' <li data-id="<%= _.escape(history_item.get("id")) %>">');f.push(' <input style="margin: 0;" type="checkbox"><%= _.escape(history_item.get("hid")) %>: <%= _.escape(history_item.get("name")) %>');f.push(" </li>");f.push(" <% }); %>");f.push("</ul>");return _.template(f.join(""))}});return{FolderToolbarView:a}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({el:"#center",events:{"click #toolbtn_create_folder":"createFolderFromModal","click #toolbtn_bulk_import":"modalBulkImport","click .toolbtn_add_files":"addFilesToFolderModal"},defaults:{can_add_library_item:false,contains_file:false},modal:null,histories:null,initialize:function(f){this.options=_.defaults(f||{},this.defaults);this.render()},render:function(f){this.options=_.extend(this.options,f);var h=this.templateToolBar();var g=false;if(Galaxy.currUser){g=Galaxy.currUser.isAdmin()}this.$el.html(h({id:this.options.id,admin_user:g}))},configureElements:function(f){this.options=_.extend(this.options,f);if(this.options.can_add_library_item===true){$("#toolbtn_create_folder").show();$(".toolbtn_add_files").show()}if(this.options.contains_file===true){$("#toolbtn_bulk_import").show();$("#toolbtn_dl").show()}this.$el.find("[data-toggle]").tooltip()},createFolderFromModal:function(){event.preventDefault();event.stopPropagation();var f=this;var g=this.templateNewFolderInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Folder",body:g(),buttons:{Create:function(){f.create_new_folder_event()},Close:function(){Galaxy.modal.hide()}}})},create_new_folder_event:function(){var f=this.serialize_new_folder();if(this.validate_new_folder(f)){var h=new c.FolderAsModel();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];h.url=h.urlRoot+"/"+current_folder_id;var g=this;h.save(f,{success:function(i){g.modal.hide();e.success("Folder created");i.set({type:"folder"});Galaxy.libraries.folderListView.collection.add(i)},error:function(){e.error("An error occured :(")}})}else{e.error("Folder's name is missing")}return false},serialize_new_folder:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val()}},validate_new_folder:function(f){return f.name!==""},modalBulkImport:function(){var f=$("#folder_table").find(":checked");if(f.length===0){e.info("You have to select some datasets first")}else{this.refreshUserHistoriesList(function(g){var h=g.templateBulkImportInModal();g.modal=Galaxy.modal;g.modal.show({closing_events:true,title:"Import into History",body:h({histories:g.histories.models}),buttons:{Import:function(){g.importAllIntoHistory()},Close:function(){Galaxy.modal.hide()}}})})}},refreshUserHistoriesList:function(g){var f=this;this.histories=new c.GalaxyHistories();this.histories.fetch({success:function(){g(f)},error:function(){}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var h=$("select[name=dataset_import_bulk] option:selected").val();var m=$("select[name=dataset_import_bulk] option:selected").text();var o=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){o.push(this.parentElement.parentElement.id)}});var n=this.templateImportIntoHistoryProgressBar();this.modal.$el.find(".modal-body").html(n({history_name:m}));var j=100/o.length;this.initProgress(j);var f=[];for(var g=o.length-1;g>=0;g--){library_dataset_id=o[g];var k=new c.HistoryItem();var l=this;k.url=k.urlRoot+h+"/contents";k.content=library_dataset_id;k.source="library";f.push(k)}this.chainCall(f)},chainCall:function(g){var f=this;var h=g.pop();if(typeof h==="undefined"){e.success("All datasets imported");this.modal.hide();return}var i=$.when(h.save({content:h.content,source:h.source})).done(function(j){f.updateProgress();f.chainCall(g)})},initProgress:function(f){this.progress=0;this.progressStep=f},updateProgress:function(){this.progress+=this.progressStep;$(".progress-bar-import").width(Math.round(this.progress)+"%");txt_representation=Math.round(this.progress)+"% Complete";$(".completion_span").text(txt_representation)},download:function(f,j){var h=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){h.push(this.parentElement.parentElement.id)}});var g="/api/libraries/datasets/download/"+j;var i={ldda_ids:h};this.processDownload(g,i,"get")},processDownload:function(g,h,i){if(g&&h){h=typeof h=="string"?h:$.param(h);var f="";$.each(h.split("&"),function(){var j=this.split("=");f+='<input type="hidden" name="'+j[0]+'" value="'+j[1]+'" />'});$('<form action="'+g+'" method="'+(i||"post")+'">'+f+"</form>").appendTo("body").submit().remove();e.info("Your download will begin soon")}},addFilesToFolderModal:function(){this.refreshUserHistoriesList(function(f){f.modal=Galaxy.modal;var g=f.templateAddFilesInModal();f.modal.show({closing_events:true,title:"Add datasets from history to "+f.options.folder_name,body:g({histories:f.histories.models}),buttons:{Add:function(){f.addAllDatasetsFromHistory()},Close:function(){Galaxy.modal.hide()}}});if(f.histories.models.length>0){f.fetchAndDisplayHistoryContents(f.histories.models[0].id);$("#dataset_add_bulk").change(function(h){f.fetchAndDisplayHistoryContents(h.target.value)})}else{e.error("Unable to retrieve histories. Please report this error.")}})},fetchAndDisplayHistoryContents:function(h){var g=new c.HistoryContents({id:h});var f=this;g.fetch({success:function(j){var i=f.templateHistoryContents();e.success("history contents fetched");f.histories.get(h).set({contents:j});f.modal.$el.find("#selected_history_content").html(i({history_contents:j.models.reverse()}))},error:function(){e.error("history contents fetch failed")}})},addAllDatasetsFromHistory:function(){this.modal.disableButton("Add");var f=[];this.modal.$el.find("#selected_history_content").find(":checked").each(function(){var i=$(this.parentElement).data("id");if(i){f.push(i)}});var m=this.options.folder_name;var l=this.templateAddingDatasetsProgressBar();this.modal.$el.find(".modal-body").html(l({folder_name:m}));this.progressStep=100/f.length;this.progress=0;var k=[];for(var j=f.length-1;j>=0;j--){history_dataset_id=f[j];var h=new c.Item();var g=this;h.url="/api/folders/"+this.options.id+"/contents";h.set({from_hda_id:history_dataset_id});k.push(h)}this.chainCallAddingHdas(k)},chainCallAddingHdas:function(g){var f=this;this.added_hdas=new c.Folder();var h=g.pop();if(typeof h==="undefined"){e.success("Selected datasets from history imported");this.modal.hide();return this.added_hdas}var i=$.when(h.save({from_hda_id:h.get("from_hda_id")})).done(function(j){Galaxy.libraries.folderListView.collection.add(j);f.updateProgress();f.chainCallAddingHdas(g)})},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>');tmpl_array.push('<div id="library_folder_toolbar" >');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Create New Folder" id="toolbtn_create_folder" class="primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-folder"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Add Datasets to Current Folder" id="toolbtn_add_files" class="toolbtn_add_files primary-button" type="button" style="display:none;"><span class="fa fa-plus"></span><span class="fa fa-file"></span></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Import selected datasets into history" id="toolbtn_bulk_import" class="primary-button" style="margin-left: 0.5em; display:none;" type="button"><span class="fa fa-book"></span> to history</button>');tmpl_array.push(' <div id="toolbtn_dl" class="btn-group" style="margin-left: 0.5em; display:none; ">');tmpl_array.push(' <button title="Download selected datasets" id="drop_toggle" type="button" class="primary-button dropdown-toggle" data-toggle="dropdown">');tmpl_array.push(' <span class="fa fa-download"></span> download <span class="caret"></span>');tmpl_array.push(" </button>");tmpl_array.push(' <ul class="dropdown-menu" role="menu">');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tgz">.tar.gz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/tbz">.tar.bz</a></li>');tmpl_array.push(' <li id="download_archive"><a href="#/folders/<%= id %>/download/zip">.zip</a></li>');tmpl_array.push(" </ul>");tmpl_array.push(" </div>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="folder_items_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_folder_modal">');tmpl_array.push("<form>");tmpl_array.push('<input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push('<input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push("</form>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateBulkImportInModal:function(){var f=[];f.push('<span id="history_modal_combo_bulk" style="width:90%; margin-left: 1em; margin-right: 1em; ">');f.push("Select history: ");f.push('<select id="dataset_import_bulk" name="dataset_import_bulk" style="width:50%; margin-bottom: 1em; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</span>");return _.template(f.join(""))},templateImportIntoHistoryProgressBar:function(){var f=[];f.push('<div class="import_text">');f.push("Importing selected datasets to history <b><%= _.escape(history_name) %></b>");f.push("</div>");f.push('<div class="progress">');f.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">');f.push(' <span class="completion_span">0% Complete</span>');f.push(" </div>");f.push("</div>");f.push("");return _.template(f.join(""))},templateAddingDatasetsProgressBar:function(){var f=[];f.push('<div class="import_text">');f.push("Adding selected datasets from history to library folder <b><%= _.escape(folder_name) %></b>");f.push("</div>");f.push('<div class="progress">');f.push(' <div class="progress-bar progress-bar-import" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 00%;">');f.push(' <span class="completion_span">0% Complete</span>');f.push(" </div>");f.push("</div>");f.push("");return _.template(f.join(""))},templateAddFilesInModal:function(){var f=[];f.push('<div id="add_files_modal">');f.push('<div id="history_modal_combo_bulk">');f.push("Select history: ");f.push('<select id="dataset_add_bulk" name="dataset_add_bulk" style="width:66%; "> ');f.push(" <% _.each(histories, function(history) { %>");f.push(' <option value="<%= _.escape(history.get("id")) %>"><%= _.escape(history.get("name")) %></option>');f.push(" <% }); %>");f.push("</select>");f.push("</div>");f.push('<div id="selected_history_content">');f.push("</div>");f.push("</div>");return _.template(f.join(""))},templateHistoryContents:function(){var f=[];f.push("Choose the datasets to import:");f.push("<ul>");f.push(" <% _.each(history_contents, function(history_item) { %>");f.push(' <li data-id="<%= _.escape(history_item.get("id")) %>">');f.push(' <input style="margin: 0;" type="checkbox"><%= _.escape(history_item.get("hid")) %>: <%= _.escape(history_item.get("name")) %>');f.push(" </li>");f.push(" <% }); %>");f.push("</ul>");return _.template(f.join(""))}});return{FolderToolbarView:a}}); \ No newline at end of file diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/packed/mvc/library/library-librarylist-view.js --- a/static/scripts/packed/mvc/library/library-librarylist-view.js +++ b/static/scripts/packed/mvc/library/library-librarylist-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","mvc/base-mvc","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-libraryrow-view"],function(b,g,d,e,c,a){var f=Backbone.View.extend({el:"#libraries_element",events:{"click .sort-libraries-link":"sort_clicked"},modal:null,collection:null,rowViews:{},initialize:function(i){this.options=_.defaults(this.options||{},i);var h=this;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(j){h.render()},error:function(k,j){e.error("An error occured. Please try again.")}})},render:function(i){var j=this.templateLibraryList();var k=null;var h=Galaxy.libraries.preferences.get("with_deleted");var l=null;if(typeof i!=="undefined"){h=typeof i.with_deleted!=="undefined"?i.with_deleted:false;l=typeof i.models!=="undefined"?i.models:null}if(this.collection!==null&&l===null){if(h){k=this.collection.models}else{k=this.collection.where({deleted:false})}}else{if(l!==null){k=l}else{k=[]}}this.$el.html(j({length:k.length,order:Galaxy.libraries.preferences.get("sort_order")}));if(k.length>0){this.renderRows(k)}$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(m){for(var l=0;l<m.length;l++){var k=m[l];var j=_.findWhere(this.rowViews,{id:k.get("id")});if(j!==undefined&&this instanceof Backbone.View){j.delegateEvents();this.$el.find("#library_list_body").append(j.el)}else{var h=new a.LibraryRowView(k);this.$el.find("#library_list_body").append(h.el);this.rowViews[k.get("id")]=h}}},sort_clicked:function(){if(Galaxy.libraries.preferences.get("sort_order")==="asc"){this.sortLibraries("name","desc");Galaxy.libraries.preferences.set({sort_order:"desc"})}else{this.sortLibraries("name","asc");Galaxy.libraries.preferences.set({sort_order:"asc"})}this.render()},sortLibraries:function(i,h){if(i==="name"){if(h==="asc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return 1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return -1}return 0}}else{if(h==="desc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return -1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return 1}return 0}}}this.collection.sort()}},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('<div class="library_container table-responsive">');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push('<div>There are no libraries visible to you. If you expected some to show up please consult the <a href="https://wiki.galaxyproject.org/Admin/DataLibraries/LibrarySecurity">library security wikipage</a>.</div>');tmpl_array.push("<% } else{ %>");tmpl_array.push('<table class="grid table table-condensed">');tmpl_array.push(" <thead>");tmpl_array.push(' <th style="width:30%;"><a class="sort-libraries-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');tmpl_array.push(' <th style="width:22%;">description</th>');tmpl_array.push(' <th style="width:22%;">synopsis</th> ');tmpl_array.push(' <th style="width:26%;"></th> ');tmpl_array.push(" </thead>");tmpl_array.push(' <tbody id="library_list_body">');tmpl_array.push(" </tbody>");tmpl_array.push("</table>");tmpl_array.push("<% }%>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_library_modal">');tmpl_array.push(" <form>");tmpl_array.push(' <input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push(' <input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push(' <input type="text" name="Synopsis" value="" placeholder="Synopsis">');tmpl_array.push(" </form>");tmpl_array.push("</div>");return tmpl_array.join("")},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},show_library_modal:function(i){i.preventDefault();i.stopPropagation();var h=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){h.create_new_library_event()},Close:function(){h.modal.hide()}}})},create_new_library_event:function(){var j=this.serialize_new_library();if(this.validate_new_library(j)){var i=new c.Library();var h=this;i.save(j,{success:function(k){h.collection.add(k);h.modal.hide();h.clear_library_modal();h.render();e.success("Library created")},error:function(){e.error("An error occured :(")}})}else{e.error("Library's name is missing")}return false},clear_library_modal:function(){$("input[name='Name']").val("");$("input[name='Description']").val("");$("input[name='Synopsis']").val("")},serialize_new_library:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val(),synopsis:$("input[name='Synopsis']").val()}},validate_new_library:function(h){return h.name!==""}});return{LibraryListView:f}}); \ No newline at end of file +define(["galaxy.masthead","mvc/base-mvc","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-libraryrow-view"],function(b,g,d,e,c,a){var f=Backbone.View.extend({el:"#libraries_element",events:{"click .sort-libraries-link":"sort_clicked"},modal:null,collection:null,rowViews:{},initialize:function(i){this.options=_.defaults(this.options||{},i);var h=this;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(j){h.render()},error:function(k,j){e.error("An error occured. Please try again.")}})},render:function(i){var j=this.templateLibraryList();var k=null;var h=Galaxy.libraries.preferences.get("with_deleted");var l=null;if(typeof i!=="undefined"){h=typeof i.with_deleted!=="undefined"?i.with_deleted:false;l=typeof i.models!=="undefined"?i.models:null}if(this.collection!==null&&l===null){if(h){k=this.collection.models}else{k=this.collection.where({deleted:false})}}else{if(l!==null){k=l}else{k=[]}}this.$el.html(j({length:k.length,order:Galaxy.libraries.preferences.get("sort_order")}));if(k.length>0){this.renderRows(k)}$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(m){for(var l=0;l<m.length;l++){var k=m[l];var j=_.findWhere(this.rowViews,{id:k.get("id")});if(j!==undefined&&this instanceof Backbone.View){j.delegateEvents();this.$el.find("#library_list_body").append(j.el)}else{var h=new a.LibraryRowView(k);this.$el.find("#library_list_body").append(h.el);this.rowViews[k.get("id")]=h}}},sort_clicked:function(){if(Galaxy.libraries.preferences.get("sort_order")==="asc"){this.sortLibraries("name","desc");Galaxy.libraries.preferences.set({sort_order:"desc"})}else{this.sortLibraries("name","asc");Galaxy.libraries.preferences.set({sort_order:"asc"})}this.render()},sortLibraries:function(i,h){if(i==="name"){if(h==="asc"){this.collection.sortByNameAsc()}else{if(h==="desc"){this.collection.sortByNameDesc()}}}},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('<div class="library_container table-responsive">');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push('<div>There are no libraries visible to you. If you expected some to show up please consult the <a href="https://wiki.galaxyproject.org/Admin/DataLibraries/LibrarySecurity">library security wikipage</a>.</div>');tmpl_array.push("<% } else{ %>");tmpl_array.push('<table class="grid table table-condensed">');tmpl_array.push(" <thead>");tmpl_array.push(' <th style="width:30%;"><a class="sort-libraries-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');tmpl_array.push(' <th style="width:22%;">description</th>');tmpl_array.push(' <th style="width:22%;">synopsis</th> ');tmpl_array.push(' <th style="width:26%;"></th> ');tmpl_array.push(" </thead>");tmpl_array.push(' <tbody id="library_list_body">');tmpl_array.push(" </tbody>");tmpl_array.push("</table>");tmpl_array.push("<% }%>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_library_modal">');tmpl_array.push(" <form>");tmpl_array.push(' <input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push(' <input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push(' <input type="text" name="Synopsis" value="" placeholder="Synopsis">');tmpl_array.push(" </form>");tmpl_array.push("</div>");return tmpl_array.join("")},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},show_library_modal:function(i){i.preventDefault();i.stopPropagation();var h=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){h.create_new_library_event()},Close:function(){h.modal.hide()}}})},create_new_library_event:function(){var j=this.serialize_new_library();if(this.validate_new_library(j)){var i=new c.Library();var h=this;i.save(j,{success:function(k){h.collection.add(k);h.modal.hide();h.clear_library_modal();h.render();e.success("Library created")},error:function(){e.error("An error occured :(")}})}else{e.error("Library's name is missing")}return false},clear_library_modal:function(){$("input[name='Name']").val("");$("input[name='Description']").val("");$("input[name='Synopsis']").val("")},serialize_new_library:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val(),synopsis:$("input[name='Synopsis']").val()}},validate_new_library:function(h){return h.name!==""}});return{LibraryListView:f}}); \ No newline at end of file diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/packed/mvc/library/library-librarytoolbar-view.js --- a/static/scripts/packed/mvc/library/library-librarytoolbar-view.js +++ b/static/scripts/packed/mvc/library/library-librarytoolbar-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(a,c,d,b){var e=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"delegate_modal","click #include_deleted_chk":"check_include_deleted"},initialize:function(){this.render()},render:function(){var h=this.templateToolBar();var g=Galaxy.currUser.isAdmin();var f=Galaxy.currUser.isAnonymous();this.$el.html(h({admin_user:g,anon_user:f}));if(Galaxy.currUser.isAdmin()===true){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},delegate_modal:function(f){Galaxy.libraries.libraryListView.show_library_modal(f)},check_include_deleted:function(f){if(f.target.checked){Galaxy.libraries.preferences.set({with_deleted:true});Galaxy.libraries.libraryListView.render()}else{Galaxy.libraries.preferences.set({with_deleted:false});Galaxy.libraries.libraryListView.render()}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push(' <div id="toolbar_form" margin-top:0.5em; ">');tmpl_array.push(' <h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>');tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push(' <div id="library_toolbar">');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"><span class="fa fa-trash-o fa-lg"></span></input></span>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Create New Library"><button id="create_new_library_btn" class="primary-button btn-xs" type="button"><span class="fa fa-plus"></span> New Library</button><span>');tmpl_array.push(" </div>");tmpl_array.push(" <% } %>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="libraries_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))}});return{LibraryToolbarView:e}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(a,c,d,b){var e=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"delegate_modal","click #include_deleted_chk":"check_include_deleted"},initialize:function(){this.render()},render:function(){var h=this.templateToolBar();var g=false;var f=false;if(Galaxy.currUser){g=Galaxy.currUser.isAdmin();f=Galaxy.currUser.isAnonymous()}else{f=true}this.$el.html(h({admin_user:g,anon_user:f}));if(g){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},delegate_modal:function(f){Galaxy.libraries.libraryListView.show_library_modal(f)},check_include_deleted:function(f){if(f.target.checked){Galaxy.libraries.preferences.set({with_deleted:true});Galaxy.libraries.libraryListView.render()}else{Galaxy.libraries.preferences.set({with_deleted:false});Galaxy.libraries.libraryListView.render()}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push(' <div id="toolbar_form" margin-top:0.5em; ">');tmpl_array.push(' <h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-fold..." target="_blank">Trello</a>.</h3>');tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push(' <div id="library_toolbar">');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"><span class="fa fa-trash-o fa-lg"></span></input></span>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Create New Library"><button id="create_new_library_btn" class="primary-button btn-xs" type="button"><span class="fa fa-plus"></span> New Library</button><span>');tmpl_array.push(" </div>");tmpl_array.push(" <% } %>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="libraries_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))}});return{LibraryToolbarView:e}}); \ No newline at end of file diff -r ed5f15df397e839a285b77797fcfc0ebcdef90ab -r 166660f085a51316976df1ffef426997ed393a24 static/scripts/packed/mvc/library/library-model.js --- a/static/scripts/packed/mvc/library/library-model.js +++ b/static/scripts/packed/mvc/library/library-model.js @@ -1,1 +1,1 @@ -define([],function(){var f=Backbone.Model.extend({urlRoot:"/api/libraries/",isVisible:function(l){var k=true;if((!show_delete)&&(this.get("deleted"))){k=false}return k}});var a=Backbone.Model.extend({urlRoot:"/api/folders"});var i=Backbone.Collection.extend({url:"/api/libraries",model:f,sort_key:"name",sort_order:null,initialize:function(k){k=k||{}},getVisible:function(l,m){m=m||[];var k=new i(this.filter(function(n){return n.isVisible(l)}));return k}});var g=Backbone.Model.extend({urlRoot:"/api/libraries/datasets"});var c=Backbone.Collection.extend({model:g});var e=Backbone.Model.extend({defaults:{folder:new c(),urlRoot:"/api/folders/",id:"unknown"},parse:function(k){this.get("folder").reset(k.folder_contents);return k}});var b=Backbone.Model.extend({urlRoot:"/api/histories/"});var d=Backbone.Collection.extend({urlRoot:"/api/histories/",initialize:function(k){this.id=k.id},url:function(){return this.urlRoot+this.id+"/contents"},model:b});var h=Backbone.Model.extend({urlRoot:"/api/histories/"});var j=Backbone.Collection.extend({url:"/api/histories",model:h});return{Library:f,FolderAsModel:a,Libraries:i,Item:g,Folder:c,FolderContainer:e,HistoryItem:b,HistoryContents:d,GalaxyHistory:h,GalaxyHistories:j}}); \ No newline at end of file +define([],function(){var f=Backbone.Model.extend({urlRoot:"/api/libraries/",isVisible:function(l){var k=true;if((!show_delete)&&(this.get("deleted"))){k=false}return k}});var i=Backbone.Collection.extend({url:"/api/libraries",model:f,sort_key:"name",sort_order:null,initialize:function(k){k=k||{}},getVisible:function(l,m){m=m||[];var k=new i(this.filter(function(n){return n.isVisible(l)}));return k},sortByNameAsc:function(){this.comparator=function(l,k){if(l.get("name").toLowerCase()>k.get("name").toLowerCase()){return 1}if(k.get("name").toLowerCase()>l.get("name").toLowerCase()){return -1}return 0};this.sort();return this},sortByNameDesc:function(){this.comparator=function(l,k){if(l.get("name").toLowerCase()>k.get("name").toLowerCase()){return -1}if(k.get("name").toLowerCase()>l.get("name").toLowerCase()){return 1}return 0};this.sort();return this}});var g=Backbone.Model.extend({urlRoot:"/api/libraries/datasets"});var a=Backbone.Model.extend({urlRoot:"/api/folders"});var c=Backbone.Collection.extend({model:g,sortByNameAsc:function(){this.comparator=function(l,k){if(l.get("type")===k.get("type")){if(l.get("name").toLowerCase()>k.get("name").toLowerCase()){return 1}if(k.get("name").toLowerCase()>l.get("name").toLowerCase()){return -1}return 0}else{if(l.get("type")==="folder"){return -1}else{return 1}}};this.sort();return this},sortByNameDesc:function(){this.comparator=function(l,k){if(l.get("type")===k.get("type")){if(l.get("name").toLowerCase()>k.get("name").toLowerCase()){return -1}if(k.get("name").toLowerCase()>l.get("name").toLowerCase()){return 1}return 0}else{if(l.get("type")==="folder"){return -1}else{return 1}}};this.sort();return this}});var e=Backbone.Model.extend({defaults:{folder:new c(),urlRoot:"/api/folders/",id:"unknown"},parse:function(k){this.get("folder").reset(k.folder_contents);return k}});var b=Backbone.Model.extend({urlRoot:"/api/histories/"});var d=Backbone.Collection.extend({urlRoot:"/api/histories/",initialize:function(k){this.id=k.id},url:function(){return this.urlRoot+this.id+"/contents"},model:b});var h=Backbone.Model.extend({urlRoot:"/api/histories/"});var j=Backbone.Collection.extend({url:"/api/histories",model:h});return{Library:f,FolderAsModel:a,Libraries:i,Item:g,Folder:c,FolderContainer:e,HistoryItem:b,HistoryContents:d,GalaxyHistory:h,GalaxyHistories:j}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org