aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/searches_controller.rb2
-rw-r--r--app/controllers/shared_searches_controller.rb1
-rw-r--r--app/javascript/controllers/search_controller.js2
-rw-r--r--app/models/search.rb2
-rw-r--r--app/views/searches/_form.html.erb6
-rw-r--r--app/views/shared_searches/show.html.erb71
6 files changed, 53 insertions, 31 deletions
diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb
index 752ccec..376455c 100644
--- a/app/controllers/searches_controller.rb
+++ b/app/controllers/searches_controller.rb
@@ -55,6 +55,6 @@ class SearchesController < ApplicationController
end
def search_params
- params.require(:search).permit(:name, :body, :shared)
+ params.require(:search).permit(:name, :body, :description, :shared)
end
end
diff --git a/app/controllers/shared_searches_controller.rb b/app/controllers/shared_searches_controller.rb
index dd33bc5..ca65539 100644
--- a/app/controllers/shared_searches_controller.rb
+++ b/app/controllers/shared_searches_controller.rb
@@ -10,5 +10,6 @@ class SharedSearchesController < ApplicationController
def show
@search = Search.where(shared: true).find(params[:search_id])
+ @results = @search.results.values.flatten
end
end
diff --git a/app/javascript/controllers/search_controller.js b/app/javascript/controllers/search_controller.js
index b35593a..63df81d 100644
--- a/app/javascript/controllers/search_controller.js
+++ b/app/javascript/controllers/search_controller.js
@@ -30,7 +30,9 @@ export default class extends Controller {
document.getElementById("search-form-submit").classList.toggle("hidden");
document.getElementById("save-search").classList.toggle("hidden");
document.getElementById("search-form-name").classList.toggle("hidden");
+ document.getElementById("search-form-description").classList.toggle("hidden");
document.getElementById("search-form-shared").classList.toggle("hidden");
+ document.getElementById("search-body-label").classList.toggle("hidden");
document.getElementById("search_name").focus();
}
}
diff --git a/app/models/search.rb b/app/models/search.rb
index e1c3a9b..9886f36 100644
--- a/app/models/search.rb
+++ b/app/models/search.rb
@@ -6,6 +6,8 @@ class Search < ApplicationRecord
belongs_to :user
+ has_rich_text :description
+
# Returns all the results that can be fetched with the current `body`. It's
# returned into a hash which groups the taggable types.
def results
diff --git a/app/views/searches/_form.html.erb b/app/views/searches/_form.html.erb
index 15b5735..e3a326f 100644
--- a/app/views/searches/_form.html.erb
+++ b/app/views/searches/_form.html.erb
@@ -8,7 +8,13 @@
<%= form.text_field :name, required: true, autocomplete: 'off', autocapitalize: 'on' %>
</div>
+ <div id="search-form-description" class="hidden">
+ <%= form.label :description %>
+ <%= form.rich_textarea :description %>
+ </div>
+
<div>
+ <%= form.label :body, id: 'search-body-label', class: 'hidden' %>
<%= form.text_field :body, "data-action": "keydown.enter->search#load", "data-search-target": "body", placeholder: 'Search body' %>
<a id="save-search" href="#" data-action="search#save" class="hidden"><%= I18n.t('searches.save') %></a>
</div>
diff --git a/app/views/shared_searches/show.html.erb b/app/views/shared_searches/show.html.erb
index d981cde..ed605bd 100644
--- a/app/views/shared_searches/show.html.erb
+++ b/app/views/shared_searches/show.html.erb
@@ -1,30 +1,41 @@
-<table id="public-search-table">
- <% @search.results.values.flatten.each do |res| %>
- <tr>
- <td>
- <details>
- <% if res.is_a? Thing %>
- <summary><%= res.title %></summary>
- <div class="details-flex">
- <div><span><b><%= I18n.t('activerecord.attributes.thing.authors') %></b>: <%= authors_or_editors(res) %></span></div>
- <div><span><b><%= I18n.t('activerecord.attributes.thing.publisher') %></b>: <%= string_maybe(res.publisher) %></span></div>
- <div><span><b><%= I18n.t('activerecord.attributes.thing.year') %></b>: <%= string_maybe(res.year) %></span></div>
- <div><span><b><%= I18n.t('activerecord.attributes.thing.kind') %></b>: <%= I18n.t("things.kind.#{res.kind}") %></span></div>
- <% if res.note.present? %>
- <div><span><b><%= I18n.t('activerecord.attributes.thing.note') %></b>: <%= res.note %></span></div>
- <% end %>
- <% unless res.url.blank? %>
- <div><span><a href="<%= res.url %>" target="_blank"><%= I18n.t('activerecord.attributes.thing.url') %></a></span></div>
- <% end %>
- </div>
- <% else %>
- <summary><b><%= I18n.t('comments.title') %></b> <%= I18n.t('general.in') %> «<i><%= res.thing.title %></i>»</summary>
- <div class="details-flex">
- <%= res.content %>
- </div>
- <% end %>
- </details>
- </td>
- </tr>
- <% end %>
-</table>
+<% unless @search.description.blank? %>
+ <div>
+ <%= @search.description %>
+ <br />
+ </div>
+<% end %>
+
+<% if @results.empty? %>
+ <p><%= I18n.t('searches.none') %>.</p>
+<% else %>
+ <table id="public-search-table">
+ <% @results.each do |res| %>
+ <tr>
+ <td>
+ <details>
+ <% if res.is_a? Thing %>
+ <summary><%= res.title %></summary>
+ <div class="details-flex">
+ <div><span><b><%= I18n.t('activerecord.attributes.thing.authors') %></b>: <%= authors_or_editors(res) %></span></div>
+ <div><span><b><%= I18n.t('activerecord.attributes.thing.publisher') %></b>: <%= string_maybe(res.publisher) %></span></div>
+ <div><span><b><%= I18n.t('activerecord.attributes.thing.year') %></b>: <%= string_maybe(res.year) %></span></div>
+ <div><span><b><%= I18n.t('activerecord.attributes.thing.kind') %></b>: <%= I18n.t("things.kind.#{res.kind}") %></span></div>
+ <% if res.note.present? %>
+ <div><span><b><%= I18n.t('activerecord.attributes.thing.note') %></b>: <%= res.note %></span></div>
+ <% end %>
+ <% unless res.url.blank? %>
+ <div><span><a href="<%= res.url %>" target="_blank"><%= I18n.t('activerecord.attributes.thing.url') %></a></span></div>
+ <% end %>
+ </div>
+ <% else %>
+ <summary><b><%= I18n.t('comments.title') %></b> <%= I18n.t('general.in') %> «<i><%= res.thing.title %></i>»</summary>
+ <div class="details-flex">
+ <%= res.content %>
+ </div>
+ <% end %>
+ </details>
+ </td>
+ </tr>
+ <% end %>
+ </table>
+<% end %>