From 71d38f6b2b95545aca04a30a4695f05be99fed74 Mon Sep 17 00:00:00 2001 From: CoralineAda Date: Mon, 21 Oct 2024 17:20:46 -0500 Subject: [PATCH] Ability to delete a theme. --- app/assets/stylesheets/styles.css | 3 ++- app/controllers/themes_controller.rb | 14 ++++++++++++-- app/views/shared/_header.html.erb | 6 +++--- app/views/themes/index.html.erb | 10 +++------- app/views/themes/new.html.erb | 19 +++++++++++++++++++ app/views/themes/show.html.erb | 10 +++++++--- 6 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 app/views/themes/new.html.erb diff --git a/app/assets/stylesheets/styles.css b/app/assets/stylesheets/styles.css index 5909d29..7cc3f72 100644 --- a/app/assets/stylesheets/styles.css +++ b/app/assets/stylesheets/styles.css @@ -805,7 +805,7 @@ input[type="email"] { } .tag.active { - background-color: var(--color-green); + background-color: var(--color-medium-black); border: 3px solid var(--color-medium-black); } @@ -835,6 +835,7 @@ input[type="email"] { float: left; min-width: 2rem; margin: 0 1rem 1rem 0; + border: 3px solid var(--color-red); float: right; } diff --git a/app/controllers/themes_controller.rb b/app/controllers/themes_controller.rb index 10bfda0..5b19753 100644 --- a/app/controllers/themes_controller.rb +++ b/app/controllers/themes_controller.rb @@ -4,6 +4,10 @@ def index @themes = Theme.all.order(&:name) end + def new + @theme = Theme.new + end + def show @contexts = Theme::CONTEXTS @theme = Theme.find(params[:id]) @@ -16,16 +20,22 @@ def create redirect_to @theme end + def destroy + @theme = Theme.find(params[:id]) + @theme.destroy + redirect_to themes_path + end + def update @theme = Theme.find(params[:id]) - new_category_ids = theme_params[:categories].split(/[\,\s]/) + new_category_ids = theme_params[:categories].split(/[\,\s]/) update_kind = @theme.categories.length == new_category_ids.length ? "metadata" : "category" if theme_params[:categories] categories = Category.where(id: new_category_ids) @theme.categories = categories end - + @theme.name = theme_params[:name] @theme.description = theme_params[:description] @theme.notes = theme_params[:notes] diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 723370a..8b64a83 100644 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -2,11 +2,11 @@ diff --git a/app/views/themes/index.html.erb b/app/views/themes/index.html.erb index 8b6013d..58a28d4 100644 --- a/app/views/themes/index.html.erb +++ b/app/views/themes/index.html.erb @@ -1,18 +1,14 @@ <%- title "Themes" %>

Explore Themes.

- -

Themes

<% @themes.each do |theme| %> <%= link_to theme_path(theme.id) do %> <% end %> <% end %> + <%= link_to new_theme_path do %> +
New Theme
+ <% end %>
-

Create a New Theme

-<%= form_with model: Theme.new, data: { turbo_frame: "tag-collection" } do |f| %> - <%= f.text_field :name %> - <%= f.submit "Add Theme" %> -<% end %> diff --git a/app/views/themes/new.html.erb b/app/views/themes/new.html.erb new file mode 100644 index 0000000..078f003 --- /dev/null +++ b/app/views/themes/new.html.erb @@ -0,0 +1,19 @@ +<%- title "New Theme" %> + +

Add a Theme

+ +<%= form_with model: @theme do |f| %> +
+ <%= label :name, "Name" %> + <%= f.text_field :name %> +
+
+ <%= label :description, "Description" %> + <%= f.text_area :description %> +
+
+ <%= label :notes, "Notes" %> + <%= f.text_area :notes %> +
+ <%= f.submit "Create" %> +<% end %> diff --git a/app/views/themes/show.html.erb b/app/views/themes/show.html.erb index d503597..12e980a 100644 --- a/app/views/themes/show.html.erb +++ b/app/views/themes/show.html.erb @@ -1,14 +1,16 @@ <%- title "Themes" %> -

<%= @theme.name %>

+

Theme: "<%= @theme.name %>"

<%= render partial: "form", locals: { theme: @theme, success: nil, update_kind: nil } %> +

Categories

+

Categories related to this theme are are highlighted in black below. Click to add or remove a category from this theme. Changes are saved automatically.

+ <% @contexts.each do |context| %> <% contextual_categories = @categories.select{ |c| c.context == context[0] } %> <% if contextual_categories.any? %> -

<%= context[1] %> Categories

-

Associated categories are highlighted in black. Click to add or remove a category from this theme. Changes are saved automatically.

+

<%= context[1] %>

<% contextual_categories.sort_by(&:name).each do |category| %> <% is_selected = @theme.categories.include? category %> @@ -22,6 +24,8 @@ <% end %> <% end %> +<%= button_to "Delete This Theme", theme_path(@theme), form: { data: { turbo_confirm: "Are you sure?" } }, method: :delete %> + <%= render partial: "/shared/filtering" %>