1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/47990c9bd4d8/ Changeset: 47990c9bd4d8 User: carlfeberhard Date: 2014-02-05 18:36:11 Summary: Visualizations API: properly return visualization model id from update; Visualizations MVC: bring setConfig into line with Backbone API Affected #: 3 files diff -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 -r 47990c9bd4d8003e0ba619d73c1022646f3bc973 lib/galaxy/webapps/galaxy/api/visualizations.py --- a/lib/galaxy/webapps/galaxy/api/visualizations.py +++ b/lib/galaxy/webapps/galaxy/api/visualizations.py @@ -176,8 +176,11 @@ or ( dbkey != visualization.latest_revision.dbkey ) or ( util.json.to_json_string( config ) != util.json.to_json_string( latest_config ) ) ): revision = self.add_visualization_revision( trans, visualization, config, title, dbkey ) - #TODO: need to somehow get what changed here? - rval = { 'id' : revision.id } + rval = { 'id' : id, 'revision' : revision.id } + + #TODO: allow updating vis title & slug + #visualization.title = title + #trans.sa_session.flush() except ( ItemAccessibilityException, ItemDeletionException ), exception: trans.response.status = 403 diff -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 -r 47990c9bd4d8003e0ba619d73c1022646f3bc973 static/scripts/mvc/visualization/visualization-model.js --- a/static/scripts/mvc/visualization/visualization-model.js +++ b/static/scripts/mvc/visualization/visualization-model.js @@ -1,24 +1,6 @@ //define([ //], function(){ -//function saveVis( title, config ){ -// var xhr = jQuery.ajax( '/api/visualizations', { -// type : 'POST', -// data : { -// type : 'scatterplot', -// title : title, -// config : JSON.stringify( config ) -// } -// }); -// xhr.fail( function( xhr, status, message ){ -// console.debug( jQuery.makeArray( arguments ) ); -// console.error( 'Error saving visualization:', xhr.responseJSON.error ); -// }); -// return xhr.then( function( saveInfo ){ -// return saveInfo; -// }); -//} - //============================================================================== /** @class Model for a saved Galaxy visualization. * @@ -36,21 +18,13 @@ /** default attributes for a model */ defaults : { - //id : null, - //type : null, - //title : null, - //dbkey : null, - //user_id : null, - //slug : null, - //revisions : [], - //latest_revision : null - - //(this is unusual in that visualizations don't have configs, revisions do) - //config : {} + config : {} }, - url : function(){ - return galaxy_config.root + 'api/visualizations'; + /** override urlRoot to handle presence/absence of galaxy_config */ + urlRoot : function(){ + var apiUrl = '/api/visualizations'; + return (( window.galaxy_config && galaxy_config.root )?( galaxy_config.root + apiUrl ):( apiUrl )); }, /** Set up the model, determine if accessible, bind listeners @@ -58,27 +32,39 @@ */ initialize : function( data ){ this.log( this + '.initialize', data, this.attributes ); + + // munge config sub-object here since bbone won't handle defaults with this + if( _.isObject( data.config ) && _.isObject( this.defaults.config ) ){ + _.defaults( data.config, this.defaults.config ); + } + this._setUpListeners(); }, /** set up any event listeners */ _setUpListeners : function(){ + //this.on( 'change', function(){ + // console.info( 'change:', arguments ); + //}); }, // ........................................................................ config - setConfig: function( config ){ - var oldConfig = this.get( 'config' ); - // extend if already exists (and clone in order to trigger change) - if( _.isObject( oldConfig ) ){ - config = _.extend( _.clone( oldConfig ), config ); + /** override set to properly allow update and trigger change when setting the sub-obj 'config' */ + set: function( key, val ){ + //TODO: validate config is object + if( key === 'config' ){ + var oldConfig = this.get( 'config' ); + // extend if already exists (is this correct behavior? no way to eliminate keys or reset entirely) + // clone in order to trigger change (diff. obj ref) + if( _.isObject( oldConfig ) ){ + val = _.extend( _.clone( oldConfig ), val ); + } } - this.set( 'config', config ); + Backbone.Model.prototype.set.call( this, key, val ); return this; }, - // ........................................................................ common queries - // ........................................................................ ajax // ........................................................................ misc /** String representation */ toString : function(){ diff -r 6af6d838db509c1ce90a885d15a6e2cda2ef1e87 -r 47990c9bd4d8003e0ba619d73c1022646f3bc973 static/scripts/packed/mvc/visualization/visualization-model.js --- a/static/scripts/packed/mvc/visualization/visualization-model.js +++ b/static/scripts/packed/mvc/visualization/visualization-model.js @@ -1,1 +1,1 @@ -var Visualization=Backbone.Model.extend(LoggableMixin).extend({defaults:{},url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(a){this.log(this+".initialize",a,this.attributes);this._setUpListeners()},_setUpListeners:function(){},setConfig:function(b){var a=this.get("config");if(_.isObject(a)){b=_.extend(_.clone(a),b)}this.set("config",b);return this},toString:function(){var a=this.get("id")||"";if(this.get("title")){a+=":"+this.get("title")}return"Visualization("+a+")"}});var VisualizationCollection=Backbone.Collection.extend(LoggableMixin).extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(b,a){a=a||{}},set:function(c,a){var b=this;c=_.map(c,function(e){var f=b.get(e.id);if(!f){return e}var d=f.toJSON();_.extend(d,e);return d});Backbone.Collection.prototype.set.call(this,c,a)},toString:function(){return(["VisualizationCollection(",[this.historyId,this.length].join(),")"].join(""))}}); \ No newline at end of file +var Visualization=Backbone.Model.extend(LoggableMixin).extend({defaults:{config:{}},urlRoot:function(){var a="/api/visualizations";return((window.galaxy_config&&galaxy_config.root)?(galaxy_config.root+a):(a))},initialize:function(a){this.log(this+".initialize",a,this.attributes);if(_.isObject(a.config)&&_.isObject(this.defaults.config)){_.defaults(a.config,this.defaults.config)}this._setUpListeners()},_setUpListeners:function(){},set:function(b,c){if(b==="config"){var a=this.get("config");if(_.isObject(a)){c=_.extend(_.clone(a),c)}}Backbone.Model.prototype.set.call(this,b,c);return this},toString:function(){var a=this.get("id")||"";if(this.get("title")){a+=":"+this.get("title")}return"Visualization("+a+")"}});var VisualizationCollection=Backbone.Collection.extend(LoggableMixin).extend({model:Visualization,url:function(){return galaxy_config.root+"api/visualizations"},initialize:function(b,a){a=a||{}},set:function(c,a){var b=this;c=_.map(c,function(e){var f=b.get(e.id);if(!f){return e}var d=f.toJSON();_.extend(d,e);return d});Backbone.Collection.prototype.set.call(this,c,a)},toString:function(){return(["VisualizationCollection(",[this.historyId,this.length].join(),")"].join(""))}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.