Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve suggestion admin tools #196

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ gem "redcarpet", "~> 3.6"
gem "country_select", "~> 8.0"
gem "avo", "~> 3.11"
gem "frozen_record", "~> 0.27.2"
gem "diffy"

# Use OmniAuth to support multi-provider authentication [https://github.com/omniauth/omniauth]
gem "omniauth"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ GEM
irb (~> 1.10)
reline (>= 0.3.8)
device_detector (1.1.3)
diffy (3.4.2)
docile (1.4.1)
dockerfile-rails (1.6.17)
rails (>= 3.0.0)
Expand Down Expand Up @@ -553,6 +554,7 @@ DEPENDENCIES
countries
country_select (~> 8.0)
debug
diffy
dockerfile-rails (>= 1.2)
dotenv-rails
dry-initializer-rails
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "tailwindcss/components";
@import "tailwindcss/utilities";

@import "components/diff.css";
@import "components/dropdown.css";
@import "components/form.css";
@import "components/markdown.css";
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/components/diff.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@layer components {
.diff {
del {
@apply text-error;
}

ins {
@apply text-success;
}
}
}
7 changes: 7 additions & 0 deletions app/models/speaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class Speaker < ApplicationRecord
scope :canonical, -> { where(canonical_id: nil) }
scope :not_canonical, -> { where.not(canonical_id: nil) }

# normalizes
normalizes :twitter, with: ->(value) { value.gsub(%r{https?://(?:www\.)?(?:x\.com|twitter\.com)/}, "").gsub(/@/, "") }

def title
name
end

def github_avatar_url(size: 200)
return "" unless github.present?

Expand Down
28 changes: 19 additions & 9 deletions app/views/admin/suggestions/_suggestion.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<div class="flex items-start gap-4">
<div class="grid grid-cols-4 gap-4">
<% suggestion.content.keys.each do |key| %>
<span><%= key %></span>
<span><%= suggestion.suggestable[key].presence || "-" %></span>
<span><%= suggestion.content[key] %></span>
<% end %>
<div class="card card-bordered">
<div class="card-body">
<div class="flex flex-col gap-4">
<% title = "#{suggestion.suggestable.class} : #{suggestion.suggestable.title}" %>
<%= link_to title, suggestion.suggestable, target: "_blank", class: "link" %>
<div class="grid grid-cols-2 gap-4">
<% suggestion.content.keys.each do |key| %>
<span><%= key %></span>
<span>
<%= sanitize Diffy::Diff.new(suggestion.suggestable[key].to_s, suggestion.content[key].to_s, include_plus_and_minus_in_html: true).to_s(:html) %>
</span>
<% end %>
</div>

<div class="flex items-center gap-4">
<%= button_to "Reject", admin_suggestion_path(suggestion), method: :delete, class: "btn btn-outline btn-sm" %>
<%= button_to "Approve", admin_suggestion_path(suggestion), method: :patch, class: "btn btn-success btn-sm" %>
</div>
</div>
</div>
<%= button_to "Approve", admin_suggestion_path(suggestion), method: :patch, class: "secondary" %>
<%= button_to "Reject", admin_suggestion_path(suggestion), method: :delete, class: "secondary" %>
</div>
7 changes: 5 additions & 2 deletions app/views/admin/suggestions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div class="flex flex-col gap-4">
<%= render partial: "admin/suggestions/suggestion", collection: @suggestions, as: :suggestion %>
<div class="container py-8">
<h1 class="mb-4">Suggestions</h1>
<div class="flex flex-col gap-4">
<%= render partial: "admin/suggestions/suggestion", collection: @suggestions, as: :suggestion %>
</div>
</div>
1 change: 0 additions & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<%= render "shared/navbar/link", link_title: "Watch List", path: watch_lists_path %>
<% if Current.user&.admin? %>
<%= render "shared/navbar/link", link_title: "Topics", path: topics_path %>
<%= render "shared/navbar/link", link_title: "Suggestions", path: admin_suggestions_path %>
<% end %>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions app/views/shared/_user_dropdown.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<% c.with_menu_item_divider %>
<% c.with_menu_item_button_to t("sign_out"), Current.session, method: :delete, id: :sign_out %>
<% if Current.user&.admin? %>
<% c.with_menu_item_link_to "Suggestions", admin_suggestions_path %>
<% c.with_menu_item_link_to t("admin"), avo_path %>
<% end %>
<% end %>
Expand Down