Commit 809aefb8 authored by randx's avatar randx

Minor improve to UI and code formatting of gitlab web editor

parent 47d9732a
...@@ -59,3 +59,11 @@ ...@@ -59,3 +59,11 @@
} }
} }
} }
.tree-btn-group {
.btn {
margin-right:-3px;
padding:2px 10px;
}
}
...@@ -21,7 +21,7 @@ class TreeController < ProjectResourceController ...@@ -21,7 +21,7 @@ class TreeController < ProjectResourceController
end end
def edit def edit
@last_commit = @project.commits(@ref, @path, 1).first.sha @last_commit = @project.last_commit_for(@ref, @path).sha
end end
def update def update
......
...@@ -32,6 +32,10 @@ module Repository ...@@ -32,6 +32,10 @@ module Repository
Commit.commits(repo, ref, path, limit, offset) Commit.commits(repo, ref, path, limit, offset)
end end
def last_commit_for(ref, path = nil)
commits(ref, path, 1).first
end
def commits_between(from, to) def commits_between(from, to)
Commit.commits_between(repo, from, to) Commit.commits_between(repo, from, to)
end end
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
= tree_file.name.force_encoding('utf-8') = tree_file.name.force_encoding('utf-8')
%small #{tree_file.mode} %small #{tree_file.mode}
%span.options %span.options
.btn-group.tree-btn-group
= link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank" = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank"
= link_to "history", project_commits_path(@project, @id), class: "btn very_small" = link_to "history", project_commits_path(@project, @id), class: "btn very_small"
= link_to "blame", project_blame_path(@project, @id), class: "btn very_small" = link_to "blame", project_blame_path(@project, @id), class: "btn very_small"
= link_to "Edit", edit_project_tree_path(@project, @id), class: "btn very_small" = link_to "edit", edit_project_tree_path(@project, @id), class: "btn very_small"
- if tree_file.text? - if tree_file.text?
- if gitlab_markdown?(tree_file.name) - if gitlab_markdown?(tree_file.name)
.file_content.wiki .file_content.wiki
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
.file_holder .file_holder
.file_title .file_title
%i.icon-file %i.icon-file
%span.file_name
= @tree.path.force_encoding('utf-8') = @tree.path.force_encoding('utf-8')
%span.options
= link_to "cancel editing", project_tree_path(@project, @id), class: "btn very_small"
.file_content.code .file_content.code
#editor= @tree.data #editor= @tree.data
......
...@@ -23,5 +23,5 @@ Feature: Project Browse files ...@@ -23,5 +23,5 @@ Feature: Project Browse files
@javascript @javascript
Scenario: I can edit file Scenario: I can edit file
Given I click on "Gemfile" file in repo Given I click on "Gemfile" file in repo
And I click button "Edit" And I click button "edit"
Then I can edit code Then I can edit code
...@@ -32,8 +32,8 @@ class ProjectBrowseFiles < Spinach::FeatureSteps ...@@ -32,8 +32,8 @@ class ProjectBrowseFiles < Spinach::FeatureSteps
page.source.should == ValidCommit::BLOB_FILE page.source.should == ValidCommit::BLOB_FILE
end end
Given 'I click button "Edit"' do Given 'I click button "edit"' do
click_link 'Edit' click_link 'edit'
end end
Then 'I can edit code' do Then 'I can edit code' do
......
module Gitlab module Gitlab
# GitLab file editor
#
# It gives you ability to make changes to files
# & commit this changes from GitLab UI.
class FileEditor class FileEditor
attr_accessor :user, :project, :ref attr_accessor :user, :project, :ref
def initialize(user, project, ref) def initialize(user, project, ref)
...@@ -35,22 +38,21 @@ module Gitlab ...@@ -35,22 +38,21 @@ module Gitlab
r.git.sh "git add ." r.git.sh "git add ."
r.git.sh "git commit -am '#{commit_message}'" r.git.sh "git commit -am '#{commit_message}'"
output = r.git.sh "git push origin #{ref}" output = r.git.sh "git push origin #{ref}"
if output =~ /reject/ if output =~ /reject/
return false return false
end end
end end
end end
end end
true true
end end
protected protected
def can_edit?(path, last_commit) def can_edit?(path, last_commit)
current_last_commit = @project.commits(ref, path, 1).first.sha current_last_commit = @project.commits(ref, path, 1).first.sha
last_commit == current_last_commit last_commit == current_last_commit
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment