binda 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -6
  3. data/app/assets/javascripts/binda/components/fileupload.js +38 -4
  4. data/app/assets/javascripts/binda/dist/binda.bundle.js +26 -3
  5. data/app/assets/stylesheets/binda/components/fileupload.scss +11 -2
  6. data/app/controllers/binda/audios_controller.rb +71 -0
  7. data/app/controllers/binda/users/audios_controller.rb +71 -0
  8. data/app/controllers/concerns/binda/fieldable_helpers.rb +26 -6
  9. data/app/models/binda/audio.rb +8 -0
  10. data/app/models/binda/field_setting.rb +8 -3
  11. data/app/models/concerns/binda/fieldable_association_helpers.rb +51 -0
  12. data/app/models/concerns/binda/fieldable_associations.rb +3 -1
  13. data/app/uploaders/binda/audio/audio_uploader.rb +27 -0
  14. data/app/views/binda/fieldable/_form_item_audio.html.erb +33 -0
  15. data/app/views/binda/fieldable/_form_item_date.html.erb +1 -1
  16. data/app/views/binda/fieldable/_form_item_image.html.erb +2 -2
  17. data/app/views/binda/fieldable/_form_item_relation.html.erb +2 -2
  18. data/app/views/binda/fieldable/_form_item_string.html.erb +1 -1
  19. data/app/views/binda/fieldable/_form_item_text.html.erb +1 -1
  20. data/app/views/binda/fieldable/_form_item_video.html.erb +2 -3
  21. data/app/views/binda/fieldable/_form_section.html.erb +5 -66
  22. data/app/views/binda/fieldable/_form_section_repeater.html.erb +9 -61
  23. data/config/initializers/simple_form__fileupload.rb +18 -7
  24. data/config/locales/en.yml +1 -0
  25. data/config/routes.rb +6 -2
  26. data/db/migrate/1_create_binda_tables.rb +1 -0
  27. data/lib/binda/version.rb +1 -1
  28. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 380a6ee6ba0e7fad66075ccd4f6d35f79b7946d3
4
- data.tar.gz: 04d50e53a323cff2202b6ea28fc422eed13d625c
3
+ metadata.gz: 7306f9f3f6f6d3c51e9bf2375d21a6ab8a3bb5db
4
+ data.tar.gz: 5bda27c8b2065709e5bbd092fc0e4d0931f91785
5
5
  SHA512:
6
- metadata.gz: 668e07be1cf3f3c424b79d48c0dbd17698a6f7919870dd0121b8efde2cb9e327f01517f4b5702284dfb31f6fc8960bcef1f4e160be96bd832d046f86199d6f52
7
- data.tar.gz: c5d557f08401dd999c81162bc7cad8f375b75f079d0ff22c75d824ca6e9840de555d51e0a58661ab6415435919f1dbde3dcb072aaa74e651e9bf0bd877632904
6
+ metadata.gz: 76deea4419854210f65bdb53a2f5e819c22ac25ace53e2a88a7030aebcfb97a62f4be81990f8cb484a7851c464f4d64b1616f116dacf1b31407a50b8d80441d2
7
+ data.tar.gz: 4dd2f2a7d51f343e1886499b3b1fcb3ce175935a23c12d55626188a2d1413c868e48ec9f81ca6faa8333d41e9320bfddebf498a01af7c6073cb61e6f546c10a3
data/README.md CHANGED
@@ -365,6 +365,7 @@ Here below a list of field types available and their use:
365
365
  | text | Store a text. TinyMCE let's you format the text as you like. | [source](http://www.rubydoc.info/gems/binda/Binda/Text) |
