From 4d45d38a566c32a5476b75e6c9edb7b1c47dba8f Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Fri, 7 Nov 2025 09:28:39 +0100 Subject: [PATCH] add change matrix --- .../users/registrations_controller.rb | 19 +++++++++ app/models/user.rb | 4 +- app/views/devise/registrations/edit.html.erb | 39 +++++++++++++------ config/routes.rb | 27 +++++++------ 4 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 app/controllers/users/registrations_controller.rb diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 0000000..7ee8bf6 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 837a9c7..f475e72 100644 --- a/app/models/user.rb +++ b/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 diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index b63826c..8ece3e0 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,5 +1,5 @@

Profil bearbeiten

- +<%= devise_error_messages! %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.label :email, "E-Mail", class: "form-label" %> @@ -35,17 +35,34 @@ -
Wöchentliche Zielstunden (weekly_target_matrix)
- <% ["propädeutikum", "fachspezifikum"].each do |typ| %> - <% ["Praktikum", "Selbsterfahrung", "Supervision"].each do |art| %> -
- <%= 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 %> -
+
Wöchentliche Zielstunden (weekly_target_matrix)
+ + + + + + + + + + + <% User::PRAKTIKUMSTYPEN.product(User::ENTRY_ARTEN).each do |typ, art| %> + + + + + <% end %> - <% end %> + +
TypArtZielstunden / Woche
<%= typ.capitalize %><%= art %> + <%= 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 + ) %> +

diff --git a/config/routes.rb b/config/routes.rb index 3343bb8..2dacea7 100644 --- a/config/routes.rb +++ b/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