ab_admin 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -6
- data/Guardfile +6 -6
- data/README.md +5 -5
- data/app/assets/images/admin/Jcrop.gif +0 -0
- data/app/assets/javascripts/ab_admin/components/admin_assets.js.coffee +20 -19
- data/app/assets/javascripts/ab_admin/components/croppable_image.js.coffee +22 -38
- data/app/assets/javascripts/ab_admin/components/gmaps.js.coffee +2 -2
- data/app/assets/javascripts/ab_admin/core/ui_utils.js.coffee +6 -2
- data/app/assets/stylesheets/ab_admin/components/_base.css.scss +17 -1
- data/app/assets/stylesheets/ab_admin/components/_form.css.scss +1 -1
- data/app/assets/stylesheets/ab_admin/main.css.scss +1 -0
- data/app/controllers/admin/assets_controller.rb +10 -10
- data/app/controllers/admin/base_controller.rb +39 -37
- data/app/controllers/admin/locators_controller.rb +5 -4
- data/app/controllers/admin/manager_controller.rb +11 -10
- data/app/controllers/admin/settings_controller.rb +4 -3
- data/app/controllers/admin/static_pages_controller.rb +1 -1
- data/app/controllers/admin/structures_controller.rb +2 -2
- data/app/views/ab_admin/devise/passwords/edit.html.slim +5 -5
- data/app/views/ab_admin/devise/passwords/new.html.slim +3 -3
- data/app/views/ab_admin/devise/sessions/new.html.slim +5 -5
- data/app/views/admin/admin_comments/_comment.html.slim +3 -3
- data/app/views/admin/admin_comments/_comments.html.slim +2 -2
- data/app/views/admin/admin_comments/_form.html.slim +5 -5
- data/app/views/admin/admin_comments/create.js.erb +1 -1
- data/app/views/admin/base/_form.html.slim +1 -1
- data/app/views/admin/base/_search_layout.html.slim +4 -4
- data/app/views/admin/base/_tree.html.slim +1 -1
- data/app/views/admin/base/create.js.erb +1 -1
- data/app/views/admin/base/index.html.slim +3 -3
- data/app/views/admin/base/update.js.erb +1 -1
- data/app/views/admin/dashboards/index.html.slim +15 -1
- data/app/views/admin/fileupload/_asset.html.slim +1 -1
- data/app/views/admin/fileupload/_container.html.slim +2 -2
- data/app/views/admin/fileupload/_file.html.slim +1 -1
- data/app/views/admin/fileupload/_tmpl.html.slim +1 -1
- data/app/views/admin/headers/_form.html.slim +3 -3
- data/app/views/admin/locators/edit.html.slim +4 -4
- data/app/views/admin/locators/show.html.slim +3 -3
- data/app/views/admin/manager/_form.html.slim +2 -1
- data/app/views/admin/manager/_table.html.slim +6 -3
- data/app/views/admin/settings/_form.html.slim +8 -8
- data/app/views/admin/shared/_batch_actions.html.slim +1 -1
- data/app/views/admin/static_pages/_form.html.slim +3 -3
- data/app/views/admin/structures/_form.html.slim +7 -7
- data/app/views/admin/users/_form.html.slim +9 -9
- data/app/views/admin/users/_search_form.html.slim +4 -4
- data/app/views/admin/users/_table.html.slim +3 -3
- data/app/views/layouts/admin/_footer.html.slim +4 -0
- data/app/views/layouts/admin/_navigation.html.slim +2 -2
- data/app/views/layouts/admin/application.html.slim +3 -3
- data/app/views/layouts/admin/devise.html.slim +2 -2
- data/config/locales/ru.yml +1 -0
- data/config/routes.rb +23 -23
- data/db/migrate/20130101000001_create_users.rb +11 -11
- data/db/migrate/20130101000003_create_assets.rb +8 -8
- data/db/migrate/20130101000004_create_headers.rb +3 -3
- data/db/migrate/20130101000005_create_static_pages.rb +2 -2
- data/db/migrate/20130101000006_create_structures.rb +8 -8
- data/db/migrate/20130101000007_base_translations.rb +3 -3
- data/db/migrate/20130101000008_create_admin_comments.rb +3 -3
- data/features/dsl/action_items.feature +1 -1
- data/features/dsl/admin_comments.feature +2 -2
- data/features/dsl/batch_actions.feature +1 -1
- data/features/dsl/config.feature +2 -2
- data/features/dsl/custom_actions.feature +5 -5
- data/features/dsl/form.feature +4 -4
- data/features/dsl/in_place_edit.feature +1 -1
- data/features/dsl/list_edit.feature +1 -1
- data/features/dsl/resource_action_items.feature +1 -1
- data/features/dsl/table.feature +3 -3
- data/features/dsl/tree.feature +3 -3
- data/features/locators.feature +1 -1
- data/features/menu.feature +3 -3
- data/features/step_definitions/dsl/action_items_steps.rb +3 -3
- data/features/step_definitions/dsl/admin_comments_steps.rb +1 -1
- data/features/step_definitions/dsl/batch_actions_steps.rb +1 -1
- data/features/step_definitions/dsl/parent_resource_steps.rb +2 -2
- data/features/step_definitions/dsl/table_steps.rb +3 -3
- data/features/step_definitions/dsl/tree_steps.rb +3 -3
- data/features/step_definitions/menu_steps.rb +3 -3
- data/features/step_definitions/structure_steps.rb +1 -1
- data/features/step_definitions/user_steps.rb +7 -7
- data/features/step_definitions/web_steps/browsing_steps.rb +2 -2
- data/features/step_definitions/web_steps/form_steps.rb +7 -7
- data/features/support/selectors.rb +5 -5
- data/features/support/tolerance_for_selenium_sync_issues.rb +1 -1
- data/lib/ab_admin/abstract_resource.rb +3 -3
- data/lib/ab_admin/carrierwave/base_uploader.rb +7 -7
- data/lib/ab_admin/carrierwave/file_size_validator.rb +4 -4
- data/lib/ab_admin/carrierwave/glue.rb +1 -1
- data/lib/ab_admin/concerns/admin_addition.rb +17 -13
- data/lib/ab_admin/concerns/headerable.rb +2 -2
- data/lib/ab_admin/concerns/nested_set.rb +23 -1
- data/lib/ab_admin/concerns/reloadable.rb +56 -0
- data/lib/ab_admin/concerns/utilities.rb +3 -3
- data/lib/ab_admin/concerns/validations.rb +2 -2
- data/lib/ab_admin/config/base.rb +5 -5
- data/lib/ab_admin/config/optional_display.rb +4 -4
- data/lib/ab_admin/controllers/callbacks.rb +1 -1
- data/lib/ab_admin/controllers/can_can_manager_resource.rb +1 -1
- data/lib/ab_admin/controllers/head_options.rb +5 -9
- data/lib/ab_admin/controllers/tree.rb +2 -2
- data/lib/ab_admin/core_ext/other.rb +2 -2
- data/lib/ab_admin/core_ext/string.rb +2 -2
- data/lib/ab_admin/devise.rb +3 -3
- data/lib/ab_admin/engine.rb +1 -1
- data/lib/ab_admin/hooks/paginate_hooks.rb +2 -2
- data/lib/ab_admin/hooks/simple_form_hooks.rb +2 -2
- data/lib/ab_admin/i18n_tools/google_translate.rb +5 -5
- data/lib/ab_admin/i18n_tools/model_translator.rb +7 -7
- data/lib/ab_admin/i18n_tools/translate_app.rb +1 -1
- data/lib/ab_admin/menu_builder.rb +3 -3
- data/lib/ab_admin/models/asset.rb +14 -6
- data/lib/ab_admin/models/attachment_file.rb +2 -2
- data/lib/ab_admin/models/header.rb +1 -1
- data/lib/ab_admin/models/locator.rb +3 -3
- data/lib/ab_admin/models/structure.rb +8 -8
- data/lib/ab_admin/models/type_model.rb +3 -3
- data/lib/ab_admin/models/user.rb +7 -7
- data/lib/ab_admin/utils/csv_document.rb +2 -2
- data/lib/ab_admin/utils/logger.rb +1 -1
- data/lib/ab_admin/utils/xls_document.rb +4 -4
- data/lib/ab_admin/utils.rb +11 -11
- data/lib/ab_admin/version.rb +1 -1
- data/lib/ab_admin/views/admin_helpers.rb +13 -13
- data/lib/ab_admin/views/admin_navigation_helpers.rb +26 -26
- data/lib/ab_admin/views/form_builder.rb +36 -22
- data/lib/ab_admin/views/helpers.rb +6 -6
- data/lib/ab_admin/views/inputs/ckeditor_input.rb +1 -1
- data/lib/ab_admin/views/inputs/color_input.rb +1 -1
- data/lib/ab_admin/views/inputs/date_time_input.rb +7 -7
- data/lib/ab_admin/views/manager_helpers.rb +3 -3
- data/lib/ab_admin/views/search_form_builder.rb +18 -18
- data/lib/ab_admin/views/url_for_routes.rb +4 -4
- data/lib/ab_admin.rb +1 -2
- data/lib/generators/ab_admin/glob/glob_generator.rb +1 -1
- data/lib/generators/ab_admin/install/install_generator.rb +2 -2
- data/lib/generators/ab_admin/install/templates/config/admin_menu.rb +2 -0
- data/lib/generators/ab_admin/install/templates/config/seeds.rb +1 -1
- data/lib/generators/ab_admin/install/templates/config/unicorn_config.rb +3 -3
- data/lib/generators/ab_admin/install/templates/helpers/admin/structures_helper.rb +2 -2
- data/lib/generators/ab_admin/install/templates/models/ability.rb +4 -4
- data/lib/generators/ab_admin/install/templates/models/admin_comment.rb +4 -4
- data/lib/generators/ab_admin/install/templates/models/asset.rb +2 -1
- data/lib/generators/ab_admin/install/templates/models/attachment_file.rb +1 -1
- data/lib/generators/ab_admin/install/templates/models/avatar.rb +2 -2
- data/lib/generators/ab_admin/install/templates/models/locator.rb +3 -0
- data/lib/generators/ab_admin/install/templates/models/picture.rb +2 -2
- data/lib/generators/ab_admin/install/templates/models/settings.rb +3 -0
- data/lib/generators/ab_admin/install/templates/models/static_page.rb +3 -3
- data/lib/generators/ab_admin/install/templates/models/structure.rb +2 -2
- data/lib/generators/ab_admin/install/templates/models/user.rb +2 -2
- data/lib/generators/ab_admin/install/templates/spec/spec_helper.rb +2 -2
- data/lib/generators/ab_admin/install/templates/spec/support/shared_connection.rb +1 -1
- data/lib/generators/ab_admin/install/templates/uploaders/avatar_uploader.rb +2 -2
- data/lib/generators/ab_admin/install/templates/uploaders/picture_uploader.rb +4 -3
- data/lib/generators/ab_admin/model/model_generator.rb +4 -2
- data/lib/generators/ab_admin/model/templates/resource.erb +6 -6
- data/lib/generators/ab_admin/resource/resource_generator.rb +9 -9
- data/lib/generators/ab_admin/resource/templates/_form.haml.erb +10 -14
- data/lib/generators/ab_admin/resource/templates/_form.slim.erb +11 -11
- data/lib/generators/ab_admin/resource/templates/_search_form.haml.erb +1 -1
- data/lib/generators/ab_admin/resource/templates/_search_form.slim.erb +1 -1
- data/lib/generators/ab_admin/resource/templates/controller.erb +1 -1
- data/lib/generators/template.rb +8 -8
- data/lib/tasks/assets.rake +5 -5
- data/lib/tasks/cache.rake +1 -1
- data/lib/tasks/i18n.rake +1 -1
- data/spec/ab_admin_spec.rb +3 -3
- data/spec/dummy/app/models/ab_admin/ab_admin_catalogue.rb +1 -1
- data/spec/dummy/app/models/ab_admin/ab_admin_collection.rb +6 -6
- data/spec/dummy/app/models/ab_admin/ab_admin_product.rb +14 -14
- data/spec/dummy/app/models/admin_menu.rb +2 -2
- data/spec/dummy/app/models/ckeditor/asset.rb +1 -1
- data/spec/dummy/app/models/ckeditor/attachment_file.rb +1 -1
- data/spec/dummy/app/models/ckeditor/picture.rb +1 -1
- data/spec/dummy/app/models/collection.rb +5 -5
- data/spec/dummy/app/models/product.rb +5 -5
- data/spec/dummy/app/uploaders/ckeditor_attachment_file_uploader.rb +1 -1
- data/spec/dummy/app/uploaders/ckeditor_picture_uploader.rb +3 -3
- data/spec/dummy/app/views/layouts/application.html.erb +2 -2
- data/spec/dummy/config/application.rb +2 -2
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/ckeditor.rb +2 -2
- data/spec/dummy/config/initializers/devise.rb +5 -5
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/simple_form.rb +8 -8
- data/spec/dummy/config/initializers/simple_form_bootstrap.rb +14 -14
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/db/migrate/20130129151853_create_ckeditor_assets.rb +5 -5
- data/spec/dummy/db/migrate/20130130161853_create_collections.rb +2 -2
- data/spec/dummy/db/migrate/20130130162046_create_products.rb +2 -2
- data/spec/dummy/db/migrate/20130130175446_create_globalize_collection_product.rb +2 -2
- data/spec/dummy/db/migrate/20130207224516_create_catalogues.rb +3 -3
- data/spec/dummy/db/migrate/20130209223506_add_lat_lon_zoom_to_products.rb +1 -1
- data/spec/dummy/db/seeds.rb +5 -5
- data/spec/dummy/lib/capybara_irb.rb +10 -10
- data/spec/dummy/lib/tasks/cucumber.rake +10 -10
- data/spec/dummy/lib/templates/slim/scaffold/_form.html.slim +2 -2
- data/spec/factories/assets.rb +9 -9
- data/spec/factories/catalogues.rb +1 -1
- data/spec/factories/collections.rb +1 -1
- data/spec/factories/products.rb +2 -2
- data/spec/factories/structures.rb +2 -2
- data/spec/generators/ckeditor_assets_generator_spec.rb +1 -1
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/model_generator_spec.rb +2 -2
- data/spec/generators/resource_generator_spec.rb +1 -1
- data/spec/models/avatar_spec.rb +1 -1
- data/spec/models/picture_uploader_spec.rb +1 -1
- data/spec/models/structure_spec.rb +2 -2
- data/spec/models/user_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/support/shared_connection.rb +1 -1
- data/vendor/assets/javascripts/ab_admin/jquery.Jcrop.js +1083 -0
- data/vendor/assets/stylesheets/ab_admin/jquery.Jcrop.min.css.scss +28 -0
- metadata +8 -6
- data/lib/ab_admin/views/inputs/association_input.rb +0 -13
- data/lib/ab_admin/views/inputs/tree_select_input.rb +0 -16
@@ -24,7 +24,7 @@ module WillPaginate
|
|
24
24
|
module Pagination
|
25
25
|
def paginate(options)
|
26
26
|
options = options.dup
|
27
|
-
pagenum = options.fetch(:page) { raise ArgumentError,
|
27
|
+
pagenum = options.fetch(:page) { raise ArgumentError, ':page parameter required' }
|
28
28
|
per_page = options.delete(:per_page) || self.per_page
|
29
29
|
total = options.delete(:total_entries)
|
30
30
|
large = options.delete(:large)
|
@@ -38,7 +38,7 @@ module WillPaginate
|
|
38
38
|
rel.total_entries = total.to_i unless total.blank?
|
39
39
|
|
40
40
|
if large
|
41
|
-
new_rel = rel.except(:limit, :offset, :where).where(:
|
41
|
+
new_rel = rel.except(:limit, :offset, :where).where(id: rel.pluck("#{quoted_table_name}.id"))
|
42
42
|
new_rel.paginate_limit = rel.limit_value.to_i
|
43
43
|
new_rel.paginate_offset = rel.offset_value.to_i
|
44
44
|
new_rel.total_entries = rel.total_entries
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
#module WrappedButton
|
4
4
|
# def wrapped_button(*args, &block)
|
5
|
-
# template.content_tag :div, :
|
5
|
+
# template.content_tag :div, class: "form-actions" do
|
6
6
|
# options = args.extract_options!
|
7
7
|
# loading = self.object.new_record? ? I18n.t('simple_form.creating') : I18n.t('simple_form.updating')
|
8
8
|
# options[:"data-loading-text"] = [loading, options[:"data-loading-text"]].compact
|
9
9
|
# options[:class] = ['btn-primary', options[:class]].compact
|
10
10
|
# args << options
|
11
11
|
# if cancel = options.delete(:cancel)
|
12
|
-
# submit(*args, &block) + ' ' + template.link_to(I18n.t('simple_form.buttons.cancel'), cancel, :
|
12
|
+
# submit(*args, &block) + ' ' + template.link_to(I18n.t('simple_form.buttons.cancel'), cancel, class: 'btn')
|
13
13
|
# else
|
14
14
|
# submit(*args, &block)
|
15
15
|
# end
|
@@ -10,11 +10,11 @@ module AbAdmin
|
|
10
10
|
return text if from == to
|
11
11
|
base = 'https://www.googleapis.com/language/translate/v2'
|
12
12
|
params = {
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
13
|
+
key: configatron.else.retrieve(:google_api_key, ENV['GOOGLE_API_KEY']),
|
14
|
+
format: 'html',
|
15
|
+
source: from,
|
16
|
+
target: to,
|
17
|
+
q: text
|
18
18
|
}
|
19
19
|
response = RestClient.post(base, params, 'X-HTTP-Method-Override' => 'GET')
|
20
20
|
|
@@ -18,11 +18,11 @@ module AbAdmin
|
|
18
18
|
|
19
19
|
models_hash = @models.each_with_object({}) do |model, h|
|
20
20
|
model_i18n = {
|
21
|
-
'zero' => model.model_name.human(:
|
22
|
-
'one' => model.model_name.human(:
|
23
|
-
'few' => (model.model_name.human(:
|
24
|
-
'many' => (model.model_name.human(:
|
25
|
-
'other' => (model.model_name.human(:
|
21
|
+
'zero' => model.model_name.human(count: 0),
|
22
|
+
'one' => model.model_name.human(count: 1),
|
23
|
+
'few' => (model.model_name.human(count: 2) rescue model.model_name.human(count: 1)),
|
24
|
+
'many' => (model.model_name.human(count: 9) rescue model.model_name.human(count: 1)),
|
25
|
+
'other' => (model.model_name.human(count: 9) rescue model.model_name.human(count: 1))
|
26
26
|
}
|
27
27
|
@models_i18n_hash[locale]['activerecord']['models'][model.model_name.i18n_key.to_s]= model_i18n
|
28
28
|
attributes = model.columns.map(&:name)
|
@@ -35,7 +35,7 @@ module AbAdmin
|
|
35
35
|
end
|
36
36
|
if model.new.respond_to?("#{attr}_#{locale.to_s}".to_sym)
|
37
37
|
@locales.each do |locale_1|
|
38
|
-
o["#{attr}_#{locale_1.to_s}"] = "#{ha(model, attr, locale)} (#{I18n.t(locale_1, :
|
38
|
+
o["#{attr}_#{locale_1.to_s}"] = "#{ha(model, attr, locale)} (#{I18n.t(locale_1, scope: [:attrs])})"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end.sort.to_hash
|
@@ -46,7 +46,7 @@ module AbAdmin
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def ha(model, attr, locale)
|
49
|
-
model.human_attribute_name(attr, :
|
49
|
+
model.human_attribute_name(attr, locale: locale)
|
50
50
|
end
|
51
51
|
|
52
52
|
def write_yaml
|
@@ -5,7 +5,7 @@ module AbAdmin
|
|
5
5
|
def self.call(env)
|
6
6
|
if env['warden'].user
|
7
7
|
params = Rack::Request.new(env).params
|
8
|
-
body = {:
|
8
|
+
body = {text: AbAdmin::I18nTools::GoogleTranslate.t(params['q'], params['from'], params['to'])}
|
9
9
|
[200, {'Content-Type' => 'application/json'}, body.to_json]
|
10
10
|
else
|
11
11
|
[401, {'Content-Type' => 'application/json'}, '']
|
@@ -9,7 +9,7 @@ module AbAdmin
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def model(model, options={})
|
12
|
-
title = model.model_name.human(:
|
12
|
+
title = model.model_name.human(count: 9)
|
13
13
|
path = options[:url] || "/admin/#{model.model_name.plural}"
|
14
14
|
@menu_tree << MenuItem.new(title, path, options)
|
15
15
|
end
|
@@ -48,7 +48,7 @@ module AbAdmin
|
|
48
48
|
class MenuGroup < BaseMenuGroup
|
49
49
|
def initialize(title, options, &block)
|
50
50
|
@menu_tree = []
|
51
|
-
@title = title.is_a?(Symbol) ? I18n.t(title, :
|
51
|
+
@title = title.is_a?(Symbol) ? I18n.t(title, scope: [:admin, :navigation]) : title
|
52
52
|
@options = options
|
53
53
|
instance_eval &block if block_given?
|
54
54
|
end
|
@@ -70,7 +70,7 @@ module AbAdmin
|
|
70
70
|
include ::AbAdmin::Utils::EvalHelpers
|
71
71
|
|
72
72
|
def initialize(title, path, options)
|
73
|
-
@title = title.is_a?(Symbol) ? I18n.t(title, :
|
73
|
+
@title = title.is_a?(Symbol) ? I18n.t(title, scope: [:admin, :navigation]) : title
|
74
74
|
@path = path
|
75
75
|
@options = options
|
76
76
|
end
|
@@ -5,12 +5,12 @@ module AbAdmin
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
belongs_to :user
|
8
|
-
belongs_to :assetable, :
|
8
|
+
belongs_to :assetable, polymorphic: true
|
9
9
|
|
10
10
|
# Store options for image manipulation
|
11
11
|
attr_reader :cropper_geometry, :rotate_degrees
|
12
12
|
|
13
|
-
delegate :url, :original_filename, :
|
13
|
+
delegate :url, :original_filename, to: :data
|
14
14
|
|
15
15
|
class_attribute :thumb_size, :max_size
|
16
16
|
self.thumb_size = :thumb
|
@@ -43,15 +43,15 @@ module AbAdmin
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def format_created_at
|
46
|
-
I18n.l(created_at, :
|
46
|
+
I18n.l(created_at, format: '%d.%m.%Y %H:%M')
|
47
47
|
end
|
48
48
|
|
49
49
|
def as_json(options = nil)
|
50
50
|
options = {
|
51
|
-
:
|
51
|
+
only: [:id, :guid, :assetable_id, :assetable_type, :user_id,
|
52
52
|
:data_file_size, :data_content_type, :is_main, :original_name],
|
53
|
-
:
|
54
|
-
:
|
53
|
+
root: 'asset',
|
54
|
+
methods: [:filename, :url, :thumb_url, :width, :height]
|
55
55
|
}.merge(options || {})
|
56
56
|
|
57
57
|
super
|
@@ -80,6 +80,14 @@ module AbAdmin
|
|
80
80
|
self
|
81
81
|
end
|
82
82
|
|
83
|
+
def crop!(geometry)
|
84
|
+
rename!
|
85
|
+
self.cropper_geometry = geometry
|
86
|
+
save!
|
87
|
+
refresh_assetable
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
83
91
|
def rename!
|
84
92
|
rename
|
85
93
|
save!
|
@@ -21,11 +21,11 @@ module AbAdmin
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def human_date
|
24
|
-
I18n.l(created_at, :
|
24
|
+
I18n.l(created_at, format: '%d %B %Y')
|
25
25
|
end
|
26
26
|
|
27
27
|
def as_json(options={})
|
28
|
-
options.reverse_merge!(:
|
28
|
+
options.reverse_merge!(methods: [:filename, :url, :preview_url, :thumb_url, :width, :height,
|
29
29
|
:file_css_class, :human_filesize, :created_at])
|
30
30
|
super
|
31
31
|
end
|
@@ -24,8 +24,8 @@ module AbAdmin
|
|
24
24
|
def prepare_data(path)
|
25
25
|
data = YAML.load_file(path)
|
26
26
|
locale = data.keys.first
|
27
|
-
OpenStruct.new({:
|
28
|
-
:
|
27
|
+
OpenStruct.new({locale: locale.to_sym, data: data[locale], flat_data: flat_hash(data[locale]),
|
28
|
+
filename: File.basename(path), path: path, dir: File.dirname(path)})
|
29
29
|
end
|
30
30
|
|
31
31
|
def flat_hash(hash, k = [])
|
@@ -65,7 +65,7 @@ module AbAdmin
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
-
{:
|
68
|
+
{message: message}
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
@@ -7,18 +7,18 @@ module AbAdmin
|
|
7
7
|
include AbAdmin::Concerns::Headerable
|
8
8
|
include AbAdmin::Concerns::NestedSet
|
9
9
|
|
10
|
-
enumerated_attribute :structure_type, :
|
11
|
-
enumerated_attribute :position_type, :
|
10
|
+
enumerated_attribute :structure_type, id_attribute: :kind
|
11
|
+
enumerated_attribute :position_type, id_attribute: :position
|
12
12
|
|
13
13
|
validates_presence_of :title
|
14
|
-
validates_numericality_of :position, :
|
14
|
+
validates_numericality_of :position, only_integer: true
|
15
15
|
|
16
|
-
has_one :static_page, :
|
17
|
-
has_many :visible_children, :
|
16
|
+
has_one :static_page, dependent: :destroy
|
17
|
+
has_many :visible_children, class_name: name, foreign_key: 'parent_id', conditions: {is_visible: true}
|
18
18
|
|
19
|
-
scope :visible, where(:
|
20
|
-
scope :with_kind, proc {|structure_type| where(:
|
21
|
-
scope :with_position, proc {|position_type| where(:
|
19
|
+
scope :visible, where(is_visible: true)
|
20
|
+
scope :with_kind, proc {|structure_type| where(kind: structure_type.id) }
|
21
|
+
scope :with_position, proc {|position_type| where(position: position_type.id).order('lft DESC') }
|
22
22
|
end
|
23
23
|
|
24
24
|
def redirect?
|
@@ -5,7 +5,7 @@ module AbAdmin
|
|
5
5
|
|
6
6
|
attr_reader :code
|
7
7
|
|
8
|
-
class_attribute :codes, :i18n_scope, :
|
8
|
+
class_attribute :codes, :i18n_scope, instance_writer: false
|
9
9
|
self.codes = []
|
10
10
|
self.i18n_scope = [:admin, :type_model]
|
11
11
|
|
@@ -16,13 +16,13 @@ module AbAdmin
|
|
16
16
|
def self.define_enum_by_codes
|
17
17
|
define_enum do |builder|
|
18
18
|
codes.each do |kind|
|
19
|
-
builder.member kind, :
|
19
|
+
builder.member kind, object: new(kind.to_s)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def title
|
25
|
-
I18n.t(@code, :
|
25
|
+
I18n.t(@code, scope: i18n_scope)
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.legal?(value)
|
data/lib/ab_admin/models/user.rb
CHANGED
@@ -4,20 +4,20 @@ module AbAdmin
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
has_one :avatar, :
|
7
|
+
has_one :avatar, as: :assetable, dependent: :destroy, autosave: true
|
8
8
|
|
9
|
-
scope :managers, where(:
|
10
|
-
scope :active, where(:
|
9
|
+
scope :managers, where(user_role_id: [::UserRoleType.admin.id, ::UserRoleType.moderator.id])
|
10
|
+
scope :active, where(trust_state: ::UserState.active.id)
|
11
11
|
scope :admin, includes(:avatar)
|
12
12
|
|
13
13
|
after_initialize :init
|
14
14
|
before_validation :generate_login
|
15
|
-
before_validation :set_default_role, :
|
15
|
+
before_validation :set_default_role, unless: :user_role_id?
|
16
16
|
|
17
17
|
validate :check_role
|
18
18
|
|
19
|
-
enumerated_attribute :user_role_type, :
|
20
|
-
enumerated_attribute :trust_state_type, :
|
19
|
+
enumerated_attribute :user_role_type, id_attribute: :user_role_id, class: ::UserRoleType
|
20
|
+
enumerated_attribute :trust_state_type, id_attribute: :trust_state, class: ::UserState
|
21
21
|
end
|
22
22
|
|
23
23
|
def set_default_role
|
@@ -27,7 +27,7 @@ module AbAdmin
|
|
27
27
|
def generate_password!
|
28
28
|
raw_password = Rails.env.test? ? '654321' : Devise.friendly_token[0..7]
|
29
29
|
self.password = self.password_confirmation = raw_password
|
30
|
-
self.save(:
|
30
|
+
self.save(validate: false)
|
31
31
|
raw_password
|
32
32
|
end
|
33
33
|
|
@@ -28,11 +28,11 @@ module AbAdmin
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def render
|
31
|
-
::CSV.generate(:
|
31
|
+
::CSV.generate(col_sep: @options[:column_separator] || ',') do |csv|
|
32
32
|
csv << columns_names
|
33
33
|
|
34
34
|
each_record do |item|
|
35
|
-
csv << column_data.map { |column| AbAdmin.pretty_data call_method_or_proc_on(item, column, :
|
35
|
+
csv << column_data.map { |column| AbAdmin.pretty_data call_method_or_proc_on(item, column, exec: false) }
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -22,14 +22,14 @@ module AbAdmin
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def render
|
25
|
-
date_format = workbook.add_format(:
|
26
|
-
time_format = workbook.add_format(:
|
25
|
+
date_format = workbook.add_format(num_format: 'dd.mm.yyyy')
|
26
|
+
time_format = workbook.add_format(num_format: 'dd.mm.yyyy HH:MM')
|
27
27
|
|
28
28
|
each_with_index do |item, index|
|
29
29
|
row = index + 1
|
30
30
|
|
31
31
|
column_data.each_with_index do |column, num|
|
32
|
-
value = call_method_or_proc_on(item, column, :
|
32
|
+
value = call_method_or_proc_on(item, column, exec: false)
|
33
33
|
|
34
34
|
case value
|
35
35
|
when Date
|
@@ -44,7 +44,7 @@ module AbAdmin
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
bold = workbook.add_format(:
|
47
|
+
bold = workbook.add_format(bold: 1)
|
48
48
|
worksheet.write('A1', columns_names, bold)
|
49
49
|
|
50
50
|
super
|
data/lib/ab_admin/utils.rb
CHANGED
@@ -11,7 +11,7 @@ module AbAdmin
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def bm(message =
|
14
|
+
def bm(message = 'Benchmarking', options = {})
|
15
15
|
result = nil
|
16
16
|
ms = Benchmark.ms { result = yield }
|
17
17
|
Rails.logger.debug '%s (%.3fms)' % [message, ms]
|
@@ -40,8 +40,8 @@ module AbAdmin
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def truncate_text(raw_text, size=200)
|
43
|
-
text = raw_text.to_s.gsub(/"|«|»|'/,
|
44
|
-
text.truncate(size, :
|
43
|
+
text = raw_text.to_s.gsub(/"|«|»|'/, '\'').gsub(/ /, ' ').gsub(/—/, '-').no_html.squish
|
44
|
+
text.truncate(size, separator: ' ')
|
45
45
|
end
|
46
46
|
|
47
47
|
def l_path(locale=nil)
|
@@ -71,12 +71,12 @@ module AbAdmin
|
|
71
71
|
|
72
72
|
def js_date_data
|
73
73
|
{
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
74
|
+
formats: I18n.t('date.formats'),
|
75
|
+
day_names: I18n.t('date.day_names'),
|
76
|
+
abbr_day_names: I18n.t('date.common_abbr_day_names'),
|
77
|
+
month_names: I18n.t('date.common_month_names'),
|
78
|
+
standalone_month_names: I18n.t('date.standalone_month_names'),
|
79
|
+
abbr_month_names: I18n.t('date.abbr_month_names')
|
80
80
|
}
|
81
81
|
end
|
82
82
|
|
@@ -85,7 +85,7 @@ module AbAdmin
|
|
85
85
|
|
86
86
|
def normalize_html(raw_html)
|
87
87
|
return '' if raw_html.blank?
|
88
|
-
html = sanitize(raw_html.gsub(/<!--(.*?)-->[\n]?/m,
|
88
|
+
html = sanitize(raw_html.gsub(/<!--(.*?)-->[\n]?/m, ''))
|
89
89
|
doc = Nokogiri::HTML.fragment(html)
|
90
90
|
#doc.xpath('comment()').each { |c| c.remove }
|
91
91
|
doc.search('div').each { |el| el.name = 'p' }
|
@@ -116,7 +116,7 @@ module AbAdmin
|
|
116
116
|
when FalseClass
|
117
117
|
'-'
|
118
118
|
when Date, DateTime, Time, ActiveSupport::TimeWithZone
|
119
|
-
I18n.l(object, :
|
119
|
+
I18n.l(object, format: :long)
|
120
120
|
when NilClass
|
121
121
|
''
|
122
122
|
else
|
data/lib/ab_admin/version.rb
CHANGED
@@ -33,19 +33,19 @@ module AbAdmin
|
|
33
33
|
end
|
34
34
|
options[:source] ||= {'true' => 'yes', 'false' => 'no'} if options[:type] == 'select'
|
35
35
|
data = {
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
36
|
+
type: options[:type], source: options[:source].try(:to_json),
|
37
|
+
model: resource_class.model_name.singular, url: resource_path(item),
|
38
|
+
name: attr, value: item[attr]
|
39
39
|
}
|
40
|
-
link_to admin_pretty_data(item[attr]).html_safe, '#', :
|
40
|
+
link_to admin_pretty_data(item[attr]).html_safe, '#', class: 'editable', data: data
|
41
41
|
end
|
42
42
|
|
43
43
|
def options_for_ckeditor(options = {})
|
44
|
-
{:
|
44
|
+
{width: 930, height: 200, toolbar: 'VeryEasy', namespace: ''}.update(options)
|
45
45
|
end
|
46
46
|
|
47
47
|
def admin_tree_item(item)
|
48
|
-
render 'tree_item', :
|
48
|
+
render 'tree_item', item: item, child_tree: admin_tree(item.cached_children)
|
49
49
|
end
|
50
50
|
|
51
51
|
def admin_tree(items)
|
@@ -80,7 +80,7 @@ module AbAdmin
|
|
80
80
|
when TrueClass, FalseClass
|
81
81
|
color_bool(object)
|
82
82
|
when Date, DateTime, Time, ActiveSupport::TimeWithZone
|
83
|
-
I18n.l(object, :
|
83
|
+
I18n.l(object, format: :long)
|
84
84
|
when NilClass
|
85
85
|
''
|
86
86
|
when ActiveRecord::Base
|
@@ -95,22 +95,22 @@ module AbAdmin
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def item_image_link(item, options={})
|
98
|
-
options.reverse_merge!(:
|
98
|
+
options.reverse_merge!(url: resource_path(item), assoc: :picture)
|
99
99
|
image = item.send(options[:assoc])
|
100
100
|
return nil unless image
|
101
101
|
version = options[:version] || image.class.thumb_size
|
102
|
-
popover_data = {:
|
103
|
-
link_to image_tag(image.url(version)), options[:url], :
|
102
|
+
popover_data = {content: "<img src='#{image.url}'></img>", title: item.name}
|
103
|
+
link_to image_tag(image.url(version)), options[:url], data: popover_data, rel: 'popover'
|
104
104
|
end
|
105
105
|
|
106
106
|
def item_image(item, assoc=:photo, size=:thumb)
|
107
107
|
image_tag_if(item.send(assoc).try(:url, size))
|
108
108
|
end
|
109
109
|
|
110
|
-
# input_set 'title', :
|
110
|
+
# input_set 'title', legend_class: 'do_sort', label_class: 'label-info' do
|
111
111
|
def input_set(title, options={}, &block)
|
112
|
-
options.reverse_merge!(:
|
113
|
-
html = content_tag(:label, title, :
|
112
|
+
options.reverse_merge!(class: "inputs well well-small #{options.delete(:legend_class) || 'do_sort'}", id: options.delete(:legend_id))
|
113
|
+
html = content_tag(:label, title, class: "input_set label #{options.delete(:label_class)}")
|
114
114
|
html.concat(capture(&block)) if block_given?
|
115
115
|
content_tag(:fieldset, html, options)
|
116
116
|
end
|
@@ -36,7 +36,7 @@ module AbAdmin
|
|
36
36
|
|
37
37
|
html_options = args.first.is_a?(Hash) ? args.shift.dup : {}
|
38
38
|
html_options[:class] = ['sort_link', current_dir, html_options[:class]].compact.join(' ')
|
39
|
-
options.merge!(:
|
39
|
+
options.merge!(q: search_params.merge(s: "#{attr_name} #{new_dir}"))
|
40
40
|
|
41
41
|
link_to [name, order_indicator_for(current_dir)].join(' ').html_safe, url_for(options), html_options
|
42
42
|
end
|
@@ -54,18 +54,18 @@ module AbAdmin
|
|
54
54
|
def short_action_link(action, item)
|
55
55
|
case action
|
56
56
|
when :edit
|
57
|
-
item_link_to_can? :update, item, icon('pencil', true), edit_resource_path(item), :
|
58
|
-
:
|
57
|
+
item_link_to_can? :update, item, icon('pencil', true), edit_resource_path(item), remote: settings[:list_edit],
|
58
|
+
class: 'btn btn-primary', title: t('admin.actions.edit.link')
|
59
59
|
when :destroy
|
60
|
-
item_link_to_can? :destroy, item, icon('trash', true), resource_path(item, :
|
61
|
-
:
|
62
|
-
:
|
60
|
+
item_link_to_can? :destroy, item, icon('trash', true), resource_path(item, return_to: request.url),
|
61
|
+
method: :delete, data: {confirm: t('admin.delete_confirmation')},
|
62
|
+
class: 'btn btn-danger', title: t('admin.actions.destroy.link')
|
63
63
|
when :show
|
64
64
|
item_link_to_can? :show, item, icon('info-sign', true), resource_path(item),
|
65
|
-
:
|
65
|
+
class: 'btn btn-info', title: t('admin.actions.show.link')
|
66
66
|
when :preview
|
67
67
|
if path = preview_resource_path(item)
|
68
|
-
link_to icon('eye-open', true), path, :
|
68
|
+
link_to icon('eye-open', true), path, class: 'btn btn-small btn-inverse', title: t('admin.actions.preview.link'), target: '_blank'
|
69
69
|
end
|
70
70
|
when AbAdmin::Config::ActionItem
|
71
71
|
instance_exec(item, &action.data) if action.for_context?(self)
|
@@ -78,17 +78,17 @@ module AbAdmin
|
|
78
78
|
def action_link(action)
|
79
79
|
case action
|
80
80
|
when :new
|
81
|
-
link_to_can? :create, t('admin.actions.new.link'), new_resource_path, :
|
81
|
+
link_to_can? :create, t('admin.actions.new.link'), new_resource_path, class: 'btn btn-primary new_resource', remote: settings[:list_edit]
|
82
82
|
when :edit
|
83
|
-
link_to_can? :update, t('admin.actions.edit.link'), edit_resource_path, :
|
83
|
+
link_to_can? :update, t('admin.actions.edit.link'), edit_resource_path, class: 'btn btn-primary'
|
84
84
|
when :destroy
|
85
|
-
link_to_can? :destroy, t('admin.actions.destroy.link'), resource_path, :
|
86
|
-
:
|
85
|
+
link_to_can? :destroy, t('admin.actions.destroy.link'), resource_path, method: :delete, data: {confirm: t('admin.delete_confirmation')},
|
86
|
+
class: 'btn btn-danger'
|
87
87
|
when :show
|
88
|
-
link_to_can? :show, t('admin.actions.show.link'), resource_path, :
|
88
|
+
link_to_can? :show, t('admin.actions.show.link'), resource_path, class: 'btn btn-info'
|
89
89
|
when :preview
|
90
90
|
if path = preview_resource_path(resource)
|
91
|
-
link_to t('admin.actions.preview.link'), path, :
|
91
|
+
link_to t('admin.actions.preview.link'), path, class: 'btn btn-inverse', title: t('admin.actions.preview.link'), target: '_blank'
|
92
92
|
end
|
93
93
|
when AbAdmin::Config::ActionItem
|
94
94
|
instance_exec(&action.data) if action.for_context?(self)
|
@@ -113,20 +113,20 @@ module AbAdmin
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def model_admin_menu_link(model)
|
116
|
-
content_tag :li, :
|
117
|
-
link_to model.model_name.human(:
|
118
|
-
#link_to model.model_name.human(:
|
116
|
+
content_tag :li, class: ('active' if controller_name.split('/').last == model.model_name.plural) do
|
117
|
+
link_to model.model_name.human(count: 9), "/admin/#{model.model_name.plural}"
|
118
|
+
#link_to model.model_name.human(count: 9), {action: :index, controller: "admin/#{model.model_name.plural}"}
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
def admin_menu_link(name, path)
|
123
|
-
content_tag :li, :
|
123
|
+
content_tag :li, class: ('active' if path == request.path_info.split('/')[2]) do
|
124
124
|
link_to name, "/admin/#{path}"
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
def admin_menu_link_without_model(name, path, path_name)
|
129
|
-
content_tag :li, :
|
129
|
+
content_tag :li, class: ('active' if path_name == request.url.split('/').last) do
|
130
130
|
link_to name, path
|
131
131
|
end
|
132
132
|
end
|
@@ -138,7 +138,7 @@ module AbAdmin
|
|
138
138
|
t('will_paginate.pagination_info_empty')
|
139
139
|
else
|
140
140
|
per_page = (params[:per_page] || resource_class.per_page).to_i
|
141
|
-
t('will_paginate.pagination_info', :
|
141
|
+
t('will_paginate.pagination_info', from: offset + 1, to: [offset + per_page, total_entries].min, count: total_entries).html_safe
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -151,7 +151,7 @@ module AbAdmin
|
|
151
151
|
def batch_action_toggle
|
152
152
|
if settings[:batch]
|
153
153
|
content_tag :th do
|
154
|
-
check_box_tag '', '', false, :
|
154
|
+
check_box_tag '', '', false, id: nil, class: 'toggle'
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
@@ -159,14 +159,14 @@ module AbAdmin
|
|
159
159
|
def batch_action_item(item)
|
160
160
|
if settings[:batch]
|
161
161
|
content_tag :td do
|
162
|
-
check_box_tag 'ids[]', item.id, false, :
|
162
|
+
check_box_tag 'ids[]', item.id, false, id: "batch_action_item_#{item.id}"
|
163
163
|
end
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
def id_link(item)
|
168
|
-
opts = {:
|
169
|
-
if can?(:edit, item)
|
167
|
+
def id_link(item, edit=true)
|
168
|
+
opts = {remote: settings[:list_edit], class: 'resource_id_link'}
|
169
|
+
if edit && can?(:edit, item)
|
170
170
|
link_to item.id, edit_resource_path(item), opts
|
171
171
|
elsif can?(:read, item)
|
172
172
|
link_to item.id, resource_path(item), opts
|
@@ -196,7 +196,7 @@ module AbAdmin
|
|
196
196
|
def admin_record_link(record, action, options={})
|
197
197
|
return unless record
|
198
198
|
record_title = options.delete(:title) || AbAdmin.display_name(record)
|
199
|
-
#url_options = {:
|
199
|
+
#url_options = {controller: record.class.model_name.plural, action: action, id: record.id}
|
200
200
|
action_url_part = action == :show ? '' : "/#{action}"
|
201
201
|
url = "/admin/#{record.class.model_name.plural}/#{record.id}#{action_url_part}"
|
202
202
|
html_options = options.delete(:html_options) || {}
|