summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/blob_controller.rb25
-rw-r--r--app/views/projects/blob/_actions.html.haml6
-rw-r--r--app/views/projects/blob/_remove.html.haml19
-rw-r--r--app/views/projects/blob/show.html.haml3
-rw-r--r--config/routes.rb2
5 files changed, 51 insertions, 4 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index ba466251b29..087c1639ac6 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController
before_filter :authorize_code_access!
before_filter :require_non_empty_project
+ before_filter :blob
+
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
diff --git a/app/views/projects/blob/_actions.html.haml b/app/views/projects/blob/_actions.html.haml
index f6cc62e707e..2f82bfe52f3 100644
--- a/app/views/projects/blob/_actions.html.haml
+++ b/app/views/projects/blob/_actions.html.haml
@@ -4,7 +4,7 @@
- if allowed_tree_edit?
= link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small"
- 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"
-# only show normal/blame view links for text files
- if @blob.text?
@@ -13,3 +13,7 @@
- else
= 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"
+
+ - if allowed_tree_edit?
+ = link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do
+ remove
diff --git a/app/views/projects/blob/_remove.html.haml b/app/views/projects/blob/_remove.html.haml
new file mode 100644
index 00000000000..1c097330c44
--- /dev/null
+++ b/app/views/projects/blob/_remove.html.haml
@@ -0,0 +1,19 @@
+%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"
diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml
index d96595bc7f0..56220e520f3 100644
--- a/app/views/projects/blob/show.html.haml
+++ b/app/views/projects/blob/show.html.haml
@@ -2,3 +2,6 @@
= render 'shared/ref_switcher', destination: 'blob', path: @path
%div#tree-holder.tree-holder
= render 'blob', blob: @blob
+
+- if allowed_tree_edit?
+ = render 'projects/blob/remove'
diff --git a/config/routes.rb b/config/routes.rb
index 06e8fddf705..d89fc20c6c9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do
end
scope module: :projects do
- resources :blob, only: [:show], constraints: {id: /.+/}
+ resources :blob, only: [:show, :destroy], constraints: {id: /.+/}
resources :raw, only: [:show], constraints: {id: /.+/}
resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ }
resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit'