-
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.
Feature/617 daterange picker and advances trainings (#626)
* User is able to see all stations and to modify them * Add bootstrap classes and improve styling * Use stimulus to hide to fields on butotn clikc * enable visiblity change by using rails only * clean up * allow datepicker to send empty values * add vogu * set attr to nil if not in params * selects has the ability to set value null in db and gets displayed properly * rework nilify * display all advanced trainings and suse edit * records can be updated and errors are shown * use global error partial * style advanced tranings * Render new form on button click * use haml instead of erb for turbostream * replace erb files with haml * commit * Try to implement create * fix error with create * add create funtionnality * show all input field per default and display correct lablel for button * clean up daterange picker * fix sort * add translations * rename visibility controller to date-range_controller * Ahhhhhh finally working \n add button to set same date * refactor date_picker_controller * add cancel button * merge * refactor * add styling * redirect to person for specific advanced_training_features * optimize tubostream requests * clean up * styling * change erb to haml * clean up * add controller tests for AdvancedTrainings * finally chli mental sanity * error tests * fixx tests * fixx all failing tests * merge * try to do magic * fix tets * Clean up styles.scss * Clean up mess * Clean up gemfile * clean up * Resolve errors in tests * Clean up * add collection rendering * use collection renderubg * clean up translations * use correct translations * Resolve erros in advanced_trainings_spec * Clean up * clean up * refactor * Refactor * add save and new functionality * Refactor and add tests * Don't use legacy hash syntax * Implement feedback and update tests * rename new_after_save var * beautify till_today --------- Co-authored-by: Yanick Minder <[email protected]>
- Loading branch information
1 parent
4e14977
commit be93be7
Showing
45 changed files
with
514 additions
and
70 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
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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class AdvancedTrainingsController < PersonRelationsController | ||
self.permitted_attrs = %i[description year_to month_to year_from month_from person_id] | ||
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
class PersonRelationsController < CrudController | ||
def index | ||
redirect_to person_path(person_id) | ||
end | ||
|
||
def show | ||
redirect_to person_path(person_id) | ||
end | ||
|
||
def new | ||
params[model_identifier] = { person_id: person_id } | ||
super | ||
end | ||
|
||
def create | ||
super(location: person_path(person_id)) do |format, success| | ||
if success && params.key?(:render_new_after_save) | ||
format.turbo_stream { render 'new_after_save' } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
super(location: person_path(person_id)) | ||
end | ||
|
||
def destroy | ||
super(location: person_path(person_id)) do |format, success| | ||
format.turbo_stream { render turbo_stream: turbo_stream.remove(entry) } if success | ||
end | ||
end | ||
|
||
def person_id | ||
params[:person_id] || model_params[:person_id] | ||
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module DateHelper | ||
def date_range_label(model_with_dates) | ||
now = "#{months[model_with_dates.month_from || 0]} #{model_with_dates.year_from} " | ||
now + date_range_end_label(model_with_dates) | ||
end | ||
|
||
def months | ||
t('date.month_names') | ||
end | ||
|
||
def date_range_end_label(model_with_dates) | ||
if model_with_dates&.till_today? | ||
return "- #{t('date_range_picker.today')}" | ||
elsif !(model_with_dates.same_year? && model_with_dates.same_month?) | ||
return "- #{months[model_with_dates&.month_to || 0]} #{model_with_dates&.year_to}" | ||
end | ||
|
||
'' | ||
end | ||
|
||
def months_with_nil | ||
months.compact.each_with_index.map { |month, index| [month, index + 1] } | ||
end | ||
|
||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module SelectHelper | ||
def select_when_availabale(obj) | ||
selected = obj ? obj.id : '' | ||
prompt = obj ? false : true | ||
{ selected: selected, prompt: prompt, disabled: '' } | ||
end | ||
|
||
def add_default_option(collection, option = {}) | ||
collection.unshift([option[:text], option[:value], option]) | ||
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,16 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="date-picker" | ||
export default class extends Controller { | ||
|
||
static targets = [ "hideable" ] | ||
|
||
toggleTargets() { | ||
this.hideableTargets.forEach((el) => { | ||
el.hidden = !el.hidden; | ||
el.querySelectorAll('select').forEach((select) => { | ||
select.value = ""; | ||
}); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -44,4 +44,4 @@ export default class extends Controller { | |
fieldParent.style.display = "none"; | ||
} | ||
} | ||
} | ||
} |
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
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,8 @@ | ||
%div.border-top | ||
%turbo-frame{id: "#{dom_id advanced_training}"} | ||
= link_to edit_person_advanced_training_path(advanced_training.person, advanced_training), data:{turbo_prefetch: :false}, class: "text-decoration-none text-dark bg-hover-gray d-block" do | ||
%div.d-flex.row.pt-3.pb-5 | ||
%span.col-3.ps-5 | ||
= date_range_label advanced_training | ||
%span.col | ||
= advanced_training.description |
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,15 @@ | ||
= 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 | ||
= 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 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,5 @@ | ||
%turbo-frame{id: "advanced_trainings_all"} | ||
%div.border.rounded.border | ||
%turbo-frame{id: "#{dom_id AdvancedTraining.new}"} | ||
= render person.advanced_trainings.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,4 @@ | ||
%div | ||
%h1.font-bold.text-2xl.mb-3 Edit Advanced Training | ||
%turbo-frame{id: "#{dom_id @advanced_training}"} | ||
= render partial: "form", locals: {advanced_training: @advanced_training} |
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 @advanced_training}" do | ||
= render "application/error_banners", errors: @advanced_training.errors | ||
= render "form", advanced_training: @advanced_training |
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 AdvancedTraining.new}"} | ||
= render partial: "form", locals: {advanced_training: @advanced_training} |
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 AdvancedTraining.new}" do | ||
= render "application/error_banners", errors: @advanced_training.errors | ||
= render partial: "form", locals: {advanced_training: @advanced_training} |
6 changes: 6 additions & 0 deletions
6
app/views/advanced_trainings/new_after_save.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.replace "advanced_trainings_all" do | ||
= render partial: "index", locals: {person: @advanced_training.person} | ||
|
||
= turbo_stream.replace "#{dom_id AdvancedTraining.new}" do | ||
= render partial: "form", locals: {advanced_training: @advanced_training.person.advanced_trainings.new} | ||
|
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,37 @@ | ||
%div.d-flex.flex-column{"data-controller": "date-picker"} | ||
%div.d-flex.row.justify-content-end | ||
%span.col-5 | ||
%span.ps-3 | ||
= t("datetime.prompts.month") | ||
%span.col-5 | ||
%span.ps-3 | ||
= t("datetime.prompts.year") | ||
%span.col-10 | ||
%hr.my-1 | ||
%div.d-flex.row.align-items-center | ||
%span.fw-bold.col-2 | ||
= "#{t('date_range_picker.from')}:" | ||
%span.col-5 | ||
= form.select :month_from, add_default_option(months_with_nil, { text: '-' }), {}, class: "form-select" | ||
%span.col-5 | ||
= form.select :year_from, add_default_option(last_100_years, { hidden: true }),{}, class: "form-select" | ||
%div{"data-date-picker-target": "hideable", hidden: end_date, id: "end_date_picker"} | ||
%div.d-flex.row.align-items-center | ||
%span.fw-bold.col-2 | ||
= "#{t('date_range_picker.to')}:" | ||
%span.col-5 | ||
= form.select :month_to, add_default_option(months_with_nil, { text: '-' }), {}, class: "form-select" | ||
%span.col-5 | ||
= form.select :year_to, add_default_option(last_100_years, { hidden: true }), {}, class: "form-select" | ||
%div{"data-date-picker-target": "hideable", hidden: !end_date} | ||
%div.d-flex.justify-content-end | ||
%span.d-flex.justify-content-center.fw-bold.py-2.col-10 | ||
= t("date_range_picker.till_today") | ||
%div.d-flex.row.justify-content-end | ||
%span.col-10 | ||
%button{"data-action": "date-picker#toggleTargets", class: "btn btn-primary w-100", type: "button"} | ||
%span{"data-date-picker-target": "hideable", hidden: end_date} | ||
= t("date_range_picker.till_today") | ||
%span{"data-date-picker-target": "hideable", hidden: !end_date} | ||
= t("date_range_picker.with_enddate") |
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,5 @@ | ||
- if errors.any? | ||
.alert.alert-danger | ||
%ul.mb-0 | ||
- errors.full_messages.each do |error| | ||
%li= error |
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 @@ | ||
%div.border.border-secondary-subtle.border-1.d-flex.flex-column | ||
%div.profile-header.mw-100.border-bottom | ||
= "#{t "activerecord.models.advanced_training"} (#{@person.advanced_trainings.count})" | ||
%div.d-flex.flex-column.ms-5.mt-3.mb-3 | ||
= link_to "#{t "activerecord.models.advanced_training"} hinzufügen", new_person_advanced_training_path(@person), data: { turbo_frame: "#{dom_id AdvancedTraining.new}"}, method: :get | ||
= render partial: 'advanced_trainings/index', locals: { person: @person } | ||
|
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,3 +1,3 @@ | ||
= form_with do |f| | ||
%section{"data-controller"=>"dropdown"} | ||
= f.collection_select :person_id, Person.all.sort_by(&:name), :id, :name, generate_select_options_with_default(person) , {class: "form-select w-100", "data-action": "change->dropdown#handleChange", "data-value": "/people/"} | ||
= f.collection_select :person_id, Person.all.sort_by(&:name), :id, :name, select_when_availabale(person) , {class: "form-select w-100", "data-action": "change->dropdown#handleChange", "data-value": "/people/"} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= turbo_stream.update "#{dom_id @person}" do | ||
= render "form", person: @person | ||
= render "application/error_banners", errors: @person.errors |
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,4 @@ | ||
= render('profile') | ||
= render('core_competences') | ||
= render('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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.