Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / views / users / profile.html.erb
index 6af3662626e815535b32c4110d71b599c0a801aa..caa22bda11cd0925fb5a9a98636860ad8827c61d 100644 (file)
@@ -1,9 +1,22 @@
-<% 
-    profile_config = Rails.configuration.user_profile_form_fields
-    this_user = User.limit(1).where(uuid: current_user.uuid).first
-    user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
-    current_user_profile = user_prefs[:profile] if user_prefs
+<%# Copyright (C) The Arvados Authors. All rights reserved.
+
+SPDX-License-Identifier: AGPL-3.0 %>
+
+<%
+    profile_config = []
+    Rails.configuration.Workbench.UserProfileFormFields.each do |k, v|
+      r = v.dup
+      r["Key"] = k
+      profile_config << r
+    end
+    profile_config.sort_by! { |v| v["Position"] }
+
+    current_user_profile = current_user.prefs[:profile]
+    show_save_button = false
+
+    profile_message = Rails.configuration.Workbench.UserProfileFormMessage
 %>
+
 <div>
     <div class="panel panel-default">
         <div class="panel-heading">
           </h4>
         </div>
         <div class="panel-body">
-          <div>
-            <% profile_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.'
-                profile_config.andand.each do |entry| 
-                  if entry['message']
-                    profile_message = entry['message']
-                    break
-                  end
-                end %>
-            <p> <%=profile_message%> </p><br/>
-          </div>
-          <div>
-            <%= form_tag update_profile_path, {method: 'put', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal', remote: true} do %>
+          <% 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="alert alert-info">
+              <p><%=raw(profile_message)%></p>
+            </div>
+          <% end %>
+
+            <%= 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>
-                  <div class="col-sm-9">
+                  <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>
-                  <div class="col-sm-9">
+                  <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>
-                  <div class="col-sm-9">
+                  <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>
               </div>
               <div class="form-group">
                   <label for="identity_url" class="col-sm-3 control-label"> Identity URL </label>
-                  <div class="col-sm-9">
-                    <p class="form-control-static" id="identity_url" name="identity_url"><%=this_user.andand.identity_url%></p>
+                  <div class="col-sm-8">
+                    <p class="form-control-static" id="identity_url" name="identity_url"><%=current_user.andand.identity_url%></p>
                   </div>
               </div>
 
-              <% profile_config.andand.each do |entry| %>
-                <% if entry['key'] %>
+              <% profile_config.kind_of?(Array) && profile_config.andand.each do |entry| %>
+                <% if entry[:Key] %>
                   <%
-                      label = entry['required'] ? '* ' : ''
-                      label += entry['form_field_title']
-                      value = current_user_profile[entry['key'].to_sym] if current_user_profile
+                      show_save_button = true
+                      label = entry[:Required] ? '* ' : ''
+                      label += entry[:FormFieldTitle]
+                      value = current_user_profile[entry[:Key].to_sym] if current_user_profile
                   %>
                   <div class="form-group">
-                    <label for="<%=entry['key']%>"
+                    <label for="<%=entry[:Key]%>"
                            class="col-sm-3 control-label"
-                           style=<%="color:red" if entry['required']&&!value%>> <%=label%>
+                           style=<%="color:red" if entry[:Required]&&(!value||value.empty?)%>> <%=label%>
                     </label>
-                    <% if entry['type'] == 'select' %>
-                      <div class="col-sm-9">
-                        <select class="form-control" id="<%=entry['key']%>" name="<%=entry['key']%>">
-                          <% entry['options'].each do |option| %>
+                    <% if entry[:Type] == 'select' %>
+                      <div class="col-sm-8">
+                        <select class="form-control" name="user[prefs][profile][<%=entry[:Key]%>]">
+                          <% entry[:Options].each do |option, _| %>
+                           <% option = option.to_s %>
                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
                           <% end %>
                         </select>
                       </div>
                     <% else %>
-                      <div class="col-sm-9">
-                        <input type="text" class="form-control" id="<%=entry['key']%>" name="<%=entry['key']%>" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
+                      <div class="col-sm-8">
+                        <input type="text" class="form-control" name="user[prefs][profile][<%=entry[:Key]%>]" placeholder="<%=entry[:FormFieldDescription]%>" value="<%=value%>" ></input>
                       </div>
                     <% end %>
                   </div>
                 <% end %>
               <% end %>
 
-              <div class="form-group">
-                <div class="col-sm-offset-3 col-sm-9">
-                  <button type="submit" class="btn btn-primary">Save profile</button>
+              <%# 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">
+                    <button type="submit" class="btn btn-primary">Save profile</button>
+                  </div>
                 </div>
-              </div>
+              <% end %>
             <% end %>
-          </div>
         </div>
     </div>
 </div>