Improve admin UI for custom emojis, add copy/disable/enable (#5231)

This commit is contained in:
Eugen Rochko
2017-10-05 23:42:05 +02:00
committed by GitHub
parent b9c76e2edb
commit 49cc0eb3e7
13 changed files with 330 additions and 15 deletions

View File

@ -9,9 +9,11 @@ class AccountFilter
def results
scope = Account.alphabetic
params.each do |key, value|
scope.merge!(scope_for(key, value)) if value.present?
end
scope
end

View File

@ -12,6 +12,7 @@
# image_updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# disabled :boolean default(FALSE), not null
#
class CustomEmoji < ApplicationRecord
@ -26,10 +27,16 @@ class CustomEmoji < ApplicationRecord
validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { in: 0..50.kilobytes }
validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 }
scope :local, -> { where(domain: nil) }
scope :local, -> { where(domain: nil) }
scope :remote, -> { where.not(domain: nil) }
scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) }
include Remotable
def local?
domain.nil?
end
class << self
def from_text(text, domain)
return [] if text.blank?
@ -38,7 +45,7 @@ class CustomEmoji < ApplicationRecord
return [] if shortcodes.empty?
where(shortcode: shortcodes, domain: domain)
where(shortcode: shortcodes, domain: domain, disabled: false)
end
end
end

View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
class CustomEmojiFilter
attr_reader :params
def initialize(params)
@params = params
end
def results
scope = CustomEmoji.alphabetic
params.each do |key, value|
scope.merge!(scope_for(key, value)) if value.present?
end
scope
end
private
def scope_for(key, value)
case key.to_s
when 'local'
CustomEmoji.local
when 'remote'
CustomEmoji.remote
when 'by_domain'
CustomEmoji.where(domain: value)
else
raise "Unknown filter: #{key}"
end
end
end