Skip to content

Commit

Permalink
Adding serialization-deserialization to save dynamic user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
anuprulez committed Aug 12, 2016
1 parent 4268d61 commit 320f17b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
14 changes: 6 additions & 8 deletions client/galaxy/scripts/mvc/user/extra-information.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var ExtraInformation = Backbone.View.extend({
/** renders the markup of extra information */
render: function( data_plugin ) {
data = data_plugin["config"],
plugins = data_plugin["plugins"];
plugins = JSON.parse(data_plugin["plugins"]) ;
var template = "",
self = this,
item_object = null,
Expand All @@ -30,10 +30,10 @@ var ExtraInformation = Backbone.View.extend({
// sets the model for each plugin data and
// values to each input field
if( item_object["name"] === "section_apollo_url" ) {
model = plugins["apollo"];
model = plugins["section_apollo_url"];
}
else if( item_object["name"] === "section_openstack_account" ) {
model = plugins["openstack"];
model = plugins["section_openstack_account"];
}

template = template + '<div class="form-row '+ item_object["name"] +' ">';
Expand Down Expand Up @@ -70,13 +70,12 @@ var ExtraInformation = Backbone.View.extend({
userurl = $( "input[name='url']" ).val(),
data = {},
messageBar = Manage.ManageUserInformation.prototype,
section_name = "",
element = {},
is_form_valid = true;

$(".form-row input").each( function( item ) {
if( $(this).attr('type') === 'text' || $(this).attr('type') === 'password' ) {
section_name = $($(this).parent().parent()[0]).attr("class").split(" ")[1];
var section_name = $($(this).parent().parent()[0]).attr("class").split(" ")[1],
element = {};
attrname = $(this).attr('name');
attrvalue = $(this).val();

Expand All @@ -88,7 +87,6 @@ var ExtraInformation = Backbone.View.extend({
}
// builds the JSON object
element[ $(this).attr('name') ] = attrvalue;

if( data[section_name] ) {
data[section_name][attrname] = attrvalue;
}
Expand All @@ -98,7 +96,7 @@ var ExtraInformation = Backbone.View.extend({
}
});
if( is_form_valid ) {
$.getJSON( url, data, function( response ) {
$.getJSON( url, {'plugin_data' : JSON.stringify(data)}, function( response ) {
messageBar.renderDone( response["message"] );
});
}
Expand Down
26 changes: 8 additions & 18 deletions lib/galaxy/webapps/galaxy/api/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import sys
import logging

import json
from markupsafe import escape
from sqlalchemy import false, and_, or_, true, func

Expand Down Expand Up @@ -559,19 +559,10 @@ def get_extra_preferences( self, trans, cntrller='user_preferences', **kwd ):
log.warn('Config file (%s) could not be found or is malformed.' % path)

user = trans.user
# builds the plugin's section data
section_apollo_url = { "apollo_url": user.preferences.get("apollo_url", "") }
section_openstack_account = {
"url": user.preferences.get("openstack_url", ""),
"password": user.preferences.get("openstack_password", ""),
"username": user.preferences.get("openstack_username", "")
}

plugins = { "apollo": section_apollo_url,
"openstack": section_openstack_account }

plugin_data = user.preferences.get("dynamic_user_preferences", {})
# deserializes the json and returns to the client
return { "config": config,
"plugins": plugins
"plugins": json.loads(plugin_data)
}


Expand All @@ -581,11 +572,10 @@ def save_extra_preferences( self, trans, cntrller='user_preferences', **kwd ):
Saves the admin defined user information
"""
user = trans.user
user.preferences["apollo_url"] = kwd.get("section_apollo_url[apollo_url]", "")
user.preferences["openstack_url"] = kwd.get("section_openstack_account[url]", "")
user.preferences["openstack_password"] = kwd.get("section_openstack_account[password]", "")
user.preferences["openstack_username"] = kwd.get("section_openstack_account[username]", "")

plugin_data = kwd.get( "plugin_data", {} )
# serializes the json and save the user preferences
user.preferences["dynamic_user_preferences"] = json.dumps( plugin_data )
# saves the user data
trans.sa_session.add( user )
trans.sa_session.flush()

Expand Down
4 changes: 2 additions & 2 deletions static/scripts/bundled/libs.bundled.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/scripts/bundled/libs.bundled.js.map

Large diffs are not rendered by default.

0 comments on commit 320f17b

Please sign in to comment.