summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-16 22:19:07 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-16 22:19:07 +0300
commit7a167cf1f74b4e74c4ba9de715585a1251165c5b (patch)
tree99ee4ea2b292d7bcfa0adecb711572daf516c44c /app
parenta466b2175adc6021a75f31baabbaa42b14203d44 (diff)
downloadgitlab-ce-7a167cf1f74b4e74c4ba9de715585a1251165c5b.tar.gz
Move branches list to own controller with pagination. Ability to remove branches from UI
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/main.js.coffee3
-rw-r--r--app/controllers/projects/branches_controller.rb24
-rw-r--r--app/controllers/projects/repositories_controller.rb4
-rw-r--r--app/models/repository.rb6
-rw-r--r--app/views/projects/branches/_branch.html.haml27
-rw-r--r--app/views/projects/branches/index.html.haml10
-rw-r--r--app/views/projects/repositories/_branch.html.haml26
-rw-r--r--app/views/projects/repositories/_filter.html.haml4
-rw-r--r--app/views/projects/repositories/branches.html.haml15
-rw-r--r--app/views/projects/repositories/show.html.haml9
10 files changed, 74 insertions, 54 deletions
diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee
index 0e7e0a4de13..a991eba3117 100644
--- a/app/assets/javascripts/main.js.coffee
+++ b/app/assets/javascripts/main.js.coffee
@@ -62,6 +62,9 @@ $ ->
# Click a .one_click_select field, select the contents
$(".one_click_select").on 'click', -> $(@).select()
+ $('.remove-row').bind 'ajax:success', ->
+ $(this).closest('li').fadeOut()
+
# Click a .appear-link, appear-data fadeout
$(".appear-link").on 'click', (e) ->
$('.appear-data').fadeIn()
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
new file mode 100644
index 00000000000..5168d4df8b4
--- /dev/null
+++ b/app/controllers/projects/branches_controller.rb
@@ -0,0 +1,24 @@
+class Projects::BranchesController < Projects::ApplicationController
+ # Authorize
+ before_filter :authorize_read_project!
+ before_filter :require_non_empty_project
+
+ before_filter :authorize_admin_project!, only: [:destroy, :create]
+
+ def index
+ @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30)
+ end
+
+ def create
+ # TODO: implement
+ end
+
+ def destroy
+ @project.repository.rm_branch(params[:id])
+
+ respond_to do |format|
+ format.html { redirect_to project_branches_path }
+ format.js { render nothing: true }
+ end
+ end
+end
diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb
index b65af029803..7094a4c1ffe 100644
--- a/app/controllers/projects/repositories_controller.rb
+++ b/app/controllers/projects/repositories_controller.rb
@@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
@activities = @repository.commits_with_refs(20)
end
- def branches
- @branches = @repository.branches
- end
-
def tags
@tags = @repository.tags
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index b18e98bdf47..384836951c3 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -1,4 +1,6 @@
class Repository
+ include Gitlab::ShellAdapter
+
attr_accessor :raw_repository
def initialize(path_with_namespace, default_branch)
@@ -33,6 +35,10 @@ class Repository
commits
end
+ def rm_branch(branch_name)
+ gitlab_shell.rm_branch(path_with_namespace, branch_name)
+ end
+
def round_commit_count
if commit_count > 10000
'10000+'
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
new file mode 100644
index 00000000000..f43b56efc3a
--- /dev/null
+++ b/app/views/projects/branches/_branch.html.haml
@@ -0,0 +1,27 @@
+- commit = Commit.new(Gitlab::Git::Commit.new(branch.commit))
+%li
+ %h4
+ = link_to project_commits_path(@project, branch.name) do
+ %strong= truncate(branch.name, length: 60)
+ - if branch.name == @repository.root_ref
+ %span.label.label-info default
+ - if @project.protected_branch? branch.name
+ %span.label.label-success
+ %i.icon-lock
+ .pull-right
+ - if can?(current_user, :download_code, @project)
+ = link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do
+ %i.icon-download-alt
+ - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref
+ = link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, confirm: 'Removed branch cannot be restored. Are you sure?', remote: true do
+ %i.icon-trash
+
+ %p
+ = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
+ = commit.short_id
+ = image_tag gravatar_icon(commit.author_email), class: "avatar s16", alt: ''
+ %span.light
+ = gfm escape_once(truncate(commit.title, length: 40))
+ %span
+ = time_ago_in_words(commit.committed_date)
+ ago
diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml
new file mode 100644
index 00000000000..4cfafe1a7af
--- /dev/null
+++ b/app/views/projects/branches/index.html.haml
@@ -0,0 +1,10 @@
+= render "projects/commits/head"
+.row
+ .span3
+ = render "projects/repositories/filter"
+ .span9
+ - unless @branches.empty?
+ %ul.bordered-list
+ - @branches.each do |branch|
+ = render "projects/branches/branch", branch: branch
+ = paginate @branches, theme: 'gitlab'
diff --git a/app/views/projects/repositories/_branch.html.haml b/app/views/projects/repositories/_branch.html.haml
deleted file mode 100644
index 2115f3c427f..00000000000
--- a/app/views/projects/repositories/_branch.html.haml
+++ /dev/null
@@ -1,26 +0,0 @@
-- commit = Commit.new(Gitlab::Git::Commit.new(branch.commit))
-%tr
- %td
- = link_to project_commits_path(@project, branch.name) do
- - if @project.protected_branch? branch.name
- %i.icon-lock
- - else
- %i.icon-unlock
- %strong= truncate(branch.name, length: 60)
- - if branch.name == @repository.root_ref
- %span.label default
- %td
- = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
- = commit.short_id
- = image_tag gravatar_icon(commit.author_email), class: "avatar s16", alt: ''
- %span.light
- = gfm escape_once(truncate(commit.title, length: 40))
- %span
- = time_ago_in_words(commit.committed_date)
- ago
- %td
- - if can? current_user, :download_code, @project
- = link_to archive_project_repository_path(@project, ref: branch.name) do
- %i.icon-download-alt
- Download
-
diff --git a/app/views/projects/repositories/_filter.html.haml b/app/views/projects/repositories/_filter.html.haml
index e718d48190a..f42493ea4a0 100644
--- a/app/views/projects/repositories/_filter.html.haml
+++ b/app/views/projects/repositories/_filter.html.haml
@@ -5,5 +5,5 @@
= link_to project_protected_branches_path(@project) do
Protected
%i.icon-lock
- = nav_link(path: 'repositories#branches') do
- = link_to 'All branches', branches_project_repository_path(@project)
+ = nav_link(path: 'branches#index') do
+ = link_to 'All branches', project_branches_path(@project)
diff --git a/app/views/projects/repositories/branches.html.haml b/app/views/projects/repositories/branches.html.haml
deleted file mode 100644
index 2bdd304cdac..00000000000
--- a/app/views/projects/repositories/branches.html.haml
+++ /dev/null
@@ -1,15 +0,0 @@
-= render "projects/commits/head"
-.row
- .span3
- = render "filter"
- .span9
- - unless @branches.empty?
- %table
- %thead
- %tr
- %th Name
- %th Last commit
- %th
- %tbody
- - @branches.each do |branch|
- = render "projects/repositories/branch", branch: branch
diff --git a/app/views/projects/repositories/show.html.haml b/app/views/projects/repositories/show.html.haml
index 84a32e62426..611d0eddc4c 100644
--- a/app/views/projects/repositories/show.html.haml
+++ b/app/views/projects/repositories/show.html.haml
@@ -3,12 +3,7 @@
.span3
= render "filter"
.span9
- %table
- %thead
- %tr
- %th Name
- %th Last commit
- %th
+ %ul.bordered-list
- @activities.each do |update|
- = render "branch", branch: update.head
+ = render "projects/branches/branch", branch: update.head