Commit e8d6c3c1b6a146ca400a3337ddde57d0042f5087
Exists in
master
and in
4 other branches
Merge pull request #1706 from riyad/refactor-tree-views-and-improve-consistency
Refactor tree views and improve consistency
Showing
15 changed files
with
79 additions
and
82 deletions
Show diff stats
app/assets/stylesheets/sections/tree.scss
app/decorators/tree_decorator.rb
... | ... | @@ -28,17 +28,4 @@ class TreeDecorator < ApplicationDecorator |
28 | 28 | file = File.join(path, "..") |
29 | 29 | h.project_tree_path(project, h.tree_join(ref, file)) |
30 | 30 | end |
31 | - | |
32 | - def history_path | |
33 | - h.project_commits_path(project, h.tree_join(ref, path)) | |
34 | - end | |
35 | - | |
36 | - def mb_size | |
37 | - size = (tree.size / 1024) | |
38 | - if size < 1024 | |
39 | - "#{size} KB" | |
40 | - else | |
41 | - "#{size/1024} MB" | |
42 | - end | |
43 | - end | |
44 | 31 | end | ... | ... |
app/views/blame/show.html.haml
1 | 1 | = render "head" |
2 | 2 | |
3 | -#tree-holder | |
3 | +#tree-holder.tree-holder | |
4 | 4 | %ul.breadcrumb |
5 | 5 | %li |
6 | 6 | %span.arrow |
... | ... | @@ -15,12 +15,9 @@ |
15 | 15 | .file_title |
16 | 16 | %i.icon-file |
17 | 17 | %span.file_name |
18 | - = @tree.name | |
19 | - %small blame | |
20 | - %span.options | |
21 | - = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank" | |
22 | - = link_to "history", project_commits_path(@project, @id), class: "btn very_small" | |
23 | - = link_to "source", project_tree_path(@project, @id), class: "btn very_small" | |
18 | + = @tree.name.force_encoding('utf-8') | |
19 | + %small= number_to_human_size @tree.size | |
20 | + %span.options= render "tree/blob_actions" | |
24 | 21 | .file_content.blame |
25 | 22 | %table |
26 | 23 | - @blame.each do |commit, lines| | ... | ... |
... | ... | @@ -0,0 +1,13 @@ |
1 | +.file_holder | |
2 | + .file_title | |
3 | + %i.icon-file | |
4 | + %span.file_name | |
5 | + = blob.name.force_encoding('utf-8') | |
6 | + %small= number_to_human_size blob.size | |
7 | + %span.options= render "tree/blob_actions" | |
8 | + - if blob.text? | |
9 | + = render "tree/blob/text", blob: blob | |
10 | + - elsif blob.image? | |
11 | + = render "tree/blob/image", blob: blob | |
12 | + - else | |
13 | + = render "tree/blob/download", blob: blob | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +.btn-group.tree-btn-group | |
2 | + -# only show edit link for text files | |
3 | + - if @tree.text? | |
4 | + = link_to "edit", edit_project_tree_path(@project, @id), class: "btn very_small" | |
5 | + = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank" | |
6 | + -# only show normal/blame view links for text files | |
7 | + - if @tree.text? | |
8 | + - if current_page? project_blame_path(@project, @id) | |
9 | + = link_to "normal view", project_tree_path(@project, @id), class: "btn very_small" | |
10 | + - else | |
11 | + = link_to "blame", project_blame_path(@project, @id), class: "btn very_small" | |
12 | + = link_to "history", project_commits_path(@project, @id), class: "btn very_small" | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +.file_holder#README | |
2 | + .file_title | |
3 | + %i.icon-file | |
4 | + = readme.name | |
5 | + .file_content.wiki | |
6 | + - if gitlab_markdown?(readme.name) | |
7 | + = preserve do | |
8 | + = markdown(readme.data) | |
9 | + - else | |
10 | + = raw GitHub::Markup.render(readme.name, readme.data) | |
0 | 11 | \ No newline at end of file | ... | ... |
app/views/tree/_submodule_item.html.haml
app/views/tree/_tree.html.haml
... | ... | @@ -12,15 +12,14 @@ |
12 | 12 | |
13 | 13 | %div#tree-content-holder.tree-content-holder |
14 | 14 | - if tree.is_blob? |
15 | - = render partial: "tree/tree_file", object: tree | |
15 | + = render "tree/blob", blob: tree | |
16 | 16 | - else |
17 | 17 | %table#tree-slider{class: "table_#{@hex_path} tree-table" } |
18 | 18 | %thead |
19 | 19 | %th Name |
20 | 20 | %th Last Update |
21 | - %th | |
22 | - Last commit | |
23 | - = link_to "History", tree.history_path, class: "right" | |
21 | + %th Last Commit | |
22 | + %th= link_to "history", project_commits_path(@project, @id), class: "btn very_small right" | |
24 | 23 | |
25 | 24 | - if tree.up_dir? |
26 | 25 | %tr.tree-item |
... | ... | @@ -29,20 +28,12 @@ |
29 | 28 | = link_to "..", tree.up_dir_path |
30 | 29 | %td |
31 | 30 | %td |
31 | + %td | |
32 | 32 | |
33 | 33 | = render_tree(tree.contents) |
34 | 34 | |
35 | - - if content = tree.contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i } | |
36 | - .file_holder#README | |
37 | - .file_title | |
38 | - %i.icon-file | |
39 | - = content.name | |
40 | - .file_content.wiki | |
41 | - - if gitlab_markdown?(content.name) | |
42 | - = preserve do | |
43 | - = markdown(content.data) | |
44 | - - else | |
45 | - = raw GitHub::Markup.render(content.name, content.data) | |
35 | + - if readme = tree.contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i } | |
36 | + = render "tree/readme", readme: readme | |
46 | 37 | |
47 | 38 | - unless tree.is_blob? |
48 | 39 | :javascript | ... | ... |
app/views/tree/_tree_file.html.haml
... | ... | @@ -1,42 +0,0 @@ |
1 | -.file_holder | |
2 | - .file_title | |
3 | - %i.icon-file | |
4 | - %span.file_name | |
5 | - = tree_file.name.force_encoding('utf-8') | |
6 | - %small #{tree_file.mode} | |
7 | - %span.options | |
8 | - .btn-group.tree-btn-group | |
9 | - = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank" | |
10 | - = link_to "history", project_commits_path(@project, @id), class: "btn very_small" | |
11 | - = link_to "blame", project_blame_path(@project, @id), class: "btn very_small" | |
12 | - = link_to "edit", edit_project_tree_path(@project, @id), class: "btn very_small" | |
13 | - - if tree_file.text? | |
14 | - - if gitlab_markdown?(tree_file.name) | |
15 | - .file_content.wiki | |
16 | - = preserve do | |
17 | - = markdown(tree_file.data) | |
18 | - - elsif markup?(tree_file.name) | |
19 | - .file_content.wiki | |
20 | - = raw GitHub::Markup.render(tree_file.name, tree_file.data) | |
21 | - - else | |
22 | - .file_content.code | |
23 | - - unless tree_file.empty? | |
24 | - %div{class: current_user.dark_scheme ? "black" : "white"} | |
25 | - = preserve do | |
26 | - = raw tree_file.colorize(options: { linenos: 'True'}) | |
27 | - - else | |
28 | - %h4.nothing_here_message Empty file | |
29 | - | |
30 | - - elsif tree_file.image? | |
31 | - .file_content.image_file | |
32 | - %img{ src: "data:#{tree_file.mime_type};base64,#{Base64.encode64(tree_file.data)}"} | |
33 | - | |
34 | - - else | |
35 | - .file_content.blob_file | |
36 | - %center | |
37 | - = link_to project_blob_path(@project, @id) do | |
38 | - %div.padded | |
39 | - %br | |
40 | - = image_tag "download.png", width: 64 | |
41 | - %h3 | |
42 | - Download (#{tree_file.mb_size}) |
app/views/tree/_tree_item.html.haml
... | ... | @@ -0,0 +1,15 @@ |
1 | +- if gitlab_markdown?(blob.name) | |
2 | + .file_content.wiki | |
3 | + = preserve do | |
4 | + = markdown(blob.data) | |
5 | +- elsif markup?(blob.name) | |
6 | + .file_content.wiki | |
7 | + = raw GitHub::Markup.render(blob.name, blob.data) | |
8 | +- else | |
9 | + .file_content.code | |
10 | + - unless blob.empty? | |
11 | + %div{class: current_user.dark_scheme ? "black" : "white"} | |
12 | + = preserve do | |
13 | + = raw blob.colorize(options: { linenos: 'True'}) | |
14 | + - else | |
15 | + %h4.nothing_here_message Empty file | ... | ... |
features/steps/project/project_browse_files.rb
... | ... | @@ -5,14 +5,14 @@ class ProjectBrowseFiles < Spinach::FeatureSteps |
5 | 5 | |
6 | 6 | Then 'I should see files from repository' do |
7 | 7 | page.should have_content "app" |
8 | - page.should have_content "History" | |
8 | + page.should have_content "history" | |
9 | 9 | page.should have_content "Gemfile" |
10 | 10 | end |
11 | 11 | |
12 | 12 | Then 'I should see files from repository for "8470d70"' do |
13 | 13 | current_path.should == project_tree_path(@project, "8470d70") |
14 | 14 | page.should have_content "app" |
15 | - page.should have_content "History" | |
15 | + page.should have_content "history" | |
16 | 16 | page.should have_content "Gemfile" |
17 | 17 | end |
18 | 18 | ... | ... |
lib/gitlab/file_editor.rb
... | ... | @@ -51,7 +51,7 @@ module Gitlab |
51 | 51 | protected |
52 | 52 | |
53 | 53 | def can_edit?(path, last_commit) |
54 | - current_last_commit = @project.commits(ref, path, 1).first.sha | |
54 | + current_last_commit = @project.last_commit_for(ref, path).sha | |
55 | 55 | last_commit == current_last_commit |
56 | 56 | end |
57 | 57 | end | ... | ... |