From e53b47b447b1f1ba8185aa07b8c53102c592ead8 Mon Sep 17 00:00:00 2001 From: Valeriy Sizov Date: Fri, 12 Oct 2012 00:15:24 +0300 Subject: [PATCH] WebEditor: sceleton --- app/controllers/tree_controller.rb | 8 ++++++++ app/views/tree/edit.html.haml | 4 ++-- lib/gitlab/file_editor.rb | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 lib/gitlab/file_editor.rb diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index 6224ed06..0a67e033 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -26,5 +26,13 @@ class TreeController < ProjectResourceController def update last_commit = @project.commits(@ref, @path, 1).first.sha + file_editor = Gitlab::FileEditor.new(current_user, @project) + if file_editor.can_edit?(@path, last_commit) + file_editor.update(@path, params[:content]) + 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/views/tree/edit.html.haml b/app/views/tree/edit.html.haml index c65d8fd3..170001a8 100644 --- a/app/views/tree/edit.html.haml +++ b/app/views/tree/edit.html.haml @@ -8,9 +8,9 @@ #editor= @tree.data .editor-commit-comment - = label_tag 'text-commit' do + = label_tag 'commit_message' do %p.slead Commit message - = text_area_tag 'text_commit' + = text_area_tag 'commit_message' .form-actions = hidden_field_tag 'last_commit', @last_commit = hidden_field_tag 'content' diff --git a/lib/gitlab/file_editor.rb b/lib/gitlab/file_editor.rb new file mode 100644 index 00000000..2a48cc45 --- /dev/null +++ b/lib/gitlab/file_editor.rb @@ -0,0 +1,20 @@ +module Gitlab + class FileEditor + + attr_accessor :user, :project + + def initialize(user, project) + self.user = user + self.project = project + end + + def can_edit?(path, last_commit) + true + end + + def update(path, content) + true + end + + end +end