refinerycms-resources 2.1.5 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/resources_controller.rb +41 -17
  3. data/app/models/refinery/resource.rb +20 -9
  4. data/app/views/refinery/admin/resources/_actions.html.erb +2 -4
  5. data/app/views/refinery/admin/resources/_existing_resource.html.erb +1 -1
  6. data/app/views/refinery/admin/resources/_form.html.erb +18 -9
  7. data/app/views/refinery/admin/resources/_records.html.erb +3 -3
  8. data/app/views/refinery/admin/resources/_resource.html.erb +31 -16
  9. data/app/views/refinery/admin/resources/insert.html.erb +1 -1
  10. data/config/locales/ca.yml +36 -0
  11. data/config/locales/cs.yml +3 -4
  12. data/config/locales/en.yml +3 -0
  13. data/config/locales/fr.yml +3 -0
  14. data/config/locales/id.yml +36 -0
  15. data/config/locales/it.yml +6 -16
  16. data/config/routes.rb +1 -1
  17. data/db/migrate/20150430180959_add_translated_title_to_refinery_resources.rb +11 -0
  18. data/lib/generators/refinery/resources/templates/config/initializers/refinery/resources.rb.erb +1 -2
  19. data/lib/refinery/resources.rb +4 -1
  20. data/lib/refinery/resources/configuration.rb +12 -4
  21. data/lib/refinery/resources/dragonfly.rb +33 -25
  22. data/lib/refinery/resources/engine.rb +2 -3
  23. data/license.md +1 -1
  24. data/refinerycms-resources.gemspec +7 -4
  25. data/spec/factories/resource.rb +1 -1
  26. data/spec/features/refinery/admin/resources_spec.rb +53 -30
  27. data/spec/lib/generators/refinery/resources/resources_generator_spec.rb +1 -1
  28. data/spec/lib/resources_spec.rb +15 -11
  29. data/spec/models/refinery/resource_spec.rb +54 -25
  30. metadata +36 -14
  31. data/app/helpers/refinery/admin/resources_helper.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52b752937e49a6295dc68ea8646ab75b04cefdd8
4
- data.tar.gz: 08388a4a7bb1c37b95d49b434760bbffc8f129e9
3
+ metadata.gz: ca9497cf65163418c0e30b2a708903d562a9272e
4
+ data.tar.gz: dc0bad5b6f5b2023eb690cb847c465b30b6ef49f
5
5
  SHA512:
6
- metadata.gz: 78a7abc45c8a9103e96319cbd966d16b9799a91a66119ab849f992ad66b50783b4325fb15636ef8ef6d012ad4496af89f0cfdfc4f879c4f5ea3abe5d2d2ae7d8
7
- data.tar.gz: bd1ff9b16185c35b5941e808ad4d1cb83e7827db7904693c1eb7482e3131c7094aa5838593583ba182f318cd29c4a36297adc516bac8b6d217cb68a1a25b2203
6
+ metadata.gz: 827a5475cb6cc2f21a4b37854a50b9cc7826ca5857e9e1cb226f675b8b681958ce2dca59f700b89f6c5643a6403c5e8f5a243ce8959472572f389a2dcde1cea0
7
+ data.tar.gz: 49f6f6352e102e0d982e460bfe8c0fa22bfd990c8b92c7aeac3bdb423b9ee33e39589e30cfa7402e50460e04e8ab55a74eccef557145b721ae0d1d6cb90482d3
@@ -3,10 +3,11 @@ module Refinery
3
3
  class ResourcesController < ::Refinery::AdminController
4
4
 
5
5
  crudify :'refinery/resource',
6
- :order => "updated_at DESC",
7
- :xhr_paging => true
6
+ include: [:translations],
7
+ order: "updated_at DESC",
8
+ sortable: false
8
9
 
9
- before_filter :init_dialog
10
+ before_action :init_dialog
10
11
 
11
12
  def new
12
13
  @resource = Resource.new if @resource.nil?
@@ -15,28 +16,28 @@ module Refinery
15
16
  end
16
17
 
17
18
  def create
18
- @resources = Resource.create_resources(params[:resource])
19
+ @resources = Resource.create_resources(resource_params)
19
20
  @resource = @resources.detect { |r| !r.valid? }
20
21
 
21
- unless params[:insert]
22
+ if params[:insert]
23
+ if @resources.all?(&:valid?)
24
+ @resource_id = @resources.detect(&:persisted?).id
25
+ @resource = nil
26
+
27
+ self.insert
28
+ end
29
+ else
22
30
  if @resources.all?(&:valid?)
