From c0befbd02559591b0c2871ea9cef1e4d913b9ef6 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 11 Nov 2024 22:45:05 +0100 Subject: Allow searching from a given tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This feature is useful if you want to have a quick search on how many resources apply for a single tag. Signed-off-by: Miquel Sabaté Solà --- app/assets/stylesheets/tags.css | 15 ++++++++++++--- app/controllers/tags_controller.rb | 10 ++++++++-- app/views/searches/show.html.erb | 2 +- app/views/tags/_tag.html.erb | 4 ++-- 4 files changed, 23 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/tags.css b/app/assets/stylesheets/tags.css index bcf74cf..6d7e725 100644 --- a/app/assets/stylesheets/tags.css +++ b/app/assets/stylesheets/tags.css @@ -16,10 +16,19 @@ .tag-container { display: flex; align-items: flex-start; -} -.tag-container .name { - flex-grow: 1; + .name { + flex-grow: 1; + } + + .name a { + text-decoration: none; + color: var(--text) !important; + } + + .name a:hover { + text-decoration: underline; + } } .tag-container .action { diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ee837ef..c5ca6a8 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class TagsController < ApplicationController - before_action :set_tag, only: %i[edit update destroy] + before_action :set_tag, only: %i[edit update destroy search] def index @tags = Tag.order(:name) @@ -57,10 +57,16 @@ class TagsController < ApplicationController redirect_to tags_url, notice: t('tags.destroy-success') end + def search + @search = Search.new(name: 'temporary', body: "tag:\"#{@tag.name}\"") + + render 'searches/show' + end + private def set_tag - @tag = Tag.find(params[:id]) + @tag = Tag.find(params[:id] || params[:tag_id]) end def tag_params diff --git a/app/views/searches/show.html.erb b/app/views/searches/show.html.erb index b7d3854..16e5996 100644 --- a/app/views/searches/show.html.erb +++ b/app/views/searches/show.html.erb @@ -1 +1 @@ -<%= render "search", items: @search.results %> +<%= render "searches/search", items: @search.results %> diff --git a/app/views/tags/_tag.html.erb b/app/views/tags/_tag.html.erb index 0a82898..9fe2669 100644 --- a/app/views/tags/_tag.html.erb +++ b/app/views/tags/_tag.html.erb @@ -1,9 +1,9 @@
- <%= tag.name %> + <%= link_to tag.name, edit_tag_path(tag), title: I18n.t('general.edit').capitalize %>
- <%= link_to I18n.t('general.edit'), edit_tag_path(tag) %> | + <%= link_to I18n.t('searches.object'), tag_search_path(tag) %> | <%= link_to I18n.t('general.delete'), tag_path(tag), data: { "turbo-method": :delete } %>
-- cgit v1.2.3