simple_form_bs5_file_input 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fcf36f702c77c1551143f7db895119ff9e97556f97a931e55900e3432f402d0
4
- data.tar.gz: d0bf284ad4ff6fddd906bd6818f38a8917d46739a2b097a2479cdaede1f0c719
3
+ metadata.gz: e3e8fedf5f192642394251e54de774c6eee4a3d0bd8aaf1743fe5764fdd08894
4
+ data.tar.gz: bcf4c4237b630ea3eda4c0aaa469e5f555c85c1003e5580272df34d77460989d
5
5
  SHA512:
6
- metadata.gz: 4efe42b607e0e4a17fabe348ab84e3d95389a155889d56cec6001b76fa322411409e1999d097c4c5a941d487d1006d4905bb13fb7bb4717f65d935882af87031
7
- data.tar.gz: 78afdfc7bb77b27c7a6ccec1b7a6756f897e7256e8019b60eaed69ea037e798f41b68a3451ae8d42b7cbabc470f0edbecefeb5d31c2123b6d664ec2ddfb73e85
6
+ metadata.gz: f72252369cf36f53ac1f5380e3140aff36e0bcc11bef09ab2f2bfc3442916d2eb48e307ecc148ca8e186fea587120009326137e8980f666b3c35a79fb8535ae8
7
+ data.tar.gz: f83dd485981568672cde5863750ef4623df3e5d729f9dc4af9a1b7c06fba4ce84187cae5481c003341a727f57b41f9e4ab9fe8fce55cd89a59db68b60085a257
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_bs5_file_input (0.1.1)
4
+ simple_form_bs5_file_input (0.1.2)
5
5
  rails
6
6
  simple_form
7
7
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Noesya
3
+ Copyright (c) 2021-2023 Noesya
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -139,6 +139,17 @@ end
139
139
 
140
140
  **Simple Form Bootstrap 5 File Input** uses the I18n API to manage the texts displayed. Feel free to overwrite the keys or add languages.
141
141
 
142
+ ## Notes
143
+
144
+ ### Callbacks
145
+
146
+ When the resize feature is activated **Simple Form Bootstrap 5 File Input** uses an `after_commit` hook to resize the image. The model linked to the attachment will then be touched.
147
+ It might cause a problem because messing with others `after_commit` hooks. For example it messes with the Devise `confirmable` module, where the confirmation email is also send on after_commit.
148
+ Before Rails 7.1 after_commit is the only hook executed backward. So if you add after_commit :function1, then after_commit :function2, function2 will be executed BEFORE function1.
149
+ After Rails 7.1 after_commit follows the regular order, so function1 will be executed before function2.
150
+ So for Devise Confirmable, it must be declared AFTER the `has_one_attached_deletable` declaration if Rails version < 7.1, and declared BEFORE the `has_one_attached_deletable` declaration if Rails version >= 7.1
151
+
152
+
142
153
  ## Information
143
154
 
144
155
  ### Supported Ruby / Rails versions
@@ -49,6 +49,7 @@ window.inputSingleDeletableFile = {
49
49
  };
50
50
  } else {
51
51
  // Previewable images
52
+ $('.js-sdfi-deletable-file__infos-field', $scope).val('');
52
53
  $scope.addClass('sdfi-deletable-file--with-file');
53
54
  $('.js-sdfi-deletable-file__label', $scope).html(file.name);
54
55
  $('.js-sdfi-deletable-file__delete-field', $scope).val('');
@@ -60,6 +61,7 @@ window.inputSingleDeletableFile = {
60
61
  }
61
62
  } else {
62
63
  // Non-resizable and non-previewable files
64
+ $('.js-sdfi-deletable-file__infos-field', $scope).val('');
63
65
  $scope.addClass('sdfi-deletable-file--with-file');
64
66
  $('.js-sdfi-deletable-file__label', $scope).html(file.name);
65
67
  $('.js-sdfi-deletable-file__delete-field', $scope).val('');
@@ -76,7 +78,7 @@ window.inputSingleDeletableFile = {
76
78
  image = $modal.attr('data-image-result'),
77
79
  ratio = $imgContainer.attr('data-ratio');
78
80
 
79
- $imgContainer.html('<img class="js-" src="' + image + '">');
81
+ $imgContainer.html('<img class="js-image" src="' + image + '">');
80
82
 
81
83
  $image = $('img', $imgContainer);
82
84
  $image.css('opacity', 0);
@@ -98,6 +100,14 @@ window.inputSingleDeletableFile = {
98
100
  }, 100);
99
101
  },
100
102
 
103
+ onResizeModalRotate: function (e) {
104
+ 'use strict';
105
+ var $scope = $(e.target).parents('.js-sdfi-deletable-file'),
106
+ $imgContainer = $('.js-sdfi-sdfi-deletable-file__resize-image', $scope),
107
+ $image = $('.js-image', $imgContainer);
108
+ $image.cropper('rotate', 90);
109
+ },
110
+
101
111
  onResizeModalCancel: function (e) {
102
112
  'use strict';
103
113
  var $scope = $(e.target).parents('.js-sdfi-deletable-file');
@@ -145,8 +155,9 @@ window.inputSingleDeletableFile = {
145
155
  });
