Skip to content

Commit

Permalink
add delete button (#754)
Browse files Browse the repository at this point in the history
* add delete button

* add test

* update translations

* add button dropdown

* fix test

* add en translations

* just use translated strings in tests

* fix tests

* fix tests
  • Loading branch information
kcinay055679 authored Jul 30, 2024
1 parent 0725de7 commit e15ddf9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/helpers/actions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ActionsHelper
# A generic helper method to create action links.
# These link could be styled to look like buttons, for example.
def action_link(label, icon = nil, url = {}, html_options = {})
add_css_class html_options, 'action btn btn-light'
add_css_class html_options, 'action btn btn-link d-flex align-items-center gap-2'
link_to(icon ? action_icon(icon, label) : label,
url, html_options)
end
Expand Down Expand Up @@ -39,7 +39,7 @@ def edit_action_link(path = nil)
def destroy_action_link(path = nil)
path ||= path_args(entry)
action_link(ti('link.delete'), 'remove', path,
data: { confirm: ti(:confirm_delete),
data: { turbo_confirm: ti(:confirm_delete),
method: :delete, 'turbo-method': :delete })
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def last_updated_at
[associations_updatet_at, updated_at].compact.max
end

def to_s
name
end

private

def picture_size
Expand Down
8 changes: 7 additions & 1 deletion app/views/layouts/person.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
=render partial:"people/search", :locals => {person: @person}
%div{"data-controller": "profile-tab highlight"}
= render "application/tabbar", tabs: person_tabs(@person) do
=link_to image_tag("export.svg")+ "Export", export_cv_person_path(@person), class: "btn text-primary", data: { turbo_frame: "remote_modal" }
%div.dropdown
= button_tag ti(:more_actions), class: "btn dropdown-toggle", data: { "bs-toggle": "dropdown" }
%ul.dropdown-menu
%li
= link_to image_tag("export.svg")+ "Export", export_cv_person_path(@person), class: "btn text-primary", data: { turbo_frame: "remote_modal" }
%li.text-nowrap
= destroy_action_link
%turbo-frame#tab-content.d-flex.gap-3{"data-controller": "scroll"}
= yield
= render template: "layouts/application"
8 changes: 7 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ de:
competence_notes: Kompetenzen
roles: Funktionen
department: Organisationseinheit
skills: Skills
skills: Skills
people:
show:
confirm_delete: Willst du diese Person wirklich löschen?
more_actions: Weitere Aktionen
link:
delete: Person löschen
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ en:
from: From
to: To
today: Today
people:
show:
confirm_delete: Are you sure you want to delete this person?
more_actions: More actions
link:
delete: Delete person
2 changes: 1 addition & 1 deletion spec/features/cv_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it 'should display 2 export buttons' do
visit person_path(people(:bob))

expect(page.all('a', text: 'Export').count).to eql(2)
expect(page.all('a', text: 'Export').count).to eql(1)
end

it 'should display range after switch was clicked' do
Expand Down
9 changes: 9 additions & 0 deletions spec/features/people_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,14 @@ def add_language(language)
visit person_path(longmax)
expect(page).to have_selector('p.alert.alert-info.d-flex.justify-content-between', text: I18n.t('profile.no_skills_rated_msg'))
end

it 'should delete person' do
visit person_path(longmax)
click_button(I18n.t("people.show.more_actions"))
accept_confirm do
click_link(I18n.t("people.show.link.delete"), href: person_path(longmax))
end
expect(page).to have_selector('.alert', text: I18n.t("crud.destroy.flash.success", model: longmax))
end
end
end
4 changes: 4 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
self.class.fixtures :all
end

config.before(:each, js: true) do
Capybara.page.current_window.resize_to(1920, 1080)
end

if Bullet.enable?
config.before(:each) do
Bullet.start_request
Expand Down
1 change: 1 addition & 0 deletions spec/support/people_skills_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def validate_interest(interest)
star_labels.each_with_index do |label, index|
body = page.document.find('body')
body.send_keys(:tab)
body.hover
if index < interest
expect(label).to match_style(color: 'rgb(255, 199, 0)').or(match_style(color: 'rgba(255, 199, 0, 1)'))
else
Expand Down

0 comments on commit e15ddf9

Please sign in to comment.