active_admin_scoped_collection_actions 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,50 @@
1
- ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){
1
+ // Fields checked by the user with their values, as they are displayed in the dialog.
2
+ // @return [Array<Object>] [{label: 'Name', value: 'test'}, ...]
3
+ ActiveAdmin.dialogMassFieldsChanges = function(form){
4
+ const changes = [];
5
+
6
+ form.find('.mass_update_protect_fild_flag:checked').each(function() {
7
+ const flag = $(this);
8
+ const field = flag.nextAll('input, select, textarea').first();
9
+ let value;
10
+
11
+ if (field.is('select')) {
12
+ value = field.find('option:selected').map((i, option) => $(option).text().trim()).get().join(', ');
13
+ } else if (field.attr('type') === 'checkbox') {
14
+ value = field.is(':checked');
15
+ } else {
16
+ value = field.val();
17
+ }
18
+
19
+ changes.push({ label: flag.next('label').text().trim(), value: value });
20
+ });
21
+
22
+ return changes;
23
+ };
24
+
25
+ // options: {summary: {text: 'You are going to delete {count} record(s).', count: countFn},
26
+ // confirmSubmit: @see ActiveAdmin.dialogConfirmSubmit}
27
+ ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback, options){
28
+ options = options || {};
29
+ const confirmSubmit = options['confirmSubmit'];
2
30
  let html = `<form id="dialog_confirm" title="${message}"><div style="padding-right:4px;padding-left:1px;margin-right:2px"><ul>`;
3
31
  for (let name in inputs) {
4
32
  var elem, opts, wrapper;
5
33
  let type = inputs[name];
6
- if (/^(datepicker|checkbox|text)$/.test(type)) {
34
+ let klass = '';
35
+ if ($.isPlainObject(type)) {
36
+ // {type: 'text', class: 'my-widget'} - input rendered with your own class,
37
+ // so it can be turned into any widget by your own JS
38
+ [wrapper, klass, type] = Array.from(['input', type['class'] || '', type['type'] || 'text']);
39
+ } else if (/^(datepicker|checkbox|text)$/.test(type)) {
7
40
  wrapper = 'input';
41
+ klass = type === 'datepicker' ? type : '';
8
42
  } else if ($.isArray(type)) {
9
43
  [wrapper, elem, opts, type] = Array.from(['select', 'option', type, '']);
10
44
  } else {
11
45
  throw new Error(`Unsupported input type: {${name}: ${type}}`);
12
46
  }
13
47
 
14
- let klass = type === 'datepicker' ? type : '';
15
48
  html += `<li>
16
49
  <input type='checkbox' class='mass_update_protect_fild_flag' value='Y' id="mass_update_dialog_${name}" />
17
50
  <label for="mass_update_dialog_${name}"> ${name.charAt(0).toUpperCase() + name.slice(1)}</label>
@@ -43,9 +76,12 @@ ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){
43
76
 
44
77
  const form = $(html).appendTo('body');
45
78
 
79
+ const summary = options['summary'] ?
80
+ ActiveAdmin.dialogRecordsSummary(options['summary']['text'], options['summary']['count']).prependTo(form) : null;
81
+
46
82
  $('body').trigger('mass_update_modal_dialog:before_open', [form]);
47
83
 
48
- return form.dialog({
84
+ const dialog = form.dialog({
49
85
  modal: true,
50
86
  classes: { 'ui-dialog': 'ui-corner-all active_admin_dialog active_admin_dialog_mass_update_by_filter' },
51
87
  dialogClass: 'active_admin_dialog active_admin_dialog_mass_update_by_filter',
@@ -61,9 +97,18 @@ ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){
61
97
  });
62
98
  },
63
99
  buttons: {
64
- OK(e){
65
- $(e.target).closest('.ui-dialog-buttonset').html('<span>Processing. Please wait...</span>');
66
- return callback($(this).serializeObject());
100
+ OK(){
101
+ // amount of affected records is not known yet
102
+ if (form.data('waiting')) { return; }
103
+
104
+ const submit = () => {
105
+ form.dialog('widget').find('.ui-dialog-buttonset').html('<span>Processing. Please wait...</span>');
106
+ return callback(form.serializeObject());
107
+ };
108
+ const changes = ActiveAdmin.dialogMassFieldsChanges(form);
109
+ // nothing is checked - there is nothing to confirm
110
+ if (!confirmSubmit || !changes.length) { return submit(); }
111
+ return ActiveAdmin.dialogConfirmSubmit(form, confirmSubmit, changes, submit);
67
112
  },
68
113
  Cancel() {
69
114
  $('.mass_update_protect_fild_flag').off('change');
@@ -71,4 +116,11 @@ ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){
71
116
  }
72
117
  }
73
118
  });
119
+
120
+ if (summary) {
121
+ ActiveAdmin.dialogSpinnerUntil(summary, summary.data('countRequest'));
122
+ ActiveAdmin.dialogWaitFor(form, summary.data('countRequest'));
123
+ }
124
+
125
+ return dialog;
74
126
  };
@@ -0,0 +1,47 @@
1
+ // Sentence about the records the action is going to be performed on,
2
+ // e.g. "You are going to delete 100500 record(s)."
3
+ // template: text where {count} is replaced with the amount
4
+ // countFn: function returning jqXHR with {count: 100500}
5
+ // @return [jQuery] paragraph, request promise is available as .data('countRequest')
6
+ ActiveAdmin.dialogRecordsSummary = function(template, countFn){
7
+ const summary = $('<p class="dialog_records_summary"></p>');
8
+ const showCount = count => summary.text(template.replace('{count}', count));
9
+
10
+ if (!countFn) {
11
+ showCount('');
12
+ return summary.data('countRequest', $.Deferred().resolve().promise());
13
+ }
14
+
15
+ const request = countFn()
16
+ .done(data => showCount(data['count']))
17
+ .fail(() => showCount('?'));
18
+
19
+ return summary.data('countRequest', request);
20
+ };
21
+
22
+ // Shows a spinner instead of the content until the promise is settled, so the user
23
+ // never sees a half of the message.
24
+ ActiveAdmin.dialogSpinnerUntil = function(content, promise){
25
+ const spinner = $('<div class="dialog_spinner"></div>').insertBefore(content.first());
26
+
27
+ content.hide();
28
+
29
+ return promise.always(function(){
30
+ spinner.remove();
31
+ content.show();
32
+ });
33
+ };
34
+
35
+ // Keeps OK of the dialog disabled while the promise is pending, so nothing can be
36
+ // confirmed before the user sees what they confirm.
37
+ ActiveAdmin.dialogWaitFor = function(dialog, promise){
38
+ const button = dialog.dialog('widget').find('.ui-dialog-buttonset button').first();
39
+
40
+ dialog.data('waiting', true);
41
+ button.prop('disabled', true).addClass('ui-state-disabled');
42
+
43
+ return promise.always(function(){
44
+ dialog.data('waiting', false);
45
+ button.prop('disabled', false).removeClass('ui-state-disabled');
46
+ });
47
+ };
@@ -23,6 +23,45 @@
23
23
  }
24
24
  }
25
25
 
26
+ .active_admin_dialog_mass_update_by_filter, .active_admin_dialog_confirm_submit {
27
+ .dialog_records_summary {
28
+ margin: 0 0 5px 0;
29
+ }
30
+ .dialog_spinner {
31
+ display: block;
32
+ box-sizing: border-box;
33
+ width: 24px;
34
+ height: 24px;
35
+ margin: 15px auto;
36
+ border: 3px solid currentColor;
37
+ border-right-color: transparent;
38
+ border-radius: 50%;
39
+ animation: dialog_spinner_rotate 0.8s linear infinite;
40
+ }
41
+ button:disabled {
42
+ cursor: default;
43
+ opacity: 0.6;
44
+ }
45
+ }
46
+
47
+ @keyframes dialog_spinner_rotate {
48
+ to { transform: rotate(360deg); }
49
+ }
50
+
51
+ .active_admin_dialog_confirm_submit {
52
+ .dialog_confirm_submit_changes {
53
+ margin: 5px 0 0 0;
54
+
55
+ li {
56
+ display: block;
57
+ margin: 3px 0 0 0;
58
+ }
59
+ }
60
+ button {
61
+ cursor: pointer;
62
+ }
63
+ }
64
+
26
65
  .sidebar_section.panel {
27
66
  .scoped_collection_action_button {
28
67
  cursor: pointer;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_scoped_collection_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gena M.
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: '3.0'
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: '4.0'
21
+ version: 5.0.0.a
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  version: '3.0'
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
- version: '4.0'
31
+ version: 5.0.0.a
32
32
  description: Plugin for ActiveAdmin. Provides batch Update and Delete for scoped_collection
33
33
  (Filters + Scope) across all pages.
34
34
  email:
@@ -37,15 +37,11 @@ executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
- - ".github/workflows/ci.yml"
41
- - ".gitignore"
42
40
  - CHANGELOG.md
43
- - CODE_OF_CONDUCT.md
44
- - Gemfile
45
41
  - LICENSE.txt
46
42
  - README.md
47
- - Rakefile
48
- - active_admin_scoped_collection_actions.gemspec
43
+ - app/javascript/active_admin_scoped_collection_actions/dialog.js
44
+ - config/importmap.rb
49
45
  - config/locales/de.yml
50
46
  - config/locales/en.yml
51
47
  - config/locales/es.yml
@@ -57,11 +53,10 @@ files:
57
53
  - lib/active_admin_scoped_collection_actions/engine.rb
58
54
  - lib/active_admin_scoped_collection_actions/resource_extension.rb
59
55
  - lib/active_admin_scoped_collection_actions/version.rb
60
- - screenshots/pupup.png
61
- - screenshots/sidebar.png
62
- - tasks/test.rake
63
56
  - vendor/assets/javascripts/active_admin_scoped_collection_actions.js
57
+ - vendor/assets/javascripts/lib/dialog_confirm_submit.js
64
58
  - vendor/assets/javascripts/lib/dialog_mass_fields_update.js
59
+ - vendor/assets/javascripts/lib/dialog_records_summary.js
65
60
  - vendor/assets/stylesheets/active_admin_scoped_collection_actions.scss
66
61
  homepage: https://github.com/activeadmin-plugins/active_admin_scoped_collection_actions
67
62
  licenses:
@@ -74,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
69
  requirements:
75
70
  - - ">="
76
71
  - !ruby/object:Gem::Version
77
- version: 3.1.0
72
+ version: '3.3'
78
73
  required_rubygems_version: !ruby/object:Gem::Requirement
79
74
  requirements:
80
75
  - - ">="
81
76
  - !ruby/object:Gem::Version
82
77
  version: '0'
83
78
  requirements: []
84
- rubygems_version: 3.7.1
79
+ rubygems_version: 3.6.9
85
80
  specification_version: 4
86
81
  summary: scoped_collection actions extension for ActiveAdmin
87
82
  test_files: []
@@ -1,87 +0,0 @@
1
- name: CI
2
- on:
3
- pull_request:
4
- push:
5
- branches: [master]
6
-
7
- permissions:
8
- contents: read
9
- pages: write
10
- id-token: write
11
-
12
- jobs:
13
- test:
14
- name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }}
15
- runs-on: ubuntu-latest
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: ['3.2', '3.3', '3.4']
20
- rails: ['7.1.0', '7.2.0', '8.0.0']
21
- activeadmin: ['3.2.0', '3.3.0', '3.4.0', '3.5.0']
22
- exclude:
23
- - rails: '8.0.0'
24
- activeadmin: '3.2.0'
25
- env:
26
- RAILS: ${{ matrix.rails }}
27
- AA: ${{ matrix.activeadmin }}
28
- steps:
29
- - uses: actions/checkout@v4
30
- - uses: ruby/setup-ruby@v1
31
- with:
32
- ruby-version: ${{ matrix.ruby }}
33
- bundler-cache: true
34
- - name: Run tests
35
- run: bundle exec rspec spec
36
-
37
- - name: Generate badge.json
38
- if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0'
39
- run: |
40
- LAST_RUN="coverage/.last_run.json"
41
- if [ ! -f "$LAST_RUN" ]; then
42
- mkdir -p badge
43
- echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json
44
- exit 0
45
- fi
46
- PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)")
47
- PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')")
48
- if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen"
49
- elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green"
50
- elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow"
51
- else COLOR="red"; fi
52
- mkdir -p badge
53
- echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json
54
-
55
- - name: Upload badge artifact
56
- if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0'
57
- uses: actions/upload-artifact@v4
58
- with:
59
- name: coverage-badge
60
- path: badge
61
-
62
- deploy-coverage:
63
- needs: test
64
- if: github.ref == 'refs/heads/master' && github.event_name == 'push'
65
- runs-on: ubuntu-latest
66
- environment:
67
- name: github-pages
68
- url: ${{ steps.deployment.outputs.page_url }}
69
-
70
- steps:
71
- - name: Download coverage badge
72
- uses: actions/download-artifact@v4
73
- with:
74
- name: coverage-badge
75
- path: coverage
76
-
77
- - name: Setup Pages
78
- uses: actions/configure-pages@v5
79
-
80
- - name: Upload Pages artifact
81
- uses: actions/upload-pages-artifact@v3
82
- with:
83
- path: coverage
84
-
85
- - name: Deploy to GitHub Pages
86
- id: deployment
87
- uses: actions/deploy-pages@v4
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /.idea
11
- .DS_Store
12
- /spec/rails
13
- .versions.conf
14
- vendor/bundle
15
- bin
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile DELETED
@@ -1,21 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- default_rails_version = '7.1.0'
5
- default_activeadmin_version = '3.5.0'
6
-
7
- gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}"
8
- gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}"
9
- gem 'sprockets-rails'
10
- gem 'sass-rails'
11
-
12
- group :test do
13
- gem 'simplecov', require: false
14
- gem 'rspec-rails'
15
- gem 'sqlite3', '~> 2.0'
16
- gem 'database_cleaner'
17
- gem 'capybara'
18
- gem 'cuprite'
19
- gem 'draper'
20
- gem 'webrick', require: false
21
- end
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require "bundler"
2
- require 'rake'
3
- Bundler.setup
4
- Bundler::GemHelper.install_tasks
5
-
6
- # Import all our rake tasks
7
- FileList['tasks/**/*.rake'].each { |task| import task }
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- require File.expand_path('../lib/active_admin_scoped_collection_actions/version', __FILE__)
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "active_admin_scoped_collection_actions"
6
- spec.version = ActiveAdminScopedCollectionActions::VERSION
7
- spec.authors = ["Gena M."]
8
- spec.email = ["workgena@gmail.com"]
9
-
10
- spec.summary = %q{scoped_collection actions extension for ActiveAdmin}
11
- spec.description = %q{Plugin for ActiveAdmin. Provides batch Update and Delete for scoped_collection (Filters + Scope) across all pages.}
12
- spec.homepage = "https://github.com/activeadmin-plugins/active_admin_scoped_collection_actions"
13
- spec.license = "MIT"
14
-
15
- spec.required_ruby_version = '>= 3.1.0'
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_dependency "activeadmin", ">= 3.0", "< 4.0"
23
- end
Binary file
Binary file
data/tasks/test.rake DELETED
@@ -1,14 +0,0 @@
1
- desc 'Creates a test rails app for the specs to run against'
2
- task :setup do
3
- require 'rails/version'
4
-
5
- rails_new_args = %w[
6
- --skip-turbolinks
7
- --skip-spring
8
- --skip-bootsnap
9
- -m
10
- spec/support/rails_template.rb
11
- ].join(' ')
12
-
13
- system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} #{rails_new_args}"
14
- end