/favorite_groups: add search, creators, timestamps, edit/delete links.
This commit is contained in:
@@ -47,9 +47,9 @@ class FavoriteGroupsController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
@favorite_group = FavoriteGroup.find(params[:id])
|
@favorite_group = FavoriteGroup.find(params[:id])
|
||||||
check_write_privilege(@favorite_group)
|
check_write_privilege(@favorite_group)
|
||||||
@favorite_group.destroy
|
@favorite_group.destroy!
|
||||||
flash[:notice] = "Favorite group deleted"
|
flash[:notice] = "Favorite group deleted" if request.format.html?
|
||||||
redirect_to favorite_groups_path
|
respond_with(@favorite_group, location: favorite_groups_path(search: { creator_name: CurrentUser.name }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_post
|
def add_post
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ class FavoriteGroup < ApplicationRecord
|
|||||||
where(is_public: true).or(where(creator_id: user.id))
|
where(is_public: true).or(where(creator_id: user.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_order
|
|
||||||
order(name: :asc)
|
|
||||||
end
|
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.visible(CurrentUser.user)
|
q = q.visible(CurrentUser.user)
|
||||||
@@ -38,6 +34,17 @@ class FavoriteGroup < ApplicationRecord
|
|||||||
q = q.name_matches(params[:name_matches])
|
q = q.name_matches(params[:name_matches])
|
||||||
end
|
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)
|
q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class UserPresenter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def favorite_group_count(template)
|
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
|
end
|
||||||
|
|
||||||
def comment_count(template)
|
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="c-favorite-groups">
|
||||||
<div id="a-index">
|
<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| %>
|
<% t.column "Name", {width: "60%"} do |favgroup| %>
|
||||||
<%= link_to favgroup.pretty_name, favorite_group_path(favgroup) %>
|
<%= link_to favgroup.pretty_name, favorite_group_path(favgroup) %>
|
||||||
<% if favgroup.post_count > CurrentUser.user.per_page %>
|
<% 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" %>
|
<%= link_to "page #{favgroup.last_page}", favorite_group_path(favgroup, :page => favgroup.last_page), :class => "last-page" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% t.column "Count", {width: "10%"} do |favgroup| %>
|
<% t.column :post_count %>
|
||||||
<%= favgroup.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 %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
<%= error_messages_for "favorite_group" %>
|
<%= error_messages_for "favorite_group" %>
|
||||||
|
|
||||||
<%= edit_form_for(@favorite_group) do |f| %>
|
<%= edit_form_for(@favorite_group) do |f| %>
|
||||||
<%= f.input :name, :as => :string, :required => true %>
|
<%= f.input :name, as: :string, required: true %>
|
||||||
<%= f.input :post_ids_string, :label => "Posts" %>
|
<%= f.input :post_ids_string, label: "Posts", as: :text %>
|
||||||
<%= f.button :submit, "Submit" %>
|
<%= f.submit "Submit" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% unless CurrentUser.is_anonymous? %>
|
<% unless CurrentUser.is_anonymous? %>
|
||||||
<%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %>
|
<%= 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") %>
|
<%= subnav_link_to "Saved searches", posts_path(tags: "search:all") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= subnav_link_to "Changes", post_versions_path %>
|
<%= subnav_link_to "Changes", post_versions_path %>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if CurrentUser.user.favorite_groups.for_post(post.id).present? %>
|
<% 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user