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
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
### UTILITY METHODS ###
|
3
3
|
def valid_user
|
4
|
-
@user ||= {:
|
4
|
+
@user ||= {email: 'test@example.com', password: '123456'}
|
5
5
|
end
|
6
6
|
|
7
7
|
def sign_in(user)
|
8
8
|
visit new_user_session_path
|
9
|
-
fill_in 'Email', :
|
10
|
-
fill_in 'Password', :
|
9
|
+
fill_in 'Email', with: user[:email]
|
10
|
+
fill_in 'Password', with: user[:password]
|
11
11
|
click_button 'Sign in'
|
12
12
|
end
|
13
13
|
|
@@ -17,7 +17,7 @@ Given /^I am signed out$/ do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
Given /^I do not exist as a user$/ do
|
20
|
-
User.where(:
|
20
|
+
User.where(email: valid_user[:email]).first.should be_nil
|
21
21
|
end
|
22
22
|
|
23
23
|
Given /^I exist as a user$/ do
|
@@ -38,7 +38,7 @@ Then /^I should be signed out$/ do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
When /^I sign in with a wrong password$/ do
|
41
|
-
sign_in valid_user.merge(:
|
41
|
+
sign_in valid_user.merge(password: 'wrong')
|
42
42
|
end
|
43
43
|
|
44
44
|
Then /^I see a successful sign in message$/ do
|
@@ -46,7 +46,7 @@ Then /^I see a successful sign in message$/ do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
Then /^I should see my name$/ do
|
49
|
-
page.should have_content(User.where(:
|
49
|
+
page.should have_content(User.where(email: valid_user[:email]).first.try(:name))
|
50
50
|
end
|
51
51
|
|
52
52
|
Given /^I am logged in$/ do
|
@@ -55,7 +55,7 @@ Given /^I am logged in$/ do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
Given /^I am logged in as "(.*)"$/ do |email|
|
58
|
-
@me = FactoryGirl.create(:admin_user, valid_user.merge(:
|
58
|
+
@me = FactoryGirl.create(:admin_user, valid_user.merge(email: email))
|
59
59
|
login_as @me
|
60
60
|
end
|
61
61
|
|
@@ -35,14 +35,14 @@ Then /^(?:|I )should see \/([^\/]*)\/([imxo])?$/ do |regexp,flags|
|
|
35
35
|
regexp_opts = [regexp,flags].compact
|
36
36
|
regexp = Regexp.new(*regexp_opts)
|
37
37
|
|
38
|
-
page.should have_xpath('//*', :
|
38
|
+
page.should have_xpath('//*', text: regexp)
|
39
39
|
end
|
40
40
|
|
41
41
|
Then /^(?:|I )should not see \/([^\/]*)\/([imxo])?$/ do |regexp,flags|
|
42
42
|
regexp_opts = [regexp,flags].compact
|
43
43
|
regexp = Regexp.new(*regexp_opts)
|
44
44
|
|
45
|
-
page.should have_no_xpath('//*', :
|
45
|
+
page.should have_no_xpath('//*', text: regexp)
|
46
46
|
end
|
47
47
|
|
48
48
|
Then /^(?:|I )should be on (.+)$/ do |page_name|
|
@@ -42,15 +42,15 @@ When /^(?:|I )fill in the following:$/ do |fields|
|
|
42
42
|
end
|
43
43
|
|
44
44
|
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
|
45
|
-
fill_in(field, :
|
45
|
+
fill_in(field, with: value)
|
46
46
|
end
|
47
47
|
|
48
48
|
When /^(?:|I )fill in "([^"]*)" with:$/ do |field, value|
|
49
|
-
fill_in(field, :
|
49
|
+
fill_in(field, with: value)
|
50
50
|
end
|
51
51
|
|
52
52
|
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
|
53
|
-
select(value, :
|
53
|
+
select(value, from: field)
|
54
54
|
end
|
55
55
|
|
56
56
|
When /^(?:|I )check "([^"]*)"$/ do |field|
|
@@ -136,7 +136,7 @@ When /^(?:I|i) select following values from "([^"]*)":$/ do |field, values|
|
|
136
136
|
end
|
137
137
|
|
138
138
|
values.each do |value|
|
139
|
-
select(value, :
|
139
|
+
select(value, from: field)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -149,7 +149,7 @@ When /^(?:I|i) unselect following values from "([^"]*)":$/ do |field, values|
|
|
149
149
|
end
|
150
150
|
|
151
151
|
values.each do |value|
|
152
|
-
unselect(value, :
|
152
|
+
unselect(value, from: field)
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
@@ -163,7 +163,7 @@ Then /^the following values should be selected in "([^"]*)":$/ do |select_box, v
|
|
163
163
|
|
164
164
|
select_box = find_field(select_box)
|
165
165
|
unless select_box['multiple']
|
166
|
-
raise
|
166
|
+
raise 'this is not multiple select box!'
|
167
167
|
else
|
168
168
|
values.each do |value|
|
169
169
|
select_box.value.should include(value)
|
@@ -181,7 +181,7 @@ Then /^the following values should not be selected in "([^"]*)":$/ do |select_bo
|
|
181
181
|
|
182
182
|
select_box = find_field(select_box)
|
183
183
|
unless select_box['multiple']
|
184
|
-
raise
|
184
|
+
raise 'this is not multiple select box!'
|
185
185
|
else
|
186
186
|
values.each do |value|
|
187
187
|
select_box.value.should_not include(value)
|
@@ -8,12 +8,12 @@ module HtmlSelectorsHelpers
|
|
8
8
|
def selector_for(locator)
|
9
9
|
case locator
|
10
10
|
|
11
|
-
when
|
12
|
-
|
13
|
-
when
|
14
|
-
|
11
|
+
when 'the page'
|
12
|
+
'html > body'
|
13
|
+
when 'table\'s header'
|
14
|
+
'table tbody > tr th'
|
15
15
|
when /^paragraphs?$/
|
16
|
-
|
16
|
+
'p'
|
17
17
|
|
18
18
|
# Add more mappings here.
|
19
19
|
# Here is an example that pulls values out of the Regexp:
|
@@ -13,7 +13,7 @@ module ToleranceForSeleniumSyncIssues
|
|
13
13
|
rescue => e
|
14
14
|
raise e if (Time.now - start_time) >= seconds
|
15
15
|
sleep(0.05)
|
16
|
-
raise Capybara::FrozenInTime,
|
16
|
+
raise Capybara::FrozenInTime, 'time appears to be frozen, Capybara does not work with libraries which freeze time, consider using time travelling instead' if Time.now == start_time
|
17
17
|
retry
|
18
18
|
end
|
19
19
|
else
|
@@ -12,7 +12,7 @@ module AbAdmin
|
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
@actions = ACTIONS
|
15
|
-
@batch_action_list = [AbAdmin::Config::BatchAction.new(:destroy, :
|
15
|
+
@batch_action_list = [AbAdmin::Config::BatchAction.new(:destroy, confirm: I18n.t('admin.delete_confirmation'))]
|
16
16
|
@action_items = []
|
17
17
|
@disabled_action_items = []
|
18
18
|
@default_action_items_for = {}
|
@@ -100,7 +100,7 @@ module AbAdmin
|
|
100
100
|
def belongs_to(*args)
|
101
101
|
options = args.extract_options!
|
102
102
|
args.each do |name|
|
103
|
-
instance.parent_resources << OpenStruct.new(:
|
103
|
+
instance.parent_resources << OpenStruct.new(name: name, options: options)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -109,7 +109,7 @@ module AbAdmin
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def collection_action(name, options={}, &block)
|
112
|
-
instance.custom_actions << AbAdmin::Config::CustomAction.new(name, options.merge(:
|
112
|
+
instance.custom_actions << AbAdmin::Config::CustomAction.new(name, options.merge(collection: true), &block)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -15,10 +15,10 @@ module AbAdmin
|
|
15
15
|
|
16
16
|
process :set_content_type
|
17
17
|
|
18
|
-
with_options :
|
18
|
+
with_options if: :image? do |img|
|
19
19
|
img.process :strip
|
20
|
-
img.process :
|
21
|
-
img.process :
|
20
|
+
img.process cropper: lambda { |model| model.cropper_geometry }
|
21
|
+
img.process rotate: lambda { |model| model.rotate_degrees }
|
22
22
|
end
|
23
23
|
|
24
24
|
process :set_model_info
|
@@ -40,7 +40,7 @@ module AbAdmin
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Reduces the quality of the image to the percentage given
|
43
|
-
# process :
|
43
|
+
# process quality: 85
|
44
44
|
#
|
45
45
|
def quality(percentage)
|
46
46
|
percentage = normalize_param(percentage)
|
@@ -55,7 +55,7 @@ module AbAdmin
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Rotate image by degress
|
58
|
-
# process :
|
58
|
+
# process rotate: "-90"
|
59
59
|
#
|
60
60
|
def rotate(degrees = nil)
|
61
61
|
degrees = normalize_param(degrees)
|
@@ -71,8 +71,8 @@ module AbAdmin
|
|
71
71
|
|
72
72
|
# Crop image by specific coordinates
|
73
73
|
# http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=6ddk6c680muj4eu2vr54vdveb7#geometry
|
74
|
-
# process :
|
75
|
-
# process :
|
74
|
+
# process cropper: [size, offset]
|
75
|
+
# process cropper: [800, 600, 10, 20]
|
76
76
|
#
|
77
77
|
def cropper(*geometry)
|
78
78
|
geometry = normalize_param(geometry[0]) if geometry.size == 1
|
@@ -2,15 +2,15 @@
|
|
2
2
|
module AbAdmin
|
3
3
|
module CarrierWave
|
4
4
|
class FileSizeValidator < ActiveModel::EachValidator
|
5
|
-
MESSAGES = { :
|
6
|
-
CHECKS = { :
|
5
|
+
MESSAGES = { is: :wrong_size, minimum: :size_too_small, maximum: :size_too_big }.freeze
|
6
|
+
CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze
|
7
7
|
|
8
8
|
DEFAULT_TOKENIZER = lambda { |value| value.split(//) }
|
9
9
|
RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
|
10
10
|
|
11
11
|
def initialize(options)
|
12
12
|
if range = (options.delete(:in) || options.delete(:within))
|
13
|
-
raise ArgumentError,
|
13
|
+
raise ArgumentError, ':in and :within must be a Range' unless range.is_a?(Range)
|
14
14
|
options[:minimum], options[:maximum] = range.begin, range.end
|
15
15
|
options[:maximum] -= 1 if range.exclude_end?
|
16
16
|
end
|
@@ -35,7 +35,7 @@ module AbAdmin
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def validate_each(record, attribute, value)
|
38
|
-
raise(ArgumentError,
|
38
|
+
raise(ArgumentError, 'A CarrierWave::Uploader::Base object was expected') unless value.kind_of? ::CarrierWave::Uploader::Base
|
39
39
|
|
40
40
|
value = (options[:tokenizer] || DEFAULT_TOKENIZER).call(value) if value.kind_of?(String)
|
41
41
|
|
@@ -6,7 +6,7 @@ module AbAdmin
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def sunrise_uploader(uploader=nil, options={}, &block)
|
9
|
-
options = { :
|
9
|
+
options = { mount_on: :data_file_name }.merge(options)
|
10
10
|
|
11
11
|
mount_uploader(:data, uploader, options, &block)
|
12
12
|
|
@@ -9,35 +9,39 @@ module AbAdmin
|
|
9
9
|
scope(:base, scoped) unless respond_to?(:base)
|
10
10
|
scope :ids, lambda { |ids| where("#{quoted_table_name}.id IN (?)", AbAdmin.val_to_array(ids).push(0)) }
|
11
11
|
|
12
|
-
class_attribute :batch_actions, :
|
12
|
+
class_attribute :batch_actions, instance_writer: false
|
13
13
|
self.batch_actions = [:destroy]
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
17
|
def for_input_token(r, attr='name_ru')
|
18
|
-
{:
|
18
|
+
{id: r.id, text: r[attr]}
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def for_input_token
|
23
|
-
{:
|
23
|
+
{id: id, text: name}
|
24
24
|
end
|
25
25
|
|
26
26
|
def token_data(method, options={})
|
27
27
|
assoc = self.class.reflect_on_association(method)
|
28
|
-
records =
|
29
|
-
data =
|
28
|
+
records = Array(send(method))
|
29
|
+
data = records.map(&:for_input_token)
|
30
30
|
data = {
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
31
|
+
pre: data.to_json,
|
32
|
+
class: assoc.klass.name,
|
33
|
+
multi: assoc.collection?,
|
34
|
+
c: options.delete(:c)
|
35
35
|
}
|
36
36
|
if options[:geo_order]
|
37
|
+
data[:c] ||= {}
|
37
38
|
singular = self.class.model_name.singular
|
38
|
-
data[:c]
|
39
|
+
data[:c].reverse_deep_merge!({with: {lat: "#{singular}_lat", lon: "#{singular}_lon"}})
|
39
40
|
end
|
40
|
-
|
41
|
+
if data[:c] && !data[:c].is_a?(String)
|
42
|
+
data[:c] = data[:c].to_json
|
43
|
+
end
|
44
|
+
options.reverse_deep_merge!(class: 'fancy_select', data: data, value: records.map(&:id).join(','))
|
41
45
|
end
|
42
46
|
|
43
47
|
def next_prev_by_url(scope, url, prev=false)
|
@@ -56,8 +60,8 @@ module AbAdmin
|
|
56
60
|
predicate = order_mode == 'desc' ? '<' : '>'
|
57
61
|
id_predicate = '>'
|
58
62
|
end
|
59
|
-
sql = "(#{quoted_order_col} #{predicate} :val OR (#{quoted_order_col} = :val AND #{self.class.quote_column('id')} #{id_predicate} #{
|
60
|
-
scope.where(sql, :
|
63
|
+
sql = "(#{quoted_order_col} #{predicate} :val OR (#{quoted_order_col} = :val AND #{self.class.quote_column('id')} #{id_predicate} #{id}))"
|
64
|
+
scope.where(sql, val: send(order_col)).ransack(query[:q]).result(distinct: true).first
|
61
65
|
end
|
62
66
|
|
63
67
|
end
|
@@ -5,11 +5,11 @@ module AbAdmin
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
has_one :header, :
|
8
|
+
has_one :header, as: :headerable, dependent: :delete
|
9
9
|
|
10
10
|
attr_accessible :header_attributes
|
11
11
|
|
12
|
-
accepts_nested_attributes_for :header, :
|
12
|
+
accepts_nested_attributes_for :header, reject_if: :all_blank
|
13
13
|
|
14
14
|
::Header.all_translated_attribute_names.each do |attr|
|
15
15
|
define_method "header_#{attr}=" do |val|
|
@@ -12,7 +12,7 @@ module AbAdmin
|
|
12
12
|
|
13
13
|
scope :nested_set, order('lft ASC')
|
14
14
|
scope :reversed_nested_set, order('lft DESC')
|
15
|
-
scope :with_depth, proc { |level| where(:
|
15
|
+
scope :with_depth, proc { |level| where(depth: level) }
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
@@ -34,6 +34,7 @@ module AbAdmin
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def nested_opts(records, mover=nil)
|
37
|
+
mover = nil if mover && !mover.is_a?(self)
|
37
38
|
res = []
|
38
39
|
records.each do |r|
|
39
40
|
next if mover && mover.id == r.id
|
@@ -41,6 +42,27 @@ module AbAdmin
|
|
41
42
|
end
|
42
43
|
res
|
43
44
|
end
|
45
|
+
|
46
|
+
def nested_opts_with_parent(records, mover=nil)
|
47
|
+
mover = nil if mover && !mover.is_a?(self)
|
48
|
+
res = []
|
49
|
+
parents = []
|
50
|
+
records.each do |r|
|
51
|
+
r.root? ? parents = [] : parents.reject! { |p| p.depth >= r.depth }
|
52
|
+
|
53
|
+
unless mover && mover.id == r.id
|
54
|
+
res << ["#{parents.map { |c| "#{AbAdmin.display_name(c)} - " }.join} <b>#{AbAdmin.display_name(r)}</b>", r.id]
|
55
|
+
end
|
56
|
+
|
57
|
+
parents << r
|
58
|
+
end
|
59
|
+
res
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def nested_opts_with_parent(collection=nil)
|
64
|
+
collection ||= self.class.all
|
65
|
+
self.class.nested_opts_with_parent(collection, self)
|
44
66
|
end
|
45
67
|
|
46
68
|
def nested_opts(collection=nil)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AbAdmin
|
2
|
+
module Concerns
|
3
|
+
module Reloadable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_attribute :reload_checker
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def has_reload_check(key=nil, logger=nil, &block)
|
13
|
+
self.reload_checker = ::AbAdmin::Concerns::Reloadable::Reloader.new(key, logger, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_reload
|
17
|
+
self.reload_checker.check
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class Reloader
|
23
|
+
|
24
|
+
def initialize(key=nil, logger=nil, &block)
|
25
|
+
@key = key || "#{model_name.singular}_check_reload_key"
|
26
|
+
@block = block
|
27
|
+
@logger = logger || Rails.logger
|
28
|
+
@stamp = fetch_stamp
|
29
|
+
log "init #@key with value #@stamp"
|
30
|
+
end
|
31
|
+
|
32
|
+
def fetch_stamp
|
33
|
+
Rails.cache.fetch(@key) { Time.now.to_i }
|
34
|
+
end
|
35
|
+
|
36
|
+
def check
|
37
|
+
stamp = fetch_stamp
|
38
|
+
if @stamp != stamp
|
39
|
+
@stamp = stamp
|
40
|
+
@block.call()
|
41
|
+
log "#@key reloaded to #@stamp"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def expire
|
46
|
+
log "#@key expire"
|
47
|
+
Rails.cache.delete(@key)
|
48
|
+
end
|
49
|
+
|
50
|
+
def log(msg)
|
51
|
+
@logger.info "[RELOADER] (#{Process.pid}) #{msg}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -5,16 +5,16 @@ module AbAdmin
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
delegate :value_to_boolean, :
|
8
|
+
delegate :value_to_boolean, to: ActiveRecord::ConnectionAdapters::Column
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def max_time
|
13
|
-
Rails.cache.fetch("by_class_#{name}", :
|
13
|
+
Rails.cache.fetch("by_class_#{name}", expires_in: 60) { maximum(:updated_at).to_i }
|
14
14
|
end
|
15
15
|
|
16
16
|
def max_time_by_scope(scope)
|
17
|
-
Rails.cache.fetch("by_class_#{name}_#{scope}", :
|
17
|
+
Rails.cache.fetch("by_class_#{name}_#{scope}", expires_in: 60) { send(scope).maximum(:updated_at).to_i }
|
18
18
|
end
|
19
19
|
|
20
20
|
def full_truncate
|
@@ -4,9 +4,9 @@ module AbAdmin
|
|
4
4
|
class UniqTranslationValidator < ActiveModel::EachValidator
|
5
5
|
def validate_each(record, attribute, value)
|
6
6
|
::I18n.available_locales.each do |l|
|
7
|
-
next if record.read_attribute(attribute, :
|
7
|
+
next if record.read_attribute(attribute, locale: l).blank?
|
8
8
|
records_scope = record.class.const_get(:Translation).where("#{record.class.model_name.foreign_key} != #{record.id || 0}")
|
9
|
-
same = records_scope.where(:
|
9
|
+
same = records_scope.where(name: record.read_attribute(attribute, locale: l), locale: l.to_s).exists?
|
10
10
|
record.errors.add("#{attribute}_#{l}", :taken) if same
|
11
11
|
end
|
12
12
|
end
|
data/lib/ab_admin/config/base.rb
CHANGED
@@ -3,7 +3,7 @@ module AbAdmin
|
|
3
3
|
class BaseBuilder
|
4
4
|
attr_reader :options, :fields
|
5
5
|
attr_accessor :partial
|
6
|
-
class_attribute :field_defaults, :partial_name, :
|
6
|
+
class_attribute :field_defaults, :partial_name, instance_writer: false
|
7
7
|
self.field_defaults = {}
|
8
8
|
|
9
9
|
def initialize(options={}, &block)
|
@@ -30,7 +30,7 @@ module AbAdmin
|
|
30
30
|
end
|
31
31
|
|
32
32
|
class Table < BaseBuilder
|
33
|
-
self.field_defaults = {:
|
33
|
+
self.field_defaults = {sortable: true}
|
34
34
|
self.partial_name = 'table'
|
35
35
|
end
|
36
36
|
|
@@ -40,7 +40,7 @@ module AbAdmin
|
|
40
40
|
|
41
41
|
class Export < BaseBuilder
|
42
42
|
def render_options
|
43
|
-
{:
|
43
|
+
{column_names: fields.map(&:name), column_data: fields.map(&:data), column_separator: options[:column_separator]}
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -53,7 +53,7 @@ module AbAdmin
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def locale_tabs(options={}, &block)
|
56
|
-
@fields << FieldGroup.new(options.update(:
|
56
|
+
@fields << FieldGroup.new(options.update(localized: true), &block)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -73,7 +73,7 @@ module AbAdmin
|
|
73
73
|
|
74
74
|
class FieldGroup < BaseBuilder
|
75
75
|
def title
|
76
|
-
options[:title].is_a?(Symbol) ? I18n.t(options[:title], :
|
76
|
+
options[:title].is_a?(Symbol) ? I18n.t(options[:title], scope: [:admin, :form]) : options[:title]
|
77
77
|
end
|
78
78
|
|
79
79
|
def localized?
|
@@ -5,10 +5,10 @@ module AbAdmin
|
|
5
5
|
#
|
6
6
|
# The options hash accepts:
|
7
7
|
#
|
8
|
-
# :
|
9
|
-
# :
|
10
|
-
# :
|
11
|
-
# :
|
8
|
+
# only: :index
|
9
|
+
# only: [:index, :show]
|
10
|
+
# except: :index
|
11
|
+
# except: [:index, :show]
|
12
12
|
#
|
13
13
|
# call #normalize_display_options! after @options has been set
|
14
14
|
# to ensure that the display options are setup correctly
|
@@ -6,7 +6,7 @@ module AbAdmin
|
|
6
6
|
def head_options(record, options = {})
|
7
7
|
return if record.nil?
|
8
8
|
|
9
|
-
options = { :
|
9
|
+
options = { spliter: AbAdmin.title_spliter, append_title: true }.merge(options)
|
10
10
|
|
11
11
|
header = options[:header] || (record.respond_to?(:header) ? record.header : nil)
|
12
12
|
|
@@ -17,20 +17,16 @@ module AbAdmin
|
|
17
17
|
end
|
18
18
|
|
19
19
|
@page_title ||= begin
|
20
|
-
view_title =
|
21
|
-
|
22
|
-
elsif record.respond_to(:name)
|
23
|
-
record.name
|
24
|
-
end
|
25
|
-
|
20
|
+
view_title = AbAdmin.display_name(record)
|
21
|
+
|
26
22
|
page_title = []
|
27
23
|
page_title << options[:title] if options.key?(:title)
|
28
24
|
page_title << view_title
|
29
|
-
page_title << I18n.t(
|
25
|
+
page_title << I18n.t('page.title') if options[:append_title]
|
30
26
|
|
31
27
|
page_title.flatten.compact.uniq.join(options[:spliter])
|
32
28
|
end
|
33
|
-
@page_description = [I18n.t(
|
29
|
+
@page_description = [I18n.t('page.prefix'), @page_description].compact.join(' - ')
|
34
30
|
end
|
35
31
|
|
36
32
|
end
|
@@ -7,7 +7,7 @@ module AbAdmin
|
|
7
7
|
prev_id = params[:prev_id].to_i
|
8
8
|
next_id = params[:next_id].to_i
|
9
9
|
|
10
|
-
render :
|
10
|
+
render text: 'Do nothing' and return if parent_id.zero? && prev_id.zero? && next_id.zero?
|
11
11
|
|
12
12
|
if prev_id.zero? && next_id.zero?
|
13
13
|
resource.move_to_child_of resource_class.find(parent_id)
|
@@ -17,7 +17,7 @@ module AbAdmin
|
|
17
17
|
resource.move_to_left_of resource_class.find(next_id)
|
18
18
|
end
|
19
19
|
|
20
|
-
render(:
|
20
|
+
render(nothing: true)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -6,11 +6,11 @@ end
|
|
6
6
|
|
7
7
|
class Time
|
8
8
|
def formatted_datetime
|
9
|
-
I18n.l(self, :
|
9
|
+
I18n.l(self, format: '%d.%m.%Y %H:%M')
|
10
10
|
end
|
11
11
|
|
12
12
|
def formatted_date
|
13
|
-
I18n.l(self, :
|
13
|
+
I18n.l(self, format: '%d.%m.%Y')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -3,8 +3,8 @@ class String
|
|
3
3
|
#LUCENE_ESCAPE_REGEX = /(\+|-|&&|\|\||!|\(|\)|{|}|\[|\]|`|"|~|\?|:|\\)/
|
4
4
|
LUCENE_ESCAPE_REGEX = /(\+|-|&&|\|\||!|\(|\)|{|}|\[|\]|`|"|~|\?|:|\\|\s)/
|
5
5
|
KEYBOARDS = {
|
6
|
-
:
|
7
|
-
:
|
6
|
+
en: 'qwertyuiop[]asdfghjkl;\'zxcvbnm,./',
|
7
|
+
ru: 'йцукенгшщзхъфывапролджэячсмитьбю/'
|
8
8
|
}
|
9
9
|
|
10
10
|
def lucene_escape
|
data/lib/ab_admin/devise.rb
CHANGED
@@ -5,9 +5,9 @@ module AbAdmin
|
|
5
5
|
|
6
6
|
def self.config
|
7
7
|
{
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
8
|
+
controllers: {
|
9
|
+
sessions: 'ab_admin/devise/sessions',
|
10
|
+
passwords: 'ab_admin/devise/passwords'
|
11
11
|
}
|
12
12
|
}
|
13
13
|
end
|
data/lib/ab_admin/engine.rb
CHANGED
@@ -6,7 +6,7 @@ module AbAdmin
|
|
6
6
|
engine_name 'ab_admin'
|
7
7
|
|
8
8
|
initializer 'ab_admin.setup' do
|
9
|
-
::Mime::Type.register
|
9
|
+
::Mime::Type.register 'application/vnd.ms-excel', :xls
|
10
10
|
|
11
11
|
ActiveSupport.on_load :active_record do
|
12
12
|
ActiveRecord::Base.send :include, AbAdmin::CarrierWave::Glue
|