23
31
  flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@resources.map(&:title).join("', '")}'")
24
32
  if from_dialog?
25
33
  @dialog_successful = true
26
- render :nothing => true, :layout => true
34
+ render '/refinery/admin/dialog_success', layout: true
27
35
  else
28
36
  redirect_to refinery.admin_resources_path
29
37
  end
30
38
  else
31
39
  self.new # important for dialogs
32
- render :action => 'new'
33
- end
34
- else
35
- if @resources.all?(&:valid?)
36
- @resource_id = @resources.detect(&:persisted?).id
37
- @resource = nil
38
-
39
- self.insert
40
+ render 'new'
40
41
  end
41
42
  end
42
43
  end
@@ -56,10 +57,10 @@ module Refinery
56
57
  else
57
58
  paginate_resources
58
59
  end
59
- render :action => "insert"
60
+ render 'insert'
60
61
  end
61
62
 
62
- protected
63
+ protected
63
64
 
64
65
  def init_dialog
65
66
  @app_dialog = params[:app_dialog].present?
@@ -76,12 +77,35 @@ module Refinery
76
77
  super unless action_name == 'insert'
77
78
  end
78
79
 
79
- def paginate_resources(conditions={})
80
+ def paginate_resources(conditions = {})
80
81
  @resources = Resource.where(conditions).
81
82
  paginate(:page => params[:page], :per_page => Resource.per_page(from_dialog?)).
82
83
  order('created_at DESC')
83
84
  end
84
85
 
86
+ def resource_params
87
+ # update only supports a single file, create supports many.
88
+ if action_name == 'update'
89
+ params.require(:resource).permit(permitted_update_resource_params)
90
+ else
91
+ params.require(:resource).permit(permitted_resource_params)
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def permitted_resource_params
98
+ [
99
+ :resource_title, :file => []
100
+ ]
101
+ end
102
+
103
+ def permitted_update_resource_params
104
+ [
105
+ :resource_title, :file
106
+ ]
107
+ end
108
+
85
109
  end
86
110
  end
87
111
  end
@@ -2,28 +2,39 @@ require 'dragonfly'
2
2
 
3
3
  module Refinery
4
4
  class Resource < Refinery::Core::BaseModel
5
- ::Refinery::Resources::Dragonfly.setup!
6
-
7
5
  include Resources::Validators
8
6
 
9
- attr_accessible :id, :file
7
+ translates :resource_title
10
8
 
11
- resource_accessor :file
9
+ dragonfly_accessor :file, :app => :refinery_resources
12
10
 
13
11
  validates :file, :presence => true
14
12
  validates_with FileSizeValidator
15
13
 
16
14
  delegate :ext, :size, :mime_type, :url, :to => :file
17
15
 
16
+ before_destroy :cached_mime_type, :prepend => true
17
+
18
+ def cached_mime_type
19
+ @cached_mime_type ||= mime_type
20
+ end
21
+
18
22
  # used for searching
19
23
  def type_of_content
20
- mime_type.split("/").join(" ")
24
+ cached_mime_type.split("/").join(" ")
21
25
  end
22
26
 
23
27
  # Returns a titleized version of the filename
24
28
  # my_file.pdf returns My File
25
29
  def title
26
- CGI::unescape(file_name.to_s).gsub(/\.\w+$/, '').titleize
30
+ resource_title.presence || CGI::unescape(file_name.to_s).gsub(/\.\w+$/, '').titleize
31
+ end
32
+
33
+ def update_index
34
+ return if self.aai_config.disable_auto_indexing
35
+ copy = self.dup.tap{ |r| r.file_uid = r.file_uid_was}
36
+ self.class.index_remove(copy)
37
+ self.class.index_add(self)
27
38
  end
28
39
 
29
40
  class << self
@@ -35,12 +46,12 @@ module Refinery
35
46
  def create_resources(params)
36
47
  resources = []
37
48
 
38
- unless params.present? and params[:file].is_a?(Array)
39
- resources << create(params)
40
- else
49
+ if params.present? and params[:file].is_a?(Array)
41
50
  params[:file].each do |resource|
42
51
  resources << create({:file => resource}.merge(params.except(:file)))
43
52
  end
53
+ else
54
+ resources << create(params)
44
55
  end
45
56
 
46
57
  resources
@@ -1,8 +1,6 @@
1
1
  <ul>
