diff --git a/app/assets/stylesheets/dashboard/dashboard_section.scss b/app/assets/stylesheets/dashboard/dashboard_section.scss index 1816ad1d9..e9d3c9aae 100644 --- a/app/assets/stylesheets/dashboard/dashboard_section.scss +++ b/app/assets/stylesheets/dashboard/dashboard_section.scss @@ -46,6 +46,11 @@ margin: $size-10 $size-0 $size-0 $size-0; padding-left: $size-0; width: 100%; + + display: flex; + flex-direction: column; + align-items: center; + gap: $size-10; } } } diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index f6f9174e1..c1ba90cf8 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -28,6 +28,10 @@ def index def show setup_stories redirect_to_path(categories_path) if @category.user_id != current_user.id + @page_new_buttons = [ + { text: t('moments.new'), path: new_moment_path(category: @category.slug) }, + { text: t('strategies.new'), path: new_strategy_path(category: @category.slug) } + ] end # GET /categories/new diff --git a/app/helpers/moments_form_helper.rb b/app/helpers/moments_form_helper.rb index 782599704..4bc0d6e61 100644 --- a/app/helpers/moments_form_helper.rb +++ b/app/helpers/moments_form_helper.rb @@ -122,7 +122,12 @@ def checkboxes_for(data) def data_for(item) case item.class.name when 'Category' - @moment.categories.pluck(:id) + ids = @moment.categories.pluck(:id) + if params[:category].present? && ids.empty? + category = Category.friendly.find_by(slug: params[:category]) + ids << category.id if category + end + ids when 'Mood' @moment.moods.pluck(:id) when 'Strategy' diff --git a/app/helpers/strategies_form_helper.rb b/app/helpers/strategies_form_helper.rb index 29ee14201..03afa56ae 100644 --- a/app/helpers/strategies_form_helper.rb +++ b/app/helpers/strategies_form_helper.rb @@ -106,11 +106,17 @@ def build_switch_input(value, checked, unchecked_value) def category_checkboxes checkboxes = [] @categories.each do |item| + checked = @strategy.categories.include?(item) + + if params[:category].present? && @strategy.new_record? && !checked + checked = item.slug == params[:category] + end + checkboxes.push( id: item.slug, label: item.name, value: item.id, - checked: @strategy.categories.include?(item) + checked: checked ) end checkboxes diff --git a/app/views/shared/_page_title.html.erb b/app/views/shared/_page_title.html.erb index 4b93dd364..4bdfc4bb1 100644 --- a/app/views/shared/_page_title.html.erb +++ b/app/views/shared/_page_title.html.erb @@ -23,6 +23,15 @@
<%= link_to @page_new, yield(:page_new), class: 'buttonM' %>
+ <% elsif @page_new_buttons.present? %> +
+ <%= yield(:title) %> +
+
+ <% @page_new_buttons.each_with_index do |button, index| %> + <%= link_to button[:text], button[:path], class: "buttonM" %> + <% end %> +
<% elsif @page_author.present? %>
<%= yield(:title) %>