From 5daf9cd834985b8420c9593ce6507bc4c8392f00 Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Fri, 22 Nov 2024 13:37:32 +0100
Subject: [PATCH 1/6] add buttons with redirect + URL query string
---
app/controllers/categories_controller.rb | 4 ++++
app/views/shared/_page_title.html.erb | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index f6f9174e11..c1ba90cf88 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/views/shared/_page_title.html.erb b/app/views/shared/_page_title.html.erb
index 4b93dd3647..c586b4b6a2 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 #{index > 0 ? 'marginLeft' : ''}" %>
+ <% end %>
+
<% elsif @page_author.present? %>
<%= yield(:title) %>
From a079f69e23e51c2eb8d78a11f520805903230826 Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Sat, 23 Nov 2024 13:21:46 +0100
Subject: [PATCH 2/6] add tagging category from URL in form
---
app/helpers/moments_form_helper.rb | 7 ++++++-
app/helpers/strategies_form_helper.rb | 8 +++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/helpers/moments_form_helper.rb b/app/helpers/moments_form_helper.rb
index 782599704b..4bc0d6e614 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 29ee14201f..03afa56ae6 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
From bc1ae8d52ad3a93b558f5f177f27cc44d175d86f Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Sat, 23 Nov 2024 13:55:23 +0100
Subject: [PATCH 3/6] fix responsivity + styling
---
app/assets/stylesheets/dashboard/dashboard_section.scss | 5 +++++
app/views/shared/_page_title.html.erb | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/assets/stylesheets/dashboard/dashboard_section.scss b/app/assets/stylesheets/dashboard/dashboard_section.scss
index 1816ad1d98..e9d3c9aae1 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/views/shared/_page_title.html.erb b/app/views/shared/_page_title.html.erb
index c586b4b6a2..4bdfc4bb1a 100644
--- a/app/views/shared/_page_title.html.erb
+++ b/app/views/shared/_page_title.html.erb
@@ -29,7 +29,7 @@
<% @page_new_buttons.each_with_index do |button, index| %>
- <%= link_to button[:text], button[:path], class: "buttonM #{index > 0 ? 'marginLeft' : ''}" %>
+ <%= link_to button[:text], button[:path], class: "buttonM" %>
<% end %>
<% elsif @page_author.present? %>
From 78792fb303920625dbc664434e9d4a2ec74bb817 Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Fri, 22 Nov 2024 13:37:32 +0100
Subject: [PATCH 4/6] add buttons with redirect + URL query string
---
app/controllers/categories_controller.rb | 4 ++++
app/views/shared/_page_title.html.erb | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index f6f9174e11..c1ba90cf88 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/views/shared/_page_title.html.erb b/app/views/shared/_page_title.html.erb
index 4b93dd3647..c586b4b6a2 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 #{index > 0 ? 'marginLeft' : ''}" %>
+ <% end %>
+
<% elsif @page_author.present? %>
<%= yield(:title) %>
From f6f3f787bacb51ef6a92142ae77982879732dafa Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Sat, 23 Nov 2024 13:21:46 +0100
Subject: [PATCH 5/6] add tagging category from URL in form
---
app/helpers/moments_form_helper.rb | 7 ++++++-
app/helpers/strategies_form_helper.rb | 8 +++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/helpers/moments_form_helper.rb b/app/helpers/moments_form_helper.rb
index 782599704b..4bc0d6e614 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 29ee14201f..03afa56ae6 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
From 9b32a52e0b574b4f0b804870f133fa4ff8e38d2e Mon Sep 17 00:00:00 2001
From: Lucas Kay <71830418+LucasKay64@users.noreply.github.com>
Date: Sat, 23 Nov 2024 13:55:23 +0100
Subject: [PATCH 6/6] fix responsivity + styling
---
app/assets/stylesheets/dashboard/dashboard_section.scss | 5 +++++
app/views/shared/_page_title.html.erb | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/assets/stylesheets/dashboard/dashboard_section.scss b/app/assets/stylesheets/dashboard/dashboard_section.scss
index 1816ad1d98..e9d3c9aae1 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/views/shared/_page_title.html.erb b/app/views/shared/_page_title.html.erb
index c586b4b6a2..4bdfc4bb1a 100644
--- a/app/views/shared/_page_title.html.erb
+++ b/app/views/shared/_page_title.html.erb
@@ -29,7 +29,7 @@
<% @page_new_buttons.each_with_index do |button, index| %>
- <%= link_to button[:text], button[:path], class: "buttonM #{index > 0 ? 'marginLeft' : ''}" %>
+ <%= link_to button[:text], button[:path], class: "buttonM" %>
<% end %>
<% elsif @page_author.present? %>