366
366
  | image | Store image. | [source](http://www.rubydoc.info/gems/binda/Binda/Image) |
367
367
  | video | Store video. | [source](http://www.rubydoc.info/gems/binda/Binda/Video) |
368
+ | audio | Store audio. | [source](http://www.rubydoc.info/gems/binda/Binda/Audio) |
368
369
  | date | Store a date. | [source](http://www.rubydoc.info/gems/binda/Binda/Date) |
369
370
  | radio | Select one choice amongst a custom set. | [source](http://www.rubydoc.info/gems/binda/Binda/Radio) |
370
371
  | selection | Select one or more choices amongst a custom set. | [source](http://www.rubydoc.info/gems/binda/Binda/Selection) |
@@ -441,7 +442,10 @@ You can retrieve field content from a instance of `Binda::Component`, `Binda::Bo
441
442
  |`get_image_mime_type`| Returns the mime type of the image. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_mime_type) |
442
443
  |`has_video`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_video) |
443
444
  |`get_video_url`| Returns the url of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_video_url) |
444
- |`get_video_path`| Returns the path of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_path) |
445
+ |`get_video_path`| Returns the path of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_video_path) |
446
+ |`has_audio`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_audio) |
447
+ |`get_audio_url`| Returns the url of the audio. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_audio_url) |
448
+ |`get_audio_path`| Returns the path of the audio. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_audio_path) |
445
449
  |`has_date`| Returns `true/false` | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_date) |
446
450
  |`get_date`| Returns the date in `datetime` format. Use [`strftime`](https://apidock.com/rails/ActiveSupport/TimeWithZone/strftime) to change date format. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_date) |
447
451
  |`has_repeaters`| Returns `true/false`| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_repeaters) |
@@ -577,8 +581,6 @@ To change appereance and behaviour of the page add your styles to `app/assets/st
577
581
 
578
582
  # Field settings and field groups
579
583
 
580
- ---
581
-
582
584
  ## Orphans
583
585
 
584
586
  Sometime playing with Rails console you might end up creating orphans, which basically are components without a field setting parent. They might cause errors in some queries and they hard to track down.
@@ -881,16 +883,21 @@ npm install --global geckodriver
881
883
  Some specs are run against the database. If you haven't installed Binda on the dummy application yet run:
882
884
 
883
885
  ```bash
884
- rails db:migrate RAILS_ENV=test
886
+ RAILS_ENV=test rails db:migrate
885
887
  ```
886
888
 
887
889
  The above command might generate an error. This is probably because you have previously installed Binda and the generator finds migration both in `binda/db/migrate` and `binda/spec/dummy/db/migrate`. To solve the issue, remove the `spec/dummy/db/migrate` folder and run the previous command again. Here below the oneliner (be aware that this destroy both development and test databases of the dummy app):
888
890
 
889
891
  ```bash
890
- rm -rf spec/dummy/db/migrate && rails db:drop && rails db:create && rails generate binda:install && rails db:migrate RAILS_ENV=test
892
+ cd spec/dummy && rm -rf db/migrate && rails db:drop && rails db:create && RAILS_ENV=test rails db:migrate
893
+ ```
894
+
895
+ In case you are creating new migrations or modifing the default one:
896
+
897
+ ```bash
898
+ cd spec/dummy && rm -r db/schema.rb && rails db:drop && rails db:create && RAILS_ENV=test rails db:migrate
891
899
  ```
892
900
 
893
- In case you are creating new migrations or modifing the default one, consider running the above command to refresh the `schema.rb` file while updating both databases.
894
901
 
895
902
  If in the future you need to clean your dummy app code, simply run:
896
903
 
@@ -116,6 +116,8 @@ function updateFileuploadField(data, id) {
116
116
  setup_image_preview(data, id);
117
117
  } else if (data.type == "video") {
118
118
  setup_video_preview(data, id);
119
+ } else if (data.type == "audio") {
120
+ setup_audio_preview(data, id);
119
121
  } else {
120
122
  alert("Something went wrong. No preview has been received.");
121
123
  }
@@ -183,14 +185,15 @@ function setup_image_preview(data, id) {
183
185
  function setup_video_preview(data, id) {
184
186
  let $parent = $("#fileupload-" + id);
185
187
  let $preview = $("#fileupload-" + id + " .fileupload--preview");
188
+ let uploadedClass = "fileupload--preview--uploaded";
186
189
 
187
190
  $preview
188
- .removeClass("fileupload--preview--uploaded")
191
+ .removeClass(uploadedClass)
189
192
  .find("video")
190
193
  .attr("id", "video-" + id)
191
194
  .find("source")
192
195
  .attr("src", data.url)
193
- .attr("type", "video/" + data.ext);
196
+ .attr("type", data.contentType);
194
197
 
195
198
  // If video source isn't blank load it (consider that a video tag is always present)
196
199
  if (typeof $preview.find("video source").attr("src") != undefined) {
@@ -201,11 +204,42 @@ function setup_video_preview(data, id) {
201
204
  }
202
205
 
203
206
  // Remove and add class to trigger css animation
207
+ $preview.addClass(uploadedClass);
208
+
209
+ // Update details
210
+ $parent.find(".fileupload--filesize").text(data.size);
211
+ $parent.find(".fileupload--filename").text(data.name);
212
+ $parent.find(".fileupload--previewlink a").attr("href", data.url);
213
+ }
214
+
215
+ function setup_audio_preview(data, id) {
216
+ let $parent = $("#fileupload-" + id);
217
+ let $preview = $("#fileupload-" + id + " .fileupload--preview");
204
218
  let uploadedClass = "fileupload--preview--uploaded";
205
- $preview.removeClass(uploadedClass).addClass(uploadedClass);
219
+
220
+ $preview
221
+ .removeClass(uploadedClass)
222
+ .find("audio")
223
+ .attr("id", "audio-" + id)
224
+ .find("source")
225
+ .attr("src", data.url)
226
+ .attr("type", data.contentType);
227
+
228
+ // If video source isn't blank load it (consider that a video tag is always present)
229
+ if (typeof $preview.find("audio source").attr("src") != undefined) {
230
+ $preview
231
+ .find("audio")
232
+ .get(0)
233
+ .load();
234
+ }
235
+
236
+ // Remove and add class to trigger css animation
237
+ $preview
238
+ .addClass(uploadedClass)
239
+ .addClass("fileupload--preview--hidden")
206
240
 
207
241
  // Update details
208
242
  $parent.find(".fileupload--filesize").text(data.size);
209
243
  $parent.find(".fileupload--filename").text(data.name);
210
- $parent.find(".fileupload--videolink a").attr("href", data.url);
244
+ $parent.find(".fileupload--previewlink a").attr("href", data.url);
211
245
  }
@@ -681,6 +681,8 @@ function updateFileuploadField(data, id) {
681
681
  setup_image_preview(data, id);
682
682
  } else if (data.type == "video") {
683
683
  setup_video_preview(data, id);
684
+ } else if (data.type == "audio") {
685
+ setup_audio_preview(data, id);
684
686
  } else {
685
687
  alert("Something went wrong. No preview has been received.");
686
688
  }
@@ -739,8 +741,9 @@ function setup_image_preview(data, id) {
739
741
  function setup_video_preview(data, id) {
740
742
  var $parent = $("#fileupload-" + id);
741
743
  var $preview = $("#fileupload-" + id + " .fileupload--preview");
744
+ var uploadedClass = "fileupload--preview--uploaded";
742
745
 
743
- $preview.removeClass("fileupload--preview--uploaded").find("video").attr("id", "video-" + id).find("source").attr("src", data.url).attr("type", "video/" + data.ext);
746
+ $preview.removeClass(uploadedClass).find("video").attr("id", "video-" + id).find("source").attr("src", data.url).attr("type", data.contentType);
744
747
 
745
748
  // If video source isn't blank load it (consider that a video tag is always present)
746
749
  if (_typeof($preview.find("video source").attr("src")) != undefined) {
@@ -748,13 +751,33 @@ function setup_video_preview(data, id) {
748
751
  }
749
752
 
750
753
  // Remove and add class to trigger css animation
754
+ $preview.addClass(uploadedClass);
755
+
756
+ // Update details
757
+ $parent.find(".fileupload--filesize").text(data.size);
758
+ $parent.find(".fileupload--filename").text(data.name);
759
+ $parent.find(".fileupload--previewlink a").attr("href", data.url);
760
+ }
761
+
762
+ function setup_audio_preview(data, id) {
763
+ var $parent = $("#fileupload-" + id);
764
+ var $preview = $("#fileupload-" + id + " .fileupload--preview");
751
765
  var uploadedClass = "fileupload--preview--uploaded";
752
- $preview.removeClass(uploadedClass).addClass(uploadedClass);
766
+
767
+ $preview.removeClass(uploadedClass).find("audio").attr("id", "audio-" + id).find("source").attr("src", data.url).attr("type", data.contentType);
768
+
769
+ // If video source isn't blank load it (consider that a video tag is always present)
770
+ if (_typeof($preview.find("audio source").attr("src")) != undefined) {
771
+ $preview.find("audio").get(0).load();
772
+ }
773
+
774
+ // Remove and add class to trigger css animation
775
+ $preview.addClass(uploadedClass).addClass("fileupload--preview--hidden");
753
776
 
754
777
  // Update details
755
778
  $parent.find(".fileupload--filesize").text(data.size);
756
779
  $parent.find(".fileupload--filename").text(data.name);
757
- $parent.find(".fileupload--videolink a").attr("href", data.url);
780
+ $parent.find(".fileupload--previewlink a").attr("href", data.url);
758
781
  }
759
782
 
760
783
  /***/ }),
@@ -47,7 +47,7 @@
47
47
  }
48
48
  }
49
49
 
50
- .fileupload--dashboard {
50
+ .fileupload--field {
51
51
  float: left;
52
52
 
53
53
  .control-label-wrap {
@@ -55,6 +55,10 @@
55
55
  }
56
56
  }
57
57
 
58
+ .fileupload--dashboard {
59
+ float: left;
60
+ }
61
+
58
62
  .fileupload input {
59
63
  position: absolute;
60
64
  z-index: -1;
@@ -112,10 +116,15 @@
112
116
  display: none;
113
117
  }
114
118
 
115
- .standard-form--video .fileupload--dimension {
119
+ .standard-form--video .fileupload--dimension,
120
+ .standard-form--audio .fileupload--dimension {
116
121
  display: none;
117
122
  }
118
123
 
119
124
  .standard-form--image .fileupload--videolink {
120
125
  display: none;
121
126
  }
127
+
128
+ .fileupload--preview--hidden {
129
+ display: none;
130
+ }
@@ -0,0 +1,71 @@
1
+ require_dependency "binda/application_controller"
2
+
3
+ module Binda
4
+ class AudiosController < ApplicationController
5
+ before_action :set_audio, only: [:show, :edit, :update, :destroy, :remove_audio]
6
+
7
+ # GET /audios
8
+ def index
9
+ @audios = Audio.all
10
+ end
11
+
12
+ # GET /audios/1
13
+ def show
14
+ end
15
+
16
+ # GET /audios/new
17
+ def new
18
+ @audio = Audio.new
19
+ end
20
+
21
+ # GET /audios/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /audios
26
+ def create
27
+ @audio = Audio.new(audio_params)
28
+
29
+ if @audio.save
30
+ redirect_to audio_path( @audio.id ), notice: 'Audio was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /audios/1
37
+ def update
38
+ if @audio.update(audio_params)
39
+ redirect_to audio_path( @audio.id ), notice: 'Audio was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /audios/1
46
+ def destroy
47
+ @audio.destroy
48
+ redirect_to audios_url, notice: 'Audio was successfully destroyed.'
49
+ end
50
+
51
+ def remove_audio
52
+ @audio.remove_audio!
53
+ if @audio.save
54
+ head :ok
55
+ else
56
+ render json: @audio.errors.full_messages, status: 400
57
+ end
58
+ end
59
+
60
+ private
61
+ # Use callbacks to share common setup or constraints between actions.
62
+ def set_audio
63
+ @audio = Audio.find(params[:id])
64
+ end
65
+
66
+ # Only allow a trusted parameter "white list" through.
67
+ def audio_params
68
+ params.require(:audio).permit( :audio, :name )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,71 @@
1
+ require_dependency "binda/application_controller"
2
+
3
+ module Binda
4
+ class AudiosController < ApplicationController
5
+ before_action :set_audio, only: [:show, :edit, :update, :destroy, :remove_audio]
6
+
7
+ # GET /audios
8
+ def index
9
+ @audios = Audio.all
10
+ end
11
+
12
+ # GET /audios/1
13
+ def show
14
+ end
15
+
16
+ # GET /audios/new
17
+ def new
18
+ @audio = Audio.new
19
+ end
20
+
21
+ # GET /audios/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /audios
26
+ def create
27
+ @audio = Audio.new(audio_params)
28
+
29
+ if @audio.save
30
+ redirect_to audio_path( @audio.id ), notice: 'Audio was successfully created.'
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ # PATCH/PUT /audios/1
37
+ def update
38
+ if @audio.update(audio_params)
39
+ redirect_to audio_path( @audio.id ), notice: 'Audio was successfully updated.'
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ # DELETE /audios/1
46
+ def destroy
47
+ @audio.destroy
48
+ redirect_to audios_url, notice: 'Audio was successfully destroyed.'
49
+ end
50
+
51
+ def remove_audio
52
+ @audio.remove_audio!
53
+ if @audio.save
54
+ head :ok
55
+ else
56
+ render json: @audio.errors.full_messages, status: 400
57
+ end
58
+ end
59
+
60
+ private
61
+ # Use callbacks to share common setup or constraints between actions.
62
+ def set_audio
63
+ @audio = Audio.find(params[:id])
64
+ end
65
+
66
+ # Only allow a trusted parameter "white list" through.
67
+ def audio_params
68
+ params.require(:audio).permit( :audio, :name )
69
+ end
70
+ end
71
+ end
@@ -9,6 +9,7 @@ module Binda
9
9
  strings_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :content ],
10
10
  images_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image, :image_cache ],
11
11
  videos_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :video, :video_cache ],
12
+ audios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :audio, :audio_cache ],
12
13
  dates_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :date ],
13
14
  galleries_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id ],
14
15
  radios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :choice_ids ],
@@ -20,6 +21,7 @@ module Binda
20
21
  strings_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :content ],