146
156
  $('.js-sdfi-deletable-file__delete-btn', $(field)).on('click', this.onFileDelete);
147
157
  $('input[type="file"]', $(field)).on('change', this.onFileSelected);
148
-
158
+
149
159
  $('.js-sdfi-deletable-file__resize', field).on('shown.bs.modal', this.onResizeModalShown);
160
+ $('.js-sdfi-deletable-file__resize-rotate', field).on('click', this.onResizeModalRotate);
150
161
  $('.js-sdfi-deletable-file__resize-cancel', field).on('click', this.onResizeModalCancel);
151
162
  $('.js-sdfi-deletable-file__resize-validate', field).on('click', this.onResizeModalValidate);
152
163
  }
@@ -68,6 +68,8 @@
68
68
  width: 0%
69
69
 
70
70
  &__resize
71
+ .modal-footer
72
+ justify-content: space-between
71
73
  .sdfi-sdfi-deletable-file__resize-image
72
74
  img
73
75
  max-width: 100%
@@ -1,6 +1,7 @@
1
1
  en:
2
2
  simple_form_bs5_file_input:
3
3
  modal_close: Close
4
+ modal_rotate: Rotate the image
4
5
  modal_title: Resize the image
5
6
  modal_validate: Validate
6
7
  replace_file: 'Change the file'
@@ -1,6 +1,7 @@
1
1
  fr:
2
2
  simple_form_bs5_file_input:
3
3
  modal_close: Fermer
4
+ modal_rotate: Tourner l'image
4
5
  modal_title: Cadrer l'image
5
6
  modal_validate: Valider
6
7
  replace_file: Remplacer le fichier
@@ -21,12 +21,16 @@ class ActiveRecord::Base
21
21
 
22
22
  # From Rails 6, ImageProcessing uses an 'auto-orient' by default to interpret the EXIF Orientation metadata.
23
23
  # We declare it in the transformations hash for Rails 5
24
- transformations = {
25
- :'auto-orient' => true,
26
- crop: "#{params['width'].round}x#{params['height'].round}+#{params['x'].round}+#{params['y'].round}",
24
+ transformations = { :'auto-orient' => true }
25
+ # Handle rotation
26
+ transformations[:rotate] = params['rotate'] if params['rotate'].present?
27
+ # Handle cropping
28
+ transformations[:crop] = "#{params['width'].round}x#{params['height'].round}+#{params['x'].round}+#{params['y'].round}"
29
+ # Finalize by repaging
30
+ transformations.merge!({
27
31
  repage: true,
28
32
  :'+' => true
29
- }
33
+ })
30
34
 
31
35
  variant = Rails::VERSION::MAJOR >= 6 ? send(name).variant(**transformations)
32
36
  : send(name).variant(combine_options: transformations)
@@ -92,12 +92,17 @@ class SingleDeletableFileInput < SimpleForm::Inputs::Base
92
92
  </div>
93
93
  </div>
94
94
  <div class="modal-footer">
95
- <button type="button" class="btn btn-sm btn-secondary js-sdfi-deletable-file__resize-cancel" data-bs-dismiss="modal">%s</button>
96
- <button type="button" class="btn btn-sm btn-primary js-sdfi-deletable-file__resize-validate">%s</button>
95
+ <button type="button" class="btn btn-sm js-sdfi-deletable-file__resize-rotate" aria-label="%s">
96
+ <i class="bi bi-arrow-clockwise"></i>
97
+ </button>
98
+ <div>
99
+ <button type="button" class="btn btn-sm btn-secondary js-sdfi-deletable-file__resize-cancel" data-bs-dismiss="modal">%s</button>
100
+ <button type="button" class="btn btn-sm btn-primary js-sdfi-deletable-file__resize-validate">%s</button>
101
+ </div>
97
102
  </div>
98
103
  </div>
99
104
  </div>
100
- </div>', modal_title, close_btn_text, resize_ratio, close_btn_text, validate_btn_text)
105
+ </div>', modal_title, close_btn_text, resize_ratio, rotate_btn_text, close_btn_text, validate_btn_text)
101
106
  end
102
107
  end
103
108
 
@@ -141,6 +146,10 @@ class SingleDeletableFileInput < SimpleForm::Inputs::Base
141
146
  I18n.t('simple_form_bs5_file_input.modal_close')
142
147
  end
143
148
 
149
+ def rotate_btn_text
150
+ I18n.t('simple_form_bs5_file_input.modal_rotate')
151
+ end
152
+
144
153
  def validate_btn_text
145
154
  I18n.t('simple_form_bs5_file_input.modal_validate')
146
155
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormBs5FileInput
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_bs5_file_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-andré Boissinot
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,7 +94,7 @@ homepage: https://github.com/noesya/simple_form_bs5_file_input
94
94
  licenses:
95
95
  - MIT
96
96
  metadata: {}
97
- post_install_message:
97
+ post_install_message:
98
98
  rdoc_options: []
99
99
  require_paths:
100
100
  - lib
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubygems_version: 3.1.4
113
- signing_key:
113
+ signing_key:
114
114
  specification_version: 4
115
115
  summary: Simple Form BS5 File Input
116
116
  test_files: []