Skip to content

Commit

Permalink
extract prevent delete category parent to a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Nov 29, 2024
1 parent d495329 commit ad9d8b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,13 @@ def categories_select(id: nil, name: nil, selected: 'None')
render Input::SelectComponent.new(id: id, name: name, value: categories_for_select, selected: selected, multiple: true)
end

def is_parent?(parents_list, category)
is_parent = parents_list.keys.include?(category.id)
parent_error_message = t('admin.categories.category_used_parent')
parents_list[category.id].each do |c|
parent_error_message = "#{parent_error_message} #{c}"
end
[is_parent,parent_error_message]
end

end
7 changes: 2 additions & 5 deletions app/views/admin/categories/_category.html.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
%tr.human{:id => category.id.split('/').last}
- count = category.ontologies&.size || 0
- is_parent = @parents_list.keys.include?(category.id)
- parent_error_message = t('admin.categories.category_used_parent')
- @parents_list[category.id].each do |c|
- parent_error_message = "#{parent_error_message} #{c}"
- count = category.ontologies&.size || 0
- is_parent, parent_error_message = is_parent?(@parents_list, category)
%td
%div{style: 'width: 250px'}
%div.text-truncate{title: category.name}
Expand Down

0 comments on commit ad9d8b1

Please sign in to comment.