21
22
  images_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image, :image_cache ],
22
23
  videos_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :video, :video_cache ],
24
+ audios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :audio, :audio_cache ],
23
25
  dates_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :date ],
24
26
  galleries_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id ],
25
27
  relations_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, dependent_component_ids: [], dependent_board_ids: [] ],
@@ -43,9 +45,11 @@ module Binda
43
45
  {categories_attributes: [ :id, :category_id ]},
44
46
  {images_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image, :image_cache ]},
45
47
  {videos_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :video, :video_cache ]},
48
+ {audios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :audio, :audio_cache ]},
46
49
  {repeaters_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id,
47
50
  images_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :image, :image_cache ],
48
- videos_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :video, :video_cache ]]})
51
+ videos_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :video, :video_cache ],
52
+ audios_attributes: [ :id, :field_setting_id, :fieldable_type, :fieldable_id, :audio, :audio_cache ]]})
49
53
  end
50
54
 
51
55
  # Uploads a details for a fieldable instance (component or board)
@@ -70,14 +74,14 @@ module Binda
70
74
  # Therefore get the latest uploaded asset
71
75
  asset = Asset.order('updated_at').last
72
76
 
73
- if asset.image.present? && asset.video.present?
74
- raise "The record Binda::Asset with id=#{asset.id} has both image and video attached. This might have been caused by updating the record outside Binda's interface. Please make sure this record has either an image or a video."
75
- elsif asset.image.present?
77
+ if asset.image.present?
76
78
  return_image_details(asset)
