Last active
September 20, 2019 17:09
-
-
Save a-x-/3c2fc8a1b05c0810e43d20f6db5c53bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# RubyReactAdmin. ActiveAdmin like controller API, возвращающее TR-D json | |
# для отображения React-интерфейсе без js-кода для дефолтных сценариев | |
# с несложными кастомизациями фронта по необходимости лучшими фронтовыми технологиями | |
# | |
# todo: render_json, render_json_error, render_json_exception | |
# todo: | |
module Admin | |
class ReactAdminController < AdminController | |
cattr_reader :scopes # for debug purposes; see also class_variables | |
def self.layout(path) | |
end | |
def self.config | |
@@config | |
end | |
def self.actions(*actions) | |
end | |
# @example scope('Все', show_count: false) { |scope| scope.all } | |
def self.scope(name, **options, &block) | |
@@scopes ||= {} | |
@@scopes[name] = { | |
scope_block: block, | |
name: (name.class == Symbol ? name.to_s.titleize : name), | |
show_count: (options[:show_count].nil? ? true : options[:show_count]), | |
display_if_block: (options[:if] || proc { true }), | |
default_scope: (options[:default] || proc { false }) | |
} | |
end | |
def self.filter(name, **options) | |
end | |
def self.sidebar(name, **options) | |
end | |
def self.collection_action | |
end | |
def self.member_action | |
end | |
def self.batch_action(name, &block) | |
end | |
def self.index | |
@@index = Proc.new {{ | |
collection: collection, | |
page: page, | |
pages: pages, | |
title: nil # todo: подтягивать перевод названия модели из i18n/*.yml active_record | |
i18n: nil # todo: подтягивать переводы ключей модели | |
}} | |
end | |
def self.show | |
end | |
def self.create | |
end | |
private | |
def collection | |
@collection ||= params[:scope].present? ? | |
@@scopes[params[:scope]].scope_block(default_scope) : | |
default_scope | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment