Browse Source

add change matrix

main
Christoph Marzell 1 month ago
parent
commit
4d45d38a56
  1. 19
      app/controllers/users/registrations_controller.rb
  2. 4
      app/models/user.rb
  3. 39
      app/views/devise/registrations/edit.html.erb
  4. 27
      config/routes.rb

19
app/controllers/users/registrations_controller.rb

@ -0,0 +1,19 @@
class Users::RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, params)
# Wenn kein Passwort gesetzt werden soll:
if params[:password].blank? && params[:password_confirmation].blank?
resource.update_without_password(params.except(:current_password))
else
super
end
end
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [
required_hours_matrix: {},
weekly_target_matrix: {}
])
end
end

4
app/models/user.rb

@ -17,8 +17,8 @@ class User < ApplicationRecord
[typ, ENTRY_ARTEN.to_h { |art| [art, default_hours_for(typ, art)] }]
end
self.weekly_target_matrix = {
"propädeutikum" => { "Praktikum" => 12, "Selbsterfahrung" => 1, "Supervision" => 1 },
"fachspezifikum" => { "Praktikum" => 10, "Selbsterfahrung" => 2, "Supervision" => 2 }
"propädeutikum" => { "Praktikum" => 12, "Selbsterfahrung" => 0.25, "Supervision" => 0.25 },
"fachspezifikum" => { "Praktikum" => 10, "Selbsterfahrung" => 0.25, "Supervision" => 0.25 }
}
end

39
app/views/devise/registrations/edit.html.erb

@ -1,5 +1,5 @@
<h2>Profil bearbeiten</h2>
<%= devise_error_messages! %>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<div class="mb-3">
<%= f.label :email, "E-Mail", class: "form-label" %>
@ -35,17 +35,34 @@
</tbody>
</table>
<h5>Wöchentliche Zielstunden (weekly_target_matrix)</h5>
<% ["propädeutikum", "fachspezifikum"].each do |typ| %>
<% ["Praktikum", "Selbsterfahrung", "Supervision"].each do |art| %>
<div class="mb-2">
<%= label_tag "user[weekly_target_matrix][#{typ}][#{art}]", "#{typ.capitalize} – #{art}" %>
<%= number_field_tag "user[weekly_target_matrix][#{typ}][#{art}]",
current_user.weekly_target_matrix.dig(typ, art),
class: "form-control", step: 1 %>
</div>
<h5 class="mt-4">Wöchentliche Zielstunden (weekly_target_matrix)</h5>
<table class="table table-bordered">
<thead class="table-light">
<tr>
<th>Typ</th>
<th>Art</th>
<th>Zielstunden / Woche</th>
</tr>
</thead>
<tbody>
<% User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art| %>
<tr>
<td><%= typ.capitalize %></td>
<td><%= art %></td>
<td>
<%= number_field_tag(
"user[weekly_target_matrix][#{typ}][#{art}]",
current_user.weekly_target_matrix.dig(typ, art),
class: "form-control",
min: 0,
step: 0.25
) %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<hr>

27
config/routes.rb

@ -1,14 +1,17 @@
Rails.application.routes.draw do
resources :entries
resource :user_goal, only: [:update]
root 'entries#index'
devise_for :users
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
# Defines the root path route ("/")
# root "posts#index"
resources :entries
resource :user_goal, only: [:update]
root 'entries#index'
devise_for :users, controllers: {
registrations: 'users/registrations'
}
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
# Defines the root path route ("/")
# root "posts#index"
end
Loading…
Cancel
Save