Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add the ability to create a new Strategy or Moment from an individual Category page #2330

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def action_delete(url_helper)
}
end

def category_input_props(field, type, label, group = false)
{ id: "moment_#{field}", type:,
name: "moment[#{field}]#{group ? '[]' : ''}", label: t(label) }
end

def category_form_inputs
[
category_name(@category&.name),
Expand Down Expand Up @@ -100,4 +105,20 @@ def category_visible(visible)
checked: visible
}
end

def quick_create_props(model_relation, form_props)
model_name = model_relation.name.downcase
category_input_props(
model_name, 'quickCreate', "#{model_name.pluralize}.plural", true
).merge(placeholder: t('common.form.search_by_keywords'),
checkboxes: checkboxes_for(model_relation), formProps: form_props)
end

def category_moment
quick_create_props(@moments, quick_create_moment_props)
end

def category_strategy
quick_create_props(@strategies, quick_create_strategy_props)
end
end
6 changes: 6 additions & 0 deletions app/helpers/moments_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ def new_moment_props
new_form_props(moment_form_inputs, moments_path)
end

def quick_create_moment_props
quick_create_form_props(
moment_form_inputs, quick_create_moments_path
)
end

def edit_moment_props
edit_form_props(moment_form_inputs(true), moment_path(@moment))
end
Expand Down
1 change: 1 addition & 0 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<% title t('categories.plural') %>
<% page_new new_category_path %>

<div class="subtitle">
<%= t('categories.index.subtitle') %>
</div>
Expand Down