Skip to content

Commit

Permalink
Adding save feature for extra user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
anuprulez committed Aug 11, 2016
1 parent 93d97d8 commit 4268d61
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 72 deletions.
93 changes: 63 additions & 30 deletions client/galaxy/scripts/mvc/user/extra-information.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/** Get extra information */
define([], function() {
define(['mvc/user/manage-user-information'], function( Manage ) {

var ExtraInformation = Backbone.View.extend({

initialize: function ( data ) {
this.render( data );
},

/** renders the markup of extra information */
render: function( data ) {
render: function( data_plugin ) {
data = data_plugin["config"],
plugins = data_plugin["plugins"];
var template = "",
self = this;
$( '.user-pref' ).css( 'display', 'none' );
self = this,
item_object = null,
model = null;
$( '.user-pref' ).hide();
$( '.donemessage' ).hide();
$( '.errormessage' ).hide();
template = template + '<div class="extra-information-section"> <h2>Extra Information</h2>';
template = template + '<ul class="manage-table-actions"> <li>' +
'<a class="action-button back-user-pref" target="galaxy_main">User preferences</a>' +
Expand All @@ -21,55 +26,83 @@ var ExtraInformation = Backbone.View.extend({
'<form name="extra_information" id="extra_information">' +
'<div class="toolFormTitle">Extra Information</div>';
for( var item in data["preferences"] ) {
var item_object = data["preferences"][item];
template = template + '<div class="form-row">';
item_object = data["preferences"][item];
// sets the model for each plugin data and
// values to each input field
if( item_object["name"] === "section_apollo_url" ) {
model = plugins["apollo"];
}
else if( item_object["name"] === "section_openstack_account" ) {
model = plugins["openstack"];
}

template = template + '<div class="form-row '+ item_object["name"] +' ">';
template = template + "<label>" + item_object["description"] + ":</label>";
for( var i = 0; i < item_object["inputs"].length; i++ ) {
var input_object = item_object["inputs"][i];
template = template + '<div class="form-row">';
template = template + "<label>" + input_object.label + ':</label><input type="'+ input_object.type +
'" name="'+ input_object.name +'" value="" '+ (input_object.required ? 'required': '') + '/>';
'" name="'+ input_object.name +'" value="'+ model[input_object.name] +'" '
+ (input_object.required ? 'required': '') + '/>';
template = template + '</div>';
}
template = template + '</div>';
}
template = template + '</div>';

template = template + '<div class="form-row">' +
'<input type="button" class="save-password action-button" name="change_password_button" value="Save"/>' +
'</div></form></div></div>';
$('.save-password').on( 'click', function( e ) { self.saveExtraInformation( self, e ) } );
'<input type="button" class="save-extra-info action-button" name="save_extra_information" value="Save"/>';
template = template + '</div></div></form></div></div>';
$('.user-preferences-all').append( template );
$('.save-extra-info').on( 'click', function( e ) { self.saveExtraInformation( self, e ) } );
$('.back-user-pref').on( 'click', function( e ) {
$('.extra-information-section').remove();
$( '.donemessage' ).hide();
$( '.errormessage' ).hide();
$( '.user-pref' ).show();
});
},

/** saves extra user information */
saveExtraInformation: function( self, e ) {
/* var url = Galaxy.root + 'api/user_preferences/change_password',
current = $( "input[name='current']" ).val(),
var url = Galaxy.root + 'api/user_preferences/save_extra_preferences/',
username = $( "input[name='username']" ).val(),
password = $( "input[name='password']" ).val(),
confirm = $( "input[name='confirm']" ).val(),
userurl = $( "input[name='url']" ).val(),
data = {},
messageBar = Manage.ManageUserInformation.prototype;
data = { 'change_password_button': true, 'password': password, 'current': current, 'confirm': confirm, 'token': "" }
$.getJSON( url, data, function( response ) {
if( response["status"] === 'error' ) {
messageBar.renderError( response["message"] );
}
else {
$('.change-password-section').remove();
messageBar.renderDone( response["message"] );
$( '.user-pref' ).show();
}
});
*/
}
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];
attrname = $(this).attr('name');
attrvalue = $(this).val();

// checks if the required fields are left empty
if( $( this ).attr("required") && attrvalue === "" ) {
messageBar.renderError( "Please fill the "+ attrname +" required field" );
is_form_valid = false;
return;
}
// builds the JSON object
element[ $(this).attr('name') ] = attrvalue;

if( data[section_name] ) {
data[section_name][attrname] = attrvalue;
}
else {
data[section_name] = element;
}
}
});
if( is_form_valid ) {
$.getJSON( url, data, function( response ) {
messageBar.renderDone( response["message"] );
});
}
}
});

return {
Expand Down
3 changes: 2 additions & 1 deletion config/user_preferences_extra_conf.xml.sample
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
preferences:
# the key you can refer to
apollo_url_01:
name: section_apollo_url
# description that is displayed to the user
description: The URL to your personal Apollo instance

inputs:
# the content can be accessed by apollo_url_01.apollo_url
- name: apollo_url
Expand All @@ -15,6 +15,7 @@ preferences:
required: True

openstack_account:
name: section_openstack_account
description: Your own Open Stack account
inputs:
- name: username
Expand Down
41 changes: 33 additions & 8 deletions lib/galaxy/webapps/galaxy/api/user_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,6 @@ def change_password( self, trans, token=None, **kwd):
'message': message,
'display_top': kwd.get('redirect_home', False)
}
'''return trans.fill_template( '/user/change_password.mako',
token=token,
status=status,
message=message,
display_top=kwd.get('redirect_home', False)
)'''


@expose_api
def get_extra_preferences( self, trans, cntrller='user_preferences', **kwd ):
Expand All @@ -564,11 +557,43 @@ def get_extra_preferences( self, trans, cntrller='user_preferences', **kwd ):
config = load(stream)
except:
log.warn('Config file (%s) could not be found or is malformed.' % path)
return config

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 }

return { "config": config,
"plugins": plugins
}


@expose_api
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]", "")

trans.sa_session.add( user )
trans.sa_session.flush()

return {
'message': "The data was successfully saved",
'status': "done"
}




Expand Down
7 changes: 7 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def paste_app_factory( global_conf, **kwargs ):
webapp.add_client_route( '/user_preferences/new_address' )
webapp.add_client_route( '/user_preferences/change_password' )
webapp.add_client_route( '/user_preferences/get_extra_preferences' )
webapp.add_client_route( '/user_preferences/save_extra_preferences' )

# STANDARD CONTROLLER ROUTES
webapp.add_ui_controllers( 'galaxy.webapps.galaxy.controllers', app )
Expand Down Expand Up @@ -519,6 +520,12 @@ def populate_api_routes( webapp, app ):
action='get_extra_preferences',
conditions=dict( method=["GET"] ) )

webapp.mapper.connect( 'save_extra_preferences',
'/api/user_preferences/save_extra_preferences',
controller='user_preferences',
action='save_extra_preferences',
conditions=dict( method=["GET"] ) )

# =======================
# ===== LIBRARY API =====
# =======================
Expand Down
23 changes: 12 additions & 11 deletions static/scripts/bundled/analysis.bundled.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

35 changes: 17 additions & 18 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.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4268d61

Please sign in to comment.