2
+ <li><%= render '/refinery/admin/search', :url => refinery.admin_resources_path -%></li>
2
3
  <li>
3
- <%= render '/refinery/admin/search', :url => refinery.admin_resources_path %>
4
- </li>
5
- <li>
6
- <%= link_to t('.upload_new'), refinery.new_admin_resource_path(:dialog => true), :class => "add_icon" %>
4
+ <%= action_label(:upload, refinery.new_admin_resource_path(:dialog => true), t('.upload_new'))%>
7
5
  </li>
8
6
  </ul>
@@ -6,7 +6,7 @@
6
6
  <% @resources.each do |resource| -%>
7
7
  <% resource_linked = ((@resource_id.present? && @resource_id == resource.id) || (params[:current_link].present? && resource.url == params[:current_link])) %>
8
8
  <li<%= ' class="linked"'.html_safe if resource_linked %>>
9
- <%= link_to "#{resource.title} (#{resource.file_name})", asset_paths.compute_public_path(resource.url, ''),
9
+ <%= link_to "#{resource.title} (#{resource.file_name})", path_to_asset(resource.url),
10
10
  :title => t('.link_to_file'),
11
11
  :rel => resource.title,
12
12
  :class => 'page_link',
@@ -6,10 +6,16 @@
6
6
  :object => @resource,
7
7
  :include_object_name => false %>
8
8
 
9
- <div class="field">
9
+ <%= render '/refinery/admin/locale_picker', :current_locale => Globalize.locale if @resource.persisted? %>
10
+
11
+ <div class="field" id="file">
12
+ <span class='label_with_help'>
13
+ <%= f.label :file, t('.resource_file') %>
14
+ <%= refinery_help_tag t('.maximum_file_size', :bytes => number_to_human_size(Refinery::Resources.max_file_size)) %>
15
+ </span>
16
+
10
17
  <% if action_name =~ /(edit)|(update)/ %>
11
- <%= link_to t('.download_current'), @resource.url,
12
- :title => @resource.title %>
18
+ <%= action_label :download, @resource.url, @resource.title, { tooltip: t('.download_current') } %>
13
19
  <em><%= t('.or')%></em><%= t('.replace') %>
14
20
  <%= f.file_field :file %>
15
21
  <% else %>
@@ -18,10 +24,12 @@
18
24
  <% end %>
19
25
  </div>
20
26
 
21
- <div class="field" id="maximum_file_size">
22
- <label>
23
- <%= t('.maximum_file_size', :bytes => number_to_human_size(Refinery::Resources.max_file_size)) %>
24
- </label>
27
+ <div class="field" id="title">
28
+ <span class='label_with_help'>
29
+ <%= f.label :resource_title, t('.resource_title') %>
30
+ <%= refinery_help_tag t('.resource_title_help') %>
31
+ </span>
32
+ <%= f.text_field :resource_title, placeholder: t('.resource_title') %>
25
33
  </div>
26
34
 
27
35
  <%= render '/refinery/admin/form_actions', :f => f,
@@ -29,7 +37,8 @@
29
37
  :hide_cancel => (@app_dialog or action_name == 'insert' or from_dialog?),
30
38
  :delete_title => t('delete', :scope => 'refinery.admin.resources'),
31
39
  :delete_confirmation => (t('message', :scope => 'refinery.admin.delete',
32
- :title => @resource.title) if @resource.persisted?) %>
40
+ :title => @resource.title) if @resource.persisted?),
41
+ cancel_url: refinery.admin_resources_path -%>
33
42
 
34
43
  <% if @app_dialog -%>
35
44
  <input type="hidden" name="app_dialog" value="<%= @app_dialog %>" />
@@ -48,4 +57,4 @@
48
57
  link_dialog.init();
49
58
  });
50
59
  </script>
51
- <% end if from_dialog? %>
60
+ <% end if from_dialog? %>
@@ -4,10 +4,10 @@
4
4
  <%= render 'resources' %>
5
5
  <% else %>
6
6
  <p>
7
- <% unless searching? %>
8
- <strong><%= t('.no_files_yet') %></strong>
9
- <% else %>
7
+ <% if searching? %>
10
8
  <%= t('no_results', :scope => 'refinery.admin.search') %>
9
+ <% else %>
10
+ <strong><%= t('.no_files_yet') %></strong>
11
11
  <% end %>
12
12
  </p>
13
13
  <% end %>
