commit/galaxy-central: carlfeberhard: Client app: allow bootstrapping data as require dependency, use window-scoped 'on ready' fn (for now), mixin Backbone.Events; galaxy.panels.mako: fix app ready v. doc ready order; Fix target fo addLogging; history.mako: simplify
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/7f05a259b98a/ Changeset: 7f05a259b98a User: carlfeberhard Date: 2014-04-18 15:34:16 Summary: Client app: allow bootstrapping data as require dependency, use window-scoped 'on ready' fn (for now), mixin Backbone.Events; galaxy.panels.mako: fix app ready v. doc ready order; Fix target fo addLogging; history.mako: simplify Affected #: 8 files diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 static/scripts/galaxy-app-base.js --- a/static/scripts/galaxy-app-base.js +++ b/static/scripts/galaxy-app-base.js @@ -2,8 +2,9 @@ 'mvc/user/user-model', 'utils/metrics-logger', 'utils/add-logging', - 'utils/localization' -], function( userModel, metricsLogger, addLogging, localize ){ + 'utils/localization', + 'bootstrapped-data' +], function( userModel, metricsLogger, addLogging, localize, bootstrapped ){ // ============================================================================ /** Base galaxy client-side application. * Iniitializes: @@ -17,39 +18,47 @@ var self = this; return self._init( options || {} ); } + // add logging shortcuts for this object addLogging( GalaxyApp, 'GalaxyApp' ); /** default options */ -GalaxyApp.defaultOptions = { +GalaxyApp.prototype.defaultOptions = { + /** monkey patch attributes from existing window.Galaxy object? */ + patchExisting : true, /** root url of this app */ // move to self.root? - root : '/' + root : '/' }; /** initalize options and sub-components */ GalaxyApp.prototype._init = function init( options ){ var self = this; + _.extend( self, Backbone.Events ); self._processOptions( options ); self.debug( 'GalaxyApp.options: ', self.options ); + self._patchGalaxy( window.Galaxy ); + self.debug( 'GalaxyApp.options: ', self.options ); + self._initLogger( options.loggerOptions || {} ); self.debug( 'GalaxyApp.logger: ', self.logger ); self._initLocale(); self.debug( 'GalaxyApp.localize: ', self.localize ); - self.config = options.config || {}; + self.config = options.config || bootstrapped.config || {}; self.debug( 'GalaxyApp.config: ', self.config ); - self._initUser( options.userJSON || {} ); + self._initUser( options.user || bootstrapped.user || {} ); self.debug( 'GalaxyApp.user: ', self.user ); //TODO: temp - if( typeof options.onload === 'function' ){ - options.onload(); - } + self.trigger( 'ready', self ); + //if( typeof options.onload === 'function' ){ + // options.onload(); + //} return self; }; @@ -57,7 +66,7 @@ /** add an option from options if the key matches an option in defaultOptions */ GalaxyApp.prototype._processOptions = function _processOptions( options ){ var self = this, - defaults = GalaxyApp.defaultOptions; + defaults = self.defaultOptions; self.debug( '_processOptions: ', options ); self.options = {}; @@ -69,14 +78,21 @@ return self; }; -/** set up the current user as a Backbone model (mvc/user/user-model) */ -GalaxyApp.prototype._initUser = function _initUser( userJSON ){ +/** add an option from options if the key matches an option in defaultOptions */ +GalaxyApp.prototype._patchGalaxy = function _processOptions( patchWith ){ var self = this; - self.debug( '_initUser:', userJSON ); - self.user = new userModel.User( userJSON ); - //TODO: temp - self.currUser = self.user; - return self; + // in case req or plain script tag order has created a prev. version of the Galaxy obj... + if( self.options.patchExisting && patchWith ){ + self.debug( 'found existing Galaxy object:', patchWith ); + // ...(for now) monkey patch any added attributes that the previous Galaxy may have had + //TODO: move those attributes to more formal assignment in GalaxyApp + for( var k in patchWith ){ + if( patchWith.hasOwnProperty( k ) ){ + self.debug( '\t patching in ' + k + ' to Galaxy' ); + self[ k ] = patchWith[ k ]; + } + } + } }; /** set up the metrics logger (utils/metrics-logger) and pass loggerOptions */ @@ -97,6 +113,16 @@ return self; }; +/** set up the current user as a Backbone model (mvc/user/user-model) */ +GalaxyApp.prototype._initUser = function _initUser( userJSON ){ + var self = this; + self.debug( '_initUser:', userJSON ); + self.user = new userModel.User( userJSON ); + //TODO: temp - old alias + self.currUser = self.user; + return self; +}; + /** string rep */ GalaxyApp.prototype.toString = function toString(){ var userEmail = this.user.get( 'email' ) || '(anonymous)'; diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 static/scripts/packed/galaxy-app-base.js --- a/static/scripts/packed/galaxy-app-base.js +++ b/static/scripts/packed/galaxy-app-base.js @@ -1,1 +1,1 @@ -define(["mvc/user/user-model","utils/metrics-logger","utils/add-logging","utils/localization"],function(a,c,f,d){function g(m){var l=this;return l._init(m||{})}f(g,"GalaxyApp");g.defaultOptions={root:"/"};g.prototype._init=function j(m){var l=this;l._processOptions(m);l.debug("GalaxyApp.options: ",l.options);l._initLogger(m.loggerOptions||{});l.debug("GalaxyApp.logger: ",l.logger);l._initLocale();l.debug("GalaxyApp.localize: ",l.localize);l.config=m.config||{};l.debug("GalaxyApp.config: ",l.config);l._initUser(m.userJSON||{});l.debug("GalaxyApp.user: ",l.user);if(typeof m.onload==="function"){m.onload()}return l};g.prototype._processOptions=function e(n){var m=this,o=g.defaultOptions;m.debug("_processOptions: ",n);m.options={};for(var l in o){if(o.hasOwnProperty(l)){m.options[l]=(n.hasOwnProperty(l))?(n[l]):(o[l])}}return m};g.prototype._initUser=function i(m){var l=this;l.debug("_initUser:",m);l.user=new a.User(m);l.currUser=l.user;return l};g.prototype._initLogger=function k(m){var l=this;l.debug("_initLogger:",m);l.logger=new c.MetricsLogger(m);return l};g.prototype._initLocale=function h(m){var l=this;l.debug("_initLocale:",m);l.localize=d;window._l=l.localize;return l};g.prototype.toString=function b(){var l=this.user.get("email")||"(anonymous)";return"GalaxyApp("+l+")"};return{GalaxyApp:g}}); \ No newline at end of file +define(["mvc/user/user-model","utils/metrics-logger","utils/add-logging","utils/localization","bootstrapped-data"],function(b,d,g,e,a){function h(n){var m=this;return m._init(n||{})}g(h,"GalaxyApp");h.prototype.defaultOptions={patchExisting:true,root:"/"};h.prototype._init=function k(n){var m=this;_.extend(m,Backbone.Events);m._processOptions(n);m.debug("GalaxyApp.options: ",m.options);m._patchGalaxy(window.Galaxy);m.debug("GalaxyApp.options: ",m.options);m._initLogger(n.loggerOptions||{});m.debug("GalaxyApp.logger: ",m.logger);m._initLocale();m.debug("GalaxyApp.localize: ",m.localize);m.config=n.config||a.config||{};m.debug("GalaxyApp.config: ",m.config);m._initUser(n.user||a.user||{});m.debug("GalaxyApp.user: ",m.user);m.trigger("ready",m);return m};h.prototype._processOptions=function f(o){var n=this,p=n.defaultOptions;n.debug("_processOptions: ",o);n.options={};for(var m in p){if(p.hasOwnProperty(m)){n.options[m]=(o.hasOwnProperty(m))?(o[m]):(p[m])}}return n};h.prototype._patchGalaxy=function f(m){var o=this;if(o.options.patchExisting&&m){o.debug("found existing Galaxy object:",m);for(var n in m){if(m.hasOwnProperty(n)){o.debug("\t patching in "+n+" to Galaxy");o[n]=m[n]}}}};h.prototype._initLogger=function l(n){var m=this;m.debug("_initLogger:",n);m.logger=new d.MetricsLogger(n);return m};h.prototype._initLocale=function j(n){var m=this;m.debug("_initLocale:",n);m.localize=e;window._l=m.localize;return m};h.prototype._initUser=function i(n){var m=this;m.debug("_initUser:",n);m.user=new b.User(n);m.currUser=m.user;return m};h.prototype.toString=function c(){var m=this.user.get("email")||"(anonymous)";return"GalaxyApp("+m+")"};return{GalaxyApp:h}}); \ No newline at end of file diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 static/scripts/packed/utils/add-logging.js --- a/static/scripts/packed/utils/add-logging.js +++ b/static/scripts/packed/utils/add-logging.js @@ -1,1 +1,1 @@ -define([],function(){function a(c,b){if(b!==undefined){c._logNamespace=b}["debug","info","warn","error","metric"].forEach(function(d){(c.prototype||c)[d]=function(){if(!this.logger){return undefined}if(this.logger.emit){return this.logger.emit(d,this._logNamespace,arguments)}if(this.logger[d]){return this.logger[d].apply(this.logger,arguments)}return undefined}});return c}return a}); \ No newline at end of file +define([],function(){function a(d,c){var b=(d.prototype!==undefined)?(d.prototype):(d);if(c!==undefined){b._logNamespace=c}["debug","info","warn","error","metric"].forEach(function(e){b[e]=function(){if(!this.logger){return undefined}if(this.logger.emit){return this.logger.emit(e,this._logNamespace,arguments)}if(this.logger[e]){return this.logger[e].apply(this.logger,arguments)}return undefined}});return d}return a}); \ No newline at end of file diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 static/scripts/utils/add-logging.js --- a/static/scripts/utils/add-logging.js +++ b/static/scripts/utils/add-logging.js @@ -2,12 +2,13 @@ ], function(){ //============================================================================== function addLogging( obj, namespace ){ + var addTo = ( obj.prototype !== undefined )?( obj.prototype ):( obj ); if( namespace !== undefined ){ - obj._logNamespace = namespace; + addTo._logNamespace = namespace; } [ 'debug', 'info', 'warn', 'error', 'metric' ].forEach( function( logFn ){ - ( obj.prototype || obj )[ logFn ] = function(){ + addTo[ logFn ] = function(){ if( !this.logger ){ return undefined; } if( this.logger.emit ){ return this.logger.emit( logFn, this._logNamespace, arguments ); diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 templates/base/base_panels.mako --- a/templates/base/base_panels.mako +++ b/templates/base/base_panels.mako @@ -1,6 +1,6 @@ <!DOCTYPE HTML> -<%namespace name="galaxy_client" file="../galaxy_client_app.mako" /> +<%namespace name="galaxy_client" file="/galaxy_client_app.mako" /><% self.has_left_panel = hasattr( self, 'left_panel' ) self.has_right_panel = hasattr( self, 'right_panel' ) @@ -59,7 +59,8 @@ 'libs/require', "mvc/ui" )} - ${ galaxy_client.bootstrap() } + + ${ galaxy_client.load() } <script type="text/javascript"> ## global configuration object @@ -72,9 +73,6 @@ if (window != window.top) $('<link href="' + galaxy_config.root + 'static/style/galaxy.frame.masthead.css" rel="stylesheet">').appendTo('head'); - // start a Galaxy namespace for objects created - window.Galaxy = window.Galaxy || {}; - // console protection window.console = window.console || { log : function(){}, diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 templates/galaxy_client_app.mako --- a/templates/galaxy_client_app.mako +++ b/templates/galaxy_client_app.mako @@ -1,33 +1,41 @@ ## ============================================================================ -<%def name="bootstrap()"> +<%def name="bootstrap( **kwargs )"> ## Bootstap dictionaries for GalaxyApp object's JSON, create GalaxyApp, ## and steal existing attributes from plain objects already created + <% + kwargs.update({ + 'config' : get_config_dict(), + 'user' : get_user_dict(), + }) + %><script type="text/javascript"> - require([ 'galaxy-app-base' ], function( app ){ - galaxy = new app.GalaxyApp({ - config : ${ get_config_json() }, - userJSON : ${ get_user_json() }, + %for key in kwargs: + ( window.bootstrapped = window.bootstrapped || {} )[ '${key}' ] = ( + ${ h.to_json_string( kwargs[ key ], indent=( 2 if trans.debug else 0 ) )} ); + %endfor + define( 'bootstrapped-data', function(){ + return window.bootstrapped; + }); + </script> +</%def> + +<%def name="load( init_fn=None, **kwargs )"> + ${ self.bootstrap( **kwargs ) } + <script type="text/javascript"> + require([ 'require', 'galaxy-app-base' ], function( require, galaxy ){ + //TODO: global... + window.Galaxy = new galaxy.GalaxyApp({ root : '${h.url_for( "/" )}', //TODO: get these options from the server - onload : window.Galaxy? window.Galaxy.onload: null, - loggerOptions : { - } + loggerOptions : {} }); - // in case req or plain script tag order has created a prev. version of the Galaxy obj... - if( window.Galaxy ){ - // ...(for now) monkey patch any added attributes that the previous Galaxy may have had - //TODO: move those attributes to more formal assignment in GalaxyApp - for( var k in window.Galaxy ){ - if( window.Galaxy.hasOwnProperty( k ) ){ - galaxy.debug( 'patching in ' + k + ' to Galaxy' ) - galaxy[ k ] = window.Galaxy[ k ]; - } - } + + var initFn = ${ 'window[ "%s" ]' %( init_fn ) if init_fn else 'undefined' }; + if( typeof initFn === 'function' ){ + initFn(); } - window.Galaxy = galaxy; }); - </script></%def> @@ -69,6 +77,7 @@ # tags used users_api_controller = trans.webapp.api_controllers[ 'users' ] user_dict[ 'tags_used' ] = users_api_controller.get_user_tags_used( trans, user=trans.user ) + user_dict[ 'is_admin' ] = trans.user_is_admin() return user_dict usage = 0 diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 templates/webapps/galaxy/galaxy.panels.mako --- a/templates/webapps/galaxy/galaxy.panels.mako +++ b/templates/webapps/galaxy/galaxy.panels.mako @@ -1,5 +1,5 @@ <%namespace name="masthead" file="/webapps/galaxy/galaxy.masthead.mako"/> -<%namespace name="galaxy_client" file="../../galaxy_client_app.mako" /> +<%namespace name="galaxy_client" file="/galaxy_client_app.mako" /><!DOCTYPE HTML> @@ -38,10 +38,7 @@ 'libs/d3', 'galaxy.base', 'galaxy.panels', - 'libs/handlebars.runtime' - )} - - ${h.js( + 'libs/handlebars.runtime', "mvc/ui" )} @@ -109,11 +106,11 @@ // load any app configured var galaxy_config = ${ h.to_json_string( self.galaxy_config ) }; - Galaxy.onload = function(){ + window.init = function(){ var jscript = galaxy_config.app.jscript; if( jscript ){ - $( function(){ - require([ jscript ], function( js_lib ){ + require([ jscript ], function( js_lib ){ + $( function(){ ## load galaxy module application var module = new js_lib.GalaxyApp(); }); @@ -123,7 +120,7 @@ } } </script> - ${ galaxy_client.bootstrap() } + ${ galaxy_client.load( init_fn='init' ) } </%def> diff -r 934681daa52e477e60bc4e99fbcc154a537dd3b3 -r 7f05a259b98a16f0cb86e69a9c2e8746f1520623 templates/webapps/galaxy/root/history.mako --- a/templates/webapps/galaxy/root/history.mako +++ b/templates/webapps/galaxy/root/history.mako @@ -1,14 +1,13 @@ <%inherit file="/base.mako"/> +<%namespace file="/galaxy_client_app.mako" name="galaxy_client" /><%def name="title()"> - ${_('Galaxy History')} + ${ _( 'Galaxy History' ) } </%def> -<%namespace file="/galaxy.masthead.mako" import="get_user_json" /> - ## ----------------------------------------------------------------------------- <%def name="stylesheets()"> - ${parent.stylesheets()} + ${ parent.stylesheets() } <style> body.historyPage { margin: 0px; @@ -19,48 +18,33 @@ ## ----------------------------------------------------------------------------- <%def name="javascripts()"> -${parent.javascripts()} +${ parent.javascripts() } <script type="text/javascript"> -if( !window.Galaxy ){ - window.Galaxy = {}; -} $(function(){ $( 'body' ).addClass( 'historyPage' ).addClass( 'history-panel' ); }); -require([ - 'mvc/user/user-model', - 'mvc/history/current-history-panel', - 'utils/localization' -], function( user, historyPanel, _l ){ - $(function(){ - window._l = _l; - Galaxy.currUser = new user.User( ${h.to_json_string( get_user_json() )} ); - // history module is already in the dpn chain from the panel. We can re-scope it here. - var historyModel = require( 'mvc/history/history-model' ), - debugging = JSON.parse( sessionStorage.getItem( 'debugging' ) ) || false, - historyJSON = ${h.to_json_string( history )}, - hdaJSON = ${h.to_json_string( hdas )}; - - var history = new historyModel.History( historyJSON, hdaJSON, { - logger: ( debugging )?( console ):( null ) - }); - - var panel = new historyPanel.CurrentHistoryPanel({ - show_deleted : ${ 'true' if show_deleted == True else ( 'null' if show_deleted == None else 'false' ) }, - show_hidden : ${ 'true' if show_hidden == True else ( 'null' if show_hidden == None else 'false' ) }, - el : $( "body.historyPage" ), - model : history, - onready : function(){ - this.render(); - if( Galaxy ){ - Galaxy.currHistoryPanel = this; +window.app = function(){ + require([ + 'mvc/history/current-history-panel' + ], function( historyPanel ){ + $(function(){ + // history module is already in the dpn chain from the panel. We can re-scope it here. + var historyModel = require( 'mvc/history/history-model' ); + window.panel = new historyPanel.CurrentHistoryPanel({ + show_deleted : bootstrapped.show_deleted, + show_hidden : bootstrapped.show_hidden, + el : $( "body" ), + model : new historyModel.History( bootstrapped.history, bootstrapped.hdas ), + onready : function(){ + this.render( 0 ); } - } + }); }); }); -}); +} </script> +${ galaxy_client.load( 'app', history=history, hdas=hdas, show_deleted=show_deleted, show_hidden=show_hidden ) } </%def> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org