Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #174 from thauma9/master
Browse files Browse the repository at this point in the history
ADD svg field to binda, with tests
  • Loading branch information
a-barbieri authored Mar 26, 2018
2 parents 1dea865 + 86fd603 commit 3430996
Show file tree
Hide file tree
Showing 43 changed files with 1,206 additions and 680 deletions.
32 changes: 16 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ GEM
sass (~> 3.4)
thor (~> 0.19)
builder (3.2.3)
bullet (5.7.3)
bullet (5.7.5)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11.0)
capybara (2.18.0)
Expand All @@ -88,22 +88,22 @@ GEM
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
childprocess (0.8.0)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
database_cleaner (1.6.2)
devise (4.4.1)
devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
devise-i18n (1.6.1)
devise (>= 4.4)
diff-lcs (1.3)
docile (1.1.5)
docile (1.3.0)
erubi (1.7.1)
ethon (0.11.0)
ffi (>= 1.3.0)
Expand Down Expand Up @@ -161,7 +161,7 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.0)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
Expand All @@ -174,18 +174,18 @@ GEM
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
mry (0.53.0.0)
mry (0.54.0.0)
rubocop (>= 0.41.0)
multi_json (1.13.1)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
net-http-pipeline (1.0.1)
nio4r (2.2.0)
nio4r (2.3.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
parallel (1.12.1)
parser (2.5.0.3)
parser (2.5.0.5)
ast (~> 2.4.0)
pg (0.21.0)
powerpack (0.1.1)
Expand Down Expand Up @@ -215,16 +215,16 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.1.5)
actionpack (= 5.1.5)
activesupport (= 5.1.5)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (12.3.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand Down Expand Up @@ -259,7 +259,7 @@ GEM
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.5)
sass (3.5.6)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -270,14 +270,14 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.10.0)
selenium-webdriver (3.11.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
simple_form (3.5.1)
actionpack (> 4, < 5.2)
activemodel (> 4, < 5.2)
simplecov (0.15.1)
docile (~> 1.1.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ Here below a list of field types available and their use:
| string | Store a string. No formatting options available. | [source](http://www.rubydoc.info/gems/binda/Binda/String) |
| text | Store a text. TinyMCE let's you format the text as you like. | [source](http://www.rubydoc.info/gems/binda/Binda/Text) |
| image | Store image. | [source](http://www.rubydoc.info/gems/binda/Binda/Image) |
| svg | Store svg. | [source](http://www.rubydoc.info/gems/binda/Binda/Svg) |
| video | Store video. | [source](http://www.rubydoc.info/gems/binda/Binda/Video) |
| audio | Store audio. | [source](http://www.rubydoc.info/gems/binda/Binda/Audio) |
| date | Store a date. | [source](http://www.rubydoc.info/gems/binda/Binda/Date) |
Expand Down Expand Up @@ -440,6 +441,12 @@ You can retrieve field content from a instance of `Binda::Component`, `Binda::Bo
|`get_image_size`| Returns the image size in MB. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_size) |
|`get_image_dimension`| Returns a hash { width: xxx, height: xxx } with image dimension. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_dimension) |
|`get_image_mime_type`| Returns the mime type of the image. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_mime_type) |
|`has_svg`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_svg) |
|`get_svg_url`| Returns the url of the svg. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_svg_url) |
|`get_svg_path`| Returns the path of the svg. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_svg_path) |
|`get_svg_size`| Returns the svg size in MB. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_svg_size) |
|`get_svg_mime_type`| Returns the mime type of the svg. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_svg_mime_type) |

|`has_video`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_video) |
|`get_video_url`| Returns the url of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_video_url) |
|`get_video_path`| Returns the path of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_video_path) |
Expand Down
19 changes: 19 additions & 0 deletions app/assets/javascripts/binda/components/fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ function updateFileuploadField(data, id) {
setup_video_preview(data, id);
} else if (data.type == "audio") {
setup_audio_preview(data, id);
} else if (data.type == "svg") {
setup_svg_preview(data, id);
} else {
alert("Something went wrong. No preview has been received.");
}
Expand Down Expand Up @@ -243,3 +245,20 @@ function setup_audio_preview(data, id) {
$parent.find(".fileupload--filename").text(data.name);
$parent.find(".fileupload--previewlink a").attr("href", data.url);
}

function setup_svg_preview(data, id) {
let $parent = $("#fileupload-" + id);
let $preview = $("#fileupload-" + id + " .fileupload--preview");

// Update thumbnail
$preview.css("background-image", `url(${data.thumbnailUrl})`);

// Remove and add class to trigger css animation
let uploadedClass = "fileupload--preview--uploaded";
$preview.removeClass(uploadedClass).addClass(uploadedClass);

// Update details
$parent.find(".fileupload--filesize").text(data.size);
$parent.find(".fileupload--filename").text(data.name);
$parent.find(".fileupload--previewlink a").attr("href", data.url);
}
Loading

0 comments on commit 3430996

Please sign in to comment.