Skip to content

Commit

Permalink
Merge pull request #4512 from martenson/improving-datalibraries
Browse files Browse the repository at this point in the history
A round of data libraries improvements.
  • Loading branch information
jmchilton committed Sep 4, 2017
2 parents 8f13032 + 65185f5 commit 3d9809a
Show file tree
Hide file tree
Showing 22 changed files with 509 additions and 381 deletions.
2 changes: 1 addition & 1 deletion .ci/flake8_lint_include_list.txt
Expand Up @@ -101,7 +101,7 @@ lib/galaxy/webapps/galaxy/api/genomes.py
lib/galaxy/webapps/galaxy/api/histories.py
lib/galaxy/webapps/galaxy/api/__init__.py
lib/galaxy/webapps/galaxy/api/jobs.py
lib/galaxy/webapps/galaxy/api/lda_datasets.py
lib/galaxy/webapps/galaxy/api/library_datasets.py
lib/galaxy/webapps/galaxy/api/requests.py
lib/galaxy/webapps/galaxy/api/roles.py
lib/galaxy/webapps/galaxy/api/samples.py
Expand Down
155 changes: 103 additions & 52 deletions client/galaxy/scripts/mvc/library/library-dataset-view.js
Expand Up @@ -16,22 +16,22 @@ var LibraryDatasetView = Backbone.View.extend({

model: null,

options: {
options: {},

defaults: {
edit_mode: false
},

events: {
"click .toolbtn_modify_dataset" : "enableModification",
"click .toolbtn_cancel_modifications" : "render",
"click .toolbtn-download-dataset" : "downloadDataset",
"click .toolbtn-import-dataset" : "importIntoHistory",
"click .toolbtn-share-dataset" : "shareDataset",
"click .btn-copy-link-to-clipboard" : "copyToClipboard",
"click .btn-make-private" : "makeDatasetPrivate",
"click .btn-remove-restrictions" : "removeDatasetRestrictions",
"click .toolbtn_save_permissions" : "savePermissions",
"click .toolbtn_save_modifications" : "comingSoon",

"click .toolbtn_save_modifications" : "saveModifications"
},

// genome select
Expand Down Expand Up @@ -134,7 +134,10 @@ var LibraryDatasetView = Backbone.View.extend({
$(".tooltip").remove();
var template = this.templateModifyDataset();
this.$el.html(template({item: this.model}));
this.renderSelectBoxes({genome_build: this.model.get('genome_build'), file_ext: this.model.get('file_ext') });
this.renderSelectBoxes({
genome_build: this.model.get('genome_build'),
file_ext: this.model.get('file_ext')
});
$(".peek").html(this.model.get("peek"));
$("#center [data-toggle]").tooltip();
},
Expand Down Expand Up @@ -245,10 +248,6 @@ var LibraryDatasetView = Backbone.View.extend({
});
},

shareDataset: function(){
mod_toastr.info('Feature coming soon.');
},

goBack: function(){
Galaxy.libraries.library_router.back();
},
Expand Down Expand Up @@ -457,8 +456,57 @@ var LibraryDatasetView = Backbone.View.extend({
}
},

comingSoon: function(){
mod_toastr.warning('Feature coming soon.');
/**
* Save the changes made to the library dataset.
*/
saveModifications: function(options){
var is_changed = false;
var ld = this.model;
var new_name = this.$el.find('.input_dataset_name').val();
if (typeof new_name !== 'undefined' && new_name !== ld.get('name') ){
if (new_name.length > 0){
ld.set("name", new_name);
is_changed = true;
} else{
mod_toastr.warning('Library dataset name has to be at least 1 character long.');
return;
}
}
var new_info = this.$el.find('.input_dataset_misc_info').val();
if (typeof new_info !== 'undefined' && new_info !== ld.get('misc_info') ){
ld.set("misc_info", new_info);
is_changed = true;
}
var new_genome_build = this.select_genome.$el.select2('data').id;
if (typeof new_genome_build !== 'undefined' && new_genome_build !== ld.get('genome_build') ){
ld.set("genome_build", new_genome_build);
is_changed = true;
}
var new_ext = this.select_extension.$el.select2('data').id;
if (typeof new_ext !== 'undefined' && new_ext !== ld.get('file_ext') ){
ld.set("file_ext", new_ext);
is_changed = true;
}
var dataset_view = this;
if (is_changed){
ld.save(null, {
patch: true,
success: function(ld) {
dataset_view.render()
mod_toastr.success('Changes to library dataset saved.');
},
error: function(model, response){
if (typeof response.responseJSON !== "undefined"){
mod_toastr.error(response.responseJSON.err_msg);
} else {
mod_toastr.error('An error occured while attempting to update the library dataset.');
}
}
});
} else {
dataset_view.render()
mod_toastr.info('Nothing has changed.');
}
},

copyToClipboard: function(){
Expand Down Expand Up @@ -523,49 +571,54 @@ var LibraryDatasetView = Backbone.View.extend({
},

/**
* Request all extensions and genomes from Galaxy
* and save them sorted in arrays.
* If needed request all extensions and/or genomes from Galaxy
* and save them in sorted arrays.
*/
fetchExtAndGenomes: function(){
var that = this;
mod_utils.get({
url : Galaxy.root + "api/datatypes?extension_only=False",
success : function( datatypes ) {
for (var 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);
}
if (this.list_genomes.length == 0){
mod_utils.get({
url : Galaxy.root + "api/datatypes?extension_only=False",
success : function( datatypes ) {
for (var 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.root + "api/genomes",
}
if (this.list_extensions.length == 0){
mod_utils.get({
url : Galaxy.root + "api/genomes",
success : function( genomes ) {
for (var 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;
});
}
});
for (var 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(options){
// This won't work properly unlesss we already have the data fetched.
// See this.fetchExtAndGenomes()
// TODO switch to common resources:
// https://trello.com/c/dIUE9YPl/1933-ui-common-resources-and-data-into-galaxy-object
var that = this;
var current_genome = '?';
var current_ext = 'auto';
if (typeof options !== 'undefined'){
Expand All @@ -576,17 +629,16 @@ var LibraryDatasetView = Backbone.View.extend({
current_ext = options.file_ext;
}
}
var that = this;
this.select_genome = new mod_select.View( {
css: 'dataset-genome-select',
data: that.list_genomes,
container: that.$el.find( '#dataset_genome_select' ),
container: that.$el.find('#dataset_genome_select'),
value: current_genome
} );
this.select_extension = new mod_select.View({
css: 'dataset-extension-select',
data: that.list_extensions,
container: that.$el.find( '#dataset_extension_select' ),
container: that.$el.find('#dataset_extension_select'),
value: current_ext
});
},
Expand Down Expand Up @@ -711,13 +763,13 @@ var LibraryDatasetView = Backbone.View.extend({
'<% } %>',
'<% if (item.get("misc_blurb")) { %>',
'<tr>',
'<th scope="row">Miscellaneous blurb</th>',
'<th scope="row">Misc. blurb</th>',
'<td scope="row"><%= _.escape(item.get("misc_blurb")) %></td>',
'</tr>',
'<% } %>',
'<% if (item.get("misc_info")) { %>',
'<tr>',
'<th scope="row">Miscellaneous information</th>',
'<th scope="row">Misc. info</th>',
'<td scope="row"><%= _.escape(item.get("misc_info")) %></td>',
'</tr>',
'<% } %>',
Expand Down Expand Up @@ -902,7 +954,6 @@ var LibraryDatasetView = Backbone.View.extend({
'</ol>',

'<div class="dataset_table">',
'<p>For full editing options please import the dataset to history and use "Edit attributes" on it.</p>',
'<table class="grid table table-striped table-condensed">',
'<tr>',
'<th class="dataset-first-column" scope="row" id="id_row" data-id="<%= _.escape(item.get("ldda_id")) %>">Name</th>',
Expand Down Expand Up @@ -956,12 +1007,12 @@ var LibraryDatasetView = Backbone.View.extend({
'<td scope="row"><%= _.escape(item.get("message")) %></td>',
'</tr>',
'<tr>',
'<th scope="row">Miscellaneous information</th>',
'<td scope="row"><%= _.escape(item.get("misc_info")) %></td>',
'<th scope="row">Misc. blurb</th>',
'<td scope="row"><%= _.escape(item.get("misc_blurb")) %></td>',
'</tr>',
'<tr>',
'<th scope="row">Miscellaneous blurb</th>',
'<td scope="row"><%= _.escape(item.get("misc_blurb")) %></td>',
'<th scope="row">Misc. information</th>',
'<td><input class="input_dataset_misc_info form-control" type="text" placeholder="info" value="<%= _.escape(item.get("misc_info")) %>"></td>',
'</tr>',
//TODO: add functionality to modify tags here
'<% if (item.get("tags")) { %>',
Expand Down
78 changes: 0 additions & 78 deletions client/galaxy/scripts/mvc/library/library-folder-view.js
Expand Up @@ -37,8 +37,6 @@ var FolderView = Backbone.View.extend({
success: function() {
if (that.options.show_permissions){
that.showPermissions();
} else {
that.render();
}
},
error: function(model, response){
Expand All @@ -51,19 +49,6 @@ var FolderView = Backbone.View.extend({
});
},

render: function(options){
$(".tooltip").remove();
this.options = _.extend(this.options, options);
var template = this.templateFolder();
this.$el.html(template({item: this.model}));
$(".peek").html(this.model.get("peek"));
$("#center [data-toggle]").tooltip();
},

shareFolder: function(){
mod_toastr.info('Feature coming soon.');
},

goBack: function(){
Galaxy.libraries.library_router.back();
},
Expand Down Expand Up @@ -165,18 +150,6 @@ var FolderView = Backbone.View.extend({
return select_options;
},

comingSoon: function(){
mod_toastr.warning('Feature coming soon.');
},

copyToClipboard: function(){
var href = Backbone.history.location.href;
if (href.lastIndexOf('/permissions') !== -1){
href = href.substr(0, href.lastIndexOf('/permissions'));
}
window.prompt("Copy to clipboard: Ctrl+C, Enter", href);
},

/**
* Extract the role ids from Select2 elements's 'data'
*/
Expand Down Expand Up @@ -206,57 +179,6 @@ var FolderView = Backbone.View.extend({
})
},

templateFolder : function(){
return _.template([
'<div class="library_style_container">',
'<div id="library_toolbar">',
'<button data-toggle="tooltip" data-placement="top" title="Modify library item" class="btn btn-default toolbtn_modify_dataset primary-button" type="button">',
'<span class="fa fa-pencil"/>',
'&nbsp;Modify',
'</button>',
'<a href="#folders/<%- item.get("folder_id") %>/datasets/<%- item.id %>/permissions">',
'<button data-toggle="tooltip" data-placement="top" title="Manage permissions" class="btn btn-default toolbtn_change_permissions primary-button" type="button">',
'<span class="fa fa-group"/>',
'&nbsp;Permissions',
'</button>',
'</a>',
'<button data-toggle="tooltip" data-placement="top" title="Share dataset" class="btn btn-default toolbtn-share-dataset primary-button" type="button">',
'<span class="fa fa-share"/>',
'&nbsp;Share',
'</span>',
'</button>',
'</div>',
'<p>',
'This dataset is unrestricted so everybody can access it. Just share the URL of this page. ',
'<button data-toggle="tooltip" data-placement="top" title="Copy to clipboard" class="btn btn-default btn-copy-link-to-clipboard primary-button" type="button">',
'<span class="fa fa-clipboard"/>',
'&nbsp;To Clipboard',
'</button> ',
'</p>',
'<div class="dataset_table">',
'<table class="grid table table-striped table-condensed">',
'<tr>',
'<th scope="row" id="id_row" data-id="<%= _.escape(item.get("ldda_id")) %>">',
'Name',
'</th>',
'<td>',
'<%= _.escape(item.get("name")) %>',
'</td>',
'</tr>',
'<% if (item.get("file_ext")) { %>',
'<tr>',
'<th scope="row">Data type</th>',
'<td>',
'<%= _.escape(item.get("file_ext")) %>',
'</td>',
'</tr>',
'<% } %>',
'</table>',
'</div>',
'</div>'
].join(''));
},

templateFolderPermissions : function(){
return _.template([
'<div class="library_style_container">',
Expand Down

0 comments on commit 3d9809a

Please sign in to comment.