@@ -1,22 +1,37 @@
1
+ <%
2
+ edit_url = refinery.edit_admin_resource_path(resource)
3
+ delete_url = refinery.admin_resource_path(resource)
4
+ delete_options = {data: {confirm: t('.message', scope: 'refinery.admin.delete', title: resource.title)}}
5
+ %>
1
6
  <li class="clearfix record <%= cycle('on', 'on-hover') %>">
7
+
2
8
  <span class="title <%= resource.ext.try(:downcase) %>">
3
- <%= resource.title %><%= ".#{resource.ext}" if resource.ext %>
4
- <span class="preview">- <%= number_to_human_size(resource.size) %></span>
9
+ <%= resource.title %>
5
10
  </span>
11
+
12
+ <% if Refinery::I18n.frontend_locales.many? %>
13
+ <span class='locales'>
14
+ <% resource.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
15
+ <% if translation.resource_title.present? %>
16
+ <%= link_to refinery.edit_admin_resource_path(resource, switch_locale: translation.locale),
17
+ class: 'locale', title: translation.locale.upcase do %>
18
+
19
+ <div class="<%=translation.locale %> locale_marker">
20
+ <%= locale_text_icon(translation.locale.upcase) %>
21
+ </div>
22
+ <% end %>
23
+ <% end %>
24
+ <% end %>
25
+ </span>
26
+ <% end %>
27
+
28
+ <span class="preview">
29
+ <%= resource.file_name %> - <%= number_to_human_size(resource.size) %>
30
+ </span>
31
+
6
32
  <span class="actions">
7
- <%= link_to refinery_icon_tag('page_white_put.png'),
8
- resource.url,
9
- :title => t('.download', :size => number_to_human_size(resource.size)) %>
10
- <%= link_to refinery_icon_tag('application_edit.png'),
11
- refinery.edit_admin_resource_path(resource),
12
- :title => t('edit', :scope => 'refinery.admin.resources') %>
13
- <%= link_to refinery_icon_tag('delete.png'),
14
- refinery.admin_resource_path(resource),
15
- :class => "cancel confirm-delete",
16
- :title => t('delete', :scope => 'refinery.admin.resources'),
17
- :data => {
18
- :confirm => t('message', :scope => 'refinery.admin.delete', :title => resource.title)
19
- },
20
- :method => :delete %>
33
+ <%= action_icon :download, resource.url, t('.download', size: number_to_human_size(resource.size)) %>
34
+ <%= action_icon :edit, edit_url, t('edit', scope: 'refinery.admin.resources') %>
35
+ <%= action_icon :delete, delete_url, t('delete', scope: 'refinery.admin.resources'), delete_options %>
21
36
  </span>
22
37
  </li>
@@ -1,4 +1,4 @@
1
- <% user_can_modify_resources = ::Refinery::Plugins.active.names.include?("refinery_files") %>
1
+ <% user_can_modify_resources = current_refinery_user.has_plugin?("refinery_files") %>
2
2
  <div class="clearfix">
3
3
  <div id="dialog_menu_left">
4
4
  <% if (any_resources = @resources.any?) %>
@@ -0,0 +1,36 @@
1
+ ca:
2
+ refinery:
3
+ plugins:
4
+ refinery_files:
5
+ title: Arxius
6
+ description: Pujar i enllaçar arxius
7
+ admin:
8
+ resources:
9
+ delete: Esborrar aquest arxiu per sempre
10
+ edit: Editar aquest arxiu
11
+ form:
12
+ download_current: Descarregar arxiu actual
13
+ or: o
14
+ replace: " reemplaçar-ho per aquest altre..."
15
+ maximum_file_size: "El pes màxim per a l'arxiu és de %{bytes}."
16
+ resource:
17
+ download: "Descarregar aquest arxiu (%{size})"
18
+ actions:
19
+ upload_new: Pujar nou arxiu
20
+ records:
21
+ no_files_yet: Encara no hi ha arxius. Prem "Pujar nou arxiu" per afegir el teu primer arxiu.
22
+ insert:
23
+ existing: Arxiu existent
24
+ new: Nou arxiu
25
+ no_files: No hi ha arxius.
26
+ existing_resource:
27
+ link_to_file: Enllaçar aquest arxiu
28
+ button_text: Inserir
29
+ activerecord:
30
+ models:
31
+ refinery/resource: "arxiu"
32
+ errors:
33
+ models:
34
+ refinery/resource:
35
+ blank: Selecciona quin arxiu vols pujar
36
+ too_big: "L'arxiu ha de pesar menys de %{size} bytes"
@@ -31,7 +31,6 @@ cs:
31
31
  refinery/resource: soubor
