Added/Updated admin dashboard tables

• Added:
- New Account filtering
- PreviewCard viewing/sorting/filtering deleting (todo)
- DeletePreviewCardWorker, Service
- Status viewing/sorting/filtering deleting
- ChatMessage viewing/sorting/filtering deleting (todo)
- Account > Follows view

• Updated:
- LinkBlock to sort alphabetically
- Groups to be under "Moderation" instead of "Admin" in navigation.rb
- Status in admin to have group name/link
- Reports reset button
- Group filtering/sorting
- LinkBlock filtering/sorting
- Account now has bio and few more data points in dashboard
This commit is contained in:
mgabdev
2021-01-19 01:25:25 -05:00
parent 24fa2d3a74
commit 51fa8f2eb4
39 changed files with 697 additions and 108 deletions

View File

@@ -51,6 +51,13 @@ class AccountFilter
valid_ip?(value) ? accounts_with_users.where('users.current_sign_in_ip <<= ?', value) : Account.none
when 'staff'
accounts_with_users.merge User.staff
when "note"
Account.where("LOWER(note) LIKE LOWER(?)", "%#{value}%")
when "status_count_gte"
# : todo :
Account.joins(:account_stat)
when "sign_up_date_gte"
Account.where("created_at >= ?", value)
else
raise "Unknown filter: #{key}"
end

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
class ChatMessageFilter
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = ChatMessage
params.each do |key, value|
scope = scope.merge scope_for(key, value) if !value.nil? && !value.empty?
end
scope
end
def scope_for(key, value)
case key.to_sym
when :text
ChatMessage.where("LOWER(text) LIKE LOWER(?)", "%#{value}%")
when :id
ChatMessage.where(id: value)
when :account_id
ChatMessage.where(from_account_id: value)
when :created_at_lte
ChatMessage.where("created_at <= ?", value)
when :created_at_gte
ChatMessage.where("created_at >= ?", value)
else
raise "Unknown filter: #{key}"
end
end
end

View File

@@ -0,0 +1,26 @@
# frozen_string_literal: true
class Form::PreviewCardBatch
include ActiveModel::Model
include AccountableConcern
attr_accessor :preview_card_ids, :action, :current_account
def save
case action
when 'delete'
delete_preview_cards
end
end
private
def delete_preview_cards
PreviewCard.where(id: preview_card_ids).reorder(nil).find_each do |preview_card|
DeletePreviewCardWorker.perform_async(preview_card.id)
log_action :destroy, preview_card
end
true
end
end

View File

@@ -0,0 +1,34 @@
# frozen_string_literal: true
class GroupFilter
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = Group
params.each do |key, value|
scope = scope.merge scope_for(key, value) if !value.nil? && !value.empty?
end
scope
end
def scope_for(key, value)
case key.to_sym
when :id
Group.where(id: value)
when :title
Group.where("LOWER(title) LIKE LOWER(?)", "%#{value}%")
when :description
Group.where("LOWER(description) LIKE LOWER(?)", "%#{value}%")
when :member_count_gte
Group.where("member_count >= ?", value)
when :created_at_gte
Group.where("created_at >= ?", value)
else
raise "Unknown filter: #{key}"
end
end
end

View File

@@ -14,6 +14,8 @@ class LinkBlock < ApplicationRecord
validates :link, presence: true, uniqueness: true
scope :alphabetical, -> { reorder(link: :asc) }
def self.block?(text)
return false if text.nil?
return false if text.length < 1

View File

@@ -0,0 +1,26 @@
# frozen_string_literal: true
class LinkBlockFilter
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = LinkBlock
params.each do |key, value|
scope = scope.merge scope_for(key, value)
end
scope
end
def scope_for(key, value)
case key.to_sym
when :link
LinkBlock.where("LOWER(link) LIKE LOWER(?)", "%#{value}%")
else
raise "Unknown filter: #{key}"
end
end
end

View File

@@ -0,0 +1,30 @@
# frozen_string_literal: true
class PreviewCardFilter
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = PreviewCard
params.each do |key, value|
scope = scope.merge scope_for(key, value)
end
scope
end
def scope_for(key, value)
case key.to_sym
when :title
PreviewCard.where("LOWER(title) LIKE LOWER(?)", "%#{value}%")
when :description
PreviewCard.where("LOWER(description) LIKE LOWER(?)", "%#{value}%")
when :url
PreviewCard.where("LOWER(url) LIKE LOWER(?)", "%#{value}%")
else
raise "Unknown filter: #{key}"
end
end
end