0002-Switch-default-behaviour-on-Attachment-click-to-view.patch

Jan from Planio www.plan.io, 2017-05-17 16:01

Download (6.41 KB)

View differences:

app/helpers/issues_helper.rb
468 468
      if detail.property == 'attachment' && value.present? &&
469 469
          atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
470 470
        # Link to the attachment if it has not been removed
471
        value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
472
        if options[:only_path] != false && (atta.is_text? || atta.is_image?)
471
        value = link_to_attachment(atta, only_path: options[:only_path])
472
        if options[:only_path] != false
473 473
          value += ' '
474
          value += link_to(l(:button_view),
475
                           { :controller => 'attachments', :action => 'show',
476
                             :id => atta, :filename => atta.filename },
477
                           :class => 'icon-only icon-magnifier',
478
                           :title => l(:button_view))
474
          value += link_to_attachment atta, class: 'icon-only icon-save', title: l(:button_download), download: true
479 475
        end
480 476
      else
481 477
        value = content_tag("i", h(value)) if value
app/models/attachment.rb
31 31
  attr_protected :id
32 32

  
33 33
  acts_as_event :title => :filename,
34
                :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
34
                :url => Proc.new {|o| {:controller => 'attachments', :action => 'show', :id => o.id, :filename => o.filename}}
35 35

  
36 36
  acts_as_activity_provider :type => 'files',
37 37
                            :permission => :view_files,
......
251 251
    Redmine::MimeType.of(filename) == "application/pdf"
252 252
  end
253 253

  
254
  def previewable?
255
    is_text? || is_image?
256
  end
257

  
254 258
  # Returns true if the file is readable
255 259
  def readable?
256 260
    disk_filename.present? && File.readable?(diskfile)
app/views/attachments/_links.html.erb
6 6
              :class => 'icon-only icon-edit'
7 7
             ) if options[:editable] %>
8 8
</div>
9
<table>
9 10
<% for attachment in attachments %>
10
<p><%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>
11
  <% if attachment.is_text? || attachment.is_image? %>
12
    <%= link_to l(:button_view),
13
                { :controller => 'attachments', :action => 'show',
14
                  :id => attachment, :filename => attachment.filename },
15
                :class => 'icon-only icon-magnifier',
16
                :title => l(:button_view) %>
17
  <% end %>
18
  <%= " - #{attachment.description}" unless attachment.description.blank? %>
19
  <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
20
  <% if options[:deletable] %>
21
    <%= link_to l(:button_delete), attachment_path(attachment),
22
                :data => {:confirm => l(:text_are_you_sure)},
23
                :method => :delete,
24
                :class => 'delete icon-only icon-del',
25
                :title => l(:button_delete) %>
26
  <% end %>
27
  <% if options[:author] %>
28
    <span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
29
  <% end %>
30
  </p>
11
<tr>
12
  <td>
13
    <%= link_to_attachment attachment, class: 'icon icon-attachment' -%>
14
    <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
15
  </td>
16
  <td><%= attachment.description unless attachment.description.blank? %></td>
17
  <td>
18
    <% if options[:author] %>
19
      <span class="author"><%= attachment.author %>, <%= format_time(attachment.created_on) %></span>
20
    <% end %>
21
  </td>
22
  <td><%= link_to_attachment attachment, class: 'icon-only icon-save', title: l(:button_download), download: true -%></td>
23
  <td>
24
    <% if options[:deletable] %>
25
      <%= link_to l(:button_delete), attachment_path(attachment),
26
                  :data => {:confirm => l(:text_are_you_sure)},
27
                  :method => :delete,
28
                  :class => 'delete icon-only icon-del',
29
                  :title => l(:button_delete) %>
30
    <% end %>
31
  </td>
32
</tr>
31 33
<% end %>
34
</table>
32 35
<% if defined?(thumbnails) && thumbnails %>
33 36
  <% images = attachments.select(&:thumbnailable?) %>
34 37
  <% if images.any? %>
app/views/files/index.html.erb
27 27
  <% end -%>
28 28
  <% container.attachments.each do |file| %>
29 29
  <tr class="file">
30
    <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %></td>
30
    <td class="filename"><%= link_to_attachment file, :title => file.description -%></td>
31 31
    <td class="created_on"><%= format_time(file.created_on) %></td>
32 32
    <td class="filesize"><%= number_to_human_size(file.filesize) %></td>
33 33
    <td class="downloads"><%= file.downloads %></td>
34 34
    <td class="digest"><%= file.digest_type %>: <%= file.digest %></td>
35 35
    <td class="buttons">
36
    <%= link_to_attachment file, class: 'icon-only icon-save', title: l(:button_download), download: true %>
36 37
    <%= link_to(image_tag('delete.png'), attachment_path(file),
37 38
                                         :data => {:confirm => l(:text_are_you_sure)}, :method => :delete) if delete_allowed %>
38 39
    </td>
39
-