diff --git a/client/galaxy/scripts/galaxy.library.js b/client/galaxy/scripts/galaxy.library.js index 201f1eeafc0..f45f2ee32b3 100644 --- a/client/galaxy/scripts/galaxy.library.js +++ b/client/galaxy/scripts/galaxy.library.js @@ -16,19 +16,19 @@ define([ "mvc/library/library-library-view", "mvc/library/library-folder-view" ], -function(mod_masthead, - mod_utils, - mod_toastr, - mod_baseMVC, - mod_library_model, - mod_folderlist_view, - mod_librarylist_view, - mod_librarytoolbar_view, - mod_foldertoolbar_view, - mod_library_dataset_view, - mod_library_library_view, - mod_library_folder_view - ) { + function(mod_masthead, + mod_utils, + mod_toastr, + mod_baseMVC, + mod_library_model, + mod_folderlist_view, + mod_librarylist_view, + mod_librarytoolbar_view, + mod_foldertoolbar_view, + mod_library_dataset_view, + mod_library_library_view, + mod_library_folder_view + ) { // ============================================================================ // ROUTER @@ -37,10 +37,11 @@ var LibraryRouter = Backbone.Router.extend({ this.routesHit = 0; //keep count of number of routes handled by the application Backbone.history.on('route', function() { this.routesHit++; }, this); - }, +}, - routes: { +routes: { "" : "libraries", + "page/:show_page" : "libraries_page", "library/:library_id/permissions" : "library_permissions", "folders/:folder_id/permissions" : "folder_permissions", "folders/:id" : "folder_content", @@ -49,27 +50,28 @@ var LibraryRouter = Backbone.Router.extend({ "folders/:folder_id/datasets/:dataset_id/versions/:ldda_id" : "dataset_version", "folders/:folder_id/download/:format" : "download", "folders/:folder_id/import/:source" : "import_datasets" - }, +}, - back: function() { +back: function() { if(this.routesHit > 1) { //more than one route hit -> user did not land to current page directly window.history.back(); - } else { + } else { //otherwise go to the home page. Use replaceState if available so //the navigation doesn't create an extra history entry this.navigate('#', {trigger:true, replace:true}); - } } +} }); // ============================================================================ /** session storage for library preferences */ var LibraryPrefs = mod_baseMVC.SessionStorageModel.extend({ defaults : { - with_deleted : false, - sort_order : 'asc', - sort_by : 'name' + with_deleted : false, + sort_order : 'asc', + sort_by : 'name', + library_page_size : 20 } }); @@ -88,77 +90,86 @@ var GalaxyLibrary = Backbone.View.extend({ initialize : function(){ Galaxy.libraries = this; - this.preferences = new LibraryPrefs( {id: 'global-lib-prefs'} ); + this.preferences = new LibraryPrefs( { id: 'global-lib-prefs' } ); this.library_router = new LibraryRouter(); this.library_router.on('route:libraries', function() { Galaxy.libraries.libraryToolbarView = new mod_librarytoolbar_view.LibraryToolbarView(); Galaxy.libraries.libraryListView = new mod_librarylist_view.LibraryListView(); + }); + + this.library_router.on('route:libraries_page', function( show_page ) { + if ( Galaxy.libraries.libraryToolbarView === null ){ + Galaxy.libraries.libraryToolbarView = new mod_librarytoolbar_view.LibraryToolbarView(); + Galaxy.libraries.libraryListView = new mod_librarylist_view.LibraryListView( { show_page: show_page } ); + } else { + Galaxy.libraries.libraryListView.render( { show_page: show_page } ) + } }); this.library_router.on('route:folder_content', function(id) { if (Galaxy.libraries.folderToolbarView){ Galaxy.libraries.folderToolbarView.$el.unbind('click'); - } - Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: id}); - Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: id}); - }); + } + Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: id}); + Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: id}); + }); - this.library_router.on('route:download', function(folder_id, format) { + this.library_router.on('route:download', function(folder_id, format) { if ($('#folder_list_body').find(':checked').length === 0) { mod_toastr.info( 'You must select at least one dataset to download' ); Galaxy.libraries.library_router.navigate('folders/' + folder_id, {trigger: true, replace: true}); - } else { + } else { Galaxy.libraries.folderToolbarView.download(folder_id, format); Galaxy.libraries.library_router.navigate('folders/' + folder_id, {trigger: false, replace: true}); - } - }); + } + }); - this.library_router.on('route:dataset_detail', function(folder_id, dataset_id){ + this.library_router.on('route:dataset_detail', function(folder_id, dataset_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id}); - }); - this.library_router.on('route:dataset_version', function(folder_id, dataset_id, ldda_id){ + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id}); + }); + this.library_router.on('route:dataset_version', function(folder_id, dataset_id, ldda_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, ldda_id: ldda_id, show_version: true}); - }); + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, ldda_id: ldda_id, show_version: true}); + }); - this.library_router.on('route:dataset_permissions', function(folder_id, dataset_id){ + this.library_router.on('route:dataset_permissions', function(folder_id, dataset_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true}); - }); + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true}); + }); - this.library_router.on('route:library_permissions', function(library_id){ + this.library_router.on('route:library_permissions', function(library_id){ if (Galaxy.libraries.libraryView){ Galaxy.libraries.libraryView.$el.unbind('click'); - } - Galaxy.libraries.libraryView = new mod_library_library_view.LibraryView({id: library_id, show_permissions: true}); - }); + } + Galaxy.libraries.libraryView = new mod_library_library_view.LibraryView({id: library_id, show_permissions: true}); + }); - this.library_router.on('route:folder_permissions', function(folder_id){ + this.library_router.on('route:folder_permissions', function(folder_id){ if (Galaxy.libraries.folderView){ Galaxy.libraries.folderView.$el.unbind('click'); - } - Galaxy.libraries.folderView = new mod_library_folder_view.FolderView({id: folder_id, show_permissions: true}); - }); - this.library_router.on('route:import_datasets', function(folder_id, source){ + } + Galaxy.libraries.folderView = new mod_library_folder_view.FolderView({id: folder_id, show_permissions: true}); + }); + this.library_router.on('route:import_datasets', function(folder_id, source){ if (Galaxy.libraries.folderToolbarView && Galaxy.libraries.folderListView){ Galaxy.libraries.folderToolbarView.showImportModal({source:source}); - } else { + } else { Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: folder_id}); Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: folder_id}); Galaxy.libraries.folderToolbarView.showImportModal({source: source}); - } - }); + } + }); - Backbone.history.start({pushState: false}); + Backbone.history.start({pushState: false}); } }); diff --git a/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js b/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js index 19cde797371..ec532b71d74 100644 --- a/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js +++ b/client/galaxy/scripts/mvc/library/library-foldertoolbar-view.js @@ -72,7 +72,7 @@ var FolderToolbarView = Backbone.View.extend({ }, render: function(options){ - this.options = _.extend(this.options, options); + this.options = _.extend( this.options, options ); var toolbar_template = this.templateToolBar(); var template_defaults = { id: this.options.id, @@ -346,18 +346,18 @@ var FolderToolbarView = Backbone.View.extend({ this.modal = Galaxy.modal; var template_modal = this.templateImportPathModal(); this.modal.show({ - closing_events : true, - title : 'Please enter paths to import', - body : template_modal({}), - buttons : { - 'Import' : function() {that.importFromPathsClicked(that);}, - 'Close' : function() {Galaxy.modal.hide();} - }, - closing_callback: function(){ - // TODO: should not trigger routes outside of the router - Galaxy.libraries.library_router.navigate('folders/' + that.id, {trigger: true}); - } - }); + closing_events : true, + title : 'Please enter paths to import', + body : template_modal({}), + buttons : { + 'Import' : function() { that.importFromPathsClicked(that); }, + 'Close' : function() { Galaxy.modal.hide(); } + }, + closing_callback: function(){ + // TODO: should not trigger routes outside of the router + Galaxy.libraries.library_router.navigate( 'folders/' + that.id, { trigger: true } ); + } + }); this.renderSelectBoxes(); }, @@ -367,34 +367,37 @@ var FolderToolbarView = Backbone.View.extend({ */ fetchExtAndGenomes: function(){ var that = this; - mod_utils.get(galaxy_config.root + "api/datatypes?extension_only=False", - function(datatypes) { - for (key in datatypes) { - that.list_extensions.push({ - id : datatypes[key].extension, - text : datatypes[key].extension, - description : datatypes[key].description, - description_url : datatypes[key].description_url - }); - } - that.list_extensions.sort(function(a, b) { - return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; - }); - that.list_extensions.unshift(that.auto); - - }); - mod_utils.get(galaxy_config.root + "api/genomes", - function(genomes) { - for (key in genomes) { - that.list_genomes.push({ - id : genomes[key][1], - text : genomes[key][0] - }); - } - that.list_genomes.sort(function(a, b) { - return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; - }); - }); + mod_utils.get({ + url : galaxy_config.root + "api/datatypes?extension_only=False", + success : function( datatypes ) { + for (key in datatypes) { + that.list_extensions.push({ + id : datatypes[key].extension, + text : datatypes[key].extension, + description : datatypes[key].description, + description_url : datatypes[key].description_url + }); + } + that.list_extensions.sort(function(a, b) { + return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; + }); + that.list_extensions.unshift(that.auto); + } + }); + mod_utils.get({ + url: galaxy_config.root + "api/genomes", + success: function( genomes ) { + for ( key in genomes ) { + that.list_genomes.push({ + id : genomes[key][1], + text : genomes[key][0] + }); + } + that.list_genomes.sort(function(a, b) { + return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; + }); + } + }); }, renderSelectBoxes: function(){ @@ -1027,7 +1030,7 @@ var FolderToolbarView = Backbone.View.extend({ tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); - tmpl_array.push(' '); + tmpl_array.push(' '); tmpl_array.push(' '); // TOOLBAR END diff --git a/client/galaxy/scripts/mvc/library/library-librarylist-view.js b/client/galaxy/scripts/mvc/library/library-librarylist-view.js index d2f97be1b02..65ddfc85c1a 100644 --- a/client/galaxy/scripts/mvc/library/library-librarylist-view.js +++ b/client/galaxy/scripts/mvc/library/library-librarylist-view.js @@ -4,13 +4,15 @@ define([ "utils/utils", "libs/toastr", "mvc/library/library-model", - "mvc/library/library-libraryrow-view"], -function(mod_masthead, - mod_baseMVC, - mod_utils, - mod_toastr, - mod_library_model, - mod_library_libraryrow_view) { + "mvc/library/library-libraryrow-view" +], function( + mod_masthead, + mod_baseMVC, + mod_utils, + mod_toastr, + mod_library_model, + mod_library_libraryrow_view +){ var LibraryListView = Backbone.View.extend({ el: '#libraries_element', @@ -19,104 +21,135 @@ var LibraryListView = Backbone.View.extend({ 'click .sort-libraries-link' : 'sort_clicked' }, - modal: null, + /** + * Initialize and fetch the libraries from server. + * Async render afterwards. + * @param {object} options an options object + */ + defaults: { + page_count: null, + show_page: null + }, - // collection of {Item}s - collection: null, + initialize : function( options ){ + this.options = _.defaults( this.options || {}, this.defaults, options ); - // map of library model ids to library views = cache - rowViews: {}, - - initialize : function(options){ - this.options = _.defaults(this.options || {}, options); - var that = this; + var that = this; + this.modal = null; + // map of library model ids to library views = cache this.rowViews = {}; + // collection of {Item}s this.collection = new mod_library_model.Libraries(); this.collection.fetch({ success: function(){ that.render(); }, - error: function(model, response){ - if (typeof response.responseJSON !== "undefined"){ - mod_toastr.error(response.responseJSON.err_msg); + error: function( model, response ){ + if ( typeof response.responseJSON !== "undefined" ){ + mod_toastr.error( response.responseJSON.err_msg ); } else { - mod_toastr.error('An error ocurred.'); + mod_toastr.error( 'An error ocurred.' ); } } }); }, - /** Renders the libraries table either from the object's own collection, - * or from a given array of library models, - * or renders an empty list in case no data is given. */ - render: function (options) { - $(".tooltip").hide(); - var template = this.templateLibraryList(); - var libraries_to_render = null; - var include_deleted = Galaxy.libraries.preferences.get('with_deleted'); - var models = null; - if (typeof options !== 'undefined'){ - include_deleted = typeof options.with_deleted !== 'undefined' ? options.with_deleted : false; - models = typeof options.models !== 'undefined' ? options.models : null; + /** + * Render the libraries table either from the object's own collection, + * or from a given array of library models, + * or render an empty list in case no data is given. + */ + render: function ( options ) { + this.options = _.extend( this.options, options ); + + if ( ( this.options.page_size != null ) && ( this.options.page_size == parseInt( this.options.page_size ) ) ) { + Galaxy.libraries.preferences.set( { 'library_page_size': parseInt( this.options.page_size ) } ); } - if (this.collection !== null && models === null){ + $( ".tooltip" ).hide(); + // this.options.show_page = this.options.show_page || 1; + var template = this.templateLibraryList(); + var libraries_to_render = null; + var models = null; + if ( this.options.show_page === null || this.options.show_page < 1 ){ + this.options.show_page = 1; + } + if ( typeof options !== 'undefined' ){ + models = typeof options.models !== 'undefined' ? options.models : null; + } + if ( this.collection !== null && models === null ){ this.sortLibraries(); - if (include_deleted){ // show all the libraries + if ( Galaxy.libraries.preferences.get( 'with_deleted' ) ){ libraries_to_render = this.collection.models; - } else{ // show only undeleted libraries - libraries_to_render = this.collection.where({deleted: false}); + } else { + libraries_to_render = this.collection.where( { deleted: false } ); } - } else if (models !== null){ + } else if ( models !== null ){ libraries_to_render = models; } else { libraries_to_render = []; - } - - this.$el.html(template({length: libraries_to_render.length, order: Galaxy.libraries.preferences.get('sort_order') })); - - if (libraries_to_render.length > 0){ - this.renderRows(libraries_to_render); } - // initialize the library tooltips - $("#center [data-toggle]").tooltip(); - // modification of upper DOM element to show scrollbars due - // to the #center element inheritance - $("#center").css('overflow','auto'); + this.options.total_libraries_count = libraries_to_render.length + var page_start = ( Galaxy.libraries.preferences.get( 'library_page_size' ) * ( this.options.show_page - 1 ) ); + this.options.page_count = Math.ceil( this.options.total_libraries_count / Galaxy.libraries.preferences.get( 'library_page_size' ) ); + if ( this.options.total_libraries_count > 0 && ( page_start < this.options.total_libraries_count ) ){ + libraries_to_render = libraries_to_render.slice( page_start, page_start + Galaxy.libraries.preferences.get( 'library_page_size' ) ); + this.options.libraries_shown = libraries_to_render.length; + // User requests page with no libraries + if ( Galaxy.libraries.preferences.get( 'library_page_size' ) * this.options.show_page > ( this.options.total_libraries_count + Galaxy.libraries.preferences.get( 'library_page_size' ) ) ){ + libraries_to_render = []; + } + this.$el.html( template({ + length: 1, + order: Galaxy.libraries.preferences.get( 'sort_order' ) + })); + Galaxy.libraries.libraryToolbarView.renderPaginator( this.options ); + this.renderRows( libraries_to_render ); + } else { + this.$el.html( template({ + length: 0, + order: Galaxy.libraries.preferences.get( 'sort_order' ) + })); + Galaxy.libraries.libraryToolbarView.renderPaginator( this.options ); + } + $( "#center [data-toggle]" ).tooltip(); + $( "#center" ).css( 'overflow','auto' ); }, - /** Renders all given models as rows in the library list */ - renderRows: function(libraries_to_render){ - for (var i = 0; i < libraries_to_render.length; i++) { + /** + * Render all given models as rows in the library list + * @param {array} libraries_to_render array of library models to render + */ + renderRows: function( libraries_to_render ){ + for ( var i = 0; i < libraries_to_render.length; i++ ) { var library = libraries_to_render[i]; - var cachedView = _.findWhere(this.rowViews, {id: library.get('id')}); - if (cachedView !== undefined && this instanceof Backbone.View){ + // search whether we have the item cached + var cachedView = _.findWhere( this.rowViews, { id: library.get( 'id' ) } ); + if ( cachedView !== undefined && this instanceof Backbone.View ){ cachedView.delegateEvents(); - this.$el.find('#library_list_body').append(cachedView.el); + this.$el.find( '#library_list_body' ).append( cachedView.el ); } else { - this.renderOne({library:library}) + this.renderOne( { library: library } ) } } }, /** - * Creates a view for the given model and adds it to the libraries view. + * Create a view for the given model and add it to the libraries view. * @param {Library} model of the view that will be rendered */ - renderOne: function(options){ + renderOne: function( options ){ var library = options.library; - var rowView = new mod_library_libraryrow_view.LibraryRowView(library); - // we want to prepend new item - if (options.prepend){ - this.$el.find('#library_list_body').prepend(rowView.el); - } else { - this.$el.find('#library_list_body').append(rowView.el); - } + var rowView = new mod_library_libraryrow_view.LibraryRowView( library ); + this.$el.find( '#library_list_body' ).append( rowView.el ); // save new rowView to cache - this.rowViews[library.get('id')] = rowView; + this.rowViews[ library.get( 'id' ) ] = rowView; }, - /** Table heading was clicked, update sorting preferences and re-render */ + /** + * Table heading was clicked, update sorting preferences and re-render. + * @return {[type]} [description] + */ sort_clicked : function(){ if (Galaxy.libraries.preferences.get('sort_order') === 'asc'){ Galaxy.libraries.preferences.set({'sort_order': 'desc'}); @@ -126,8 +159,10 @@ var LibraryListView = Backbone.View.extend({ this.render(); }, - /** Sorts the underlying collection according to the parameters received. - Currently supports only sorting by name. */ + /** + * Sort the underlying collection according to the parameters received. + * Currently supports only sorting by name. + */ sortLibraries: function(){ if (Galaxy.libraries.preferences.get('sort_by') === 'name'){ if (Galaxy.libraries.preferences.get('sort_order') === 'asc'){ @@ -138,6 +173,13 @@ var LibraryListView = Backbone.View.extend({ } }, + redirectToHome: function(){ + window.location = '../'; + }, + redirectToLogin: function(){ + window.location = '/user/login'; + }, + // MMMMMMMMMMMMMMMMMM // === TEMPLATES ==== // MMMMMMMMMMMMMMMMMM @@ -147,14 +189,14 @@ var LibraryListView = Backbone.View.extend({ tmpl_array.push('
'); tmpl_array.push('<% if(length === 0) { %>'); - tmpl_array.push('
There are no libraries visible to you. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
'); + tmpl_array.push('
There are no libraries visible to you here. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
'); tmpl_array.push('<% } else{ %>'); tmpl_array.push(''); tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); - tmpl_array.push(' '); + tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); // library item views will attach here @@ -166,14 +208,6 @@ var LibraryListView = Backbone.View.extend({ return _.template(tmpl_array.join('')); }, - - redirectToHome: function(){ - window.location = '../'; - }, - redirectToLogin: function(){ - window.location = '/user/login'; - }, - }); return { diff --git a/client/galaxy/scripts/mvc/library/library-librarytoolbar-view.js b/client/galaxy/scripts/mvc/library/library-librarytoolbar-view.js index b233eeec82e..3fb41d82cb9 100644 --- a/client/galaxy/scripts/mvc/library/library-librarytoolbar-view.js +++ b/client/galaxy/scripts/mvc/library/library-librarytoolbar-view.js @@ -11,11 +11,13 @@ var LibraryToolbarView = Backbone.View.extend({ el: '#center', events: { - 'click #create_new_library_btn' : 'show_library_modal', - 'click #include_deleted_chk' : 'check_include_deleted' + 'click #create_new_library_btn' : 'showLibraryModal', + 'click #include_deleted_chk' : 'includeDeletedChecked', + 'click #page_size_prompt' : 'showPageSizePrompt' }, - initialize: function(){ + initialize: function( options ){ + this.options = _.defaults( this.options || {}, options ); this.render(); }, @@ -23,21 +25,34 @@ var LibraryToolbarView = Backbone.View.extend({ var toolbar_template = this.templateToolBar(); var is_admin = false; var is_anonym = true; - if (Galaxy.currUser){ + if ( Galaxy.currUser ){ is_admin = Galaxy.currUser.isAdmin(); is_anonym = Galaxy.currUser.isAnonymous(); } - this.$el.html(toolbar_template({admin_user: is_admin, anon_user: is_anonym})); - if (is_admin){ - this.$el.find('#include_deleted_chk')[0].checked = Galaxy.libraries.preferences.get('with_deleted'); + this.$el.html(toolbar_template( { admin_user: is_admin, anon_user: is_anonym } ) ); + if ( is_admin ){ + this.$el.find( '#include_deleted_chk' )[0].checked = Galaxy.libraries.preferences.get( 'with_deleted' ); } }, - show_library_modal : function (event){ + /** + * Called from LibraryListView when needed. + * @param {object} options common options + */ + renderPaginator: function( options ){ + this.options = _.extend( this.options, options ); + var paginator_template = this.templatePaginator(); + this.$el.find( '#library_paginator' ).html( paginator_template({ + show_page: parseInt( this.options.show_page ), + page_count: parseInt( this.options.page_count ), + total_libraries_count: this.options.total_libraries_count, + libraries_shown: this.options.libraries_shown + })); + }, + + showLibraryModal : function (event){ event.preventDefault(); event.stopPropagation(); - - // create modal var self = this; this.modal = Galaxy.modal; this.modal.show({ @@ -45,22 +60,22 @@ var LibraryToolbarView = Backbone.View.extend({ title : 'Create New Library', body : this.templateNewLibraryInModal(), buttons : { - 'Create' : function() {self.create_new_library_event();}, - 'Close' : function() {self.modal.hide();} + 'Create' : function() { self.createNewLibrary(); }, + 'Close' : function() { self.modal.hide(); } } }); }, - create_new_library_event: function(){ - var libraryDetails = this.serialize_new_library(); - if (this.validate_new_library(libraryDetails)){ + createNewLibrary: function(){ + var libraryDetails = this.serializeNewLibrary(); + if (this.valdiateNewLibrary(libraryDetails)){ var library = new mod_library_model.Library(); var self = this; library.save(libraryDetails, { success: function (library) { Galaxy.libraries.libraryListView.collection.add(library); self.modal.hide(); - self.clear_library_modal(); + self.clearLibraryModal(); Galaxy.libraries.libraryListView.render(); mod_toastr.success('Library created.'); }, @@ -78,15 +93,22 @@ var LibraryToolbarView = Backbone.View.extend({ return false; }, + showPageSizePrompt: function(){ + var library_page_size = prompt( 'How many libraries per page do you want to see?', Galaxy.libraries.preferences.get( 'library_page_size' ) ); + if ( ( library_page_size != null ) && ( library_page_size == parseInt( library_page_size ) ) ) { + Galaxy.libraries.preferences.set( { 'library_page_size': parseInt( library_page_size ) } ); + Galaxy.libraries.libraryListView.render(); + } + }, + // clear the library modal once saved - clear_library_modal : function(){ + clearLibraryModal : function(){ $("input[name='Name']").val(''); $("input[name='Description']").val(''); $("input[name='Synopsis']").val(''); }, - // serialize data from the new library form - serialize_new_library : function(){ + serializeNewLibrary : function(){ return { name: $("input[name='Name']").val(), description: $("input[name='Description']").val(), @@ -94,18 +116,20 @@ var LibraryToolbarView = Backbone.View.extend({ }; }, - // validate new library info - validate_new_library: function(libraryDetails){ + valdiateNewLibrary: function( libraryDetails ){ return libraryDetails.name !== ''; }, - // include or exclude deleted libraries from the view - check_include_deleted: function(event){ + /** + * Include or exclude deleted libraries in the view. + * @param {object} event common event + */ + includeDeletedChecked: function( event ){ if (event.target.checked){ - Galaxy.libraries.preferences.set({'with_deleted': true}); + Galaxy.libraries.preferences.set( { 'with_deleted': true } ); Galaxy.libraries.libraryListView.render(); } else{ - Galaxy.libraries.preferences.set({'with_deleted': false}); + Galaxy.libraries.preferences.set( { 'with_deleted': false } ); Galaxy.libraries.libraryListView.render(); } }, @@ -113,22 +137,26 @@ var LibraryToolbarView = Backbone.View.extend({ templateToolBar: function(){ tmpl_array = []; + tmpl_array.push('
'); - // TOOLBAR tmpl_array.push('
'); tmpl_array.push('
'); - tmpl_array.push(' DATA LIBRARIES'); - tmpl_array.push(' <% if(admin_user === true) { %>'); - tmpl_array.push(' | include deleted |'); - tmpl_array.push(' '); - tmpl_array.push(' <% } %>'); - tmpl_array.push(' '); - tmpl_array.push('
'); - - tmpl_array.push('
'); - tmpl_array.push(' '); - tmpl_array.push('
'); - + tmpl_array.push('
'); + tmpl_array.push(' DATA LIBRARIES'); + tmpl_array.push(' <% if(admin_user === true) { %>'); + tmpl_array.push('
'); + tmpl_array.push(' '); + tmpl_array.push('
'); + tmpl_array.push(' '); + tmpl_array.push(' <% } %>'); + tmpl_array.push(' '); + tmpl_array.push(' '); + // paginator will append here + tmpl_array.push(' '); + tmpl_array.push(' '); + tmpl_array.push('
'); tmpl_array.push('
'); tmpl_array.push('
'); // table with libraries will append here @@ -138,6 +166,39 @@ var LibraryToolbarView = Backbone.View.extend({ return _.template(tmpl_array.join('')); }, + templatePaginator: function(){ + tmpl_array = []; + + tmpl_array.push(' '); + tmpl_array.push(' '); + tmpl_array.push(' showing <%- libraries_shown %> of <%- total_libraries_count %> libraries'); + tmpl_array.push(' '); + + return _.template(tmpl_array.join('')); + }, templateNewLibraryInModal: function(){ tmpl_array = []; diff --git a/lib/galaxy/managers/libraries.py b/lib/galaxy/managers/libraries.py index d73cae3bb08..c3949608bb5 100644 --- a/lib/galaxy/managers/libraries.py +++ b/lib/galaxy/managers/libraries.py @@ -103,6 +103,9 @@ class LibraryManager( object ): :param deleted: if True, show only ``deleted`` libraries, if False show only ``non-deleted`` :type deleted: boolean (optional) + + :returns: query that will emit all accessible libraries + :rtype: sqlalchemy query """ is_admin = trans.user_is_admin() query = trans.sa_session.query( trans.app.model.Library ) diff --git a/static/scripts/galaxy.library.js b/static/scripts/galaxy.library.js index 201f1eeafc0..f45f2ee32b3 100644 --- a/static/scripts/galaxy.library.js +++ b/static/scripts/galaxy.library.js @@ -16,19 +16,19 @@ define([ "mvc/library/library-library-view", "mvc/library/library-folder-view" ], -function(mod_masthead, - mod_utils, - mod_toastr, - mod_baseMVC, - mod_library_model, - mod_folderlist_view, - mod_librarylist_view, - mod_librarytoolbar_view, - mod_foldertoolbar_view, - mod_library_dataset_view, - mod_library_library_view, - mod_library_folder_view - ) { + function(mod_masthead, + mod_utils, + mod_toastr, + mod_baseMVC, + mod_library_model, + mod_folderlist_view, + mod_librarylist_view, + mod_librarytoolbar_view, + mod_foldertoolbar_view, + mod_library_dataset_view, + mod_library_library_view, + mod_library_folder_view + ) { // ============================================================================ // ROUTER @@ -37,10 +37,11 @@ var LibraryRouter = Backbone.Router.extend({ this.routesHit = 0; //keep count of number of routes handled by the application Backbone.history.on('route', function() { this.routesHit++; }, this); - }, +}, - routes: { +routes: { "" : "libraries", + "page/:show_page" : "libraries_page", "library/:library_id/permissions" : "library_permissions", "folders/:folder_id/permissions" : "folder_permissions", "folders/:id" : "folder_content", @@ -49,27 +50,28 @@ var LibraryRouter = Backbone.Router.extend({ "folders/:folder_id/datasets/:dataset_id/versions/:ldda_id" : "dataset_version", "folders/:folder_id/download/:format" : "download", "folders/:folder_id/import/:source" : "import_datasets" - }, +}, - back: function() { +back: function() { if(this.routesHit > 1) { //more than one route hit -> user did not land to current page directly window.history.back(); - } else { + } else { //otherwise go to the home page. Use replaceState if available so //the navigation doesn't create an extra history entry this.navigate('#', {trigger:true, replace:true}); - } } +} }); // ============================================================================ /** session storage for library preferences */ var LibraryPrefs = mod_baseMVC.SessionStorageModel.extend({ defaults : { - with_deleted : false, - sort_order : 'asc', - sort_by : 'name' + with_deleted : false, + sort_order : 'asc', + sort_by : 'name', + library_page_size : 20 } }); @@ -88,77 +90,86 @@ var GalaxyLibrary = Backbone.View.extend({ initialize : function(){ Galaxy.libraries = this; - this.preferences = new LibraryPrefs( {id: 'global-lib-prefs'} ); + this.preferences = new LibraryPrefs( { id: 'global-lib-prefs' } ); this.library_router = new LibraryRouter(); this.library_router.on('route:libraries', function() { Galaxy.libraries.libraryToolbarView = new mod_librarytoolbar_view.LibraryToolbarView(); Galaxy.libraries.libraryListView = new mod_librarylist_view.LibraryListView(); + }); + + this.library_router.on('route:libraries_page', function( show_page ) { + if ( Galaxy.libraries.libraryToolbarView === null ){ + Galaxy.libraries.libraryToolbarView = new mod_librarytoolbar_view.LibraryToolbarView(); + Galaxy.libraries.libraryListView = new mod_librarylist_view.LibraryListView( { show_page: show_page } ); + } else { + Galaxy.libraries.libraryListView.render( { show_page: show_page } ) + } }); this.library_router.on('route:folder_content', function(id) { if (Galaxy.libraries.folderToolbarView){ Galaxy.libraries.folderToolbarView.$el.unbind('click'); - } - Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: id}); - Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: id}); - }); + } + Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: id}); + Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: id}); + }); - this.library_router.on('route:download', function(folder_id, format) { + this.library_router.on('route:download', function(folder_id, format) { if ($('#folder_list_body').find(':checked').length === 0) { mod_toastr.info( 'You must select at least one dataset to download' ); Galaxy.libraries.library_router.navigate('folders/' + folder_id, {trigger: true, replace: true}); - } else { + } else { Galaxy.libraries.folderToolbarView.download(folder_id, format); Galaxy.libraries.library_router.navigate('folders/' + folder_id, {trigger: false, replace: true}); - } - }); + } + }); - this.library_router.on('route:dataset_detail', function(folder_id, dataset_id){ + this.library_router.on('route:dataset_detail', function(folder_id, dataset_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id}); - }); - this.library_router.on('route:dataset_version', function(folder_id, dataset_id, ldda_id){ + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id}); + }); + this.library_router.on('route:dataset_version', function(folder_id, dataset_id, ldda_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, ldda_id: ldda_id, show_version: true}); - }); + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, ldda_id: ldda_id, show_version: true}); + }); - this.library_router.on('route:dataset_permissions', function(folder_id, dataset_id){ + this.library_router.on('route:dataset_permissions', function(folder_id, dataset_id){ if (Galaxy.libraries.datasetView){ Galaxy.libraries.datasetView.$el.unbind('click'); - } - Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true}); - }); + } + Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true}); + }); - this.library_router.on('route:library_permissions', function(library_id){ + this.library_router.on('route:library_permissions', function(library_id){ if (Galaxy.libraries.libraryView){ Galaxy.libraries.libraryView.$el.unbind('click'); - } - Galaxy.libraries.libraryView = new mod_library_library_view.LibraryView({id: library_id, show_permissions: true}); - }); + } + Galaxy.libraries.libraryView = new mod_library_library_view.LibraryView({id: library_id, show_permissions: true}); + }); - this.library_router.on('route:folder_permissions', function(folder_id){ + this.library_router.on('route:folder_permissions', function(folder_id){ if (Galaxy.libraries.folderView){ Galaxy.libraries.folderView.$el.unbind('click'); - } - Galaxy.libraries.folderView = new mod_library_folder_view.FolderView({id: folder_id, show_permissions: true}); - }); - this.library_router.on('route:import_datasets', function(folder_id, source){ + } + Galaxy.libraries.folderView = new mod_library_folder_view.FolderView({id: folder_id, show_permissions: true}); + }); + this.library_router.on('route:import_datasets', function(folder_id, source){ if (Galaxy.libraries.folderToolbarView && Galaxy.libraries.folderListView){ Galaxy.libraries.folderToolbarView.showImportModal({source:source}); - } else { + } else { Galaxy.libraries.folderToolbarView = new mod_foldertoolbar_view.FolderToolbarView({id: folder_id}); Galaxy.libraries.folderListView = new mod_folderlist_view.FolderListView({id: folder_id}); Galaxy.libraries.folderToolbarView.showImportModal({source: source}); - } - }); + } + }); - Backbone.history.start({pushState: false}); + Backbone.history.start({pushState: false}); } }); diff --git a/static/scripts/mvc/library/library-foldertoolbar-view.js b/static/scripts/mvc/library/library-foldertoolbar-view.js index 19cde797371..ec532b71d74 100644 --- a/static/scripts/mvc/library/library-foldertoolbar-view.js +++ b/static/scripts/mvc/library/library-foldertoolbar-view.js @@ -72,7 +72,7 @@ var FolderToolbarView = Backbone.View.extend({ }, render: function(options){ - this.options = _.extend(this.options, options); + this.options = _.extend( this.options, options ); var toolbar_template = this.templateToolBar(); var template_defaults = { id: this.options.id, @@ -346,18 +346,18 @@ var FolderToolbarView = Backbone.View.extend({ this.modal = Galaxy.modal; var template_modal = this.templateImportPathModal(); this.modal.show({ - closing_events : true, - title : 'Please enter paths to import', - body : template_modal({}), - buttons : { - 'Import' : function() {that.importFromPathsClicked(that);}, - 'Close' : function() {Galaxy.modal.hide();} - }, - closing_callback: function(){ - // TODO: should not trigger routes outside of the router - Galaxy.libraries.library_router.navigate('folders/' + that.id, {trigger: true}); - } - }); + closing_events : true, + title : 'Please enter paths to import', + body : template_modal({}), + buttons : { + 'Import' : function() { that.importFromPathsClicked(that); }, + 'Close' : function() { Galaxy.modal.hide(); } + }, + closing_callback: function(){ + // TODO: should not trigger routes outside of the router + Galaxy.libraries.library_router.navigate( 'folders/' + that.id, { trigger: true } ); + } + }); this.renderSelectBoxes(); }, @@ -367,34 +367,37 @@ var FolderToolbarView = Backbone.View.extend({ */ fetchExtAndGenomes: function(){ var that = this; - mod_utils.get(galaxy_config.root + "api/datatypes?extension_only=False", - function(datatypes) { - for (key in datatypes) { - that.list_extensions.push({ - id : datatypes[key].extension, - text : datatypes[key].extension, - description : datatypes[key].description, - description_url : datatypes[key].description_url - }); - } - that.list_extensions.sort(function(a, b) { - return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; - }); - that.list_extensions.unshift(that.auto); - - }); - mod_utils.get(galaxy_config.root + "api/genomes", - function(genomes) { - for (key in genomes) { - that.list_genomes.push({ - id : genomes[key][1], - text : genomes[key][0] - }); - } - that.list_genomes.sort(function(a, b) { - return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; - }); - }); + mod_utils.get({ + url : galaxy_config.root + "api/datatypes?extension_only=False", + success : function( datatypes ) { + for (key in datatypes) { + that.list_extensions.push({ + id : datatypes[key].extension, + text : datatypes[key].extension, + description : datatypes[key].description, + description_url : datatypes[key].description_url + }); + } + that.list_extensions.sort(function(a, b) { + return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; + }); + that.list_extensions.unshift(that.auto); + } + }); + mod_utils.get({ + url: galaxy_config.root + "api/genomes", + success: function( genomes ) { + for ( key in genomes ) { + that.list_genomes.push({ + id : genomes[key][1], + text : genomes[key][0] + }); + } + that.list_genomes.sort(function(a, b) { + return a.id > b.id ? 1 : a.id < b.id ? -1 : 0; + }); + } + }); }, renderSelectBoxes: function(){ @@ -1027,7 +1030,7 @@ var FolderToolbarView = Backbone.View.extend({ tmpl_array.push('
'); tmpl_array.push(' '); tmpl_array.push(' '); - tmpl_array.push(' '); + tmpl_array.push(' '); tmpl_array.push(' '); // TOOLBAR END diff --git a/static/scripts/mvc/library/library-librarylist-view.js b/static/scripts/mvc/library/library-librarylist-view.js index d2f97be1b02..65ddfc85c1a 100644 --- a/static/scripts/mvc/library/library-librarylist-view.js +++ b/static/scripts/mvc/library/library-librarylist-view.js @@ -4,13 +4,15 @@ define([ "utils/utils", "libs/toastr", "mvc/library/library-model", - "mvc/library/library-libraryrow-view"], -function(mod_masthead, - mod_baseMVC, - mod_utils, - mod_toastr, - mod_library_model, - mod_library_libraryrow_view) { + "mvc/library/library-libraryrow-view" +], function( + mod_masthead, + mod_baseMVC, + mod_utils, + mod_toastr, + mod_library_model, + mod_library_libraryrow_view +){ var LibraryListView = Backbone.View.extend({ el: '#libraries_element', @@ -19,104 +21,135 @@ var LibraryListView = Backbone.View.extend({ 'click .sort-libraries-link' : 'sort_clicked' }, - modal: null, + /** + * Initialize and fetch the libraries from server. + * Async render afterwards. + * @param {object} options an options object + */ + defaults: { + page_count: null, + show_page: null + }, - // collection of {Item}s - collection: null, + initialize : function( options ){ + this.options = _.defaults( this.options || {}, this.defaults, options ); - // map of library model ids to library views = cache - rowViews: {}, - - initialize : function(options){ - this.options = _.defaults(this.options || {}, options); - var that = this; + var that = this; + this.modal = null; + // map of library model ids to library views = cache this.rowViews = {}; + // collection of {Item}s this.collection = new mod_library_model.Libraries(); this.collection.fetch({ success: function(){ that.render(); }, - error: function(model, response){ - if (typeof response.responseJSON !== "undefined"){ - mod_toastr.error(response.responseJSON.err_msg); + error: function( model, response ){ + if ( typeof response.responseJSON !== "undefined" ){ + mod_toastr.error( response.responseJSON.err_msg ); } else { - mod_toastr.error('An error ocurred.'); + mod_toastr.error( 'An error ocurred.' ); } } }); }, - /** Renders the libraries table either from the object's own collection, - * or from a given array of library models, - * or renders an empty list in case no data is given. */ - render: function (options) { - $(".tooltip").hide(); - var template = this.templateLibraryList(); - var libraries_to_render = null; - var include_deleted = Galaxy.libraries.preferences.get('with_deleted'); - var models = null; - if (typeof options !== 'undefined'){ - include_deleted = typeof options.with_deleted !== 'undefined' ? options.with_deleted : false; - models = typeof options.models !== 'undefined' ? options.models : null; + /** + * Render the libraries table either from the object's own collection, + * or from a given array of library models, + * or render an empty list in case no data is given. + */ + render: function ( options ) { + this.options = _.extend( this.options, options ); + + if ( ( this.options.page_size != null ) && ( this.options.page_size == parseInt( this.options.page_size ) ) ) { + Galaxy.libraries.preferences.set( { 'library_page_size': parseInt( this.options.page_size ) } ); } - if (this.collection !== null && models === null){ + $( ".tooltip" ).hide(); + // this.options.show_page = this.options.show_page || 1; + var template = this.templateLibraryList(); + var libraries_to_render = null; + var models = null; + if ( this.options.show_page === null || this.options.show_page < 1 ){ + this.options.show_page = 1; + } + if ( typeof options !== 'undefined' ){ + models = typeof options.models !== 'undefined' ? options.models : null; + } + if ( this.collection !== null && models === null ){ this.sortLibraries(); - if (include_deleted){ // show all the libraries + if ( Galaxy.libraries.preferences.get( 'with_deleted' ) ){ libraries_to_render = this.collection.models; - } else{ // show only undeleted libraries - libraries_to_render = this.collection.where({deleted: false}); + } else { + libraries_to_render = this.collection.where( { deleted: false } ); } - } else if (models !== null){ + } else if ( models !== null ){ libraries_to_render = models; } else { libraries_to_render = []; - } - - this.$el.html(template({length: libraries_to_render.length, order: Galaxy.libraries.preferences.get('sort_order') })); - - if (libraries_to_render.length > 0){ - this.renderRows(libraries_to_render); } - // initialize the library tooltips - $("#center [data-toggle]").tooltip(); - // modification of upper DOM element to show scrollbars due - // to the #center element inheritance - $("#center").css('overflow','auto'); + this.options.total_libraries_count = libraries_to_render.length + var page_start = ( Galaxy.libraries.preferences.get( 'library_page_size' ) * ( this.options.show_page - 1 ) ); + this.options.page_count = Math.ceil( this.options.total_libraries_count / Galaxy.libraries.preferences.get( 'library_page_size' ) ); + if ( this.options.total_libraries_count > 0 && ( page_start < this.options.total_libraries_count ) ){ + libraries_to_render = libraries_to_render.slice( page_start, page_start + Galaxy.libraries.preferences.get( 'library_page_size' ) ); + this.options.libraries_shown = libraries_to_render.length; + // User requests page with no libraries + if ( Galaxy.libraries.preferences.get( 'library_page_size' ) * this.options.show_page > ( this.options.total_libraries_count + Galaxy.libraries.preferences.get( 'library_page_size' ) ) ){ + libraries_to_render = []; + } + this.$el.html( template({ + length: 1, + order: Galaxy.libraries.preferences.get( 'sort_order' ) + })); + Galaxy.libraries.libraryToolbarView.renderPaginator( this.options ); + this.renderRows( libraries_to_render ); + } else { + this.$el.html( template({ + length: 0, + order: Galaxy.libraries.preferences.get( 'sort_order' ) + })); + Galaxy.libraries.libraryToolbarView.renderPaginator( this.options ); + } + $( "#center [data-toggle]" ).tooltip(); + $( "#center" ).css( 'overflow','auto' ); }, - /** Renders all given models as rows in the library list */ - renderRows: function(libraries_to_render){ - for (var i = 0; i < libraries_to_render.length; i++) { + /** + * Render all given models as rows in the library list + * @param {array} libraries_to_render array of library models to render + */ + renderRows: function( libraries_to_render ){ + for ( var i = 0; i < libraries_to_render.length; i++ ) { var library = libraries_to_render[i]; - var cachedView = _.findWhere(this.rowViews, {id: library.get('id')}); - if (cachedView !== undefined && this instanceof Backbone.View){ + // search whether we have the item cached + var cachedView = _.findWhere( this.rowViews, { id: library.get( 'id' ) } ); + if ( cachedView !== undefined && this instanceof Backbone.View ){ cachedView.delegateEvents(); - this.$el.find('#library_list_body').append(cachedView.el); + this.$el.find( '#library_list_body' ).append( cachedView.el ); } else { - this.renderOne({library:library}) + this.renderOne( { library: library } ) } } }, /** - * Creates a view for the given model and adds it to the libraries view. + * Create a view for the given model and add it to the libraries view. * @param {Library} model of the view that will be rendered */ - renderOne: function(options){ + renderOne: function( options ){ var library = options.library; - var rowView = new mod_library_libraryrow_view.LibraryRowView(library); - // we want to prepend new item - if (options.prepend){ - this.$el.find('#library_list_body').prepend(rowView.el); - } else { - this.$el.find('#library_list_body').append(rowView.el); - } + var rowView = new mod_library_libraryrow_view.LibraryRowView( library ); + this.$el.find( '#library_list_body' ).append( rowView.el ); // save new rowView to cache - this.rowViews[library.get('id')] = rowView; + this.rowViews[ library.get( 'id' ) ] = rowView; }, - /** Table heading was clicked, update sorting preferences and re-render */ + /** + * Table heading was clicked, update sorting preferences and re-render. + * @return {[type]} [description] + */ sort_clicked : function(){ if (Galaxy.libraries.preferences.get('sort_order') === 'asc'){ Galaxy.libraries.preferences.set({'sort_order': 'desc'}); @@ -126,8 +159,10 @@ var LibraryListView = Backbone.View.extend({ this.render(); }, - /** Sorts the underlying collection according to the parameters received. - Currently supports only sorting by name. */ + /** + * Sort the underlying collection according to the parameters received. + * Currently supports only sorting by name. + */ sortLibraries: function(){ if (Galaxy.libraries.preferences.get('sort_by') === 'name'){ if (Galaxy.libraries.preferences.get('sort_order') === 'asc'){ @@ -138,6 +173,13 @@ var LibraryListView = Backbone.View.extend({ } }, + redirectToHome: function(){ + window.location = '../'; + }, + redirectToLogin: function(){ + window.location = '/user/login'; + }, + // MMMMMMMMMMMMMMMMMM // === TEMPLATES ==== // MMMMMMMMMMMMMMMMMM @@ -147,14 +189,14 @@ var LibraryListView = Backbone.View.extend({ tmpl_array.push('
'); tmpl_array.push('<% if(length === 0) { %>'); - tmpl_array.push('
There are no libraries visible to you. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
'); + tmpl_array.push('
There are no libraries visible to you here. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
'); tmpl_array.push('<% } else{ %>'); tmpl_array.push('
name descriptionsynopsis
'); tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); - tmpl_array.push(' '); + tmpl_array.push(' '); tmpl_array.push(' '); tmpl_array.push(' '); // library item views will attach here @@ -166,14 +208,6 @@ var LibraryListView = Backbone.View.extend({ return _.template(tmpl_array.join('')); }, - - redirectToHome: function(){ - window.location = '../'; - }, - redirectToLogin: function(){ - window.location = '/user/login'; - }, - }); return { diff --git a/static/scripts/mvc/library/library-librarytoolbar-view.js b/static/scripts/mvc/library/library-librarytoolbar-view.js index b233eeec82e..3fb41d82cb9 100644 --- a/static/scripts/mvc/library/library-librarytoolbar-view.js +++ b/static/scripts/mvc/library/library-librarytoolbar-view.js @@ -11,11 +11,13 @@ var LibraryToolbarView = Backbone.View.extend({ el: '#center', events: { - 'click #create_new_library_btn' : 'show_library_modal', - 'click #include_deleted_chk' : 'check_include_deleted' + 'click #create_new_library_btn' : 'showLibraryModal', + 'click #include_deleted_chk' : 'includeDeletedChecked', + 'click #page_size_prompt' : 'showPageSizePrompt' }, - initialize: function(){ + initialize: function( options ){ + this.options = _.defaults( this.options || {}, options ); this.render(); }, @@ -23,21 +25,34 @@ var LibraryToolbarView = Backbone.View.extend({ var toolbar_template = this.templateToolBar(); var is_admin = false; var is_anonym = true; - if (Galaxy.currUser){ + if ( Galaxy.currUser ){ is_admin = Galaxy.currUser.isAdmin(); is_anonym = Galaxy.currUser.isAnonymous(); } - this.$el.html(toolbar_template({admin_user: is_admin, anon_user: is_anonym})); - if (is_admin){ - this.$el.find('#include_deleted_chk')[0].checked = Galaxy.libraries.preferences.get('with_deleted'); + this.$el.html(toolbar_template( { admin_user: is_admin, anon_user: is_anonym } ) ); + if ( is_admin ){ + this.$el.find( '#include_deleted_chk' )[0].checked = Galaxy.libraries.preferences.get( 'with_deleted' ); } }, - show_library_modal : function (event){ + /** + * Called from LibraryListView when needed. + * @param {object} options common options + */ + renderPaginator: function( options ){ + this.options = _.extend( this.options, options ); + var paginator_template = this.templatePaginator(); + this.$el.find( '#library_paginator' ).html( paginator_template({ + show_page: parseInt( this.options.show_page ), + page_count: parseInt( this.options.page_count ), + total_libraries_count: this.options.total_libraries_count, + libraries_shown: this.options.libraries_shown + })); + }, + + showLibraryModal : function (event){ event.preventDefault(); event.stopPropagation(); - - // create modal var self = this; this.modal = Galaxy.modal; this.modal.show({ @@ -45,22 +60,22 @@ var LibraryToolbarView = Backbone.View.extend({ title : 'Create New Library', body : this.templateNewLibraryInModal(), buttons : { - 'Create' : function() {self.create_new_library_event();}, - 'Close' : function() {self.modal.hide();} + 'Create' : function() { self.createNewLibrary(); }, + 'Close' : function() { self.modal.hide(); } } }); }, - create_new_library_event: function(){ - var libraryDetails = this.serialize_new_library(); - if (this.validate_new_library(libraryDetails)){ + createNewLibrary: function(){ + var libraryDetails = this.serializeNewLibrary(); + if (this.valdiateNewLibrary(libraryDetails)){ var library = new mod_library_model.Library(); var self = this; library.save(libraryDetails, { success: function (library) { Galaxy.libraries.libraryListView.collection.add(library); self.modal.hide(); - self.clear_library_modal(); + self.clearLibraryModal(); Galaxy.libraries.libraryListView.render(); mod_toastr.success('Library created.'); }, @@ -78,15 +93,22 @@ var LibraryToolbarView = Backbone.View.extend({ return false; }, + showPageSizePrompt: function(){ + var library_page_size = prompt( 'How many libraries per page do you want to see?', Galaxy.libraries.preferences.get( 'library_page_size' ) ); + if ( ( library_page_size != null ) && ( library_page_size == parseInt( library_page_size ) ) ) { + Galaxy.libraries.preferences.set( { 'library_page_size': parseInt( library_page_size ) } ); + Galaxy.libraries.libraryListView.render(); + } + }, + // clear the library modal once saved - clear_library_modal : function(){ + clearLibraryModal : function(){ $("input[name='Name']").val(''); $("input[name='Description']").val(''); $("input[name='Synopsis']").val(''); }, - // serialize data from the new library form - serialize_new_library : function(){ + serializeNewLibrary : function(){ return { name: $("input[name='Name']").val(), description: $("input[name='Description']").val(), @@ -94,18 +116,20 @@ var LibraryToolbarView = Backbone.View.extend({ }; }, - // validate new library info - validate_new_library: function(libraryDetails){ + valdiateNewLibrary: function( libraryDetails ){ return libraryDetails.name !== ''; }, - // include or exclude deleted libraries from the view - check_include_deleted: function(event){ + /** + * Include or exclude deleted libraries in the view. + * @param {object} event common event + */ + includeDeletedChecked: function( event ){ if (event.target.checked){ - Galaxy.libraries.preferences.set({'with_deleted': true}); + Galaxy.libraries.preferences.set( { 'with_deleted': true } ); Galaxy.libraries.libraryListView.render(); } else{ - Galaxy.libraries.preferences.set({'with_deleted': false}); + Galaxy.libraries.preferences.set( { 'with_deleted': false } ); Galaxy.libraries.libraryListView.render(); } }, @@ -113,22 +137,26 @@ var LibraryToolbarView = Backbone.View.extend({ templateToolBar: function(){ tmpl_array = []; + tmpl_array.push('
'); - // TOOLBAR tmpl_array.push('
'); tmpl_array.push('
'); - tmpl_array.push(' DATA LIBRARIES'); - tmpl_array.push(' <% if(admin_user === true) { %>'); - tmpl_array.push(' | include deleted |'); - tmpl_array.push(' '); - tmpl_array.push(' <% } %>'); - tmpl_array.push(' '); - tmpl_array.push('
'); - - tmpl_array.push('
'); - tmpl_array.push(' '); - tmpl_array.push('
'); - + tmpl_array.push('
'); + tmpl_array.push(' DATA LIBRARIES'); + tmpl_array.push(' <% if(admin_user === true) { %>'); + tmpl_array.push('
'); + tmpl_array.push(' '); + tmpl_array.push('
'); + tmpl_array.push(' '); + tmpl_array.push(' <% } %>'); + tmpl_array.push(' '); + tmpl_array.push(' '); + // paginator will append here + tmpl_array.push(' '); + tmpl_array.push(' '); + tmpl_array.push('
'); tmpl_array.push('
'); tmpl_array.push('
'); // table with libraries will append here @@ -138,6 +166,39 @@ var LibraryToolbarView = Backbone.View.extend({ return _.template(tmpl_array.join('')); }, + templatePaginator: function(){ + tmpl_array = []; + + tmpl_array.push(' '); + tmpl_array.push(' '); + tmpl_array.push(' showing <%- libraries_shown %> of <%- total_libraries_count %> libraries'); + tmpl_array.push(' '); + + return _.template(tmpl_array.join('')); + }, templateNewLibraryInModal: function(){ tmpl_array = []; diff --git a/static/scripts/packed/galaxy.library.js b/static/scripts/packed/galaxy.library.js index 412d4f506b6..f1235f884d0 100644 --- a/static/scripts/packed/galaxy.library.js +++ b/static/scripts/packed/galaxy.library.js @@ -1 +1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/base-mvc","mvc/library/library-model","mvc/library/library-folderlist-view","mvc/library/library-librarylist-view","mvc/library/library-librarytoolbar-view","mvc/library/library-foldertoolbar-view","mvc/library/library-dataset-view","mvc/library/library-library-view","mvc/library/library-folder-view"],function(h,e,j,n,k,c,i,g,l,f,b,a){var o=Backbone.Router.extend({initialize:function(){this.routesHit=0;Backbone.history.on("route",function(){this.routesHit++},this)},routes:{"":"libraries","library/:library_id/permissions":"library_permissions","folders/:folder_id/permissions":"folder_permissions","folders/:id":"folder_content","folders/:folder_id/datasets/:dataset_id":"dataset_detail","folders/:folder_id/datasets/:dataset_id/permissions":"dataset_permissions","folders/:folder_id/datasets/:dataset_id/versions/:ldda_id":"dataset_version","folders/:folder_id/download/:format":"download","folders/:folder_id/import/:source":"import_datasets"},back:function(){if(this.routesHit>1){window.history.back()}else{this.navigate("#",{trigger:true,replace:true})}}});var m=n.SessionStorageModel.extend({defaults:{with_deleted:false,sort_order:"asc",sort_by:"name"}});var d=Backbone.View.extend({libraryToolbarView:null,libraryListView:null,library_router:null,libraryView:null,folderToolbarView:null,folderListView:null,datasetView:null,initialize:function(){Galaxy.libraries=this;this.preferences=new m({id:"global-lib-prefs"});this.library_router=new o();this.library_router.on("route:libraries",function(){Galaxy.libraries.libraryToolbarView=new g.LibraryToolbarView();Galaxy.libraries.libraryListView=new i.LibraryListView()});this.library_router.on("route:folder_content",function(p){if(Galaxy.libraries.folderToolbarView){Galaxy.libraries.folderToolbarView.$el.unbind("click")}Galaxy.libraries.folderToolbarView=new l.FolderToolbarView({id:p});Galaxy.libraries.folderListView=new c.FolderListView({id:p})});this.library_router.on("route:download",function(p,q){if($("#folder_list_body").find(":checked").length===0){j.info("You must select at least one dataset to download");Galaxy.libraries.library_router.navigate("folders/"+p,{trigger:true,replace:true})}else{Galaxy.libraries.folderToolbarView.download(p,q);Galaxy.libraries.library_router.navigate("folders/"+p,{trigger:false,replace:true})}});this.library_router.on("route:dataset_detail",function(q,p){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p})});this.library_router.on("route:dataset_version",function(q,p,r){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p,ldda_id:r,show_version:true})});this.library_router.on("route:dataset_permissions",function(q,p){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p,show_permissions:true})});this.library_router.on("route:library_permissions",function(p){if(Galaxy.libraries.libraryView){Galaxy.libraries.libraryView.$el.unbind("click")}Galaxy.libraries.libraryView=new b.LibraryView({id:p,show_permissions:true})});this.library_router.on("route:folder_permissions",function(p){if(Galaxy.libraries.folderView){Galaxy.libraries.folderView.$el.unbind("click")}Galaxy.libraries.folderView=new a.FolderView({id:p,show_permissions:true})});this.library_router.on("route:import_datasets",function(p,q){if(Galaxy.libraries.folderToolbarView&&Galaxy.libraries.folderListView){Galaxy.libraries.folderToolbarView.showImportModal({source:q})}else{Galaxy.libraries.folderToolbarView=new l.FolderToolbarView({id:p});Galaxy.libraries.folderListView=new c.FolderListView({id:p});Galaxy.libraries.folderToolbarView.showImportModal({source:q})}});Backbone.history.start({pushState:false})}});return{GalaxyApp:d}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/base-mvc","mvc/library/library-model","mvc/library/library-folderlist-view","mvc/library/library-librarylist-view","mvc/library/library-librarytoolbar-view","mvc/library/library-foldertoolbar-view","mvc/library/library-dataset-view","mvc/library/library-library-view","mvc/library/library-folder-view"],function(h,e,j,n,k,c,i,g,l,f,b,a){var o=Backbone.Router.extend({initialize:function(){this.routesHit=0;Backbone.history.on("route",function(){this.routesHit++},this)},routes:{"":"libraries","page/:show_page":"libraries_page","library/:library_id/permissions":"library_permissions","folders/:folder_id/permissions":"folder_permissions","folders/:id":"folder_content","folders/:folder_id/datasets/:dataset_id":"dataset_detail","folders/:folder_id/datasets/:dataset_id/permissions":"dataset_permissions","folders/:folder_id/datasets/:dataset_id/versions/:ldda_id":"dataset_version","folders/:folder_id/download/:format":"download","folders/:folder_id/import/:source":"import_datasets"},back:function(){if(this.routesHit>1){window.history.back()}else{this.navigate("#",{trigger:true,replace:true})}}});var m=n.SessionStorageModel.extend({defaults:{with_deleted:false,sort_order:"asc",sort_by:"name",library_page_size:20}});var d=Backbone.View.extend({libraryToolbarView:null,libraryListView:null,library_router:null,libraryView:null,folderToolbarView:null,folderListView:null,datasetView:null,initialize:function(){Galaxy.libraries=this;this.preferences=new m({id:"global-lib-prefs"});this.library_router=new o();this.library_router.on("route:libraries",function(){Galaxy.libraries.libraryToolbarView=new g.LibraryToolbarView();Galaxy.libraries.libraryListView=new i.LibraryListView()});this.library_router.on("route:libraries_page",function(p){if(Galaxy.libraries.libraryToolbarView===null){Galaxy.libraries.libraryToolbarView=new g.LibraryToolbarView();Galaxy.libraries.libraryListView=new i.LibraryListView({show_page:p})}else{Galaxy.libraries.libraryListView.render({show_page:p})}});this.library_router.on("route:folder_content",function(p){if(Galaxy.libraries.folderToolbarView){Galaxy.libraries.folderToolbarView.$el.unbind("click")}Galaxy.libraries.folderToolbarView=new l.FolderToolbarView({id:p});Galaxy.libraries.folderListView=new c.FolderListView({id:p})});this.library_router.on("route:download",function(p,q){if($("#folder_list_body").find(":checked").length===0){j.info("You must select at least one dataset to download");Galaxy.libraries.library_router.navigate("folders/"+p,{trigger:true,replace:true})}else{Galaxy.libraries.folderToolbarView.download(p,q);Galaxy.libraries.library_router.navigate("folders/"+p,{trigger:false,replace:true})}});this.library_router.on("route:dataset_detail",function(q,p){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p})});this.library_router.on("route:dataset_version",function(q,p,r){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p,ldda_id:r,show_version:true})});this.library_router.on("route:dataset_permissions",function(q,p){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new f.LibraryDatasetView({id:p,show_permissions:true})});this.library_router.on("route:library_permissions",function(p){if(Galaxy.libraries.libraryView){Galaxy.libraries.libraryView.$el.unbind("click")}Galaxy.libraries.libraryView=new b.LibraryView({id:p,show_permissions:true})});this.library_router.on("route:folder_permissions",function(p){if(Galaxy.libraries.folderView){Galaxy.libraries.folderView.$el.unbind("click")}Galaxy.libraries.folderView=new a.FolderView({id:p,show_permissions:true})});this.library_router.on("route:import_datasets",function(p,q){if(Galaxy.libraries.folderToolbarView&&Galaxy.libraries.folderListView){Galaxy.libraries.folderToolbarView.showImportModal({source:q})}else{Galaxy.libraries.folderToolbarView=new l.FolderToolbarView({id:p});Galaxy.libraries.folderListView=new c.FolderListView({id:p});Galaxy.libraries.folderToolbarView.showImportModal({source:q})}});Backbone.history.start({pushState:false})}});return{GalaxyApp:d}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/library/library-foldertoolbar-view.js b/static/scripts/packed/mvc/library/library-foldertoolbar-view.js index 02b4fe31a26..261ca796839 100644 --- a/static/scripts/packed/mvc/library/library-foldertoolbar-view.js +++ b/static/scripts/packed/mvc/library/library-foldertoolbar-view.js @@ -1 +1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model","mvc/ui/ui-select"],function(c,e,f,d,a){var b=Backbone.View.extend({el:"#center",events:{"click #toolbtn_create_folder":"createFolderFromModal","click #toolbtn_bulk_import":"modalBulkImport","click #include_deleted_datasets_chk":"checkIncludeDeleted","click #toolbtn_show_libinfo":"showLibInfo","click #toolbtn_bulk_delete":"deleteSelectedDatasets"},defaults:{can_add_library_item:false,contains_file:false,chain_call_control:{total_number:0,failed_number:0},disabled_jstree_element:"folders"},modal:null,jstree:null,histories:null,select_genome:null,select_extension:null,list_extensions:[],auto:{id:"auto",text:"Auto-detect",description:"This system will try to detect the file type automatically. If your file is not detected properly as one of the known formats, it most likely means that it has some format problems (e.g., different number of columns on different rows). You can still coerce the system to set your data to the format you think it should be. You can also upload compressed files, which will automatically be decompressed."},list_genomes:[],initialize:function(g){this.options=_.defaults(g||{},this.defaults);this.fetchExtAndGenomes();this.render()},render:function(g){this.options=_.extend(this.options,g);var i=this.templateToolBar();var h={id:this.options.id,is_admin:false,is_anonym:true,mutiple_add_dataset_options:false};if(Galaxy.currUser){h.is_admin=Galaxy.currUser.isAdmin();h.is_anonym=Galaxy.currUser.isAnonymous();if(Galaxy.config.user_library_import_dir!==null||Galaxy.config.allow_library_path_paste!==false||Galaxy.config.library_import_dir!==null){h.mutiple_add_dataset_options=true}}this.$el.html(i(h))},configureElements:function(g){this.options=_.extend(this.options,g);if(this.options.can_add_library_item===true){$(".add-library-items").show()}else{$(".add-library-items").hide()}if(this.options.contains_file===true){if(Galaxy.currUser){if(!Galaxy.currUser.isAnonymous()){$(".logged-dataset-manipulation").show();$(".dataset-manipulation").show()}else{$(".dataset-manipulation").show();$(".logged-dataset-manipulation").hide()}}else{$(".logged-dataset-manipulation").hide();$(".dataset-manipulation").hide()}}else{$(".logged-dataset-manipulation").hide();$(".dataset-manipulation").hide()}this.$el.find("[data-toggle]").tooltip()},createFolderFromModal:function(i){i.preventDefault();i.stopPropagation();var g=this;var h=this.templateNewFolderInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Folder",body:h(),buttons:{Create:function(){g.create_new_folder_event()},Close:function(){Galaxy.modal.hide()}}})},create_new_folder_event:function(){var g=this.serialize_new_folder();if(this.validate_new_folder(g)){var h=new d.FolderAsModel();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];h.url=h.urlRoot+"/"+current_folder_id;h.save(g,{success:function(i){Galaxy.modal.hide();f.success("Folder created.");i.set({type:"folder"});Galaxy.libraries.folderListView.collection.add(i)},error:function(j,i){Galaxy.modal.hide();if(typeof i.responseJSON!=="undefined"){f.error(i.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})}else{f.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(g){return g.name!==""},modalBulkImport:function(){var g=$("#folder_table").find(":checked");if(g.length===0){f.info("You must select some datasets first.")}else{this.refreshUserHistoriesList(function(i){var h=i.templateBulkImportInModal();i.modal=Galaxy.modal;i.modal.show({closing_events:true,title:"Import into History",body:h({histories:i.histories.models}),buttons:{Import:function(){i.importAllIntoHistory()},Close:function(){Galaxy.modal.hide()}}})})}},refreshUserHistoriesList:function(h){var g=this;this.histories=new d.GalaxyHistories();this.histories.fetch({success:function(){h(g)},error:function(j,i){if(typeof i.responseJSON!=="undefined"){f.error(i.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var k=$("select[name=dataset_import_bulk] option:selected").val();var n=$("select[name=dataset_import_bulk] option:selected").text();this.options.last_used_history_id=k;var h=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){h.push(this.parentElement.parentElement.id)}});var m=[];for(var j=h.length-1;j>=0;j--){var g=h[j];var l=new d.HistoryItem();l.url=l.urlRoot+k+"/contents";l.content=g;l.source="library";m.push(l)}this.initChainCallControl({length:m.length,action:"to_history",history_name:n});jQuery.getJSON(galaxy_config.root+"history/set_as_current?id="+k);this.chainCallImportingIntoHistory(m,n)},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(g,k){var i=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){i.push(this.parentElement.parentElement.id)}});var h="/api/libraries/datasets/download/"+k;var j={ld_ids:i};this.processDownload(h,j,"get")},processDownload:function(h,i,j){if(h&&i){i=typeof i==="string"?i:$.param(i);var g="";$.each(i.split("&"),function(){var k=this.split("=");g+=''});$('
'+g+"").appendTo("body").submit().remove();f.info("Your download will begin soon.")}else{f.error("An error occurred.")}},addFilesFromHistoryModal:function(){this.refreshUserHistoriesList(function(g){g.modal=Galaxy.modal;var h=g.templateAddFilesFromHistory();var i=g.options.full_path[g.options.full_path.length-1][1];g.modal.show({closing_events:true,title:"Adding datasets from your history to folder "+i,body:h({histories:g.histories.models}),buttons:{Add:function(){g.addAllDatasetsFromHistory()},Close:function(){Galaxy.modal.hide()}},closing_callback:function(){Galaxy.libraries.library_router.back()}});if(g.histories.models.length>0){g.fetchAndDisplayHistoryContents(g.histories.models[0].id);$("#dataset_add_bulk").change(function(j){g.fetchAndDisplayHistoryContents(j.target.value)})}else{f.error("An error ocurred.")}})},importFilesFromPathModal:function(){var h=this;this.modal=Galaxy.modal;var g=this.templateImportPathModal();this.modal.show({closing_events:true,title:"Please enter paths to import",body:g({}),buttons:{Import:function(){h.importFromPathsClicked(h)},Close:function(){Galaxy.modal.hide()}},closing_callback:function(){Galaxy.libraries.library_router.navigate("folders/"+h.id,{trigger:true})}});this.renderSelectBoxes()},fetchExtAndGenomes:function(){var g=this;e.get(galaxy_config.root+"api/datatypes?extension_only=False",function(h){for(key in h){g.list_extensions.push({id:h[key].extension,text:h[key].extension,description:h[key].description,description_url:h[key].description_url})}g.list_extensions.sort(function(j,i){return j.id>i.id?1:j.idi.id?1:j.id=0;k--){trimmed=m[k].trim();if(trimmed.length!==0){l.push(trimmed)}}this.initChainCallControl({length:l.length,action:"adding_datasets"});this.chainCallImportingFolders({paths:l,preserve_dirs:g,link_data:n,source:"admin_path",file_type:h,dbkey:j})}},initChainCallControl:function(g){var h;switch(g.action){case"adding_datasets":h=this.templateAddingDatasetsProgressBar();this.modal.$el.find(".modal-body").html(h({folder_name:this.options.folder_name}));break;case"deleting_datasets":h=this.templateDeletingDatasetsProgressBar();this.modal.$el.find(".modal-body").html(h());break;case"to_history":h=this.templateImportIntoHistoryProgressBar();this.modal.$el.find(".modal-body").html(h({history_name:g.history_name}));break;default:console.error("Wrong action specified.");break}this.progress=0;this.progressStep=100/g.length;this.options.chain_call_control.total_number=g.length;this.options.chain_call_control.failed_number=0},importFromJstreePath:function(n,r){var g=$("#jstree_browser").jstree().get_selected(true);var m=this.modal.$el.find(".preserve-checkbox").is(":checked");var o=this.modal.$el.find(".link-checkbox").is(":checked");var j=this.select_extension.value();var p=this.select_genome.value();var k=g[0].type;var q=[];if(g.length<1){f.info("Please select some items first.")}else{this.modal.disableButton("Import");for(var l=g.length-1;l>=0;l--){if(g[l].li_attr.full_path!==undefined){q.push(g[l].li_attr.full_path)}}this.initChainCallControl({length:q.length,action:"adding_datasets"});if(k==="folder"){var h=r.source+"_folder";this.chainCallImportingFolders({paths:q,preserve_dirs:m,link_data:o,source:h,file_type:j,dbkey:p})}else{if(k==="file"){var h=r.source+"_file";this.chainCallImportingUserdirFiles({paths:q,file_type:j,dbkey:p,source:h})}}}},fetchAndDisplayHistoryContents:function(i){var h=new d.HistoryContents({id:i});var g=this;h.fetch({success:function(k){var j=g.templateHistoryContents();g.histories.get(i).set({contents:k});g.modal.$el.find("#selected_history_content").html(j({history_contents:k.models.reverse()}))},error:function(k,j){if(typeof j.responseJSON!=="undefined"){f.error(j.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})},addAllDatasetsFromHistory:function(){var l=this.modal.$el.find("#selected_history_content").find(":checked");var g=[];var k=[];if(l.length<1){f.info("You must select some datasets first.")}else{this.modal.disableButton("Add");l.each(function(){var i=$(this.parentElement).data("id");if(i){g.push(i)}});for(var j=g.length-1;j>=0;j--){history_dataset_id=g[j];var h=new d.Item();h.url="/api/folders/"+this.options.id+"/contents";h.set({from_hda_id:history_dataset_id});k.push(h)}this.initChainCallControl({length:k.length,action:"adding_datasets"});this.chainCallAddingHdas(k)}},chainCallImportingIntoHistory:function(h,k){var g=this;var i=h.pop();if(typeof i=="undefined"){if(this.options.chain_call_control.failed_number===0){f.success("Selected datasets imported into history. Click this to start analysing it.","",{onclick:function(){window.location="/"}})}else{if(this.options.chain_call_control.failed_number===this.options.chain_call_control.total_number){f.error("There was an error and no datasets were imported into history.")}else{if(this.options.chain_call_control.failed_number=0;j--){var l=new d.Item({id:h[j]});m.push(l)}this.options.chain_call_control.total_number=h.length;this.chainCallDeletingHdas(m)}},showLibInfo:function(){var h=Galaxy.libraries.folderListView.folderContainer.attributes.metadata.parent_library_id;var g=null;var i=this;if(Galaxy.libraries.libraryListView!==null){g=Galaxy.libraries.libraryListView.collection.get(h);this.showLibInfoModal(g)}else{g=new d.Library({id:h});g.fetch({success:function(){i.showLibInfoModal(g)},error:function(k,j){if(typeof j.responseJSON!=="undefined"){f.error(j.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})}},showLibInfoModal:function(g){var h=this.templateLibInfoInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Library Information",body:h({library:g}),buttons:{Close:function(){Galaxy.modal.hide()}}})},showImportModal:function(g){switch(g.source){case"history":this.addFilesFromHistoryModal();break;case"importdir":this.importFilesFromGalaxyFolderModal({source:"importdir"});break;case"path":this.importFilesFromPathModal();break;case"userdir":this.importFilesFromGalaxyFolderModal({source:"userdir"});break;default:Galaxy.libraries.library_router.back();f.error("Invalid import source.");break}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push('
');tmpl_array.push(" DATA LIBRARIES");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("<% if(mutiple_add_dataset_options) { %>");tmpl_array.push(' ");tmpl_array.push("<% } else { %>");tmpl_array.push(' ');tmpl_array.push("<% } %>");tmpl_array.push(' ');tmpl_array.push(' ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateLibInfoInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("

