4951: localStorage lookup much simplified and handled during page loading.
authorRadhika Chippada <radhika@curoverse.com>
Fri, 6 Feb 2015 18:38:18 +0000 (13:38 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Fri, 6 Feb 2015 18:38:18 +0000 (13:38 -0500)
apps/workbench/app/assets/javascripts/application.js
apps/workbench/app/assets/javascripts/request_shell_access.js
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/app/views/users/_manage_virtual_machines.html.erb
apps/workbench/config/routes.rb

index 8d929676ad7ec2fb111eae4e81581b9bb88a3761..d80420b3e51ac7a4ab56b67bb2d372695fd7caae 100644 (file)
@@ -239,13 +239,8 @@ function hasHTML5History() {
     return !!(window.history && window.history.pushState);
 }
 
-function invokeUrlWithLocalStorageValue(url, alias, item) {
-    value = localStorage.getItem(item);
-    if (value) {
-      window.location = alias;
-    } else {
-      window.location = url;
-    }
+function getLocalStorageValue(item) {
+    return localStorage.getItem(item);
 }
 
 function clearLocalStorageValue(item) {
index c8cbe347fc257bd2b2b1e0e352131fd98b19e8af..9378c6b0bf3f3b125ba5a4272533517f71b3c0b1 100644 (file)
@@ -1,3 +1,14 @@
+$(document).ready(function(){
+    var $noShellAccessDiv = $('#no_shell_access');
+    if ($noShellAccessDiv.length) {
+      if (getLocalStorageValue('request_shell_access') == 'sent') {
+        $('div').remove('.no_shell_access_msg');
+      } else {
+        $('div').remove('.shell_access_requested');
+      }
+    }
+  });
+
 $(document).
   on('click', "#request_shell_submit", function(e){
     $(this).html('Sending request ...');
index dae9ae5eb205c6903daea731b2a4eab12725e548..6d9d8cb7d193f80300601b1bb1e42d516041387a 100644 (file)
@@ -264,9 +264,6 @@ class UsersController < ApplicationController
     # current user's ssh keys
     @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid)
 
-    # when localStorage indicating previous shell access request, the url used is "manage_acct"
-    @local_storage_request_shell_access = true if request.url.include?('/manage_acct')
-
     respond_to do |f|
       f.html { render template: 'users/manage_account' }
     end
index 8b1fd739ab377a51ca76283dd029a275ae563ecc..5b456eae62f24914e25e4965f6838ffbb3da8155 100644 (file)
@@ -46,9 +46,7 @@
               </a>
               <ul class="dropdown-menu" role="menu">
                 <% if current_user.is_active %>
-                <li id='manage_account_link' role="menuitem"><a href="#"
-                    onClick="invokeUrlWithLocalStorageValue('/manage_account', '/manage_acct', 'request_shell_access');"
-                    role="menuitem"><i class="fa fa-key fa-fw"></i> Manage account</a></li>
+                <li id='manage_account_link' role="menuitem"><a href="/manage_account" role="menuitem"><i class="fa fa-key fa-fw"></i> Manage account</a></li>
                 <% if Rails.configuration.user_profile_form_fields %>
                   <li role="menuitem"><a href="/users/<%=current_user.uuid%>/profile" role="menuitem"><i class="fa fa-key fa-fw"></i> Manage profile</a></li>
                 <% end %>
index b324572f11cde7618c12bf5dbb12a363643ad86c..56833168418ae487ae3e38df6e7e3bafcf94cd16 100644 (file)
@@ -6,24 +6,22 @@
   </p>
 
   <% if !@my_virtual_machines.any? %>
-    <% if @local_storage_request_shell_access %>
+    <div id='no_shell_access' class='no_shell_access'>
       <div id='shell_access_requested' class='shell_access_requested'>
         <div class="alert alert-info">
           <p class="contain-align-left">You do not have access to any virtual machines. A request was sent on your behalf.</p>
         </div>
       </div>
-    <% else %>
-      <div id='no_shell_access' class='no_shell_access'>
-        <div id='no_shell_access_msg' class='no_shell_access_msg'>
-          You do not have access to any virtual machines. Many of the Arvados features depend on having shell access to a hosted VM.
-          &nbsp;&nbsp;&nbsp;
-          <div style='display:inline-block'>
-            <%= button_to('Request shell access', request_shell_access_user_url(id: current_user.uuid),
-                           id: 'request_shell_submit', class: 'btn btn-xs btn-primary', remote: true) %>
-          </div>
+
+      <div id='no_shell_access_msg' class='no_shell_access_msg'>
+        You do not have access to any virtual machines. Many of the Arvados features depend on having shell access to a hosted VM.
+        &nbsp;&nbsp;&nbsp;
+        <div style='display:inline-block'>
+          <%= button_to('Request shell access', request_shell_access_user_url(id: current_user.uuid),
+                         id: 'request_shell_submit', class: 'btn btn-xs btn-primary', remote: true) %>
         </div>
       </div>
-    <% end %>
+    </div>
   <% else %>
     <script> clearLocalStorageValue('request_shell_access'); </script>
     <table class="table virtual-machines-table">
index a077c2e7c1453d71dfa54374f965a1fe3f7d07a1..7ed02e7dc9ba11aa8beb07cae5f9c934ce77fd9f 100644 (file)
@@ -42,7 +42,6 @@ ArvadosWorkbench::Application.routes.draw do
     post 'request_shell_access', :on => :member
   end
   get '/manage_account' => 'users#manage_account'
-  get '/manage_acct' => 'users#manage_account', :as => :manage_acct
   get "/add_ssh_key_popup" => 'users#add_ssh_key_popup', :as => :add_ssh_key_popup
   get "/add_ssh_key" => 'users#add_ssh_key', :as => :add_ssh_key
   resources :logs