77
79
  elsif asset.video.present?
78
80
  return_video_details(asset)
81
+ elsif asset.audio.present?
82
+ return_audio_details(asset)
79
83
  else
80
- raise "The record Binda::Asset with id=#{asset.id} doesn't have any image or video attached. This might be due to a bug. Please report it in Binda official Github page."
84
+ raise "The record Binda::Asset with id=#{asset.id} doesn't have any image, video or audio attached. This might be due to a bug. Please report it in Binda official Github page."
81
85
  end
82
86
  end
83
87
 
@@ -117,7 +121,23 @@ module Binda
117
121
  name: asset.video_identifier,
118
122
  size: "#{bytes_to_megabytes( asset.video.size )}MB",
119
123
  url: asset.video.url,
120
- ext: asset.video.file.extension.downcase
124
+ contentType: asset.content_type
125
+ }
126
+ end
127
+
128
+
129
+ # Return audio details
130
+ #
131
+ # This helper is used internally by the `upload_details` method
132
+ # to retrieve and return the necessary details to be displayed on
133
+ # the editor.
134
+ def return_audio_details asset
135
+ return {
136
+ type: 'audio',
137
+ name: asset.audio_identifier,
138
+ size: "#{bytes_to_megabytes( asset.audio.size )}MB",
139
+ url: asset.audio.url,
140
+ contentType: asset.content_type
121
141
  }
122
142
  end
123
143
 
@@ -0,0 +1,8 @@
1
+ module Binda
2
+ # This class provides support for uploading videos.
3
+ class Audio < Asset
4
+
5
+ mount_uploader :audio, AudioUploader
6
+
7
+ end
8
+ end
@@ -6,7 +6,7 @@ module Binda
6
6
  # An array of all classes which represent fields associated to Binda::FieldSetting
7
7
  # This definition must stay on the top of the file
8
8
  def self.get_field_classes
9
- %w( String Text Date Image Video Repeater Radio Selection Checkbox Relation )
9
+ %w( String Text Date Image Video Audio Repeater Radio Selection Checkbox Relation )
10
10
  end
11
11
 
12
12
  # ASSOCIATIONS
@@ -27,6 +27,7 @@ module Binda
27
27
  has_many :assets, as: :fieldable
28
28
  has_many :images, as: :fieldable
29
29
  has_many :videos, as: :fieldable
30
+ has_many :audios, as: :fieldable
30
31
  has_many :repeaters, as: :fieldable
31
32
  has_many :radios, as: :fieldable
32
33
  has_many :selections, as: :fieldable
@@ -48,6 +49,7 @@ module Binda
48
49
  has_many :assets, dependent: :destroy
49
50
  has_many :images, dependent: :destroy
50
51
  has_many :videos, dependent: :destroy
52
+ has_many :audios, dependent: :destroy
51
53
 
52
54
  # We don't want to run callbacks for choices!
53
55
  # If you run a callback the last choice will throw a error
@@ -59,7 +61,7 @@ module Binda
59
61
  has_and_belongs_to_many :accepted_structures, class_name: 'Binda::Structure'
60
62
 
61
63
  accepts_nested_attributes_for :accepted_structures, :texts, :strings, :dates, :galleries,
62
- :assets, :images, :videos, :repeaters, :radios, :selections,
64
+ :assets, :images, :videos, :audios, :repeaters, :radios, :selections,
63
65
  :checkboxes, :relations, :choices, allow_destroy: true, reject_if: :is_rejected
64
66
 
65
67
  # Sets the validation rules to accept and save an attribute
@@ -78,12 +80,12 @@ module Binda
78
80
 
79
81
  after_save do
80
82
  add_choice_if_allow_null_is_false
83
+ create_field_instances
81
84
  end
82
85
 
83
86
  after_create do
84
87
  self.class.reset_field_settings_array
85
88
  convert_allow_null__nil_to_false
86
- create_field_instances
87
89
  set_default_position
88
90
  end
89
91
 
@@ -249,7 +251,10 @@ module Binda
249
251
  # A similar script runs after saving components and boards which makes sure
250
252
  # a field instance is always present no matter if the component has been created
251
253
  # before the field setting or the other way around.
254
+ #
255
+ # TODO this MUST be optimized
252
256
  def create_field_instances
257
+ FieldSetting.remove_orphan_fields
253
258
  # Get the structure
254
259
  structure = self.structures.includes(:board, components: [:repeaters]).first
255
260
  structure.components.each do |component|
@@ -241,6 +241,57 @@ module Binda
241
241
  end
242
242
  end
243
243
 
244
+
245
+ # Check if the field has an attached audio
246
+ #
247
+ # @param field_slug [string] The slug of the field setting
248
+ # @return [boolean]
249
+ def has_audio(field_slug)
250
+ obj = self.audios.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
251
+ # Alternative query
252
+ # obj = Image.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first
253
+ raise ArgumentError, "There isn't any audio associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
254
+ return obj.audio.present?
255
+ end
256
+
257
+ # Get the audio url based on the size provided,
258
+ # default is Carrierwave default (usually the real size)
259
+ #
260
+ # @param field_slug [string] The slug of the field setting
261
+ # @param size [string] The size. It can be 'thumb' 200x200 cropped,
262
+ # 'medium' 700x700 max size, 'large' 1400x1400 max size, or blank
263
+ # @return [string] The url of the audio
264
+ def get_audio_url(field_slug)
265
+ get_audio_info( field_slug, 'url' )
266
+ end
267
+
268
+ # Get the audio path based on the size provided,
269
+ # default is Carrierwave default (usually the real size)
270
+ #
271
+ # @param field_slug [string] The slug of the field setting
272
+ # @param size [string] The size. It can be 'thumb' 200x200 cropped,
273
+ # 'medium' 700x700 max size, 'large' 1400x1400 max size, or blank
274
+ # @return [string] The url of the audio
275
+ def get_audio_path(field_slug)
276
+ get_audio_info( field_slug, 'path' )
277
+ end
278
+
279
+ # Get the object related to that field setting
280
+ #
281
+ # @param field_slug [string] The slug of the field setting
282
+ # @param info [string] String of the info to be retrieved
283
+ # @return [string] The info requested if present
284
+ # @return [boolean] Returns false if no info is found or if image isn't found
285
+ def get_audio_info(field_slug, info)
286
+ obj = self.audios.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
287
+ # Alternative query
288
+ # obj = audio.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first
289
+ raise ArgumentError, "There isn't any audio associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
290
+ if obj.audio.present?
291
+ obj.audio.send(info)
292
+ end
293
+ end
294
+
244
295
  # Check if the field has an attached date
