-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize date range entities (#647)
* squash all commits * merge and bugfix * clean up * readd save and new functionality * refeactor * refactor new and index and fix failing tests * refactor * refactor routes.rb * Use convention over configuration * implement feedback --------- Co-authored-by: Yanick Minder <[email protected]>
- Loading branch information
1 parent
8a01cff
commit 40b4ea3
Showing
32 changed files
with
1,807 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdvancedTrainingsController < PersonRelationsController | ||
class AdvancedTrainingsController < People::PersonRelationsController | ||
self.permitted_attrs = %i[description year_to month_to year_from month_from person_id] | ||
self.nesting = Person | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class People::PersonRelationsController < CrudController | ||
|
||
def index | ||
redirect_to person_path(entry.person) | ||
end | ||
|
||
def show | ||
redirect_to person_path(entry.person) | ||
end | ||
|
||
def create | ||
super do |format, success| | ||
if success && params.key?(:render_new_after_save) | ||
remove_instance_variable(model_ivar_name) | ||
format.turbo_stream { render('save_and_new') } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
super(location: person_path(entry.person)) | ||
end | ||
|
||
def destroy | ||
super do |format, success| | ||
format.turbo_stream { render turbo_stream: turbo_stream.remove(entry) } if success | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ def months_with_nil | |
def last_100_years | ||
(100.years.ago.year..Time.zone.today.year).to_a.reverse | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module GenerifyHelper | ||
def name_of_obj(obj) | ||
obj.model_name.element | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,5 @@ | ||
= form_with model: ([advanced_training.person, advanced_training]) do |f| | ||
= f.hidden_field :person_id | ||
%div.d-flex.row.py-3.ps-5 | ||
%span.col-3 | ||
= render partial: 'application/daterange_picker', locals: { form: f, end_date: f.object.till_today? } | ||
%span.col-5.d-flex.flex-column | ||
= form_with model: ([entry.person, entry]) do |f| | ||
= render('people/person_relations/form', form: f) do | ||
- content_for :input do | ||
= t "activerecord.attributes.advanced_training.description" | ||
= f.text_area :description, placeholder: "Description", class: "form-control w-100" | ||
%div.col-3.d-flex.flex-column | ||
= f.button(name: :"save", class:"btn btn-primary", data: { turbo_frame: "advanced_trainings_all"}) | ||
- if advanced_training.persisted? | ||
= link_to t("helpers.submit.delete"), person_advanced_training_path(advanced_training.person, advanced_training), data: { turbo_method: :delete, turbo_frame: ["#{dom_id advanced_training}"]}, class: "btn btn-link" | ||
- else | ||
= f.button(t("helpers.submit.save-and-new"), name: :"render_new_after_save", class:"btn btn-link", data: { turbo_frame: "advanced_trainings_all"}) | ||
= link_to t("helpers.submit.cancel"), person_path(advanced_training.person), data: { turbo_frame: "#{dom_id advanced_training}"}, method: :get, class: "btn btn-link" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app/views/advanced_trainings/new_after_save.turbo_stream.haml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
= render('profile') | ||
= render('core_competences') | ||
= render('advanced_trainings') | ||
= render('people/person_relations/index', list: @person.advanced_trainings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
= yield | ||
= form.hidden_field :person_id | ||
%div.d-flex.row.py-3.ps-5 | ||
%span.col-3 | ||
= render partial: 'application/daterange_picker', locals: { form: form, end_date: form.object.till_today? } | ||
%span.col-5.d-flex.flex-column | ||
= yield :input | ||
%div.col-3.d-flex.flex-column | ||
= form.button(name: :"save", class:"btn btn-primary") | ||
- if entry.persisted? | ||
= link_to t("helpers.submit.delete"),polymorphic_path([entry.person, entry]), data: { turbo_method: :delete, turbo_frame: dom_id(entry)}, class: "btn btn-link" | ||
- else | ||
= form.button(t("helpers.submit.save-and-new"), name: :"render_new_after_save", class:"btn btn-link", data: { turbo_frame: dom_id(entry.class.new)}) | ||
= link_to t("helpers.submit.cancel"), polymorphic_path(entry.person), data: { turbo_frame: dom_id(entry.persisted? ? entry : entry.class.new)}, method: :get, class: "btn btn-link" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%div.border.border-secondary-subtle.border-1.d-flex.flex-column | ||
%div.profile-header.mw-100.border-bottom | ||
= "#{t "activerecord.models.#{name_of_obj(list)}"} (#{list.count})" | ||
%div.d-flex.flex-column.ms-5.mt-3.mb-3 | ||
= link_to "#{t "activerecord.models.#{name_of_obj(list)}"} hinzufügen", new_polymorphic_path([entry, name_of_obj(list).to_sym]), data: { turbo_frame: dom_id(list.model.new)}, method: :get | ||
%div.border.rounded.border | ||
%turbo-frame{id: dom_id(list.model.new)} | ||
%turbo-frame{id: name_of_obj(list)} | ||
= render list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%turbo-frame{id: dom_id(entry) } | ||
= render partial: "form" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= turbo_stream.update dom_id(entry) do | ||
= render "application/error_banners", errors: entry.errors | ||
= render "form", attribute: entry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%turbo-frame{id: dom_id(entry.class.new)} | ||
= render partial: "form" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= turbo_stream.update dom_id(entry.class.new) do | ||
= render "application/error_banners", errors: entry.errors | ||
= render partial: "form", locals: {attribute: entry} |
6 changes: 6 additions & 0 deletions
6
app/views/people/person_relations/save_and_new.turbo_stream.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
= turbo_stream.update name_of_obj(entry) do | ||
= render entries | ||
|
||
= turbo_stream.update dom_id(entry.class.new) do | ||
= render partial: "form" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.