2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-03-21 10:28:52 -04:00
|
|
|
require 'reviewable/collection'
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
class Reviewable < ActiveRecord::Base
|
|
|
|
class Actions < Reviewable::Collection
|
|
|
|
attr_reader :bundles
|
|
|
|
|
|
|
|
def initialize(reviewable, guardian, args = nil)
|
|
|
|
super(reviewable, guardian, args)
|
|
|
|
@bundles = []
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add common actions here to make them easier for reviewables to re-use. If it's a
|
|
|
|
# one off, add it manually.
|
|
|
|
def self.common_actions
|
|
|
|
{
|
|
|
|
approve: Action.new(:approve, 'thumbs-up', 'reviewables.actions.approve.title'),
|
|
|
|
reject: Action.new(:reject, 'thumbs-down', 'reviewables.actions.reject.title'),
|
2019-05-01 11:36:48 -04:00
|
|
|
delete: Action.new(:delete, 'trash-alt', 'reviewables.actions.delete_single.title')
|
2019-01-03 12:03:01 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
class Bundle < Item
|
|
|
|
attr_accessor :icon, :label, :actions
|
|
|
|
|
|
|
|
def initialize(id, icon: nil, label: nil)
|
|
|
|
super(id)
|
|
|
|
@icon = icon
|
|
|
|
@label = label
|
|
|
|
@actions = []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Action < Item
|
2021-03-02 11:28:27 -05:00
|
|
|
attr_accessor :icon, :button_class, :label, :description, :confirm_message, :client_action, :require_reject_reason, :custom_modal
|
2019-01-03 12:03:01 -05:00
|
|
|
|
2019-09-18 06:28:59 -04:00
|
|
|
def initialize(id, icon = nil, button_class = nil, label = nil)
|
2019-01-03 12:03:01 -05:00
|
|
|
super(id)
|
2019-09-18 06:28:59 -04:00
|
|
|
@icon, @button_class, @label = icon, button_class, label
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_bundle(id, icon: nil, label: nil)
|
|
|
|
bundle = Bundle.new(id, icon: icon, label: label)
|
|
|
|
@bundles << bundle
|
|
|
|
bundle
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(id, bundle: nil)
|
|
|
|
action = Actions.common_actions[id] || Action.new(id)
|
|
|
|
yield action if block_given?
|
|
|
|
@content << action
|
|
|
|
|
|
|
|
bundle ||= add_bundle(id)
|
|
|
|
bundle.actions << action
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|