245
296
  #
246
297
  # @param field_slug [string] The slug of the field setting
@@ -25,6 +25,7 @@ module Binda
25
25
  has_many :assets, as: :fieldable, dependent: :delete_all
26
26
  has_many :images, as: :fieldable, dependent: :delete_all
27
27
  has_many :videos, as: :fieldable, dependent: :delete_all
28
+ has_many :audios, as: :fieldable, dependent: :delete_all
28
29
  has_many :radios, as: :fieldable, dependent: :delete_all
29
30
  has_many :selections, as: :fieldable, dependent: :delete_all
30
31
  has_many :checkboxes, as: :fieldable, dependent: :delete_all
@@ -52,7 +53,7 @@ module Binda
52
53
  source: :owner
53
54
 
54
55
 
55
- accepts_nested_attributes_for :texts, :strings, :dates, :assets, :images, :videos, :galleries, :repeaters, :radios, :selections, :checkboxes, :relations, allow_destroy: true
56
+ accepts_nested_attributes_for :texts, :strings, :dates, :assets, :images, :videos, :audios, :galleries, :repeaters, :radios, :selections, :checkboxes, :relations, allow_destroy: true
56
57
 
57
58
  validates_associated :texts
58
59
  validates_associated :strings
@@ -60,6 +61,7 @@ module Binda
60
61
  validates_associated :assets
61
62
  validates_associated :images
62
63
  validates_associated :videos
64
+ validates_associated :audios
63
65
  validates_associated :repeaters
64
66
  validates_associated :radios
65
67
  validates_associated :selections
@@ -0,0 +1,27 @@
1
+ module Binda
2
+ class Audio::AudioUploader < CarrierWave::Uploader::Base
3
+
4
+ process :register_details
5
+
6
+ # Override the directory where uploaded files will be stored.
7
+ # This is a sensible default for uploaders that are meant to be mounted:
8
+ def store_dir
9
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
10
+ end
11
+
12
+ # Add a white list of extensions which are allowed to be uploaded.
13
+ # For images you might use something like this:
14
+ def extension_whitelist
15
+ %w(mp3 m4a m4b ra ram wav ogg oga mid midi wma wax mka)
16
+ end
17
+
18
+ # @see https://github.com/carrierwaveuploader/carrierwave/wiki/how-to:-store-the-uploaded-file-size-and-content-type
19
+ def register_details
20
+ if file && model
21
+ model.content_type = file.content_type if file.content_type
22
+ model.file_size = file.size
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ <div id="standard-form--audio-<%= field_setting.id %>" class="standard-form--audio form-item">
2
+ <div id="fileupload-<%= ff.object.id %>"
3
+ class="fileupload form-group"
4
+ data-message="<%= t('binda.upload_loading_message') %>"
5
+ data-error="<%= t('binda.upload_error_message')%>">
6
+
7
+ <p class="control-label"><%= field_setting.name %></p>
8
+
9
+ <div class="fileupload--field">
10
+
11
+ <%= ff.input :audio,
12
+ label: "<i class=\"fa fa-upload\" aria-hidden=\"true\"></i> #{t('binda.choose_file_button')}".html_safe,
13
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
14
+ url: url_for([ff.object, action: :remove_audio]).html_safe,
15
+ object: ff.object,
16
+ wrapper: false,
17
+ input_html: {
18
+ class: 'form-item--audio--uploader',
19
+ 'data-url': url_for([@instance.structure, @instance, action: :upload]),
20
+ 'data-id': ff.object.id,
21
+ } %>
22
+
23
+ </div>
24
+
25
+ <%= ff.input :audio_cache, as: :hidden %>
26
+ <%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
27
+ <%= ff.input :id, as: :hidden, input_html: { value: ff.object.id } %>
28
+ <%= ff.input :fieldable_id, as: :hidden %>
29
+ <%= ff.input :fieldable_type, as: :hidden %>
30
+ <div class="clearfix"></div>
31
+
32
+ </div>
33
+ </div>
@@ -3,7 +3,7 @@
3
3
  as: :date,
4
4
  start_year: Date.today.year - 200,
5
5
  end_year: Date.today.year + 200,
6
- hint: field_setting.description,
6
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
7
7
  label: field_setting.name,
8
8
  input_html: { class: 'select2-item' } %>
9
9
  <%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
@@ -7,10 +7,10 @@
7
7
  <%= field_setting.name %>
8
8
  </p>
9
9
  <% image = ff.object.image.thumb.url if ff.object.image.present? %>
10
- <div class="fileupload--dashboard">
10
+ <div class="fileupload--field">
11
11
  <%= ff.input :image,
12
12
  label: "<i class=\"fa fa-upload\" aria-hidden=\"true\"></i> #{t('binda.choose_file_button')}".html_safe,
13
- hint: field_setting.description,
13
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
14
14
  url: url_for([ff.object, action: :remove_image]).html_safe,
15
15
  object: ff.object,
16
16
  wrapper: false,
@@ -7,7 +7,7 @@
7
7
  as: :select,
8
8
  input_html: { multiple: true, class: 'select2-item' },
9
9
  label: field_setting.name,
10
- hint: field_setting.description,
10
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
11
11
  value_method: :id,
12
12
  checked: ff.object.dependent_component_ids,
13
13
  include_blank: true,
@@ -20,7 +20,7 @@
20
20
  as: :select,
21
21
  input_html: { multiple: true, class: 'select2-item' },
22
22
  label: field_setting.name,
23
- hint: field_setting.description,
23
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
24
24
  value_method: :id,
25
25
  checked: ff.object.dependent_board_ids,
26
26
  include_blank: true,
