diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/main.scss | 6 | ||||
-rw-r--r-- | app/assets/stylesheets/sections/editor.scss | 14 | ||||
-rw-r--r-- | app/assets/stylesheets/sections/tree.scss | 8 | ||||
-rw-r--r-- | app/controllers/tree_controller.rb | 21 | ||||
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/observers/note_observer.rb | 3 | ||||
-rw-r--r-- | app/roles/repository.rb | 4 | ||||
-rw-r--r-- | app/views/notify/note_wiki_email.html.haml | 2 | ||||
-rw-r--r-- | app/views/tree/_tree_file.html.haml | 8 | ||||
-rw-r--r-- | app/views/tree/edit.html.haml | 30 |
11 files changed, 93 insertions, 6 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d582a1a1727..21554ba396d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,4 +18,5 @@ //= require chosen-jquery //= require raphael //= require branch-graph +//= require ace-src-noconflict/ace.js //= require_tree . diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index bff24493820..f8cf8e449b4 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -182,3 +182,9 @@ $hover: #D9EDF7; * */ @import "highlight/dark.scss"; + +/** + * File Editor styles + * + */ +@import "sections/editor.scss"; diff --git a/app/assets/stylesheets/sections/editor.scss b/app/assets/stylesheets/sections/editor.scss new file mode 100644 index 00000000000..84f221bd621 --- /dev/null +++ b/app/assets/stylesheets/sections/editor.scss @@ -0,0 +1,14 @@ +.file-editor { + #editor{ + height: 500px; + width: 100%; + position: relative; + } + .editor-commit-comment { + padding-top:20px; + textarea { + width: 50%; + margin-left: 20px; + } + } +} diff --git a/app/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss index cd31b6a3ee4..c08a93fc8af 100644 --- a/app/assets/stylesheets/sections/tree.scss +++ b/app/assets/stylesheets/sections/tree.scss @@ -59,3 +59,11 @@ } } } + +.tree-btn-group { + .btn { + margin-right:-3px; + padding:2px 10px; + } +} + diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index 2270eede84d..475e2b61a18 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -19,4 +19,25 @@ class TreeController < ProjectResourceController format.js { no_cache_headers } end end + + def edit + @last_commit = @project.last_commit_for(@ref, @path).sha + end + + def update + file_editor = Gitlab::FileEditor.new(current_user, @project, @ref) + update_status = file_editor.update( + @path, + params[:content], + params[:commit_message], + params[:last_commit] + ) + + if update_status + redirect_to project_tree_path(@project, @id), :notice => "File has been successfully changed" + else + flash[:notice] = "You can't save file because it has been changed" + render :edit + end + end end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 5b3c37249fc..f4644dacc61 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -23,7 +23,7 @@ class MergeRequest < ActiveRecord::Base validate :validate_branches def self.find_all_by_branch(branch_name) - where("source_branch like :branch or target_branch like :branch", branch: branch_name) + where("source_branch LIKE :branch OR target_branch LIKE :branch", branch: branch_name) end def human_state diff --git a/app/observers/note_observer.rb b/app/observers/note_observer.rb index 3d51b9c2e2e..d328338a706 100644 --- a/app/observers/note_observer.rb +++ b/app/observers/note_observer.rb @@ -16,7 +16,8 @@ class NoteObserver < ActiveRecord::Observer protected def notify_team_of_new_note(note) - notify_method = 'note_' + note.noteable_type.underscore + '_email' + note_is_on = note.noteable_type || 'Wall' + notify_method = 'note_' + note_is_on.underscore + '_email' if Notify.respond_to? notify_method team_without_note_author(note).map do |u| diff --git a/app/roles/repository.rb b/app/roles/repository.rb index 35093a2fc75..88fd90d061f 100644 --- a/app/roles/repository.rb +++ b/app/roles/repository.rb @@ -32,6 +32,10 @@ module Repository Commit.commits(repo, ref, path, limit, offset) end + def last_commit_for(ref, path = nil) + commits(ref, path, 1).first + end + def commits_between(from, to) Commit.commits_between(repo, from, to) end diff --git a/app/views/notify/note_wiki_email.html.haml b/app/views/notify/note_wiki_email.html.haml index d3840cdac06..41a237fc53e 100644 --- a/app/views/notify/note_wiki_email.html.haml +++ b/app/views/notify/note_wiki_email.html.haml @@ -5,7 +5,7 @@ %td{align: "left", style: "padding: 20px 0 0;"} %h2{style: "color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} New comment for Wiki page - = link_to_gfm @wiki.title, project_issue_url(@wiki.project, @wiki, anchor: "note_#{@note.id}") + = link_to_gfm @wiki.title, project_wiki_url(@wiki.project, @wiki, anchor: "note_#{@note.id}") %td{style: "font-size: 1px; line-height: 1px;", width: "21"} %tr %td{style: "font-size: 1px; line-height: 1px;", width: "21"} diff --git a/app/views/tree/_tree_file.html.haml b/app/views/tree/_tree_file.html.haml index 82aaed24bdc..5202126792a 100644 --- a/app/views/tree/_tree_file.html.haml +++ b/app/views/tree/_tree_file.html.haml @@ -5,9 +5,11 @@ = tree_file.name.force_encoding('utf-8') %small #{tree_file.mode} %span.options - = 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 "blame", project_blame_path(@project, @id), class: "btn very_small" + .btn-group.tree-btn-group + = 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 "blame", project_blame_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 gitlab_markdown?(tree_file.name) .file_content.wiki diff --git a/app/views/tree/edit.html.haml b/app/views/tree/edit.html.haml new file mode 100644 index 00000000000..b81373b5587 --- /dev/null +++ b/app/views/tree/edit.html.haml @@ -0,0 +1,30 @@ +.file-editor + = form_tag(project_tree_path(@project, @id), :method => :put) do + .file_holder + .file_title + %i.icon-file + %span.file_name + = @tree.path.force_encoding('utf-8') + %span.options + = link_to "cancel editing", project_tree_path(@project, @id), class: "btn very_small" + .file_content.code + #editor= @tree.data + + .editor-commit-comment + = label_tag 'commit_message' do + %p.slead Commit message + = text_area_tag 'commit_message', '', :required => true + .form-actions + = hidden_field_tag 'last_commit', @last_commit + = hidden_field_tag 'content', '', :id => :file_content + = button_tag "Save", class: 'btn save-btn' + +:javascript + var editor = ace.edit("editor"); + editor.setTheme("ace/theme/twilight"); + editor.getSession().setMode("ace/mode/javascript"); + + $(".save-btn").click(function(){ + $("#file_content").val(editor.getValue()); + $(".form_editor form").submit(); + }); |