udongo 7.5.1 → 7.6.0

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
  SHA1:
3
- metadata.gz: 4177132fc9f3839266578b24b8bc6fbf4e089668
4
- data.tar.gz: c162d73c7d75c2548d75e5f4ea373717427300d9
3
+ metadata.gz: 2e20d783baae057351c563f2514db5462a72d8c0
4
+ data.tar.gz: 940bd8b8561b52694055008c8c05439ed0c9133a
5
5
  SHA512:
6
- metadata.gz: 63a75acceeae182eed74dd8179808ab06eceb45a2087a5efc225688200bba608ff7d6a9e155e5197f2b6880799511133b67210e57000433c710c6c673527008e
7
- data.tar.gz: e5ac2f9ccaad7c46a2409cbb57de43eb555c6748bb86806b4709b1e99149bb6e386485edfc3dc2703c37f799011ec00960d6306d9ad39a7e14fbb758e21fb9de
6
+ metadata.gz: c17c2da16a1c5aa122a21960dfe71ab5f5835942017022dbb5ed2d92cc57d2bdf920141c71347566c59fce9c04f006bf8eafef212c5cc9eb69812d2e25880f43
7
+ data.tar.gz: 37adb92ec5869a8c74b78384e3b66d748805309fd9d1cd319bb0796145c1fed9f198a82d1d899e69fd558f8901b13cff29bb267d6170eb6593b1fca2a56bc7ee
@@ -10,7 +10,11 @@ class Backend::AssetsController < Backend::BaseController
10
10
  end
11
11
 
12
12
  def show
13
- redirect_to @model.filename.url
13
+ send_data(
14
+ File.open(@model.filename.path).read,
15
+ filename: @model.read_attribute(:filename),
16
+ type: @model.content_type
17
+ )
14
18
  end
15
19
 
16
20
  def new
data/app/models/asset.rb CHANGED
@@ -5,6 +5,7 @@ class Asset < ApplicationRecord
5
5
 
6
6
  has_many :images, dependent: :destroy
7
7
  has_many :content_pictures, dependent: :destroy
8
+ has_many :attachments, dependent: :destroy
8
9
 
9
10
  scope :image, -> { where(content_type: %w(image/gif image/jpeg image/png)) }
10
11
 
@@ -25,7 +26,7 @@ class Asset < ApplicationRecord
25
26
  end
26
27
 
27
28
  def deletable?
28
- images.empty? && content_pictures.empty?
29
+ images.empty? && content_pictures.empty? && attachments.empty?
29
30
  end
30
31
 
31
32
  private
@@ -0,0 +1,7 @@
1
+ class Attachment < ApplicationRecord
2
+ include Concerns::Sortable
3
+ include Concerns::Visible
4
+
5
+ belongs_to :asset
6
+ belongs_to :attachable, polymorphic: true
7
+ end
@@ -0,0 +1,9 @@
1
+ module Concerns
2
+ module Attachable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :attachments, as: :attachable, dependent: :destroy
7
+ end
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- <% count = asset.images.count + asset.content_pictures.count %>
1
+ <% count = asset.images.count + asset.content_pictures.count + asset.attachments.count %>
2
2
  <% lbl = "#{t(true.to_s)} (#{count})" %>
3
3
  <%= link_to icon(:search, lbl), '#', data: { toggle: 'modal', target: "#asset-usages-#{asset.id}" }%>
4
4
 
@@ -26,6 +26,13 @@
26
26
  <%= link_to_edit_with_label [:backend, picture.parent], default_app_locale %>
27
27
  </li>
28
28
  <% end %>
29
+
30
+ <% asset.attachments.each do |attachment| %>
31
+ <li>
32
+ <%= t "b.#{attachment.attachable.class.name.underscore}" %> &gt;
33
+ <%= link_to_edit_with_label [:backend, attachment.attachable], attachment.locale %>
34
+ </li>
35
+ <% end %>
29
36
  </ul>
30
37
  </div>
31
38
  <div class="modal-footer">
@@ -24,9 +24,9 @@
24
24
  <tr>
25
25
  <td>
26
26
  <% if a.image? %>
27
- <%= image_tag a.image.url(150, 150), alt: '', class: 'img-fluid' %>
27
+ <%= link_to image_tag(a.image.url(150, 150), alt: '', class: 'img-fluid'), backend_asset_path(a) %>
28
28
  <% else %>