@@ -3,7 +3,7 @@
3
3
  <%= ff.input :content,
4
4
  input_html: { value: ff.object.content },
5
5
  as: :string,
6
- hint: field_setting.description,
6
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
7
7
  label: field_setting.name %>
8
8
 
9
9
  <%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
@@ -3,7 +3,7 @@
3
3
  <%= ff.input :content,
4
4
  input_html: { value: ff.object.content, class: 'tinymce' },
5
5
  as: :text,
6
- hint: field_setting.description,
6
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
7
7
  label: field_setting.name %>
8
8
 
9
9
  <%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
@@ -6,11 +6,11 @@
6
6
 
7
7
  <p class="control-label"><%= field_setting.name %></p>
8
8
 
9
- <div class="fileupload--dashboard">
9
+ <div class="fileupload--field">
10
10
 
11
11
  <%= ff.input :video,
12
12
  label: "<i class=\"fa fa-upload\" aria-hidden=\"true\"></i> #{t('binda.choose_file_button')}".html_safe,
13
- hint: field_setting.description,
13
+ hint: field_setting.description.nil? ? false : field_setting.description.html_safe,
14
14
  url: url_for([ff.object, action: :remove_video]).html_safe,
15
15
  object: ff.object,
16
16
  wrapper: false,
@@ -19,7 +19,6 @@
19
19
  'data-url': url_for([@instance.structure, @instance, action: :upload]),
20
20
  'data-id': ff.object.id,
21
21
  } %>
22
-
23
22
 
24
23
  </div>
25
24
 
@@ -1,75 +1,14 @@
1
- <%# - - - - - - - - - - - - %>
2
- <%# TEXT %>
3
- <%# - - - - - - - - - - - - %>
4
- <% if field_setting.field_type == 'text' %>
5
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'text' ) %>
6
- <%= f.simple_fields_for "texts_attributes[]", current do |ff| %>
7
- <%= render 'binda/fieldable/form_item_text', f: f, ff: ff, field_setting: field_setting %>
1
+ <% if %w(text string date image video audio relation).include? field_setting.field_type %>
2
+ <% current = @instance.find_or_create_a_field_by( field_setting.id, field_setting.field_type) %>
3
+ <%= f.simple_fields_for "#{field_setting.field_type}s_attributes[]", current do |ff| %>
4
+ <%= render "binda/fieldable/form_item_#{field_setting.field_type}", f: f, ff: ff, field_setting: field_setting %>
8
5
  <% end %>
9
6
 
10
-
11
- <%# - - - - - - - - - - - - %>
12
- <%# STRING %>
13
- <%# - - - - - - - - - - - - %>
14
- <% elsif field_setting.field_type == 'string' %>
15
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'string' ) %>
16
- <%= f.simple_fields_for "strings_attributes[]", current do |ff| %>
17
- <%= render 'binda/fieldable/form_item_string', f: f, ff: ff, field_setting: field_setting %>
18
- <% end %>
19
-
20
-
21
- <%# - - - - - - - - - - - - %>
22
- <%# DATE %>
23
- <%# - - - - - - - - - - - - %>
24
- <% elsif field_setting.field_type == 'date' %>
25
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'date' ) %>
26
- <%= f.simple_fields_for "dates_attributes[]", current do |ff| %>
27
- <%= render 'binda/fieldable/form_item_date', ff: ff, field_setting: field_setting %>
28
- <% end %>
29
-
30
-
31
- <%# - - - - - - - - - - - - %>
32
- <%# IMAGE %>
33
- <%# - - - - - - - - - - - - %>
34
- <% elsif field_setting.field_type == 'image' %>
35
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'image' ) %>
36
- <%= f.simple_fields_for "images_attributes[]", current do |ff| %>
37
- <%= render 'binda/fieldable/form_item_image', ff: ff, field_setting: field_setting %>
38
- <% end %>
39
-
40
-
41
- <%# - - - - - - - - - - - - %>
42
- <%# VIDEO %>
43
- <%# - - - - - - - - - - - - %>
44
- <% elsif field_setting.field_type == 'video' %>
45
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'video' ) %>
46
- <%= f.simple_fields_for "videos_attributes[]", current do |ff| %>
47
- <%= render 'binda/fieldable/form_item_video', ff: ff, field_setting: field_setting %>
48
- <% end %>
49
-
50
-
51
- <%# - - - - - - - - - - - - %>
52
- <%# RELATED_FIELD %>
53
- <%# - - - - - - - - - - - - %>
54
- <% elsif field_setting.field_type == 'relation' %>
55
- <% current = @instance.find_or_create_a_field_by( field_setting.id, 'relation' ) %>
56
- <%= f.simple_fields_for "relations_attributes[]", current do |ff| %>
57
- <%= render 'binda/fieldable/form_item_relation', ff: ff, field_setting: field_setting %>
58
- <% end %>
59
-
60
- <%# - - - - - - - - - - - - %>
61
- <%# SELECTION TYPES %>
62
- <%# - - - - - - - - - - - - %>
63
- <% elsif ['radio', 'selection', 'checkbox'].include? field_setting.field_type %>
7
+ <% elsif %w(radio selection checkbox).include? field_setting.field_type %>
64
8
  <%= render 'binda/fieldable/form_item_selections', f: f, field_setting: field_setting %>
65
9
 
66
-
67
- <%# - - - - - - - - - - - - %>
68
- <%# REPEATER %>
69
- <%# - - - - - - - - - - - - %>
70
10
  <% elsif field_setting.field_type == 'repeater' %>
71
11
  <% repeaters = @instance.repeaters.where( field_setting: field_setting ).order('position ASC') %>
72
12
  <%= render 'binda/fieldable/form_item_repeater', f: f, repeater_setting: field_setting, repeaters: repeaters %>
73
13
 
74
-
75
14
  <% end %>
@@ -1,67 +1,15 @@
1
- <%# - - - - - - - - - - - - %>
2
- <%# TEXT / STRING %>
3
- <%# - - - - - - - - - - - - %>
4
- <% if repeater_setting_child.field_type == 'text' %>
5
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'text' ) %>
6
- <%= f.simple_fields_for "texts_attributes[]", current do |ff| %>
7
- <%= render 'binda/fieldable/form_item_text', f: f, ff: ff, field_setting: repeater_setting_child %>
1
+ <% if %w(text string date image video audio relation).include? repeater_setting_child.field_type %>
2
+ <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, repeater_setting_child.field_type ) %>
3
+ <%= f.simple_fields_for "#{repeater_setting_child.field_type}s_attributes[]", current do |ff| %>
4
+ <%= render "binda/fieldable/form_item_#{repeater_setting_child.field_type}", f: f, ff: ff, field_setting: repeater_setting_child %>
8
5
  <% end %>
