Commit 809aefb828e0d4b5c06304fcde2dcfced66ab4e9

Authored by randx
1 parent 47d9732a

Minor improve to UI and code formatting of gitlab web editor

app/assets/stylesheets/sections/tree.scss
... ... @@ -59,3 +59,11 @@
59 59 }
60 60 }
61 61 }
  62 +
  63 +.tree-btn-group {
  64 + .btn {
  65 + margin-right:-3px;
  66 + padding:2px 10px;
  67 + }
  68 +}
  69 +
... ...
app/controllers/tree_controller.rb
... ... @@ -21,23 +21,23 @@ class TreeController < ProjectResourceController
21 21 end
22 22  
23 23 def edit
24   - @last_commit = @project.commits(@ref, @path, 1).first.sha
  24 + @last_commit = @project.last_commit_for(@ref, @path).sha
25 25 end
26 26  
27 27 def update
28 28 file_editor = Gitlab::FileEditor.new(current_user, @project, @ref)
29 29 update_status = file_editor.update(
30   - @path,
31   - params[:content],
32   - params[:commit_message],
  30 + @path,
  31 + params[:content],
  32 + params[:commit_message],
33 33 params[:last_commit]
34 34 )
35   -
  35 +
36 36 if update_status
37 37 redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed"
38 38 else
39 39 flash[:notice] = "You can't save file because it has been changed"
40   - render :edit
  40 + render :edit
41 41 end
42 42 end
43 43 end
... ...
app/roles/repository.rb
... ... @@ -32,6 +32,10 @@ module Repository
32 32 Commit.commits(repo, ref, path, limit, offset)
33 33 end
34 34  
  35 + def last_commit_for(ref, path = nil)
  36 + commits(ref, path, 1).first
  37 + end
  38 +
35 39 def commits_between(from, to)
36 40 Commit.commits_between(repo, from, to)
37 41 end
... ...
app/views/tree/_tree_file.html.haml
... ... @@ -5,10 +5,11 @@
5 5 = tree_file.name.force_encoding('utf-8')
6 6 %small #{tree_file.mode}
7 7 %span.options
8   - = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank"
9   - = link_to "history", project_commits_path(@project, @id), class: "btn very_small"
10   - = link_to "blame", project_blame_path(@project, @id), class: "btn very_small"
11   - = link_to "Edit", edit_project_tree_path(@project, @id), class: "btn very_small"
  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"
12 13 - if tree_file.text?
13 14 - if gitlab_markdown?(tree_file.name)
14 15 .file_content.wiki
... ...
app/views/tree/edit.html.haml
... ... @@ -3,7 +3,10 @@
3 3 .file_holder
4 4 .file_title
5 5 %i.icon-file
6   - = @tree.path.force_encoding('utf-8')
  6 + %span.file_name
  7 + = @tree.path.force_encoding('utf-8')
  8 + %span.options
  9 + = link_to "cancel editing", project_tree_path(@project, @id), class: "btn very_small"
7 10 .file_content.code
8 11 #editor= @tree.data
9 12  
... ...
features/project/source/browse_files.feature
... ... @@ -23,5 +23,5 @@ Feature: Project Browse files
23 23 @javascript
24 24 Scenario: I can edit file
25 25 Given I click on "Gemfile" file in repo
26   - And I click button "Edit"
  26 + And I click button "edit"
27 27 Then I can edit code
... ...
features/steps/project/project_browse_files.rb
... ... @@ -32,8 +32,8 @@ class ProjectBrowseFiles < Spinach::FeatureSteps
32 32 page.source.should == ValidCommit::BLOB_FILE
33 33 end
34 34  
35   - Given 'I click button "Edit"' do
36   - click_link 'Edit'
  35 + Given 'I click button "edit"' do
  36 + click_link 'edit'
37 37 end
38 38  
39 39 Then 'I can edit code' do
... ...
lib/gitlab/file_editor.rb
1 1 module Gitlab
  2 + # GitLab file editor
  3 + #
  4 + # It gives you ability to make changes to files
  5 + # & commit this changes from GitLab UI.
2 6 class FileEditor
3   -
4 7 attr_accessor :user, :project, :ref
5 8  
6 9 def initialize(user, project, ref)
... ... @@ -35,22 +38,21 @@ module Gitlab
35 38 r.git.sh "git add ."
36 39 r.git.sh "git commit -am '#{commit_message}'"
37 40 output = r.git.sh "git push origin #{ref}"
  41 +
38 42 if output =~ /reject/
39 43 return false
40 44 end
41 45 end
42 46 end
43 47 end
44   -
45 48 true
46   -
47 49 end
48   -
  50 +
49 51 protected
  52 +
50 53 def can_edit?(path, last_commit)
51 54 current_last_commit = @project.commits(ref, path, 1).first.sha
52 55 last_commit == current_last_commit
53 56 end
54   -
55 57 end
56 58 end
... ...