29
- <%= link_to icon(:download, t('b.download')), a.filename.url %>
29
+ <%= link_to icon(:download, t('b.download')), backend_asset_path(a) %>
30
30
  <% end %>
31
31
  </td>
32
32
  <td><%= a.actual_filename.split('.').last.upcase %></td>
data/changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ 7.6.0 - 2018-08-22
2
+ --
3
+ * Add the 'Attachment' model that makes it easier to link your own models to
4
+ assets from the media module.
5
+ * Make it easier to download the original file in the asset module.
6
+
7
+
1
8
  7.5.1 - 2018-07-26
2
9
  --
3
10
  * Let Udongo search ignore diacritics in search terms.
@@ -0,0 +1,19 @@
1
+ class CreateAttachments < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :attachments do |t|
4
+ t.string :attachable_type
5
+ t.integer :attachable_id
6
+ t.references :asset
7
+ t.integer :position
8
+ t.boolean :visible
9
+ t.string :locale
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :attachments, [:attachable_type, :attachable_id]
15
+ add_index :attachments, :position
16
+ add_index :attachments, :visible
17
+ add_index :attachments, :locale
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Udongo
2
- VERSION = '7.5.1'
2
+ VERSION = '7.6.0'
3
3
  end
data/readme.md CHANGED
@@ -267,6 +267,9 @@ u.address
267
267
  u.address(:personal)
268
268
  ```
269
269
 
270
+ # Attachments
271
+ There's an ```Attachment``` model that links to the assets. If an asset is linked to an attachment it can't be deleted. You can use this feature to use files linked to the asset module that can't be deleted when in use.
272
+
270
273
  # Queue
271
274
  ## Add tasks to the queue
272
275
  You can add tasks to the queue by executing:
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :attachment do
3
+ asset
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_helper'
2
+
3
+ shared_examples_for :attachable do
4
+ let(:model) { described_class }
5
+ let(:klass) { model.to_s.underscore.to_sym }
6
+
7
+ it '#respond_to?' do
8
+ expect(model.new).to respond_to(:attachable)
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.5.1
4
+ version: 7.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davy Hellemans
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-07-26 00:00:00.000000000 Z
12
+ date: 2018-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -545,12 +545,14 @@ files:
545
545
  - app/models/application_record.rb
546
546
  - app/models/article.rb
547
547
  - app/models/asset.rb
548
+ - app/models/attachment.rb
548
549
  - app/models/ckeditor/asset.rb
549
550
  - app/models/ckeditor/attachment_file.rb
550
551
  - app/models/ckeditor/picture.rb
551
552
  - app/models/comment.rb
552
553
  - app/models/concerns/addressable.rb
553
554
  - app/models/concerns/addressable/config.rb
555
+ - app/models/concerns/attachable.rb
554
556
  - app/models/concerns/cacheable.rb
555
557
  - app/models/concerns/commentable.rb
556
558
  - app/models/concerns/content_type.rb
@@ -873,6 +875,7 @@ files:
873
875
  - db/migrate/20180613113816_add_content_picture_bg_image_fields.rb
874
876
  - db/migrate/20180719160953_create_searches.rb
875
877
  - db/migrate/20180719164016_rename_search_to_search_terms.rb
878
+ - db/migrate/20180821135446_create_attachments.rb
876
879
  - lib/tasks/task_extras.rb
877
880
  - lib/tasks/udongo_tasks.rake
878
881
  - lib/udongo.rb
@@ -925,6 +928,7 @@ files:
925
928
  - spec/factories/admins.rb
926
929
  - spec/factories/articles.rb
927
930
  - spec/factories/assets.rb
931
+ - spec/factories/attachments.rb
928
932
  - spec/factories/comments.rb
929
933
  - spec/factories/content_columns.rb
930
934
  - spec/factories/content_forms.rb
@@ -960,6 +964,7 @@ files:
960
964
  - spec/factories/tags.rb
961
965
  - spec/factories/translation_with_seo_forms.rb
962
966
  - spec/factories/users.rb
967
+ - spec/support/concerns/attachable.rb
963
968
  - spec/support/concerns/cacheable.rb
964
969
  - spec/support/concerns/commentable.rb
965
970
  - spec/support/concerns/content_type.rb