Commit 5ab3e38ecd58d0b90e5bdc430facf52a0b9b7835
Exists in
master
and in
4 other branches
Merge pull request #1371 from tsigo/project_panel
Refactor the project clone panel
Showing
11 changed files
with
66 additions
and
96 deletions
Show diff stats
app/assets/javascripts/projects.js
... | ... | @@ -1,25 +0,0 @@ |
1 | -function Projects() { | |
2 | - $("#project_name").live("change", function(){ | |
3 | - var slug = slugify($(this).val()); | |
4 | - $("#project_code").val(slug); | |
5 | - $("#project_path").val(slug); | |
6 | - }); | |
7 | - | |
8 | - $('.new_project, .edit_project').live('ajax:before', function() { | |
9 | - $('.project_new_holder, .project_edit_holder').hide(); | |
10 | - $('.save-project-loader').show(); | |
11 | - }); | |
12 | - | |
13 | - $('form #project_default_branch').chosen(); | |
14 | - | |
15 | - disableButtonIfEmtpyField("#project_name", ".project-submit") | |
16 | -} | |
17 | - | |
18 | -function initGitCloneSwitcher() { | |
19 | - var link_sel = ".project_clone_holder button"; | |
20 | - $(link_sel).bind("click", function(e) { | |
21 | - $(link_sel).removeClass("active"); | |
22 | - $(this).addClass("active"); | |
23 | - $("#project_clone").val($(this).attr("data-clone")); | |
24 | - }) | |
25 | -} |
... | ... | @@ -0,0 +1,21 @@ |
1 | +window.Projects = -> | |
2 | + $("#project_name").live "change", -> | |
3 | + slug = slugify($(this).val()) | |
4 | + $("#project_code").val(slug) | |
5 | + $("#project_path").val(slug) | |
6 | + | |
7 | + $(".new_project, .edit_project").live "ajax:before", -> | |
8 | + $(".project_new_holder, .project_edit_holder").hide() | |
9 | + $(".save-project-loader").show() | |
10 | + | |
11 | + $("form #project_default_branch").chosen() | |
12 | + disableButtonIfEmtpyField "#project_name", ".project-submit" | |
13 | + | |
14 | +# Git clone panel switcher | |
15 | +$ -> | |
16 | + scope = $('.project_clone_holder') | |
17 | + if scope.length > 0 | |
18 | + $('a, button', scope).click -> | |
19 | + $('a, button', scope).removeClass('active') | |
20 | + $(this).addClass('active') | |
21 | + $('#project_clone', scope).val($(this).data('clone')) | ... | ... |
app/controllers/application_controller.rb
... | ... | @@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base |
135 | 135 | end |
136 | 136 | |
137 | 137 | def require_non_empty_project |
138 | - redirect_to @project unless @project.repo_exists? && @project.has_commits? | |
138 | + redirect_to @project if @project.empty_repo? | |
139 | 139 | end |
140 | 140 | |
141 | 141 | def no_cache_headers | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -50,7 +50,7 @@ class ProjectsController < ApplicationController |
50 | 50 | |
51 | 51 | respond_to do |format| |
52 | 52 | format.html do |
53 | - if @project.repo_exists? && @project.has_commits? | |
53 | + unless @project.empty_repo? | |
54 | 54 | @last_push = current_user.recent_push(@project.id) |
55 | 55 | render :show |
56 | 56 | else | ... | ... |
app/roles/repository.rb
... | ... | @@ -8,6 +8,10 @@ module Repository |
8 | 8 | false |
9 | 9 | end |
10 | 10 | |
11 | + def empty_repo? | |
12 | + !repo_exists? || !has_commits? | |
13 | + end | |
14 | + | |
11 | 15 | def commit(commit_id = nil) |
12 | 16 | Commit.find_or_first(repo, commit_id, root_ref) |
13 | 17 | end |
... | ... | @@ -38,7 +42,7 @@ module Repository |
38 | 42 | |
39 | 43 | def has_post_receive_file? |
40 | 44 | hook_file = File.join(path_to_repo, 'hooks', 'post-receive') |
41 | - File.exists?(hook_file) | |
45 | + File.exists?(hook_file) | |
42 | 46 | end |
43 | 47 | |
44 | 48 | def tags |
... | ... | @@ -67,7 +71,7 @@ module Repository |
67 | 71 | |
68 | 72 | def repo_exists? |
69 | 73 | @repo_exists ||= (repo && !repo.branches.empty?) |
70 | - rescue | |
74 | + rescue | |
71 | 75 | @repo_exists = false |
72 | 76 | end |
73 | 77 | |
... | ... | @@ -94,7 +98,7 @@ module Repository |
94 | 98 | !!commit |
95 | 99 | end |
96 | 100 | |
97 | - def root_ref | |
101 | + def root_ref | |
98 | 102 | default_branch || "master" |
99 | 103 | end |
100 | 104 | |
... | ... | @@ -104,7 +108,7 @@ module Repository |
104 | 108 | |
105 | 109 | # Archive Project to .tar.gz |
106 | 110 | # |
107 | - # Already packed repo archives stored at | |
111 | + # Already packed repo archives stored at | |
108 | 112 | # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz |
109 | 113 | # |
110 | 114 | def archive_repo ref | ... | ... |
app/views/projects/_clone_panel.html.haml
... | ... | @@ -8,14 +8,14 @@ |
8 | 8 | = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" |
9 | 9 | .span4.right |
10 | 10 | .right |
11 | - - if can? current_user, :download_code, @project | |
12 | - = link_to archive_project_repository_path(@project), class: "btn small grouped" do | |
13 | - %i.icon-download-alt | |
14 | - Download | |
15 | - - if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project) | |
16 | - = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do | |
17 | - Merge Request | |
18 | - - if @project.issues_enabled && can?(current_user, :write_issue, @project) | |
19 | - = link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do | |
20 | - Issue | |
21 | - | |
11 | + - unless @project.empty_repo? | |
12 | + - if can? current_user, :download_code, @project | |
13 | + = link_to archive_project_repository_path(@project), class: "btn small grouped" do | |
14 | + %i.icon-download-alt | |
15 | + Download | |
16 | + - if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project) | |
17 | + = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do | |
18 | + Merge Request | |
19 | + - if @project.issues_enabled && can?(current_user, :write_issue, @project) | |
20 | + = link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do | |
21 | + Issue | ... | ... |
app/views/projects/_show.html.haml
... | ... | @@ -1,23 +0,0 @@ |
1 | -%h5.title | |
2 | - = @project.name | |
3 | -%br | |
4 | -%div | |
5 | - %a.btn.info{href: tree_project_ref_path(@project, @project.root_ref)} Browse code | |
6 | - | |
7 | - %a.btn{href: project_commits_path(@project)} Commits | |
8 | - %strong.right | |
9 | - = link_to project_path(@project) do | |
10 | - Switch to project → | |
11 | -%br | |
12 | -.alert-message.block-message.warning | |
13 | - .input | |
14 | - .input-prepend | |
15 | - %span.add-on git clone | |
16 | - = text_field_tag :project_clone, @project.url_to_repo, class: "xlarge one_click_select git_clone_url" | |
17 | - | |
18 | -= simple_format @project.description | |
19 | -- unless @events.blank? | |
20 | - %h4.middle_title Recent Activity | |
21 | - .content_list= render @events | |
22 | - | |
23 | - |
app/views/projects/empty.html.haml
1 | 1 | = render 'shared/no_ssh' |
2 | -.project_clone_panel | |
3 | - .row | |
4 | - .span7 | |
5 | - .form-horizontal | |
6 | - .input-prepend.project_clone_holder | |
7 | - = link_to "SSH", "#", class: "btn small active", :"data-clone" => @project.ssh_url_to_repo | |
8 | - = link_to "HTTP", "#", class: "btn small", :"data-clone" => @project.http_url_to_repo | |
9 | - = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" | |
2 | += render 'clone_panel' | |
3 | + | |
10 | 4 | %div.git-empty |
11 | 5 | %h4 Git global setup: |
12 | 6 | %pre.dark |
... | ... | @@ -36,16 +30,3 @@ |
36 | 30 | - if can? current_user, :admin_project, @project |
37 | 31 | .prepend-top-20 |
38 | 32 | = link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right" |
39 | - | |
40 | - | |
41 | - | |
42 | -:javascript | |
43 | - $(function(){ | |
44 | - var link_sel = ".project_clone_holder a"; | |
45 | - $(link_sel).bind("click", function() { | |
46 | - $(link_sel).removeClass("active"); | |
47 | - $(this).addClass("active"); | |
48 | - $("#project_clone").val($(this).attr("data-clone")); | |
49 | - }) | |
50 | - }) | |
51 | - | ... | ... |
app/views/projects/show.html.haml
app/views/refs/_head.html.haml
... | ... | @@ -12,8 +12,3 @@ |
12 | 12 | %button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH |
13 | 13 | %button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP |
14 | 14 | = text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5" |
15 | - | |
16 | -:javascript | |
17 | - $(function(){ | |
18 | - initGitCloneSwitcher(); | |
19 | - }) | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe Project, "Repository" do | |
4 | + let(:project) { build(:project) } | |
5 | + | |
6 | + describe "#empty_repo?" do | |
7 | + it "should return true if the repo doesn't exist" do | |
8 | + project.stub(repo_exists?: false, has_commits?: true) | |
9 | + project.should be_empty_repo | |
10 | + end | |
11 | + | |
12 | + it "should return true if the repo has commits" do | |
13 | + project.stub(repo_exists?: true, has_commits?: false) | |
14 | + project.should be_empty_repo | |
15 | + end | |
16 | + | |
17 | + it "should return false if the repo exists and has commits" do | |
18 | + project.stub(repo_exists?: true, has_commits?: true) | |
19 | + project.should_not be_empty_repo | |
20 | + end | |
21 | + end | |
22 | +end | ... | ... |