Commit 14d0ef8f37b68c0911edfb197581bb7e818b1e50

Authored by Dmitriy Zaporozhets
1 parent ef5b36ea

Show images preview in notes. Show line additions/deletions for commit

app/models/commit.rb
... ... @@ -11,7 +11,7 @@ class Commit
11 11 attr_accessor :commit, :head, :refs
12 12  
13 13 delegate :message, :authored_date, :committed_date, :parents, :sha,
14   - :date, :committer, :author, :diffs, :tree, :id,
  14 + :date, :committer, :author, :diffs, :tree, :id, :stats,
15 15 :to_patch, to: :commit
16 16  
17 17 class << self
... ...
app/uploaders/attachment_uploader.rb
1 1 # encoding: utf-8
2 2  
3 3 class AttachmentUploader < CarrierWave::Uploader::Base
4   -
5   - # Include RMagick or ImageScience support:
6   - # include CarrierWave::RMagick
7   - # include CarrierWave::MiniMagick
8   - # include CarrierWave::ImageScience
9   -
10   - # Choose what kind of storage to use for this uploader:
11 4 storage :file
12   - # storage :fog
13 5  
14   - # Override the directory where uploaded files will be stored.
15   - # This is a sensible default for uploaders that are meant to be mounted:
16 6 def store_dir
17 7 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
18 8 end
19 9  
20   - # Provide a default URL as a default if there hasn't been a file uploaded:
21   - # def default_url
22   - # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
23   - # end
24   -
25   - # Process files as they are uploaded:
26   - # process scale: [200, 300]
27   - #
28   - # def scale(width, height)
29   - # # do something
30   - # end
31   -
32   - # Create different versions of your uploaded files:
33   - # version :thumb do
34   - # process scale: [50, 50]
35   - # end
36   -
37   - # Add a white list of extensions which are allowed to be uploaded.
38   - # For images you might use something like this:
39   - # def extension_white_list
40   - # %w(jpg jpeg gif png)
41   - # end
42   -
43   - # Override the filename of the uploaded files:
44   - # Avoid using model.id or version_name here, see uploader/store.rb for details.
45   - # def filename
46   - # "something.jpg" if original_filename
47   - # end
48   -
  10 + def image?
  11 + %w(png jpg jpeg).include?(file.extension)
  12 + end
49 13 end
... ...
app/views/commit/show.html.haml
1 1 = render "commits/commit_box"
  2 +
  3 +%p.right
  4 + This commit has
  5 + %span.cgreen #{@commit.stats.additions} additions
  6 + and
  7 + %span.cred #{@commit.stats.deletions} deletions
  8 +
2 9 = render "commits/diffs", diffs: @commit.diffs
3 10 = render "notes/notes_with_form", tid: @commit.id, tt: "commit"
4 11 = render "notes/per_line_form"
5 12  
6   -
7 13 :javascript
8 14 $(function(){
9 15 PerLineNotes.init();
... ... @@ -19,7 +25,7 @@
19 25 , h = event.currentTarget.naturalHeight;
20 26 $('.image.diff_added .image-info', this).append(' | <b>W:</b> ' + w + 'px | <b>H:</b> ' + h + 'px');
21 27 }, this));
22   -
  28 +
23 29 });
24   -
  30 +
25 31 });
... ...
app/views/notes/_note.html.haml
... ... @@ -34,6 +34,8 @@
34 34 = preserve do
35 35 = markdown(note.note)
36 36 - if note.attachment.url
  37 + - if note.attachment.image?
  38 + = image_tag note.attachment.url, class: 'thumbnail span4'
37 39 .right
38 40 %div.file
39 41 = link_to note.attachment_identifier, note.attachment.url, target: "_blank"
... ...