Library name:

");tmpl_array.push('

<%- library.get("name") %>

');tmpl_array.push("

Library description:

");tmpl_array.push('

<%- library.get("description") %>

');tmpl_array.push("

Library synopsis:

");tmpl_array.push('

<%- library.get("synopsis") %>

');tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push('');tmpl_array.push('');tmpl_array.push("");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateBulkImportInModal:function(){var g=[];g.push('');g.push("Select history: ");g.push('");g.push("");return _.template(g.join(""))},templateImportIntoHistoryProgressBar:function(){var g=[];g.push('
');g.push("Importing selected datasets to history <%= _.escape(history_name) %>");g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateAddingDatasetsProgressBar:function(){var g=[];g.push('
');g.push("Adding selected datasets to library folder <%= _.escape(folder_name) %>");g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateDeletingDatasetsProgressBar:function(){var g=[];g.push('
');g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateBrowserModal:function(){var g=[];g.push('
');g.push('
All files you select will be imported into the current folder.
');g.push('');g.push('
');g.push('");g.push('");g.push("
");g.push('
');g.push('");g.push('");g.push("
");g.push('
');g.push("
");g.push("
");g.push("

You can set extension type and genome for all imported datasets at once:

");g.push("
");g.push('Type: ');g.push(' Genome: ');g.push("
");g.push("
");return _.template(g.join(""))},templateImportPathModal:function(){var g=[];g.push('
');g.push('
All files within the given folders and their subfolders will be imported into the current folder.
');g.push('
');g.push('");g.push('");g.push("
");g.push('');g.push("
");g.push("

You can set extension type and genome for all imported datasets at once:

");g.push("
");g.push('Type: ');g.push(' Genome: ');g.push("
");g.push("
");return _.template(g.join(""))},templateAddFilesFromHistory:function(){var g=[];g.push('
');g.push('
');g.push("Select history: ");g.push('");g.push("
");g.push("
");g.push('
');g.push("
");g.push("
");return _.template(g.join(""))},templateHistoryContents:function(){var g=[];g.push("Choose the datasets to import:");g.push("
    ");g.push(" <% _.each(history_contents, function(history_item) { %>");g.push('
  • ">');g.push(' <%= _.escape(history_item.get("hid")) %>: <%= _.escape(history_item.get("name")) %>');g.push("
  • ");g.push(" <% }); %>");g.push("
");return _.template(g.join(""))}});return{FolderToolbarView:b}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model","mvc/ui/ui-select"],function(c,e,f,d,a){var b=Backbone.View.extend({el:"#center",events:{"click #toolbtn_create_folder":"createFolderFromModal","click #toolbtn_bulk_import":"modalBulkImport","click #include_deleted_datasets_chk":"checkIncludeDeleted","click #toolbtn_show_libinfo":"showLibInfo","click #toolbtn_bulk_delete":"deleteSelectedDatasets"},defaults:{can_add_library_item:false,contains_file:false,chain_call_control:{total_number:0,failed_number:0},disabled_jstree_element:"folders"},modal:null,jstree:null,histories:null,select_genome:null,select_extension:null,list_extensions:[],auto:{id:"auto",text:"Auto-detect",description:"This system will try to detect the file type automatically. If your file is not detected properly as one of the known formats, it most likely means that it has some format problems (e.g., different number of columns on different rows). You can still coerce the system to set your data to the format you think it should be. You can also upload compressed files, which will automatically be decompressed."},list_genomes:[],initialize:function(g){this.options=_.defaults(g||{},this.defaults);this.fetchExtAndGenomes();this.render()},render:function(g){this.options=_.extend(this.options,g);var i=this.templateToolBar();var h={id:this.options.id,is_admin:false,is_anonym:true,mutiple_add_dataset_options:false};if(Galaxy.currUser){h.is_admin=Galaxy.currUser.isAdmin();h.is_anonym=Galaxy.currUser.isAnonymous();if(Galaxy.config.user_library_import_dir!==null||Galaxy.config.allow_library_path_paste!==false||Galaxy.config.library_import_dir!==null){h.mutiple_add_dataset_options=true}}this.$el.html(i(h))},configureElements:function(g){this.options=_.extend(this.options,g);if(this.options.can_add_library_item===true){$(".add-library-items").show()}else{$(".add-library-items").hide()}if(this.options.contains_file===true){if(Galaxy.currUser){if(!Galaxy.currUser.isAnonymous()){$(".logged-dataset-manipulation").show();$(".dataset-manipulation").show()}else{$(".dataset-manipulation").show();$(".logged-dataset-manipulation").hide()}}else{$(".logged-dataset-manipulation").hide();$(".dataset-manipulation").hide()}}else{$(".logged-dataset-manipulation").hide();$(".dataset-manipulation").hide()}this.$el.find("[data-toggle]").tooltip()},createFolderFromModal:function(i){i.preventDefault();i.stopPropagation();var g=this;var h=this.templateNewFolderInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Folder",body:h(),buttons:{Create:function(){g.create_new_folder_event()},Close:function(){Galaxy.modal.hide()}}})},create_new_folder_event:function(){var g=this.serialize_new_folder();if(this.validate_new_folder(g)){var h=new d.FolderAsModel();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];h.url=h.urlRoot+"/"+current_folder_id;h.save(g,{success:function(i){Galaxy.modal.hide();f.success("Folder created.");i.set({type:"folder"});Galaxy.libraries.folderListView.collection.add(i)},error:function(j,i){Galaxy.modal.hide();if(typeof i.responseJSON!=="undefined"){f.error(i.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})}else{f.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(g){return g.name!==""},modalBulkImport:function(){var g=$("#folder_table").find(":checked");if(g.length===0){f.info("You must select some datasets first.")}else{this.refreshUserHistoriesList(function(i){var h=i.templateBulkImportInModal();i.modal=Galaxy.modal;i.modal.show({closing_events:true,title:"Import into History",body:h({histories:i.histories.models}),buttons:{Import:function(){i.importAllIntoHistory()},Close:function(){Galaxy.modal.hide()}}})})}},refreshUserHistoriesList:function(h){var g=this;this.histories=new d.GalaxyHistories();this.histories.fetch({success:function(){h(g)},error:function(j,i){if(typeof i.responseJSON!=="undefined"){f.error(i.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var k=$("select[name=dataset_import_bulk] option:selected").val();var n=$("select[name=dataset_import_bulk] option:selected").text();this.options.last_used_history_id=k;var h=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){h.push(this.parentElement.parentElement.id)}});var m=[];for(var j=h.length-1;j>=0;j--){var g=h[j];var l=new d.HistoryItem();l.url=l.urlRoot+k+"/contents";l.content=g;l.source="library";m.push(l)}this.initChainCallControl({length:m.length,action:"to_history",history_name:n});jQuery.getJSON(galaxy_config.root+"history/set_as_current?id="+k);this.chainCallImportingIntoHistory(m,n)},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(g,k){var i=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!==""){i.push(this.parentElement.parentElement.id)}});var h="/api/libraries/datasets/download/"+k;var j={ld_ids:i};this.processDownload(h,j,"get")},processDownload:function(h,i,j){if(h&&i){i=typeof i==="string"?i:$.param(i);var g="";$.each(i.split("&"),function(){var k=this.split("=");g+=''});$('
'+g+"").appendTo("body").submit().remove();f.info("Your download will begin soon.")}else{f.error("An error occurred.")}},addFilesFromHistoryModal:function(){this.refreshUserHistoriesList(function(g){g.modal=Galaxy.modal;var h=g.templateAddFilesFromHistory();var i=g.options.full_path[g.options.full_path.length-1][1];g.modal.show({closing_events:true,title:"Adding datasets from your history to folder "+i,body:h({histories:g.histories.models}),buttons:{Add:function(){g.addAllDatasetsFromHistory()},Close:function(){Galaxy.modal.hide()}},closing_callback:function(){Galaxy.libraries.library_router.back()}});if(g.histories.models.length>0){g.fetchAndDisplayHistoryContents(g.histories.models[0].id);$("#dataset_add_bulk").change(function(j){g.fetchAndDisplayHistoryContents(j.target.value)})}else{f.error("An error ocurred.")}})},importFilesFromPathModal:function(){var h=this;this.modal=Galaxy.modal;var g=this.templateImportPathModal();this.modal.show({closing_events:true,title:"Please enter paths to import",body:g({}),buttons:{Import:function(){h.importFromPathsClicked(h)},Close:function(){Galaxy.modal.hide()}},closing_callback:function(){Galaxy.libraries.library_router.navigate("folders/"+h.id,{trigger:true})}});this.renderSelectBoxes()},fetchExtAndGenomes:function(){var g=this;e.get({url:galaxy_config.root+"api/datatypes?extension_only=False",success:function(h){for(key in h){g.list_extensions.push({id:h[key].extension,text:h[key].extension,description:h[key].description,description_url:h[key].description_url})}g.list_extensions.sort(function(j,i){return j.id>i.id?1:j.idi.id?1:j.id=0;k--){trimmed=m[k].trim();if(trimmed.length!==0){l.push(trimmed)}}this.initChainCallControl({length:l.length,action:"adding_datasets"});this.chainCallImportingFolders({paths:l,preserve_dirs:g,link_data:n,source:"admin_path",file_type:h,dbkey:j})}},initChainCallControl:function(g){var h;switch(g.action){case"adding_datasets":h=this.templateAddingDatasetsProgressBar();this.modal.$el.find(".modal-body").html(h({folder_name:this.options.folder_name}));break;case"deleting_datasets":h=this.templateDeletingDatasetsProgressBar();this.modal.$el.find(".modal-body").html(h());break;case"to_history":h=this.templateImportIntoHistoryProgressBar();this.modal.$el.find(".modal-body").html(h({history_name:g.history_name}));break;default:console.error("Wrong action specified.");break}this.progress=0;this.progressStep=100/g.length;this.options.chain_call_control.total_number=g.length;this.options.chain_call_control.failed_number=0},importFromJstreePath:function(n,r){var g=$("#jstree_browser").jstree().get_selected(true);var m=this.modal.$el.find(".preserve-checkbox").is(":checked");var o=this.modal.$el.find(".link-checkbox").is(":checked");var j=this.select_extension.value();var p=this.select_genome.value();var k=g[0].type;var q=[];if(g.length<1){f.info("Please select some items first.")}else{this.modal.disableButton("Import");for(var l=g.length-1;l>=0;l--){if(g[l].li_attr.full_path!==undefined){q.push(g[l].li_attr.full_path)}}this.initChainCallControl({length:q.length,action:"adding_datasets"});if(k==="folder"){var h=r.source+"_folder";this.chainCallImportingFolders({paths:q,preserve_dirs:m,link_data:o,source:h,file_type:j,dbkey:p})}else{if(k==="file"){var h=r.source+"_file";this.chainCallImportingUserdirFiles({paths:q,file_type:j,dbkey:p,source:h})}}}},fetchAndDisplayHistoryContents:function(i){var h=new d.HistoryContents({id:i});var g=this;h.fetch({success:function(k){var j=g.templateHistoryContents();g.histories.get(i).set({contents:k});g.modal.$el.find("#selected_history_content").html(j({history_contents:k.models.reverse()}))},error:function(k,j){if(typeof j.responseJSON!=="undefined"){f.error(j.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})},addAllDatasetsFromHistory:function(){var l=this.modal.$el.find("#selected_history_content").find(":checked");var g=[];var k=[];if(l.length<1){f.info("You must select some datasets first.")}else{this.modal.disableButton("Add");l.each(function(){var i=$(this.parentElement).data("id");if(i){g.push(i)}});for(var j=g.length-1;j>=0;j--){history_dataset_id=g[j];var h=new d.Item();h.url="/api/folders/"+this.options.id+"/contents";h.set({from_hda_id:history_dataset_id});k.push(h)}this.initChainCallControl({length:k.length,action:"adding_datasets"});this.chainCallAddingHdas(k)}},chainCallImportingIntoHistory:function(h,k){var g=this;var i=h.pop();if(typeof i=="undefined"){if(this.options.chain_call_control.failed_number===0){f.success("Selected datasets imported into history. Click this to start analysing it.","",{onclick:function(){window.location="/"}})}else{if(this.options.chain_call_control.failed_number===this.options.chain_call_control.total_number){f.error("There was an error and no datasets were imported into history.")}else{if(this.options.chain_call_control.failed_number=0;j--){var l=new d.Item({id:h[j]});m.push(l)}this.options.chain_call_control.total_number=h.length;this.chainCallDeletingHdas(m)}},showLibInfo:function(){var h=Galaxy.libraries.folderListView.folderContainer.attributes.metadata.parent_library_id;var g=null;var i=this;if(Galaxy.libraries.libraryListView!==null){g=Galaxy.libraries.libraryListView.collection.get(h);this.showLibInfoModal(g)}else{g=new d.Library({id:h});g.fetch({success:function(){i.showLibInfoModal(g)},error:function(k,j){if(typeof j.responseJSON!=="undefined"){f.error(j.responseJSON.err_msg)}else{f.error("An error ocurred.")}}})}},showLibInfoModal:function(g){var h=this.templateLibInfoInModal();this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Library Information",body:h({library:g}),buttons:{Close:function(){Galaxy.modal.hide()}}})},showImportModal:function(g){switch(g.source){case"history":this.addFilesFromHistoryModal();break;case"importdir":this.importFilesFromGalaxyFolderModal({source:"importdir"});break;case"path":this.importFilesFromPathModal();break;case"userdir":this.importFilesFromGalaxyFolderModal({source:"userdir"});break;default:Galaxy.libraries.library_router.back();f.error("Invalid import source.");break}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push('
');tmpl_array.push(" DATA LIBRARIES");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("<% if(mutiple_add_dataset_options) { %>");tmpl_array.push(' ");tmpl_array.push("<% } else { %>");tmpl_array.push(' ');tmpl_array.push("<% } %>");tmpl_array.push(' ');tmpl_array.push(' ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateLibInfoInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("

Library name:

");tmpl_array.push('

<%- library.get("name") %>

');tmpl_array.push("

Library description:

");tmpl_array.push('

<%- library.get("description") %>

');tmpl_array.push("

Library synopsis:

");tmpl_array.push('

<%- library.get("synopsis") %>

');tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push('');tmpl_array.push('');tmpl_array.push("");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateBulkImportInModal:function(){var g=[];g.push('');g.push("Select history: ");g.push('");g.push("");return _.template(g.join(""))},templateImportIntoHistoryProgressBar:function(){var g=[];g.push('
');g.push("Importing selected datasets to history <%= _.escape(history_name) %>");g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateAddingDatasetsProgressBar:function(){var g=[];g.push('
');g.push("Adding selected datasets to library folder <%= _.escape(folder_name) %>");g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateDeletingDatasetsProgressBar:function(){var g=[];g.push('
');g.push("
");g.push('
');g.push('
');g.push(' 0% Complete');g.push("
");g.push("
");g.push("");return _.template(g.join(""))},templateBrowserModal:function(){var g=[];g.push('
');g.push('
All files you select will be imported into the current folder.
');g.push('');g.push('
');g.push('");g.push('");g.push("
");g.push('
');g.push('");g.push('");g.push("
");g.push('
');g.push("
");g.push("
");g.push("

You can set extension type and genome for all imported datasets at once:

");g.push("
");g.push('Type: ');g.push(' Genome: ');g.push("
");g.push("
");return _.template(g.join(""))},templateImportPathModal:function(){var g=[];g.push('
');g.push('
All files within the given folders and their subfolders will be imported into the current folder.
');g.push('
');g.push('");g.push('");g.push("
");g.push('');g.push("
");g.push("

You can set extension type and genome for all imported datasets at once:

");g.push("
");g.push('Type: ');g.push(' Genome: ');g.push("
");g.push("
");return _.template(g.join(""))},templateAddFilesFromHistory:function(){var g=[];g.push('
');g.push('
');g.push("Select history: ");g.push('");g.push("
");g.push("
");g.push('
');g.push("
");g.push("
");return _.template(g.join(""))},templateHistoryContents:function(){var g=[];g.push("Choose the datasets to import:");g.push("
    ");g.push(" <% _.each(history_contents, function(history_item) { %>");g.push('
  • ">');g.push(' <%= _.escape(history_item.get("hid")) %>: <%= _.escape(history_item.get("name")) %>');g.push("
  • ");g.push(" <% }); %>");g.push("
");return _.template(g.join(""))}});return{FolderToolbarView:b}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/library/library-librarylist-view.js b/static/scripts/packed/mvc/library/library-librarylist-view.js index 721233d295e..71457da652e 100644 --- a/static/scripts/packed/mvc/library/library-librarylist-view.js +++ b/static/scripts/packed/mvc/library/library-librarylist-view.js @@ -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(h){this.options=_.defaults(this.options||{},h);var i=this;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(){i.render()},error:function(k,j){if(typeof j.responseJSON!=="undefined"){e.error(j.responseJSON.err_msg)}else{e.error("An error ocurred.")}}})},render:function(i){$(".tooltip").hide();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){this.sortLibraries();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(l){for(var k=0;k');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push('
There are no libraries visible to you. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
');tmpl_array.push("<% } else{ %>");tmpl_array.push('
name descriptionsynopsis
');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push("
name descriptionsynopsis
");tmpl_array.push("<% }%>");tmpl_array.push("
");return _.template(tmpl_array.join(""))},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},});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"},defaults:{page_count:null,show_page:null},initialize:function(h){this.options=_.defaults(this.options||{},this.defaults,h);var i=this;this.modal=null;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(){i.render()},error:function(k,j){if(typeof j.responseJSON!=="undefined"){e.error(j.responseJSON.err_msg)}else{e.error("An error ocurred.")}}})},render:function(i){this.options=_.extend(this.options,i);if((this.options.page_size!=null)&&(this.options.page_size==parseInt(this.options.page_size))){Galaxy.libraries.preferences.set({library_page_size:parseInt(this.options.page_size)})}$(".tooltip").hide();var j=this.templateLibraryList();var k=null;var l=null;if(this.options.show_page===null||this.options.show_page<1){this.options.show_page=1}if(typeof i!=="undefined"){l=typeof i.models!=="undefined"?i.models:null}if(this.collection!==null&&l===null){this.sortLibraries();if(Galaxy.libraries.preferences.get("with_deleted")){k=this.collection.models}else{k=this.collection.where({deleted:false})}}else{if(l!==null){k=l}else{k=[]}}this.options.total_libraries_count=k.length;var h=(Galaxy.libraries.preferences.get("library_page_size")*(this.options.show_page-1));this.options.page_count=Math.ceil(this.options.total_libraries_count/Galaxy.libraries.preferences.get("library_page_size"));if(this.options.total_libraries_count>0&&(h(this.options.total_libraries_count+Galaxy.libraries.preferences.get("library_page_size"))){k=[]}this.$el.html(j({length:1,order:Galaxy.libraries.preferences.get("sort_order")}));Galaxy.libraries.libraryToolbarView.renderPaginator(this.options);this.renderRows(k)}else{this.$el.html(j({length:0,order:Galaxy.libraries.preferences.get("sort_order")}));Galaxy.libraries.libraryToolbarView.renderPaginator(this.options)}$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(l){for(var k=0;k');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push('
There are no libraries visible to you here. If you expected some to show up please consult the library security wikipage or visit the Galaxy support site.
');tmpl_array.push("<% } else{ %>");tmpl_array.push('');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push("
name descriptionsynopsis
");tmpl_array.push("<% }%>");tmpl_array.push("");return _.template(tmpl_array.join(""))},});return{LibraryListView:f}}); \ No newline at end of file diff --git a/static/scripts/packed/mvc/library/library-librarytoolbar-view.js b/static/scripts/packed/mvc/library/library-librarytoolbar-view.js index 26190bdda94..3f2da11caf5 100644 --- a/static/scripts/packed/mvc/library/library-librarytoolbar-view.js +++ b/static/scripts/packed/mvc/library/library-librarytoolbar-view.js @@ -1 +1 @@ -define(["libs/toastr","mvc/library/library-model"],function(b,a){var c=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"show_library_modal","click #include_deleted_chk":"check_include_deleted"},initialize:function(){this.render()},render:function(){var f=this.templateToolBar();var e=false;var d=true;if(Galaxy.currUser){e=Galaxy.currUser.isAdmin();d=Galaxy.currUser.isAnonymous()}this.$el.html(f({admin_user:e,anon_user:d}));if(e){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},show_library_modal:function(e){e.preventDefault();e.stopPropagation();var d=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){d.create_new_library_event()},Close:function(){d.modal.hide()}}})},create_new_library_event:function(){var f=this.serialize_new_library();if(this.validate_new_library(f)){var e=new a.Library();var d=this;e.save(f,{success:function(g){Galaxy.libraries.libraryListView.collection.add(g);d.modal.hide();d.clear_library_modal();Galaxy.libraries.libraryListView.render();b.success("Library created.")},error:function(h,g){if(typeof g.responseJSON!=="undefined"){b.error(g.responseJSON.err_msg)}else{b.error("An error occured.")}}})}else{b.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(d){return d.name!==""},check_include_deleted:function(d){if(d.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('
');tmpl_array.push('
');tmpl_array.push('
');tmpl_array.push(" DATA LIBRARIES");tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push(' | include deleted |');tmpl_array.push(' ');tmpl_array.push(" <% } %>");tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push("
");tmpl_array.push(" ");tmpl_array.push("
");tmpl_array.push("
");tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")}});return{LibraryToolbarView:c}}); \ No newline at end of file +define(["libs/toastr","mvc/library/library-model"],function(b,a){var c=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"showLibraryModal","click #include_deleted_chk":"includeDeletedChecked","click #page_size_prompt":"showPageSizePrompt"},initialize:function(d){this.options=_.defaults(this.options||{},d);this.render()},render:function(){var f=this.templateToolBar();var e=false;var d=true;if(Galaxy.currUser){e=Galaxy.currUser.isAdmin();d=Galaxy.currUser.isAnonymous()}this.$el.html(f({admin_user:e,anon_user:d}));if(e){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},renderPaginator:function(e){this.options=_.extend(this.options,e);var d=this.templatePaginator();this.$el.find("#library_paginator").html(d({show_page:parseInt(this.options.show_page),page_count:parseInt(this.options.page_count),total_libraries_count:this.options.total_libraries_count,libraries_shown:this.options.libraries_shown}))},showLibraryModal:function(e){e.preventDefault();e.stopPropagation();var d=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){d.createNewLibrary()},Close:function(){d.modal.hide()}}})},createNewLibrary:function(){var f=this.serializeNewLibrary();if(this.valdiateNewLibrary(f)){var e=new a.Library();var d=this;e.save(f,{success:function(g){Galaxy.libraries.libraryListView.collection.add(g);d.modal.hide();d.clearLibraryModal();Galaxy.libraries.libraryListView.render();b.success("Library created.")},error:function(h,g){if(typeof g.responseJSON!=="undefined"){b.error(g.responseJSON.err_msg)}else{b.error("An error occured.")}}})}else{b.error("Library's name is missing.")}return false},showPageSizePrompt:function(){var d=prompt("How many libraries per page do you want to see?",Galaxy.libraries.preferences.get("library_page_size"));if((d!=null)&&(d==parseInt(d))){Galaxy.libraries.preferences.set({library_page_size:parseInt(d)});Galaxy.libraries.libraryListView.render()}},clearLibraryModal:function(){$("input[name='Name']").val("");$("input[name='Description']").val("");$("input[name='Synopsis']").val("")},serializeNewLibrary:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val(),synopsis:$("input[name='Synopsis']").val()}},valdiateNewLibrary:function(d){return d.name!==""},includeDeletedChecked:function(d){if(d.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('
');tmpl_array.push('
');tmpl_array.push('
');tmpl_array.push('
');tmpl_array.push(' DATA LIBRARIES');tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push('
');tmpl_array.push(" ");tmpl_array.push("
");tmpl_array.push(' ');tmpl_array.push(" <% } %>");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push("
");tmpl_array.push("
");tmpl_array.push("
");tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push("
");return _.template(tmpl_array.join(""))},templatePaginator:function(){tmpl_array=[];tmpl_array.push(' ");tmpl_array.push(" ");tmpl_array.push(' showing <%- libraries_shown %> of <%- total_libraries_count %> libraries');tmpl_array.push(" ");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")}});return{LibraryToolbarView:c}}); \ No newline at end of file diff --git a/static/style/blue/base.css b/static/style/blue/base.css index dba87583199..d8281269fd2 100644 --- a/static/style/blue/base.css +++ b/static/style/blue/base.css @@ -757,6 +757,7 @@ pre{overflow:auto;word-wrap:normal;white-space:pre} .dropdown-menu{max-width:auto} input[type="checkbox"],input[type="radio"]{margin-left:0.5ex;margin-right:0.5ex} .modal-dialog{width:690px} +.pagination>.active>a{background-color:#ebd9b2;color:black}.pagination>.active>a:hover{color:black;background-color:#ebd9b2} .modal-body{overflow:auto} .nav-tabs{margin-bottom:15px} a{text-decoration:underline} @@ -1360,6 +1361,8 @@ span.expandLink{padding-left:12px;display:inline-block;vertical-align:middle;bac .libraryItem-queued{margin-right:2px;padding:0 2px 0 2px;border:1px solid #bfbfbf;background:#eee} .libraryItem-running{margin-right:2px;padding:0 2px 0 2px;border:1px solid #aa6;background:#ffc} .libraryItem-upload{margin-right:2px;padding:0 2px 0 2px;border:1px solid #1197c0;background:#a6e4f7} +.pagination-sm{height:15px} +.library-paginator{margin-left:2em} .toast-title{font-weight:bold} .toast-message{-ms-word-wrap:break-word;word-wrap:break-word}.toast-message a,.toast-message label{color:#fff} .toast-message a:hover{color:#ccc;text-decoration:none} diff --git a/static/style/blue/library.css b/static/style/blue/library.css index 535f3f7b40b..ba61cd00ded 100644 --- a/static/style/blue/library.css +++ b/static/style/blue/library.css @@ -42,3 +42,5 @@ span.expandLink{padding-left:12px;display:inline-block;vertical-align:middle;bac .libraryItem-queued{margin-right:2px;padding:0 2px 0 2px;border:1px solid #bfbfbf;background:#eee} .libraryItem-running{margin-right:2px;padding:0 2px 0 2px;border:1px solid #aa6;background:#ffc} .libraryItem-upload{margin-right:2px;padding:0 2px 0 2px;border:1px solid #1197c0;background:#a6e4f7} +.pagination-sm{height:15px} +.library-paginator{margin-left:2em} diff --git a/static/style/src/less/galaxy_bootstrap/overrides.less b/static/style/src/less/galaxy_bootstrap/overrides.less index 3b2a3d022a4..711d1418604 100644 --- a/static/style/src/less/galaxy_bootstrap/overrides.less +++ b/static/style/src/less/galaxy_bootstrap/overrides.less @@ -35,6 +35,16 @@ input[type="checkbox"],input[type="radio"] { width: 690px; } +.pagination { + > .active > a { + background-color: #ebd9b2; + color: black; + &:hover { + color: black; + background-color: #ebd9b2; + } + } +} /* NOTE: these styles do not currently work. @@ -70,4 +80,4 @@ NOTE: these styles do not currently work. .nav-tabs { margin-bottom: 15px; -} \ No newline at end of file +} diff --git a/static/style/src/less/library.less b/static/style/src/less/library.less index 2060bac3abe..2aef506401e 100644 --- a/static/style/src/less/library.less +++ b/static/style/src/less/library.less @@ -98,8 +98,7 @@ a.dark } } -th.button_heading -{ +th.button_heading{ width: 2em; } @@ -209,3 +208,9 @@ span.expandLink { border: 1px solid @state-upload-border; background: @state-upload-bg; } +.pagination-sm { + height: 15px; +} +.library-paginator { + margin-left: 2em; +}