Merge pull request #1371 from tsigo/project_panel
Refactor the project clone panel
This commit is contained in:
commit
5ab3e38ecd
11 changed files with 66 additions and 96 deletions
|
@ -1,25 +0,0 @@
|
||||||
function Projects() {
|
|
||||||
$("#project_name").live("change", function(){
|
|
||||||
var slug = slugify($(this).val());
|
|
||||||
$("#project_code").val(slug);
|
|
||||||
$("#project_path").val(slug);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.new_project, .edit_project').live('ajax:before', function() {
|
|
||||||
$('.project_new_holder, .project_edit_holder').hide();
|
|
||||||
$('.save-project-loader').show();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('form #project_default_branch').chosen();
|
|
||||||
|
|
||||||
disableButtonIfEmtpyField("#project_name", ".project-submit")
|
|
||||||
}
|
|
||||||
|
|
||||||
function initGitCloneSwitcher() {
|
|
||||||
var link_sel = ".project_clone_holder button";
|
|
||||||
$(link_sel).bind("click", function(e) {
|
|
||||||
$(link_sel).removeClass("active");
|
|
||||||
$(this).addClass("active");
|
|
||||||
$("#project_clone").val($(this).attr("data-clone"));
|
|
||||||
})
|
|
||||||
}
|
|
21
app/assets/javascripts/projects.js.coffee
Normal file
21
app/assets/javascripts/projects.js.coffee
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
window.Projects = ->
|
||||||
|
$("#project_name").live "change", ->
|
||||||
|
slug = slugify($(this).val())
|
||||||
|
$("#project_code").val(slug)
|
||||||
|
$("#project_path").val(slug)
|
||||||
|
|
||||||
|
$(".new_project, .edit_project").live "ajax:before", ->
|
||||||
|
$(".project_new_holder, .project_edit_holder").hide()
|
||||||
|
$(".save-project-loader").show()
|
||||||
|
|
||||||
|
$("form #project_default_branch").chosen()
|
||||||
|
disableButtonIfEmtpyField "#project_name", ".project-submit"
|
||||||
|
|
||||||
|
# Git clone panel switcher
|
||||||
|
$ ->
|
||||||
|
scope = $('.project_clone_holder')
|
||||||
|
if scope.length > 0
|
||||||
|
$('a, button', scope).click ->
|
||||||
|
$('a, button', scope).removeClass('active')
|
||||||
|
$(this).addClass('active')
|
||||||
|
$('#project_clone', scope).val($(this).data('clone'))
|
|
@ -135,7 +135,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_non_empty_project
|
def require_non_empty_project
|
||||||
redirect_to @project unless @project.repo_exists? && @project.has_commits?
|
redirect_to @project if @project.empty_repo?
|
||||||
end
|
end
|
||||||
|
|
||||||
def no_cache_headers
|
def no_cache_headers
|
||||||
|
|
|
@ -50,7 +50,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html do
|
format.html do
|
||||||
if @project.repo_exists? && @project.has_commits?
|
unless @project.empty_repo?
|
||||||
@last_push = current_user.recent_push(@project.id)
|
@last_push = current_user.recent_push(@project.id)
|
||||||
render :show
|
render :show
|
||||||
else
|
else
|
||||||
|
|
|
@ -8,6 +8,10 @@ module Repository
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty_repo?
|
||||||
|
!repo_exists? || !has_commits?
|
||||||
|
end
|
||||||
|
|
||||||
def commit(commit_id = nil)
|
def commit(commit_id = nil)
|
||||||
Commit.find_or_first(repo, commit_id, root_ref)
|
Commit.find_or_first(repo, commit_id, root_ref)
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
= text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
|
= text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
|
||||||
.span4.right
|
.span4.right
|
||||||
.right
|
.right
|
||||||
- if can? current_user, :download_code, @project
|
- unless @project.empty_repo?
|
||||||
= link_to archive_project_repository_path(@project), class: "btn small grouped" do
|
- if can? current_user, :download_code, @project
|
||||||
%i.icon-download-alt
|
= link_to archive_project_repository_path(@project), class: "btn small grouped" do
|
||||||
Download
|
%i.icon-download-alt
|
||||||
- if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project)
|
Download
|
||||||
= link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do
|
- if @project.merge_requests_enabled && can?(current_user, :write_merge_request, @project)
|
||||||
Merge Request
|
= link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn small grouped" do
|
||||||
- if @project.issues_enabled && can?(current_user, :write_issue, @project)
|
Merge Request
|
||||||
= link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do
|
- if @project.issues_enabled && can?(current_user, :write_issue, @project)
|
||||||
Issue
|
= link_to new_project_issue_path(@project), title: "New Issue", class: "btn small grouped" do
|
||||||
|
Issue
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
%h5.title
|
|
||||||
= @project.name
|
|
||||||
%br
|
|
||||||
%div
|
|
||||||
%a.btn.info{href: tree_project_ref_path(@project, @project.root_ref)} Browse code
|
|
||||||
|
|
||||||
%a.btn{href: project_commits_path(@project)} Commits
|
|
||||||
%strong.right
|
|
||||||
= link_to project_path(@project) do
|
|
||||||
Switch to project →
|
|
||||||
%br
|
|
||||||
.alert-message.block-message.warning
|
|
||||||
.input
|
|
||||||
.input-prepend
|
|
||||||
%span.add-on git clone
|
|
||||||
= text_field_tag :project_clone, @project.url_to_repo, class: "xlarge one_click_select git_clone_url"
|
|
||||||
|
|
||||||
= simple_format @project.description
|
|
||||||
- unless @events.blank?
|
|
||||||
%h4.middle_title Recent Activity
|
|
||||||
.content_list= render @events
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
= render 'shared/no_ssh'
|
= render 'shared/no_ssh'
|
||||||
.project_clone_panel
|
= render 'clone_panel'
|
||||||
.row
|
|
||||||
.span7
|
|
||||||
.form-horizontal
|
|
||||||
.input-prepend.project_clone_holder
|
|
||||||
= link_to "SSH", "#", class: "btn small active", :"data-clone" => @project.ssh_url_to_repo
|
|
||||||
= link_to "HTTP", "#", class: "btn small", :"data-clone" => @project.http_url_to_repo
|
|
||||||
= text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
|
|
||||||
%div.git-empty
|
%div.git-empty
|
||||||
%h4 Git global setup:
|
%h4 Git global setup:
|
||||||
%pre.dark
|
%pre.dark
|
||||||
|
@ -36,16 +30,3 @@
|
||||||
- if can? current_user, :admin_project, @project
|
- if can? current_user, :admin_project, @project
|
||||||
.prepend-top-20
|
.prepend-top-20
|
||||||
= link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right"
|
= link_to 'Remove project', @project, confirm: 'Are you sure?', method: :delete, class: "btn danger right"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:javascript
|
|
||||||
$(function(){
|
|
||||||
var link_sel = ".project_clone_holder a";
|
|
||||||
$(link_sel).bind("click", function() {
|
|
||||||
$(link_sel).removeClass("active");
|
|
||||||
$(this).addClass("active");
|
|
||||||
$("#project_clone").val($(this).attr("data-clone"));
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,3 @@
|
||||||
= render 'clone_panel'
|
= render 'clone_panel'
|
||||||
= render "events/event_last_push", event: @last_push
|
= render "events/event_last_push", event: @last_push
|
||||||
.content_list= render @events
|
.content_list= render @events
|
||||||
|
|
||||||
:javascript
|
|
||||||
$(function(){
|
|
||||||
initGitCloneSwitcher();
|
|
||||||
})
|
|
||||||
|
|
|
@ -12,8 +12,3 @@
|
||||||
%button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
|
%button{class: "btn small active", :"data-clone" => @project.ssh_url_to_repo} SSH
|
||||||
%button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP
|
%button{class: "btn small", :"data-clone" => @project.http_url_to_repo} HTTP
|
||||||
= text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
|
= text_field_tag :project_clone, @project.url_to_repo, class: "one_click_select span5"
|
||||||
|
|
||||||
:javascript
|
|
||||||
$(function(){
|
|
||||||
initGitCloneSwitcher();
|
|
||||||
})
|
|
||||||
|
|
22
spec/roles/repository_spec.rb
Normal file
22
spec/roles/repository_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Project, "Repository" do
|
||||||
|
let(:project) { build(:project) }
|
||||||
|
|
||||||
|
describe "#empty_repo?" do
|
||||||
|
it "should return true if the repo doesn't exist" do
|
||||||
|
project.stub(repo_exists?: false, has_commits?: true)
|
||||||
|
project.should be_empty_repo
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true if the repo has commits" do
|
||||||
|
project.stub(repo_exists?: true, has_commits?: false)
|
||||||
|
project.should be_empty_repo
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return false if the repo exists and has commits" do
|
||||||
|
project.stub(repo_exists?: true, has_commits?: true)
|
||||||
|
project.should_not be_empty_repo
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue