/favorite_groups: add search, creators, timestamps, edit/delete links.
This commit is contained in:
@@ -47,9 +47,9 @@ class FavoriteGroupsController < ApplicationController
|
||||
def destroy
|
||||
@favorite_group = FavoriteGroup.find(params[:id])
|
||||
check_write_privilege(@favorite_group)
|
||||
@favorite_group.destroy
|
||||
flash[:notice] = "Favorite group deleted"
|
||||
redirect_to favorite_groups_path
|
||||
@favorite_group.destroy!
|
||||
flash[:notice] = "Favorite group deleted" if request.format.html?
|
||||
respond_with(@favorite_group, location: favorite_groups_path(search: { creator_name: CurrentUser.name }))
|
||||
end
|
||||
|
||||
def add_post
|
||||
|
||||
@@ -25,10 +25,6 @@ class FavoriteGroup < ApplicationRecord
|
||||
where(is_public: true).or(where(creator_id: user.id))
|
||||
end
|
||||
|
||||
def default_order
|
||||
order(name: :asc)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
q = q.visible(CurrentUser.user)
|
||||
@@ -38,6 +34,17 @@ class FavoriteGroup < ApplicationRecord
|
||||
q = q.name_matches(params[:name_matches])
|
||||
end
|
||||
|
||||
case params[:order]
|
||||
when "name"
|
||||
q = q.order(name: :asc, id: :desc)
|
||||
when "created_at"
|
||||
q = q.order(id: :desc)
|
||||
when "post_count"
|
||||
q = q.order(Arel.sql("cardinality(post_ids) desc")).order(id: :desc)
|
||||
else
|
||||
q = q.apply_default_order(params)
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,7 +88,7 @@ class UserPresenter
|
||||
end
|
||||
|
||||
def favorite_group_count(template)
|
||||
template.link_to(user.favorite_group_count, template.user_favorite_groups_path(user.id))
|
||||
template.link_to(user.favorite_group_count, template.favorite_groups_path(search: { creator_name: user.name }))
|
||||
end
|
||||
|
||||
def comment_count(template)
|
||||
|
||||
2
app/views/favorite_groups/destroy.js.erb
Normal file
2
app/views/favorite_groups/destroy.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
$("tr#favorite-group-<%= @favorite_group.id %>").remove();
|
||||
Danbooru.notice("Favorite group deleted.");
|
||||
@@ -1,15 +1,35 @@
|
||||
<div id="c-favorite-groups">
|
||||
<div id="a-index">
|
||||
<%= search_form_for(favorite_groups_path) do |f| %>
|
||||
<%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches) } %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %>
|
||||
<%= f.input :order, collection: [%w[Created created_at], %w[Updated updated_at], %w[Name name], %w[Post\ count post_count]], include_blank: true, selected: params.dig(:search, :order) %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
<%= table_for @favorite_groups, width: "100%" do |t| %>
|
||||
<%= table_for @favorite_groups.includes(:creator), width: "100%" do |t| %>
|
||||
<% t.column "Name", {width: "60%"} do |favgroup| %>
|
||||
<%= link_to favgroup.pretty_name, favorite_group_path(favgroup) %>
|
||||
<% if favgroup.post_count > CurrentUser.user.per_page %>
|
||||
<%= link_to "page #{favgroup.last_page}", favorite_group_path(favgroup, :page => favgroup.last_page), :class => "last-page" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Count", {width: "10%"} do |favgroup| %>
|
||||
<%= favgroup.post_count %>
|
||||
<% t.column :post_count %>
|
||||
<% t.column "Creator" do |favgroup| %>
|
||||
<%= link_to_user favgroup.creator %>
|
||||
<%= link_to "»", favorite_groups_path(search: { creator_name: favgroup.creator.name }) %>
|
||||
<% end %>
|
||||
<% t.column "Created" do |favgroup| %>
|
||||
<%= time_ago_in_words_tagged(favgroup.created_at) %>
|
||||
<% end %>
|
||||
<% t.column "Updated" do |favgroup| %>
|
||||
<%= time_ago_in_words_tagged(favgroup.updated_at) %>
|
||||
<% end %>
|
||||
<% t.column column: "control" do |favgroup| %>
|
||||
<% if favgroup.editable_by?(CurrentUser.user) %>
|
||||
<%= link_to "Edit", edit_favorite_group_path(favgroup) %> |
|
||||
<%= link_to "Delete", favorite_group_path(favgroup), method: :delete, remote: true, "data-confirm": "Are you sure you want to delete this favgroup? This cannot be undone." %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<%= error_messages_for "favorite_group" %>
|
||||
|
||||
<%= edit_form_for(@favorite_group) do |f| %>
|
||||
<%= f.input :name, :as => :string, :required => true %>
|
||||
<%= f.input :post_ids_string, :label => "Posts" %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= f.input :name, as: :string, required: true %>
|
||||
<%= f.input :post_ids_string, label: "Posts", as: :text %>
|
||||
<%= f.submit "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<% end %>
|
||||
<% unless CurrentUser.is_anonymous? %>
|
||||
<%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %>
|
||||
<%= subnav_link_to "Fav groups", user_favorite_groups_path(CurrentUser.id) %>
|
||||
<%= subnav_link_to "Fav groups", favorite_groups_path(search: { creator_name: CurrentUser.name }) %>
|
||||
<%= subnav_link_to "Saved searches", posts_path(tags: "search:all") %>
|
||||
<% end %>
|
||||
<%= subnav_link_to "Changes", post_versions_path %>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.user.favorite_groups.for_post(post.id).present? %>
|
||||
<%= render "posts/partials/show/favorite_groups", post: post, favgroups: CurrentUser.user.favorite_groups.for_post(post.id) %>
|
||||
<%= render "posts/partials/show/favorite_groups", post: post, favgroups: CurrentUser.user.favorite_groups.for_post(post.id).order(name: :asc) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user