Commit bd20ec1a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Remove file from repository feature

After click on remove file button you will be asked for commit message
via modal window. After submitting modal form file will be removed from
repository
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4cac195a
...@@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController
before_filter :authorize_code_access! before_filter :authorize_code_access!
before_filter :require_non_empty_project before_filter :require_non_empty_project
before_filter :blob
def show def show
@blob = @repository.blob_at(@commit.id, @path) end
def destroy
result = Files::DeleteContext.new(@project, current_user, params, @ref, @path).execute
if result[:status] == :success
flash[:notice] = "Your changes have been successfully commited"
redirect_to project_tree_path(@project, @ref)
else
flash[:alert] = result[:error]
render :show
end
end
private
def blob
@blob ||= @repository.blob_at(@commit.id, @path)
return not_found! unless @blob
not_found! unless @blob @blob
end end
end end
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- if allowed_tree_edit? - if allowed_tree_edit?
= link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small" = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small"
- else - else
%span.btn.btn-small.disabled Edit %span.btn.btn-small.disabled edit
= link_to "raw", project_raw_path(@project, @id), class: "btn btn-small", target: "_blank" = link_to "raw", project_raw_path(@project, @id), class: "btn btn-small", target: "_blank"
-# only show normal/blame view links for text files -# only show normal/blame view links for text files
- if @blob.text? - if @blob.text?
...@@ -13,3 +13,7 @@ ...@@ -13,3 +13,7 @@
- else - else
= link_to "blame", project_blame_path(@project, @id), class: "btn btn-small" unless @blob.empty? = link_to "blame", project_blame_path(@project, @id), class: "btn btn-small" unless @blob.empty?
= link_to "history", project_commits_path(@project, @id), class: "btn btn-small" = link_to "history", project_commits_path(@project, @id), class: "btn btn-small"
- if allowed_tree_edit?
= link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do
remove
%div#modal-remove-blob.modal.hide
.modal-header
%a.close{href: "#", "data-dismiss" => "modal"} ×
%h3.page-title Remove #{@blob.name}
%p.light
From branch
%strong= @ref
.modal-body
= form_tag project_blob_path(@project, @id), method: :delete do
.control-group.commit_message-group
= label_tag 'commit_message', class: "control-label" do
Commit message
.controls
= text_area_tag 'commit_message', params[:commit_message], placeholder: "Removed this file because...", required: true, rows: 3
.control-group
.controls
= submit_tag 'Remove file', class: 'btn btn-remove'
= link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal"
...@@ -2,3 +2,6 @@ ...@@ -2,3 +2,6 @@
= render 'shared/ref_switcher', destination: 'blob', path: @path = render 'shared/ref_switcher', destination: 'blob', path: @path
%div#tree-holder.tree-holder %div#tree-holder.tree-holder
= render 'blob', blob: @blob = render 'blob', blob: @blob
- if allowed_tree_edit?
= render 'projects/blob/remove'
...@@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do ...@@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do
end end
scope module: :projects do scope module: :projects do
resources :blob, only: [:show], constraints: {id: /.+/} resources :blob, only: [:show, :destroy], constraints: {id: /.+/}
resources :raw, only: [:show], constraints: {id: /.+/} resources :raw, only: [:show], constraints: {id: /.+/}
resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ } resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ }
resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit' resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit'
......
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