9
6
 
10
-
11
- <%# - - - - - - - - - - - - %>
12
- <%# STRING %>
13
- <%# - - - - - - - - - - - - %>
14
- <% elsif repeater_setting_child.field_type == 'string' %>
15
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'string' ) %>
16
- <%= f.simple_fields_for "strings_attributes[]", current do |ff| %>
17
- <%= render 'binda/fieldable/form_item_string', f: f, ff: ff, field_setting: repeater_setting_child %>
18
- <% end %>
19
-
20
-
21
- <%# - - - - - - - - - - - - %>
22
- <%# DATE %>
23
- <%# - - - - - - - - - - - - %>
24
- <% elsif repeater_setting_child.field_type == 'date' %>
25
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'date' ) %>
26
- <%= f.simple_fields_for "dates_attributes[]", current do |ff| %>
27
- <%= render 'binda/fieldable/form_item_date', ff: ff, field_setting: repeater_setting_child %>
28
- <% end %>
29
-
30
-
31
- <%# - - - - - - - - - - - - %>
32
- <%# IMAGE %>
33
- <%# - - - - - - - - - - - - %>
34
- <% elsif repeater_setting_child.field_type == 'image' %>
35
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'image' ) %>
36
- <%= f.simple_fields_for "images_attributes[]", current do |ff| %>
37
- <%= render 'binda/fieldable/form_item_image', ff: ff, field_setting: repeater_setting_child %>
38
- <% end %>
39
-
40
-
41
- <%# - - - - - - - - - - - - %>
42
- <%# VIDEO %>
43
- <%# - - - - - - - - - - - - %>
44
- <% elsif repeater_setting_child.field_type == 'video' %>
45
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'video' ) %>
46
- <%= f.simple_fields_for "videos_attributes[]", current do |ff| %>
47
- <%= render 'binda/fieldable/form_item_video', ff: ff, field_setting: repeater_setting_child %>
48
- <% end %>
49
-
50
-
51
- <%# - - - - - - - - - - - - %>
52
- <%# RELATED_FIELD %>
53
- <%# - - - - - - - - - - - - %>
54
- <% elsif repeater_setting_child.field_type == 'relation' %>
55
- <% current = @instance.repeaters.select{|r| r.id == f.object.id}.first.find_or_create_a_field_by( repeater_setting_child.id, 'relation' ) %>
56
- <%= f.simple_fields_for "relations_attributes[]", current do |ff| %>
57
- <%= render 'binda/fieldable/form_item_relation', ff: ff, field_setting: repeater_setting_child %>
58
- <% end %>
59
-
60
- <%# - - - - - - - - - - - - %>
61
- <%# SELECTABLES %>
62
- <%# - - - - - - - - - - - - %>
63
- <% elsif ['radio', 'selection', 'checkbox'].include? repeater_setting_child.field_type %>
7
+ <% elsif %w(radio selection checkbox).include? repeater_setting_child.field_type %>
64
8
  <%# current = f.object.find_or_create_a_field_by( repeater_setting_child.id, 'radio' ) %>
65
9
  <%= render 'binda/fieldable/form_item_selections', f: f, field_setting: repeater_setting_child %>
66
10
 
11
+ <% elsif repeater_setting_child.field_type == 'repeater' %>
12
+ <% repeaters = @instance.repeaters.where( field_setting: field_setting ).order('position ASC') %>
13
+ <%= render 'binda/fieldable/form_item_repeater', f: f, repeater_setting: field_setting, repeaters: repeaters %>
14
+
67
15
  <% end %>
@@ -8,13 +8,15 @@ module SimpleForm
8
8
  def preview(wrapper_options = nil)
9
9
  @preview ||= begin
10
10
  # open a div tag for the file preview
11
- html = '<div class="fileupload--preview'
11
+ html = '<div class="fileupload--preview'
12
12
 
13
13
  # add preview image if it's set
14
14
  if options[:object].image.present?
15
15
  html << " fileupload--preview--uploaded\" style=\"background-image: url(#{options[:object].image.url})"
16
16
  elsif options[:object].video.present?
17
- html << " fileupload--preview--uploaded"
17
+ html << " fileupload--preview--uploaded"
18
+ elsif options[:object].audio.present?
19
+ html << " fileupload--preview--uploaded fileupload--preview--hidden"
18
20
  end
19
21
 
20
22
  # Add no-preview text
@@ -23,9 +25,15 @@ module SimpleForm
23
25
  # Add video tag
24
26
  if options[:object].video.present?
25
27
  html << "<video id=\"video-#{options[:object].id}\" class=\"form-item--video--video\">"
26
- html << "<source src=\"#{options[:object].video.url}\" type=\"video/#{options[:object].video.file.extension.downcase}\"></video>"
28
+ html << "<source src=\"#{options[:object].video.url}\" type=\"#{options[:object].video.content_type}\"></video>"
29
+ html << "<audio class=\"form-item--audio--audio\"><source></audio>"
30
+ elsif options[:object].audio.present?
31
+ html << "<audio id=\"audio-#{options[:object].id}\" class=\"from-item--audio--audio\">"
32
+ html << "<source src=\"#{options[:object].audio.url}\" type=\"#{options[:object].audio.content_type}\"></audio>"
33
+ html << "<video class=\"form-item--video--video\"><source></video>"
27
34
  else
28
35
  html << "<video class=\"form-item--video--video\"><source></video>"
36
+ html << "<audio class=\"form-item--audio--audio\"><source></audio>"
29
37
  end
30
38
 
31
39
  # Close preview container
@@ -46,7 +54,7 @@ module SimpleForm
46
54
  obj = options[:object]
47
55
  url = options[:url]
48
56
  html = '<a class="b-btn b-btn-outline-danger fileupload--remove-image-btn'
49
- html << ' fileupload--remove-image-btn--hidden' unless obj.image.present? || obj.video.present?
57
+ html << ' fileupload--remove-image-btn--hidden' unless obj.image.present? || obj.video.present? || obj.audio.present?
50
58
  html << '" href="'
51
59
  html << url
