diff options
Diffstat (limited to 'helper.rb')
-rw-r--r-- | helper.rb | 48 |
1 files changed, 46 insertions, 2 deletions
@@ -1,5 +1,42 @@ helpers do + def login(username, password) + logout + session[:subjectid] = OpenTox::Authorization.authenticate(username, password) + LOGGER.debug "ToxCreate login user #{username} with subjectid: " + session[:subjectid].to_s + if session[:subjectid] != nil + session[:username] = username + return true + else + session[:username] = "" + return false + end + end + + def logout + if session[:subjectid] != nil + session[:subjectid] = nil + session[:username] = "" + return true + end + return false + end + + def logged_in() + return true if !AA_SERVER + if session[:subjectid] != nil + return OpenTox::Authorization.is_token_valid(session[:subjectid]) + end + return false + end + + def is_authorized(uri, action) + if session[:subjectid] != nil + return OpenTox::Authorization.authorize(uri, action, session[:subjectid]) + end + return false + end + def hide_link(destination) @link_id = 0 unless @link_id @link_id += 1 @@ -12,8 +49,15 @@ helpers do haml :js_link, :locals => {:name => name, :destination => destination, :method => "toggle"}, :layout => false end - def compound_image(compound,features) - haml :compound_image, :locals => {:compound => compound, :features => features}, :layout => false + def sort(descriptors) + features = {:activating => [], :deactivating => []} + + descriptors.each { |d| LOGGER.debug d.inspect; features[d[OT.effect].to_sym] << {:smarts => d[OT.smarts],:p_value => d[OT.pValue]} } + features + end + + def compound_image(compound,descriptors) + haml :compound_image, :locals => {:compound => compound, :features => sort(descriptors)}, :layout => false end def activity_markup(activity) |