Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / app / views / users / profile.html.erb
index 2c40fefb63d39c36d6bdc8aeed3fb5e76a5ada0a..26d1f57211b257a524461dd70f049a3e2afd9bf6 100644 (file)
@@ -1,16 +1,13 @@
+<%# Copyright (C) The Arvados Authors. All rights reserved.
+
+SPDX-License-Identifier: AGPL-3.0 %>
+
 <%
     profile_config = Rails.configuration.user_profile_form_fields
     current_user_profile = current_user.prefs[:profile]
     show_save_button = false
 
-    profile_message = Rails.configuration.user_profile_form_message ? Rails.configuration.user_profile_form_message : 'You can manage your profile using this page. Any feilds in red are required and missing. Please fill in those fields before you can accesse Arvados Workbench.'
-
-    missing_required = missing_required_profile?
-
-    profile_url = '/users/'+current_user.uuid+'/profile'
-    target = request.url.partition('?target=')[-1]
-    target = request.url if target.empty?
-    return_to_url = (request.url.ends_with? profile_url) ? profile_url : profile_url+'?target='+target
+    profile_message = Rails.configuration.user_profile_form_message
 %>
 
 <div>
           </h4>
         </div>
         <div class="panel-body">
-          <% if !missing_required && params.andand.keys.include?('target') %>
-            <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
-              <p style="margin: 8px;">Thank you for filling in your profile. If you are done updating your profile,
-                 you can now access Arvados Workbench by clicking on this button.
-                  <form action="<%=target%>">
-                    <input style="margin-left: 8px;" class="btn btn-primary" type="submit" value="Access Arvados Workbench">
-                  </form>
-              </p>
+          <% if !missing_required_profile? && params[:offer_return_to] %>
+            <div class="alert alert-success">
+              <% if current_user.prefs[:getting_started_shown] %>
+                <p>Thank you for filling in your profile. <%= link_to 'Back to work!', params[:offer_return_to], class: 'btn btn-sm btn-primary' %></p>
+              <% else %>
+                <p>Thank you for filling in your profile. <%= link_to 'Get started', params[:offer_return_to], class: 'btn btn-sm btn-primary' %></p>
+              <% end %>
             </div>
           <% else %>
-            <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
-              <p style="margin: 8px;"> <%=raw(profile_message)%> </p>
+            <div class="alert alert-info">
+              <p><%=raw(profile_message)%></p>
             </div>
           <% end %>
 
-          <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
-            <%= form_tag "/users/#{current_user.uuid}", {method: 'patch', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
-              <%= hidden_field_tag :return_to, return_to_url %>
+            <%= form_for current_user, html: {id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
+              <%= hidden_field_tag :offer_return_to, params[:offer_return_to] %>
+              <%= hidden_field_tag :return_to, profile_user_path(current_user.uuid, offer_return_to: params[:offer_return_to]) %>
               <div class="form-group">
-                  <label for="email" class="col-sm-3 control-label"> Email </label>
+                  <label for="email" class="col-sm-3 control-label"> E-mail </label>
                   <div class="col-sm-8">
                     <p class="form-control-static" id="email" name="email"><%=current_user.email%></p>
                   </div>
               </div>
               <div class="form-group">
-                  <label for="first_name" class="col-sm-3 control-label"> First name </label>
+                  <label for="first_name" class="col-sm-3 control-label"> First Name </label>
                   <div class="col-sm-8">
                     <p class="form-control-static" id="first_name" name="first_name"><%=current_user.first_name%></p>
                   </div>
               </div>
               <div class="form-group">
-                  <label for="last_name" class="col-sm-3 control-label"> Last name </label>
+                  <label for="last_name" class="col-sm-3 control-label"> Last Name </label>
                   <div class="col-sm-8">
                     <p class="form-control-static" id="last_name" name="last_name"><%=current_user.last_name%></p>
                   </div>
@@ -79,7 +75,7 @@
                     </label>
                     <% if entry['type'] == 'select' %>
                       <div class="col-sm-8">
-                        <select class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]">
+                        <select class="form-control" name="user[prefs][profile][<%=entry['key']%>]">
                           <% entry['options'].each do |option| %>
                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
                           <% end %>
                       </div>
                     <% else %>
                       <div class="col-sm-8">
-                        <input type="text" class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
+                        <input type="text" class="form-control" name="user[prefs][profile][<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
                       </div>
                     <% end %>
                   </div>
                 <% end %>
               <% end %>
 
+              <%# If the user has other prefs, we need to preserve them %>
+              <% current_user.prefs.each do |key, value| %>
+                <% if key != :profile %>
+                  <input type="hidden" name="user[prefs][<%=key%>]" value="<%=value.to_json%>">
+                <% end %>
+              <% end %>
+
               <% if show_save_button %>
                 <div class="form-group">
                   <div class="col-sm-offset-3 col-sm-8">
                 </div>
               <% end %>
             <% end %>
-          </div>
         </div>
     </div>
 </div>