simple_form_bs5_file_input 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 439120eb0e6d62259b113e3311f1caed4f298cbd87e6e6ca33f6c9bab2ef7d81
4
- data.tar.gz: 5b12e73dc2d4e2148ca0bfb70a434af18cbe8fecf45316374cc4ad50aaba912e
3
+ metadata.gz: e3e8fedf5f192642394251e54de774c6eee4a3d0bd8aaf1743fe5764fdd08894
4
+ data.tar.gz: bcf4c4237b630ea3eda4c0aaa469e5f555c85c1003e5580272df34d77460989d
5
5
  SHA512:
6
- metadata.gz: 0a082f4b129046db5f0f3a1aa25d69f0363943105055caa6b1dbc624816d528517f861ccc1c9ff0f9ad7a2432633be7b7eab7b3ebf1aee25ece783c8403dc081
7
- data.tar.gz: 4a671fa1b1db17903a9ce3f4b79ad198027cfeca95831f53694a04e440fdf31318cada8f79270851c2ebe37756cab563c4ab878b9bc2bff3478dc18fc36186c1
6
+ metadata.gz: f72252369cf36f53ac1f5380e3140aff36e0bcc11bef09ab2f2bfc3442916d2eb48e307ecc148ca8e186fea587120009326137e8980f666b3c35a79fb8535ae8
7
+ data.tar.gz: f83dd485981568672cde5863750ef4623df3e5d729f9dc4af9a1b7c06fba4ce84187cae5481c003341a727f57b41f9e4ab9fe8fce55cd89a59db68b60085a257
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
@@ -78,7 +78,7 @@ window.inputSingleDeletableFile = {
78
78
  image = $modal.attr('data-image-result'),
79
79
  ratio = $imgContainer.attr('data-ratio');
80
80
 
81
- $imgContainer.html('<img class="js-" src="' + image + '">');
81
+ $imgContainer.html('<img class="js-image" src="' + image + '">');
82
82
 
83
83
  $image = $('img', $imgContainer);
84
84
  $image.css('opacity', 0);
@@ -100,6 +100,14 @@ window.inputSingleDeletableFile = {
100
100
  }, 100);
101
101
  },
102
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
+
103
111
  onResizeModalCancel: function (e) {
104
112
  'use strict';
105
113
  var $scope = $(e.target).parents('.js-sdfi-deletable-file');
@@ -147,8 +155,9 @@ window.inputSingleDeletableFile = {
147
155
  });
148
156
  $('.js-sdfi-deletable-file__delete-btn', $(field)).on('click', this.onFileDelete);
149
157
  $('input[type="file"]', $(field)).on('change', this.onFileSelected);
150
-
158
+
151
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);
152
161
  $('.js-sdfi-deletable-file__resize-cancel', field).on('click', this.onResizeModalCancel);
153
162
  $('.js-sdfi-deletable-file__resize-validate', field).on('click', this.onResizeModalValidate);
154
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.2".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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-andré Boissinot
8
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
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.13
112
+ rubygems_version: 3.1.4
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Simple Form BS5 File Input