diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 38043a6..e1ee5f6 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb @@ -32,7 +32,7 @@ class EntriesController < ApplicationController @total_kilometer_costs_by_year = Entry.total_kilometer_cost_by_year(current_user) @fortbildungskosten_by_year = Entry.total_fortbildungskosten_by_year(current_user) - @selbstsupervision_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user) + @selbstsupervision_by_year = Entry.total_supervision_by_year(current_user) @selbsterfahrungskosten_by_year = Entry.total_selbsterfahrungskosten_by_year(current_user) @allekosten_by_year = Entry.total_semesterkosten_by_year(current_user) @@ -91,7 +91,11 @@ class EntriesController < ApplicationController end def create - @entry = current_user.entries.build(entry_params) + @entry = current_user.entries.new(entry_params) + if current_user.praepedeutikum_abgeschlossen? && @entry.praktikums_typ == 'propädeutikum' + redirect_to entries_path, alert: "Propädeutikum ist bereits abgeschlossen – Neuer Eintrag dieses Typs ist nicht erlaubt." + return + end if @entry.save redirect_to entries_path, notice: "Eintrag gespeichert" else diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 7ee8bf6..fb7dc80 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,19 +1,20 @@ 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 + 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: [ + :praepedeutikum_done, + required_hours_matrix: {}, + weekly_target_matrix: {} + ]) + end end \ No newline at end of file diff --git a/app/models/entry.rb b/app/models/entry.rb index 128e41d..ef6abb6 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -112,6 +112,7 @@ class Entry < ApplicationRecord end end + def total_minutes_including_break return nil unless start_time && end_time diff --git a/app/models/user.rb b/app/models/user.rb index fbdfd80..ef3e081 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,8 +10,10 @@ class User < ApplicationRecord ENTRY_ARTEN = %w[Praktikum Selbsterfahrung Supervision] after_initialize :set_default, if: :new_record? - + def praepedeutikum_abgeschlossen? + praepedeutikum_done + end def is_admin? self.email =="christoph@marzell.net" end diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 0432ec5..fdf69de 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -85,6 +85,11 @@ <%= f.password_field :current_password, autocomplete: "current-password", class: "form-control" %> +
+ <%= f.check_box :praepedeutikum_done, class: "form-check-input" %> + <%= f.label :praepedeutikum_done, "Propädeutikum abgeschlossen", class: "form-check-label" %> +
+ <%= f.submit "Profil aktualisieren", class: "btn btn-primary" %> <% end %> diff --git a/app/views/entries/_form.html.erb b/app/views/entries/_form.html.erb index 33b70d0..b94d96f 100644 --- a/app/views/entries/_form.html.erb +++ b/app/views/entries/_form.html.erb @@ -92,7 +92,12 @@
<%= form.label :praktikums_typ, 'Praktikumstyp', class: 'form-label' %> - <%= form.select :praktikums_typ, Entry::PRAKTIKUMSTYPEN, {}, class: 'form-select' %> + <%= form.select :praktikums_typ, + current_user.praepedeutikum_abgeschlossen? ? + Entry::PRAKTIKUMSTYPEN.reject { |typ| typ == 'propädeutikum' } : + Entry::PRAKTIKUMSTYPEN, + {}, + class: 'form-select' %>
diff --git a/app/views/entries/index.html.erb b/app/views/entries/index.html.erb index a62238f..a940dac 100644 --- a/app/views/entries/index.html.erb +++ b/app/views/entries/index.html.erb @@ -129,7 +129,13 @@
<%= label_tag :typ, 'Typ' %> - <%= select_tag :typ, options_for_select(Entry::PRAKTIKUMSTYPEN), class: "form-select" %> + <%= select_tag :typ, + options_for_select( + current_user.praepedeutikum_abgeschlossen? ? + Entry::PRAKTIKUMSTYPEN.reject { |typ| typ == 'propädeutikum' } : + Entry::PRAKTIKUMSTYPEN + ), + class: "form-select" %>
diff --git a/db/migrate/20251118075147_add_praepedeutikum_done_to_users.rb b/db/migrate/20251118075147_add_praepedeutikum_done_to_users.rb new file mode 100644 index 0000000..be9e0bb --- /dev/null +++ b/db/migrate/20251118075147_add_praepedeutikum_done_to_users.rb @@ -0,0 +1,5 @@ +class AddPraepedeutikumDoneToUsers < ActiveRecord::Migration[7.1] + def change + add_column :users, :praepedeutikum_done, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8a0c036..a7847db 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2025_11_13_045029) do +ActiveRecord::Schema[7.1].define(version: 2025_11_18_075147) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -48,6 +48,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_11_13_045029) do t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" + t.boolean "praepedeutikum_done", default: false, null: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true