52
60
  html << '" data-method="delete" data-remote="true" data-confirm="'
@@ -73,12 +81,13 @@ module SimpleForm
73
81
  obj = options[:object]
74
82
 
75
83
  html = '<div class="fileupload--details'
76
- html << ' fileupload--details--hidden' unless obj.image.present? || obj.video.present?
84
+ html << ' fileupload--details--hidden' unless obj.image.present? || obj.video.present? || obj.audio.present?
77
85
  html << '"><p class="fileupload--name">'
78
86
  html << "<strong>#{t 'binda.filename'}:</strong> "
79
87
  html << '<span class="fileupload--filename">'
80
88
  html << File.basename(obj.image.path).to_s if obj.image.present?
81
89
  html << File.basename(obj.video.path).to_s if obj.video.present?
90
+ html << File.basename(obj.audio.path).to_s if obj.audio.present?
82
91
  html << '</span></p>'
83
92
  html << '<p class="fileupload--size">'
84
93
  html << "<strong>#{t 'binda.filesize'}:</strong> "
@@ -92,10 +101,12 @@ module SimpleForm
92
101
  html << '</span> x <span class="fileupload--height">'
93
102
  html << obj.file_height.round.to_s unless obj.file_height.blank?
94
103
  html << '</span> px</p>'
95
- html << '<p class="fileupload--videolink"><a href="'
104
+ html << '<p class="fileupload--previewlink"><a href="'
96
105
  html << obj.video.url if obj.video.present?
106
+ html << obj.audio.url if obj.audio.present?
97
107
  html << '" target="_blank"><i class="fas fa-external-link-alt"></i> <strong>'
98
- html << t('binda.filevideolink')
108
+ html << t('binda.filevideolink') if obj.class.name.demodulize == 'Video'
109
+ html << t('binda.fileaudiolink') if obj.class.name.demodulize == 'Audio'
99
110
  html << '</strong></a></p>'
100
111
 
101
112
  html << '</div>'
@@ -58,6 +58,7 @@ en:
58
58
  filesize: Size
59
59
  filedimension: Dimension
60
60
  filevideolink: Preview video
61
+ fileaudiolink: Preview audio
61
62
  select_placeholder: Select a option
62
63
  new_item_in_repeater: New %{arg1} item
63
64
  null_is_not_allowed: You need to select at least one choice
@@ -69,13 +69,17 @@ Binda::Engine.routes.draw do
69
69
  end
70
70
 
71
71
  resources :choices, only: [:destroy]
72
-
72
+
73
+ resources :audios do
74
+ member do
75
+ delete 'remove_audio'
76
+ end
77
+ end
73
78
  resources :videos do
74
79
  member do
75
80
  delete 'remove_video'
76
81
  end
77
82
  end
78
-
79
83
  resources :images do
80
84
  member do
81
85
  delete 'remove_image'
@@ -90,6 +90,7 @@ class CreateBindaTables < ActiveRecord::Migration[5.0]
90
90
  t.string :type
91
91
  t.string :video
92
92
  t.string :image
93
+ t.string :audio
93
94
  t.belongs_to :field_setting
94
95
  t.references :fieldable, polymorphic: true, index: true
95
96
  t.string :content_type
@@ -1,3 +1,3 @@
1
1
  module Binda
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Barbieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-25 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -539,7 +539,7 @@ dependencies:
539
539
  version: '1.6'
540
540
  - - "<"
541
541
  - !ruby/object:Gem::Version
542
- version: '2'
542
+ version: '2.1'
543
543
  type: :development
544
544
  prerelease: false
545
545
  version_requirements: !ruby/object:Gem::Requirement
@@ -549,7 +549,7 @@ dependencies:
549
549
  version: '1.6'
550
550
  - - "<"
551
551
  - !ruby/object:Gem::Version
552
- version: '2'
552
+ version: '2.1'
553
553
  - !ruby/object:Gem::Dependency
554
554
  name: travis
555
555
  requirement: !ruby/object:Gem::Requirement
@@ -668,6 +668,7 @@ files:
668
668
  - app/assets/stylesheets/scaffolds.scss
669
669
  - app/controllers/binda/application_controller.rb
670
670
  - app/controllers/binda/assets_controller.rb
671
+ - app/controllers/binda/audios_controller.rb
671
672
  - app/controllers/binda/boards_controller.rb
672
673
  - app/controllers/binda/categories_controller.rb
673
674
  - app/controllers/binda/choices_controller.rb
@@ -679,6 +680,7 @@ files:
679
680
  - app/controllers/binda/manage/users_controller.rb
680
681
  - app/controllers/binda/repeaters_controller.rb
681
682
  - app/controllers/binda/structures_controller.rb
683
+ - app/controllers/binda/users/audios_controller.rb
682
684
  - app/controllers/binda/users/confirmations_controller.rb
683
685
  - app/controllers/binda/users/omniauth_callbacks_controller.rb
684
686
  - app/controllers/binda/users/passwords_controller.rb
@@ -704,6 +706,7 @@ files:
704
706
  - app/mailers/binda/application_mailer.rb
705
707
  - app/models/binda/application_record.rb
706
708
  - app/models/binda/asset.rb
709
+ - app/models/binda/audio.rb
707
710
  - app/models/binda/b.rb
708
711
  - app/models/binda/board.rb
709
712
  - app/models/binda/category.rb
@@ -732,6 +735,7 @@ files:
732
735
  - app/models/concerns/binda/fieldable_association_helpers.rb
733
736
  - app/models/concerns/binda/fieldable_associations.rb
734
737
  - app/models/concerns/binda/fields.rb
738
+ - app/uploaders/binda/audio/audio_uploader.rb
735
739
  - app/uploaders/binda/image/image_uploader.rb
736
740
  - app/uploaders/binda/video/video_uploader.rb
737
741
  - app/views/binda/assets/_form.html.erb
@@ -774,6 +778,7 @@ files:
774
778
  - app/views/binda/field_settings/index.html.erb
775
779
  - app/views/binda/field_settings/new.html.erb
776
780
  - app/views/binda/fieldable/_form_body.html.erb
781
+ - app/views/binda/fieldable/_form_item_audio.html.erb
777
782
  - app/views/binda/fieldable/_form_item_date.html.erb
778
783
  - app/views/binda/fieldable/_form_item_gallery.html.erb
779
784
  - app/views/binda/fieldable/_form_item_image.html.erb