lato_media 2.1 → 2.1.2

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
- SHA1:
3
- metadata.gz: d98dcf681865bedf65da24fa84faf6de698dafcf
4
- data.tar.gz: 1b59c4832da05d4f69385656040ebf2f8ec78be3
2
+ SHA256:
3
+ metadata.gz: fdec1c78649d43fde79735eea890260d8b7480c7517a21553bbfb4d8211af60a
4
+ data.tar.gz: 7e017a2081d22c2f18671bcae0070fdf5e335839d9142f53502176a0e9ca789d
5
5
  SHA512:
6
- metadata.gz: c11d7f15b2b5f721605dcb39120f7ccedef89355a81f0fefb49f777d3ae7894762763961758dc740d60751f967e168ad932c2f5e7a5e9da6728a0f67c8d6d7f0
7
- data.tar.gz: 5622ff9d9ccea5382d9da718d7d3e7c1d6176db3b029a49a82d131b28dae3847dfb79018a598fc66936ba04359818f498aa04ed15ce1007f660c5ae7a317eb54
6
+ metadata.gz: 6528d7f4d47d7cdb316ba44c22cabfcadc5945e368c0bb9ccc82f9211050d571f73f37bc53b3be756d979175b602de696f0be16ea397d2948ad67d6cb40607aa
7
+ data.tar.gz: 3857671f304d8e5cc65ff98bd17e6b53ec09e7723af0d0100fc643405c68c1b0625fe0e284ef45636f2ac5037371239906fd9541b303e769c16b23a2c9c0bc68
@@ -1,4 +1,4 @@
1
- Copyright 2017 Gregorio Galante
1
+ Copyright 2017 Ideo SRL
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,27 +1,33 @@
1
1
  # Lato Media
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/lato_media.svg)](https://badge.fury.io/rb/lato_media)
4
+
5
+ Lato is a Rails engine used to develop modular admin panels. This is the module used to manage attachments and media files.
6
+
3
7
  ## Installation
4
8
 
5
- Add the lato_media gem on your Gemfile
9
+ Install [lato_core](https://github.com/ideonetwork/lato-core) gem as required dependency.
10
+
11
+ Add the lato_media gem on your Gemfile:
6
12
 
7
13
  ```ruby
8
14
  gem 'lato_media'
9
15
  ```
10
16
 
11
- Install the gem
17
+ Install the gem:
12
18
 
13
19
  ```console
14
20
  bundle install
15
21
  ```
16
22
 
17
- Copy the migrations
23
+ Copy the migrations:
18
24
 
19
25
  ```console
20
26
  rails lato_media:install:migrations
21
27
  ```
22
28
 
23
- Exec migrations
29
+ Exec migrations:
24
30
 
25
31
  ```console
26
32
  bundle exec rake db:migrate
27
- ```
33
+ ```
@@ -10,9 +10,8 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require_tree ./initializers
14
- //= require_tree ./interfaces
13
+ //= require_tree ./modules
15
14
 
16
15
  $(window).load(function () {
17
- MediaInputsInitializer.init()
16
+ MediaPicker.init()
18
17
  })
@@ -1,4 +1,38 @@
1
- var MediaSelector = (function () {
1
+ var MediaPicker = (function () {
2
+
3
+ function initializeMediaInput (media) {
4
+ var mediaInput = $(media).find('.inputs-media__input')
5
+ $(mediaInput).change(function () {
6
+ // get utils data
7
+ var id = $(this).attr('id')
8
+ var value = $(this).attr('value')
9
+ var action = $(media).find('.inputs-media__reload')
10
+ // generate new url
11
+ var url = action.attr('href')
12
+ url = _updateQueryStringParameter(url, 'id', id)
13
+ url = _updateQueryStringParameter(url, 'value', value)
14
+ // update url and send request
15
+ $(action).attr('href', url)
16
+ $(action).trigger('click')
17
+ })
18
+ }
19
+
20
+ function initializeGalleryInput (gallery) {
21
+ var galleryInput = $(gallery).find('.inputs-gallery__input')
22
+ $(galleryInput).change(function () {
23
+ // get utils data
24
+ var id = $(this).attr('id')
25
+ var value = $(this).attr('value')
26
+ var action = $(gallery).find('.inputs-gallery__reload')
27
+ // generate new url
28
+ var url = action.attr('href')
29
+ url = _updateQueryStringParameter(url, 'id', id)
30
+ url = _updateQueryStringParameter(url, 'value', value)
31
+ // update url and send request
32
+ $(action).attr('href', url)
33
+ $(action).trigger('click')
34
+ })
35
+ }
2
36
 
3
37
  // This is the main function used to active the media selector.
4
38
  // The inputId is the input used by the selector to save the selected data.
@@ -14,7 +48,7 @@ var MediaSelector = (function () {
14
48
  // load index for media selector
15
49
  _reloadIndex()
16
50
  // open the modal
17
- Modal.open('media__media_selector')
51
+ CoreModal.open('media__media_selector')
18
52
  }
19
53
 
20
54
  // This function closes the media selector and remove all event watcher on it.
@@ -24,7 +58,7 @@ var MediaSelector = (function () {
24
58
  $('#media__media_selector').unbind('loadIndexAction')
25
59
  $('#media__media_selector_cancel_button').unbind('click')
26
60
  // close the modal
27
- Modal.close('media__media_selector')
61
+ CoreModal.close('media__media_selector')
28
62
  }
29
63
 
30
64
  // This function reload the index list for the medias.
@@ -120,9 +154,42 @@ var MediaSelector = (function () {
120
154
  })
121
155
  }
122
156
 
157
+ // This function updates uri params.
158
+ function _updateQueryStringParameter (uri, key, value) {
159
+ var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i')
160
+ var separator = uri.indexOf('?') !== -1 ? '&' : '?'
161
+ if (uri.match(re)) {
162
+ return uri.replace(re, '$1' + key + '=' + value + '$2')
163
+ }
164
+ else {
165
+ return uri + separator + key + '=' + value
166
+ }
167
+ }
168
+
169
+ function _initMediaInput () {
170
+ $('.inputs-media').each(function () {
171
+ initializeMediaInput(this)
172
+ })
173
+ }
174
+
175
+ function _initGalleryInput () {
176
+ $('.inputs-gallery').each(function () {
177
+ initializeGalleryInput(this)
178
+ })
179
+ }
180
+
181
+ // Init:
182
+ function init () {
183
+ _initMediaInput()
184
+ _initGalleryInput()
185
+ }
186
+
123
187
  return {
188
+ init: init,
124
189
  open: open,
125
- close: close
190
+ close: close,
191
+ initializeMediaInput: initializeMediaInput,
192
+ initializeGalleryInput: initializeGalleryInput
126
193
  }
127
194
 
128
- })()
195
+ })()
@@ -13,7 +13,7 @@
13
13
  <div class="inputs-gallery__preview">
14
14
 
15
15
  <%=raw LatoMedia::Elements::Previews::Cell.new(medias: @medias, url: '#',
16
- onclick: "MediaSelector.open('#{@id}', 99, event);") %>
16
+ onclick: "MediaPicker.open('#{@id}', 99, event);") %>
17
17
 
18
18
  </div>
19
19
 
@@ -13,7 +13,7 @@
13
13
  <div class="inputs-media__preview">
14
14
 
15
15
  <%=raw LatoMedia::Elements::Preview::Cell.new(media: @media, url: '#',
16
- onclick: "MediaSelector.open('#{@id}', 1, event);") %>
16
+ onclick: "MediaPicker.open('#{@id}', 1, event);") %>
17
17
 
18
18
  </div>
19
19
 
@@ -3,6 +3,8 @@ module LatoMedia
3
3
  # This class contains actions used by media cells.
4
4
  class Back::MediaSelectorController < Back::BackController
5
5
 
6
+ skip_before_action :verify_authenticity_token, only: [:add_media]
7
+
6
8
  def load_index
7
9
  medias = LatoMedia::Media.all
8
10
  # set data for view
@@ -39,5 +41,19 @@ module LatoMedia
39
41
  @id = params[:id]
40
42
  end
41
43
 
44
+ def add_media
45
+ @media = LatoMedia::Media.new(attachment: params[:file])
46
+
47
+ unless @media.save
48
+ render json: { error: @media.errors.full_messages.to_sentence }, status: 400
49
+ return
50
+ end
51
+
52
+ render json: {}, status: 200
53
+ rescue => e
54
+ puts e
55
+ render json: { error: 'There was an internal error' }, status: 500
56
+ end
57
+
42
58
  end
43
59
  end
@@ -1,8 +1,6 @@
1
1
  module LatoMedia
2
2
  class Back::MediasController < Back::BackController
3
3
 
4
- skip_before_action :verify_authenticity_token, only: [:create]
5
-
6
4
  before_action do
7
5
  core__set_menu_active_item('media_medias')
8
6
  end
@@ -37,6 +35,9 @@ module LatoMedia
37
35
  end
38
36
 
39
37
  render json: {}, status: 200
38
+ rescue => e
39
+ puts e
40
+ render json: {error: 'There was an internal error'}, status: 500
40
41
  end
41
42
 
42
43
  def edit
@@ -7,13 +7,18 @@ module LatoMedia
7
7
  thumb: "#{CONFIGS[:lato_media][:thumb_media_width]}x#{CONFIGS[:lato_media][:thumb_media_width]}>"
8
8
  }
9
9
 
10
+ IMAGES_PROCESSORS = [:thumbnail, :paperclip_optimizer]
11
+
10
12
  # Dependencies:
11
13
 
12
14
  include Media::EntityHelpers
13
15
 
14
16
  # Other settings:
15
17
 
16
- has_attached_file :attachment, styles: lambda { |a| a.content_type =~ /^image/ ? IMAGES_SIZES : {} }
18
+ has_attached_file :attachment,
19
+ styles: lambda { |a| a.content_type =~ /^image/ ? IMAGES_SIZES : {} },
20
+ processors: IMAGES_PROCESSORS
21
+
17
22
  do_not_validate_attachment_file_type :attachment
18
23
 
19
24
  # Callbacks:
@@ -5,5 +5,6 @@ $('#media__media_selector .partials__media-selector-index-container').html('<%=j
5
5
  // trigger event of change
6
6
  $('#media__media_selector').trigger('loadIndexAction')
7
7
 
8
- // initialize inputs
9
- InputsInitializer.init()
8
+ // initialize dropzone input
9
+ var dropzone = $('#media__media_selector').find('.inputs-dropzone')
10
+ CoreMediapicker.initializeDropzone(dropzone)
@@ -8,6 +8,24 @@
8
8
  <!-- MAIN CONTAINER -->
9
9
  <%=raw row.open %>
10
10
 
11
+ <!-- BIG SECTION CONTAINER -->
12
+ <%=raw container_block_big.open %>
13
+
14
+ <%=raw row.open %>
15
+
16
+ <%=raw block.open %>
17
+
18
+ <%=raw cell(:elements, :title).new(label: @media.title, size: 4) %>
19
+
20
+ <%= render 'lato_media/back/medias/shared/form', url: lato_media.media_path(@media.id), method: :put %>
21
+
22
+ <%=raw block.close %>
23
+
24
+ <%=raw row.close %>
25
+
26
+ <%=raw container_block_big.close %>
27
+ <!-- / BIG SECTION CONTAINER -->
28
+
11
29
  <!-- SMALL SECTION CONTAINER -->
12
30
  <%=raw container_block_small.open %>
13
31
 
@@ -31,21 +49,5 @@
31
49
  <%=raw container_block_small.close %>
32
50
  <!-- / SMALL SECTION CONTAINER -->
33
51
 
34
- <!-- BIG SECTION CONTAINER -->
35
- <%=raw container_block_big.open %>
36
-
37
- <%=raw row.open %>
38
-
39
- <%=raw block.open %>
40
-
41
- <%= render 'lato_media/back/medias/shared/form', url: lato_media.media_path(@media.id), method: :put %>
42
-
43
- <%=raw block.close %>
44
-
45
- <%=raw row.close %>
46
-
47
- <%=raw container_block_big.close %>
48
- <!-- / BIG SECTION CONTAINER -->
49
-
50
52
  <%=raw row.close %>
51
53
  <!-- / MAIN CONTAINER -->
@@ -10,7 +10,7 @@
10
10
 
11
11
  <div class="text-right">
12
12
  <%=raw cell(:elements, :button).new(label: LANGUAGES[:lato_media][:mixed][:add_media], icon: 'plus',
13
- onclick: "Modal.open('dropzone-modal', event);") %>
13
+ onclick: "CoreModal.open('dropzone-modal', event);") %>
14
14
  </div>
15
15
  <br>
16
16
 
@@ -2,10 +2,12 @@
2
2
  $('.medias__medias-index').replaceWith('<%=j render 'lato_media/back/medias/shared/index' %>')
3
3
 
4
4
  // Close modal
5
- Modal.close('dropzone-modal')
5
+ CoreModal.close('dropzone-modal')
6
6
 
7
7
  // Refresh modal content
8
- $('.medias__dropzone-modal').replaceWith('<%=j render 'lato_media/back/medias/shared/dropzone_modal' %>')
8
+ var dropzoneContainer = $('#dropzone-modal').find('.medias__dropzone-modal')
9
+ $(dropzoneContainer).replaceWith('<%=j render 'lato_media/back/medias/shared/dropzone_modal' %>')
9
10
 
10
11
  // Re-initialize dropzone
11
- InputsInitializer.init()
12
+ var dropzone = $('#dropzone-modal').find('.inputs-dropzone')
13
+ CoreMediapicker.initializeDropzone(dropzone)
@@ -10,7 +10,7 @@
10
10
  <%=raw LatoCore::Elements::Button::Cell.new(url: '#', label: LANGUAGES[:lato_media][:mixed][:cancel],
11
11
  style: 'danger', icon: 'ban', id: 'media__media_selector_cancel_button') %>
12
12
  <%=raw LatoCore::Elements::Button::Cell.new(url: '#', label: LANGUAGES[:lato_media][:mixed][:confirm],
13
- style: 'success', icon: 'check', onclick: 'MediaSelector.close(event);') %>
13
+ style: 'success', icon: 'check', onclick: 'MediaPicker.close(event);') %>
14
14
  </div>
15
15
 
16
16
  </div>
@@ -1,6 +1,6 @@
1
1
  <div class="partials__media-selector-form">
2
2
 
3
- <%=raw cell(:inputs, :dropzone).new(url: lato_media.medias_path, max_size: CONFIGS[:lato_media][:max_media_accepted_size],
3
+ <%=raw cell(:inputs, :dropzone).new(url: lato_media.media_selector_add_media_path, max_size: CONFIGS[:lato_media][:max_media_accepted_size],
4
4
  label: LANGUAGES[:lato_media][:mixed][:load_media_files]) %>
5
5
 
6
6
  </div>
@@ -6,4 +6,5 @@ get 'medias_extra/refresh_index', to: 'back/medias#refresh_index', as: 'medias_r
6
6
  get 'media_selector/load_index', to: 'back/media_selector#load_index', as: 'media_selector_load_index'
7
7
  get 'media_selector/load_form', to: 'back/media_selector#load_form', as: 'media_selector_load_form'
8
8
  get 'media_selector/load_inputs_media', to: 'back/media_selector#load_inputs_media', as: 'media_selector_load_inputs_media'
9
- get 'media_selector/load_inputs_gallery', to: 'back/media_selector#load_inputs_gallery', as: 'media_selector_load_inputs_gallery'
9
+ get 'media_selector/load_inputs_gallery', to: 'back/media_selector#load_inputs_gallery', as: 'media_selector_load_inputs_gallery'
10
+ post 'media_selector/add_media', to: 'back/media_selector#add_media', as: 'media_selector_add_media'
@@ -4,6 +4,7 @@ module LatoMedia
4
4
 
5
5
  require 'rubygems'
6
6
  require 'paperclip'
7
+ require 'paperclip-optimizer'
7
8
 
8
9
  # add routes support
9
10
  initializer 'Add gem routes to application', before: :load_config_initializers do
@@ -1,3 +1,3 @@
1
1
  module LatoMedia
2
- VERSION = '2.1'
2
+ VERSION = '2.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_media
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.1'
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ideonetwork
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 5.0.0
47
+ version: 5.2.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 5.0.0
54
+ version: 5.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: paperclip-optimizer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: sqlite3
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -78,8 +92,7 @@ files:
78
92
  - Rakefile
79
93
  - app/assets/config/lato_media_manifest.js
80
94
  - app/assets/javascripts/lato_media/application.js
81
- - app/assets/javascripts/lato_media/initializers/Inputs.js
82
- - app/assets/javascripts/lato_media/interfaces/MediaSelector.js
95
+ - app/assets/javascripts/lato_media/modules/MediaPicker.js
83
96
  - app/assets/stylesheets/lato_media/application.scss
84
97
  - app/assets/stylesheets/lato_media/cells/_cells.scss
85
98
  - app/assets/stylesheets/lato_media/cells/elements/_elements.scss
@@ -152,7 +165,7 @@ files:
152
165
  - lib/lato_media/engine.rb
153
166
  - lib/lato_media/version.rb
154
167
  - lib/tasks/lato_media_tasks.rake
155
- homepage: http://naturaldesign.cc/
168
+ homepage: http://ideonetwork.it/
156
169
  licenses:
157
170
  - MIT
158
171
  metadata: {}
@@ -172,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
185
  version: '0'
173
186
  requirements: []
174
187
  rubyforge_project:
175
- rubygems_version: 2.6.12
188
+ rubygems_version: 2.7.3
176
189
  signing_key:
177
190
  specification_version: 4
178
191
  summary: Lato media module
@@ -1,62 +0,0 @@
1
- var MediaInputsInitializer = (function () {
2
-
3
- function initializeMedia () {
4
- $('.inputs-media .inputs-media__input').change(function () {
5
- // get utils data
6
- var id = $(this).attr('id')
7
- var media = $('#inputs-media-' + id)
8
- var input = $(media).find('.inputs-media__input')
9
- var action = $(media).find('.inputs-media__reload')
10
- var value = $(input).attr('value')
11
- // generate new url
12
- var url = action.attr('href')
13
- url = _updateQueryStringParameter(url, 'id', id)
14
- url = _updateQueryStringParameter(url, 'value', value)
15
- // update url and send request
16
- $(action).attr('href', url)
17
- $(action).trigger('click')
18
- })
19
- }
20
-
21
- function initializeGallery () {
22
- $('.inputs-gallery .inputs-gallery__input').change(function () {
23
- // get utils data
24
- var id = $(this).attr('id')
25
- var gallery = $('#inputs-gallery-' + id)
26
- var input = $(gallery).find('.inputs-gallery__input')
27
- var action = $(gallery).find('.inputs-gallery__reload')
28
- var value = $(input).attr('value')
29
- // generate new url
30
- var url = action.attr('href')
31
- url = _updateQueryStringParameter(url, 'id', id)
32
- url = _updateQueryStringParameter(url, 'value', value)
33
- // update url and send request
34
- $(action).attr('href', url)
35
- $(action).trigger('click')
36
- })
37
- }
38
-
39
- // This function updates uri params.
40
- function _updateQueryStringParameter(uri, key, value) {
41
- var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
42
- var separator = uri.indexOf('?') !== -1 ? "&" : "?";
43
- if (uri.match(re)) {
44
- return uri.replace(re, '$1' + key + "=" + value + '$2');
45
- }
46
- else {
47
- return uri + separator + key + "=" + value;
48
- }
49
- }
50
-
51
- // Init:
52
-
53
- function init () {
54
- initializeMedia()
55
- initializeGallery()
56
- }
57
-
58
- return {
59
- init: init
60
- }
61
-
62
- })()