32
32
  errors:
33
33
  models:
34
- refinery:
35
- resource:
36
- blank: Musíte vybrat soubor pro nahrání
37
- too_big: Maximální velikost souboru je %{size} MB
34
+ refinery/resource:
35
+ blank: Musíte vybrat soubor pro nahrání
36
+ too_big: Maximální velikost souboru je %{size} MB
@@ -13,6 +13,9 @@ en:
13
13
  or: or
14
14
  replace: " replace it with this one..."
15
15
  maximum_file_size: The maximum file size is %{bytes}.
16
+ resource_file: File
17
+ resource_title: Title
18
+ resource_title_help: The title visible to users.
16
19
  resource:
17
20
  download: Download this file (%{size})
18
21
  actions:
@@ -13,6 +13,9 @@ fr:
13
13
  or: ou
14
14
  replace: " le remplacer par celui-ci..."
15
15
  maximum_file_size: "La taille du fichier ne doit pas excéder %{bytes}."
16
+ resource_file: Fichier
17
+ resource_title: Titre
18
+ resource_title_help: Le titre visible pour les utilisateurs.
16
19
  resource:
17
20
  download: Télécharger ce fichier (%{size})
18
21
  actions:
@@ -0,0 +1,36 @@
1
+ id:
2
+ refinery:
3
+ plugins:
4
+ refinery_files:
5
+ title: Berkas
6
+ description: Unggah dan link ke berkas
7
+ admin:
8
+ resources:
9
+ delete: Hapus berkas ini
10
+ edit: Ubah berkas
11
+ form:
12
+ download_current: Unduh berkas ini
13
+ or: atau
14
+ replace: " ganti berkas..."
15
+ maximum_file_size: Maksimal berkas adalah %{bytes}.
16
+ resource:
17
+ download: Unduh berkas ini (%{size})
18
+ actions:
19
+ upload_new: Unggah berkas baru
20
+ records:
21
+ no_files_yet: Tidak ada berkas. Klik "Unggah berkas baru" untuk menambahkan berkas.
22
+ insert:
23
+ existing: Berkas sudah ada
24
+ new: Berkas Baru
25
+ no_files: Tidak ada berkas.
26
+ existing_resource:
27
+ link_to_file: Link ke berkas
28
+ button_text: Sisipkan
29
+ activerecord:
30
+ models:
31
+ refinery/resource: berkas
32
+ errors:
33
+ models:
34
+ refinery/resource:
35
+ blank: Tentukan berkas untuk diunggah
36
+ too_big: Berkas harus lebih kecil dari %{size} byte
@@ -3,22 +3,18 @@ it:
3
3
  plugins:
4
4
  refinery_files:
5
5
  title: Risorse
6
+ description: Carica ed effettua il link a dei file
6
7
  admin:
7
8
  resources:
8
9
  delete: Elimina il file corrente
9
10
  edit: Modifica il file corrente
10
11
  form:
11
- file_to_upload: File da caricare
12
12
  download_current: Scarica il file corrente
13
13
  or: o
14
14
  replace: ", sostituirlo con questo..."
15
15
  maximum_file_size: "La dimensione massima consentita è %{bytes}."
16
16
  resource:
17
17
  download: Scarica il file corrente (%{size})
18
- edit: Modifica il file corrente
19
- delete:
20
- message: Sei sicuro di voler eliminare '%{title}'?
21
- title: Elimina il file corrente
22
18
  actions:
23
19
  upload_new: Carica un nuovo file
24
20
  records:
@@ -27,20 +23,14 @@ it:
27
23
  existing: File esistente
28
24
  new: Nuovo file
29
25
  no_files: Non ci sono files.
30
- existing_file: File esistente
31
- link_to_resource: 'Link a questa risorsa'
32
- previous: Precedente
33
- next: Successivo
34
- submit_insert: Carica
35
- or: o
36
- cancel: Annulla
37
26
  existing_resource:
38
27
  link_to_file: Collegamento a questo file
39
28
  button_text: Inserisci
40
29
  activerecord:
30
+ models:
31
+ refinery/resource: file
41
32
  errors:
42
33
  models:
43
- refinery:
44
- resource:
45
- blank: Devi selezionare un file da caricare
46
- too_big: Le dimensioni del file devono essere inferiori a %{size} bytes
34
+ refinery/resource:
35
+ blank: Devi selezionare un file da caricare
36
+ too_big: Le dimensioni del file devono essere inferiori a %{size} bytes