From 0eb553770e189ca360da33fc022a3744ba18db48 Mon Sep 17 00:00:00 2001 From: Christoph Marzell Date: Tue, 11 Nov 2025 08:42:42 +0100 Subject: [PATCH] add time from time to with break flag --- app/controllers/calculations_controller.rb | 7 + app/javascript/application.js | 0 app/models/user.rb | 4 + app/views/calculations/new.html.erb | 38 +++++ app/views/devise/passwords/edit.html.erb | 2 +- app/views/devise/registrations/edit.html.erb | 2 +- app/views/entries/_form.html.erb | 138 +++++++++++++++++++ app/views/layouts/application.html.erb | 8 +- 8 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 app/controllers/calculations_controller.rb create mode 100644 app/javascript/application.js create mode 100644 app/views/calculations/new.html.erb diff --git a/app/controllers/calculations_controller.rb b/app/controllers/calculations_controller.rb new file mode 100644 index 0000000..5b4121b --- /dev/null +++ b/app/controllers/calculations_controller.rb @@ -0,0 +1,7 @@ +class CalculationsController < ApplicationController + before_action :authenticate_user! + + def new + @entry = Entry.new + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..e69de29 diff --git a/app/models/user.rb b/app/models/user.rb index bb0ed0a..fbdfd80 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,10 @@ class User < ApplicationRecord after_initialize :set_default, if: :new_record? + def is_admin? + self.email =="christoph@marzell.net" + end + def set_default self.required_hours_matrix = PRAKTIKUMSTYPEN.to_h do |typ| [typ, ENTRY_ARTEN.to_h { |art| [art, default_hours_for(typ, art)] }] diff --git a/app/views/calculations/new.html.erb b/app/views/calculations/new.html.erb new file mode 100644 index 0000000..a288e2d --- /dev/null +++ b/app/views/calculations/new.html.erb @@ -0,0 +1,38 @@ +

Minutenrechner

+ +
+ + + +
+ +
+

Gesamtsumme: 0h 0min (0min)

+
+ +<%= render "entries/form", entry: @entry %> + + diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index 14bd32f..84b7056 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -1,7 +1,7 @@

🔐 Passwort zurücksetzen

- <%= devise_error_messages! %> + <%= render "devise/shared/error_messages", resource: resource %> <%= form_with(scope: resource_name, url: password_path(resource_name), method: :put, local: true) do |f| %> <%= f.hidden_field :reset_password_token, value: params[:reset_password_token] %> diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 76dc956..0432ec5 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,6 +1,6 @@

Profil bearbeiten

-<%= devise_error_messages! %> +<%= render "devise/shared/error_messages", resource: resource %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
diff --git a/app/views/entries/_form.html.erb b/app/views/entries/_form.html.erb index 7ec4310..7134cb1 100644 --- a/app/views/entries/_form.html.erb +++ b/app/views/entries/_form.html.erb @@ -1,3 +1,15 @@ +
+ + + +
+ +
+

Gesamtsumme: 0h 0min (0min)

+
+ + + <%= form_with(model: entry, local: true) do |form| %> <% if entry.errors.any? %>
@@ -10,6 +22,7 @@
<% end %> +
@@ -27,6 +40,21 @@ value: (form.object.date) %>
+ +
+ <%= form.label :start_time, 'Beginn (Uhrzeit)', class: 'form-label' %> + <%= form.time_field :start_time, class: 'form-control', step: 60 %> +
+ +
+ <%= form.label :end_time, 'Ende (Uhrzeit)', class: 'form-label' %> + <%= form.time_field :end_time, class: 'form-control', step: 60 %> +
+ + + + +
<%= form.label :hours, 'Stunden', class: 'form-label' %> <%= form.number_field :hours, @@ -42,6 +70,22 @@ min: 0, max: 59, value: form.object.minutes || 0 %>
+ + +
+
+
+ <%= form.check_box :has_break, { class: 'form-check-input', id: 'entry_has_break' }, true, false %> + <%= form.label :has_break, '30 Min. Mittagspause abziehen', class: 'form-check-label ms-2' %> +
+
+
+ +
+ + +
+

Gesamt: 0 min

@@ -99,3 +143,97 @@ } }); + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 803fce3..46849bc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -93,7 +93,13 @@ <%= link_to "Profil", edit_user_registration_path, class: "nav-link" %> - <% if current_user&.email =="christoph@marzell.net" %> + <% if current_user.is_admin? %> + + <% end %> + + <% if current_user.is_admin? %>