Enhance Internal Index Pages (#1747)
* add more info to internal users index * create tag show page and add tag moderation form * fix linting * add tag index view and alias field * add pagination to tag index * fix spec
This commit is contained in:
parent
fe9da91c57
commit
54426ea20b
9 changed files with 161 additions and 68 deletions
|
|
@ -3,28 +3,53 @@ class Internal::TagsController < Internal::ApplicationController
|
|||
|
||||
def index
|
||||
@tags = if params[:state] == "supported"
|
||||
Tag.where(supported: true).order("taggings_count DESC").limit(120)
|
||||
Tag.where(supported: true).order("taggings_count DESC").page(params[:page]).per(50)
|
||||
elsif params[:state] == "unsupported"
|
||||
Tag.where(supported: false).order("taggings_count DESC").limit(120)
|
||||
Tag.where(supported: false).order("taggings_count DESC").page(params[:page]).per(50)
|
||||
else
|
||||
Tag.order("taggings_count DESC").limit(120)
|
||||
Tag.order("taggings_count DESC").page(params[:page]).per(50)
|
||||
end
|
||||
if params[:search].present?
|
||||
@tags = @tags.where("tags.name ILIKE :search", search: "%#{params[:search]}%")
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@tag = Tag.find(params[:id])
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag = Tag.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@tag = Tag.find(params[:id])
|
||||
add_moderator if params[:tag][:tag_moderator_id]
|
||||
remove_moderator if params[:tag][:remove_moderator_id]
|
||||
@tag.update!(tag_params)
|
||||
redirect_to(action: :index)
|
||||
redirect_to "/internal/tags/#{params[:id]}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_moderator
|
||||
User.find(params[:tag][:remove_moderator_id]).remove_role :tag_moderator, @tag
|
||||
end
|
||||
|
||||
def add_moderator
|
||||
user_id = params[:tag][:tag_moderator_id]
|
||||
AssignTagModerator.add_tag_moderators([user_id], [@tag.id])
|
||||
end
|
||||
|
||||
def tag_params
|
||||
params.require(:tag).permit(:supported,
|
||||
:rules_markdown,
|
||||
:short_summary,
|
||||
:pretty_name,
|
||||
:bg_color_hex,
|
||||
:text_color_hex)
|
||||
:text_color_hex,
|
||||
:tag_moderator_id,
|
||||
:remove_moderator_id,
|
||||
:alias_for)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
module AssignTagModerator
|
||||
def self.add_tag_moderators(user_ids, tag_names)
|
||||
def self.add_tag_moderators(user_ids, tag_ids)
|
||||
user_ids.each_with_index do |user_id, index|
|
||||
user = User.find(user_id)
|
||||
tag = Tag.find_by(name: tag_names[index])
|
||||
tag = Tag.find(tag_ids[index])
|
||||
user.add_role(:tag_moderator, tag)
|
||||
if user.chat_channels.find_by(slug: "tag-moderators").blank?
|
||||
ChatChannel.find_by(slug: "tag-moderators").add_users(user)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ class Tag < ActsAsTaggableOn::Tag
|
|||
clojure ubuntu elm gamedev flutter bash
|
||||
).freeze
|
||||
|
||||
attr_accessor :tag_moderator_id, :remove_moderator_id
|
||||
|
||||
mount_uploader :profile_image, ProfileImageUploader
|
||||
mount_uploader :social_image, ProfileImageUploader
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ class UserRoleService
|
|||
end
|
||||
return false if tag.errors[:moderator_ids].present?
|
||||
|
||||
# Don't have to worry about comparing old and new values.
|
||||
tag.tag_moderator_ids.each do |id|
|
||||
User.find(id).remove_role(:tag_moderator, tag)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,59 +4,40 @@
|
|||
height: 140px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h1>Tags</h1>
|
||||
<h2>
|
||||
|
||||
<a href="/internal/tags"
|
||||
style="<%= 'background: yellow' if params[:state].blank? %>">All</a> |
|
||||
<a href="/internal/tags?state=supported"
|
||||
style="<%= 'background: yellow' if params[:state] == "supported" %>">Supported</a> |
|
||||
<a href="/internal/tags?state=unsupported"
|
||||
style="<%= 'background: yellow' if params[:state] == "unsupported" %>">Unsupported</a> |
|
||||
</h2>
|
||||
<hr/><hr/>
|
||||
<%= form_tag("/internal/tags", method: "get") do %>
|
||||
<%= label_tag(:search, "Find by tag name:") %>
|
||||
<%= text_field_tag(:search, params[:search]) %>
|
||||
<% if params[:state].present? %>
|
||||
<%= hidden_field_tag(:state, params[:state]) %>
|
||||
<% end %>
|
||||
<%= submit_tag("Search") %>
|
||||
<% end %>
|
||||
|
||||
<h3>
|
||||
<a href="/internal/tags"
|
||||
style="<%= "background: yellow" if params[:state].blank? %>">All</a> |
|
||||
<a href="/internal/tags?state=supported"
|
||||
style="<%= "background: yellow" if params[:state] == "supported" %>">Supported</a> |
|
||||
<a href="/internal/tags?state=unsupported"
|
||||
style="<%= "background: yellow" if params[:state] == "unsupported" %>">Unsupported</a> |
|
||||
</h3>
|
||||
|
||||
<%= paginate @tags %>
|
||||
<div class="wrapper" style="font-weight: 600; border-bottom: 2px solid black;">
|
||||
<div>Tag</div>
|
||||
<div>ID</div>
|
||||
<div>Alias For</div>
|
||||
<div>Taggings Count</div>
|
||||
<div>Is Moderated?</div>
|
||||
</div>
|
||||
<% @tags.each do |tag| %>
|
||||
<div>
|
||||
<h1><a href="/t/<%= tag.name %>" style="background:<%= tag.bg_color_hex %>;color:<%= tag.text_color_hex %>;">#<%= tag.name %></a></h1>
|
||||
<p>count: <%= tag.taggings_count %></p>
|
||||
<br/>
|
||||
<%= form_for [:internal, tag] do |f| %>
|
||||
<div>
|
||||
<%= f.label :supported %>
|
||||
<%= f.check_box :supported %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :pretty_name %>
|
||||
<%= f.text_field :pretty_name %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :short_summary %>
|
||||
<%= f.text_field :short_summary %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :rules_markdown %>
|
||||
<br/>
|
||||
<%= f.text_area :rules_markdown %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :wiki_body_markdown %>
|
||||
<br/>
|
||||
<%= f.text_area :wiki_body_markdown %>
|
||||
<div>
|
||||
</div>
|
||||
<%= f.label :bg_color_hex %>
|
||||
<%= f.text_field :bg_color_hex, class: "jscolor {hash:true}", required: true %>
|
||||
<div>
|
||||
</div>
|
||||
<%= f.label :text_color_hex %>
|
||||
<%= f.text_field :text_color_hex, class: "jscolor {hash:true}", required: true %>
|
||||
<div>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<hr/>
|
||||
<% end %>
|
||||
<div class="wrapper" style="border-bottom: 1px solid grey; padding: 10px;">
|
||||
<div class="grid-item"><a href="/internal/tags/<%= tag.id %>" target="_blank">#<%= tag.name %></a></div>
|
||||
<div><%= tag.id %></div>
|
||||
<div><%= tag.alias_for %></div>
|
||||
<div><%= tag.taggings_count %></div>
|
||||
<div><%= tag.tag_moderator_ids.any? %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= paginate @tags %>
|
||||
|
|
|
|||
66
app/views/internal/tags/show.html.erb
Normal file
66
app/views/internal/tags/show.html.erb
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<h1><a href="/t/<%= @tag.name %>" style="background:<%= @tag.bg_color_hex %>;color:<%= @tag.text_color_hex %>;">#<%= @tag.name %></a>, tagged <%= @tag.taggings_count %> times.</h1>
|
||||
<% if @tag.tag_moderator_ids.any? %>
|
||||
<p><strong>Moderators: </strong></p>
|
||||
<% else %>
|
||||
<p>This tag currently has no moderators.</p>
|
||||
<% end %>
|
||||
<ul>
|
||||
<% @tag.tag_moderator_ids.each do |id| %>
|
||||
<%= form_for [:internal, @tag] do |f| %>
|
||||
<li>
|
||||
<a href="/<%= User.find(id).username %>">@<%= User.find(id).username %></a>
|
||||
<%= f.hidden_field :remove_moderator_id, value: id %>
|
||||
<%= f.submit "Remove" %>
|
||||
</li>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<%= form_for [:internal, @tag] do |f| %>
|
||||
<div>
|
||||
<%= f.label "Add Moderator (id): " %>
|
||||
<%= f.text_field :tag_moderator_id %>
|
||||
<%= f.submit "Add Moderator" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= form_for [:internal, @tag] do |f| %>
|
||||
<hr>
|
||||
<div>
|
||||
<%= f.label :supported %>
|
||||
<%= f.check_box :supported %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :alias_for %>
|
||||
<%= f.text_field :alias_for %>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.label :pretty_name %>
|
||||
<%= f.text_field :pretty_name %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :short_summary %>
|
||||
<%= f.text_field :short_summary %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :rules_markdown %>
|
||||
<br>
|
||||
<%= f.text_area :rules_markdown %>
|
||||
<div>
|
||||
<div>
|
||||
<%= f.label :wiki_body_markdown %>
|
||||
<br>
|
||||
<%= f.text_area :wiki_body_markdown %>
|
||||
<div>
|
||||
</div>
|
||||
<%= f.label :bg_color_hex %>
|
||||
<%= f.text_field :bg_color_hex, class: "jscolor {hash:true}", required: true %>
|
||||
<div>
|
||||
</div>
|
||||
<%= f.label :text_color_hex %>
|
||||
<%= f.text_field :text_color_hex, class: "jscolor {hash:true}", required: true %>
|
||||
<div>
|
||||
</div>
|
||||
<div>
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -22,10 +22,22 @@
|
|||
<em style="font-size:0.78em;">(<b>fields:</b> name, username, twitter_username, github_username, email)</em>
|
||||
<% end %>
|
||||
<%= paginate @users %>
|
||||
<br>
|
||||
<div class="wrapper" style="font-weight: 600; border-bottom: 2px solid black;">
|
||||
<div>User</div>
|
||||
<div>ID</div>
|
||||
<div>Name</div>
|
||||
<div>Twitter</div>
|
||||
<div>GitHub</div>
|
||||
</div>
|
||||
|
||||
<% @users.each do |user| %>
|
||||
<div class="row">
|
||||
<h2><%= user.name %></h2>
|
||||
<h3><a href="/internal/users/<%= user.id %>" target="_blank">@<%= user.username %></a></h3>
|
||||
<div class="wrapper" style="border-bottom: 1px solid grey; padding: 10px;">
|
||||
<div class="grid-item"><a href="/internal/users/<%= user.id %>" target="_blank">@<%= user.username %></a></div>
|
||||
<div class="grid-item"><%= user.id %></div>
|
||||
<div class="grid-item"><%= user.name %></div>
|
||||
<div class="grid-item"><%= user.twitter_username %></div>
|
||||
<div class="grid-item"><%= user.github_username %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= paginate @users %>
|
||||
|
|
|
|||
|
|
@ -31,11 +31,19 @@
|
|||
padding:1vw;
|
||||
border-radius:3px;
|
||||
}
|
||||
.wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: 20% 20% 20% 20% 20%;
|
||||
padding: 2px;
|
||||
}
|
||||
.grid-item {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.inner-row form{
|
||||
display:inline-block;
|
||||
}
|
||||
textarea {
|
||||
font-size: 12px;
|
||||
font-size: 12px;
|
||||
width: 75%;
|
||||
}
|
||||
.btn{
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ RSpec.describe AssignTagModerator do
|
|||
|
||||
before do
|
||||
user_ids = [user_one.id, user_two.id]
|
||||
tag_names = [tag_one.name, tag_two.name]
|
||||
tag_ids = [tag_one.id, tag_two.id]
|
||||
ChatChannel.create(slug: "tag-moderators", channel_name: "Tag Moderators", channel_type: "invite_only")
|
||||
described_class.add_tag_moderators(user_ids, tag_names)
|
||||
described_class.add_tag_moderators(user_ids, tag_ids)
|
||||
end
|
||||
|
||||
it "assigns the correct moderators and tags" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue