Browse Source

PR: create interface

pull/1007/head
Unknwon 10 years ago
parent
commit
b5c5bc5334
  1. 3
      conf/locale/locale_en-US.ini
  2. 7
      models/issue.go
  3. 22
      models/repo.go
  4. 8
      public/ng/css/gogs.css
  5. 16
      public/ng/js/gogs.js
  6. 10
      public/ng/js/min/gogs-min.js
  7. 3
      public/ng/less/gogs/repository.less
  8. 11
      routers/repo/pull.go
  9. 38
      templates/repo/pull_new.tmpl

3
conf/locale/locale_en-US.ini

@ -415,7 +415,10 @@ release.tag_name_already_exist = Release with this tag name has already existed.
pulls.new = New Pull Request pulls.new = New Pull Request
pulls.request_from = Request From pulls.request_from = Request From
pulls.from_branch = From Branch
pulls.request_to = Request To pulls.request_to = Request To
pulls.to_branch = To Branch
pulls.create = Create Pull Requst
[org] [org]
org_name_holder = Organization Name org_name_holder = Organization Name

7
models/issue.go

@ -114,19 +114,16 @@ func (i *Issue) AfterDelete() {
// CreateIssue creates new issue for repository. // CreateIssue creates new issue for repository.
func NewIssue(issue *Issue) (err error) { func NewIssue(issue *Issue) (err error) {
sess := x.NewSession() sess := x.NewSession()
defer sess.Close() defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if _, err = sess.Insert(issue); err != nil { if _, err = sess.Insert(issue); err != nil {
sess.Rollback()
return err return err
} }
rawSql := "UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?" if _, err = sess.Exec("UPDATE `repository` SET num_issues=num_issues+1 WHERE id = ?", issue.RepoId); err != nil {
if _, err = sess.Exec(rawSql, issue.RepoId); err != nil {
sess.Rollback()
return err return err
} }

22
models/repo.go

@ -162,6 +162,8 @@ type Repository struct {
ForkId int64 ForkId int64
ForkRepo *Repository `xorm:"-"` ForkRepo *Repository `xorm:"-"`
Branches []string `xorm:"-"`
Created time.Time `xorm:"CREATED"` Created time.Time `xorm:"CREATED"`
Updated time.Time `xorm:"UPDATED"` Updated time.Time `xorm:"UPDATED"`
} }
@ -183,7 +185,7 @@ func (repo *Repository) GetMirror() (err error) {
} }
func (repo *Repository) GetForkRepo() (err error) { func (repo *Repository) GetForkRepo() (err error) {
if !repo.IsFork { if !repo.IsFork || repo.ForkRepo != nil {
return nil return nil
} }
@ -191,6 +193,24 @@ func (repo *Repository) GetForkRepo() (err error) {
return err return err
} }
func (repo *Repository) GetBranches() error {
if repo.Branches != nil {
return nil
}
repoPath, err := repo.RepoPath()
if err != nil {
return err
}
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
return err
}
repo.Branches, err = gitRepo.GetBranches()
return err
}
func (repo *Repository) RepoPath() (string, error) { func (repo *Repository) RepoPath() (string, error) {
if err := repo.GetOwner(); err != nil { if err := repo.GetOwner(); err != nil {
return "", err return "", err

8
public/ng/css/gogs.css

@ -1365,31 +1365,37 @@ The register and sign-in page style
margin-left: 4em; margin-left: 4em;
} }
#release-new-target-branch-list, #release-new-target-branch-list,
#repo-pull-branch-list,
#repo-create-owner-list { #repo-create-owner-list {
top: 30px; top: 25px;
left: 0; left: 0;
width: auto; width: auto;
max-width: 300px; max-width: 300px;
} }
#release-new-target-branch-list .octicon, #release-new-target-branch-list .octicon,
#repo-pull-branch-list .octicon,
#repo-create-owner-list .octicon { #repo-create-owner-list .octicon {
margin-right: 12px; margin-right: 12px;
opacity: 0; opacity: 0;
} }
#release-new-target-branch-list .avatar, #release-new-target-branch-list .avatar,
#repo-pull-branch-list .avatar,
#repo-create-owner-list .avatar { #repo-create-owner-list .avatar {
width: 20px; width: 20px;
height: 20px; height: 20px;
} }
#release-new-target-branch-list li, #release-new-target-branch-list li,
#repo-pull-branch-list li,
#repo-create-owner-list li { #repo-create-owner-list li {
white-space: nowrap; white-space: nowrap;
} }
#release-new-target-branch-list li.checked .octicon, #release-new-target-branch-list li.checked .octicon,
#repo-pull-branch-list li.checked .octicon,
#repo-create-owner-list li.checked .octicon { #repo-create-owner-list li.checked .octicon {
opacity: 1; opacity: 1;
} }
#release-new-target-branch-list li a, #release-new-target-branch-list li a,
#repo-pull-branch-list li a,
#repo-create-owner-list li a { #repo-create-owner-list li a {
text-overflow: ellipsis; text-overflow: ellipsis;
-o-text-overflow: ellipsis; -o-text-overflow: ellipsis;

16
public/ng/js/gogs.js

@ -457,6 +457,22 @@ function initRepoCreate() {
} }
}); });
// Branch switch menu click.
$('.repo-pull-branch-list').on('click', 'li', function () {
if (!$(this).hasClass('checked')) {
var branch_name = $(this).data('branch-name');
var target = $(this).data('target');
var target_show = $(this).data('target-show');
$(target).val(branch_name);
$(target_show).text($(this).text().trim());
$(this).parent().find('.checked').removeClass('checked');
$(this).addClass('checked');
console.log("set branch: ", branch_name, $(this).text().trim());
}
});
$('#auth-button').click(function (e) { $('#auth-button').click(function (e) {
$('#repo-migrate-auth').slideToggle('fast'); $('#repo-migrate-auth').slideToggle('fast');
e.preventDefault(); e.preventDefault();

10
public/ng/js/min/gogs-min.js vendored

File diff suppressed because one or more lines are too long

3
public/ng/less/gogs/repository.less

@ -394,8 +394,9 @@
margin-left: 4em; margin-left: 4em;
} }
#release-new-target-branch-list, #release-new-target-branch-list,
#repo-pull-branch-list,
#repo-create-owner-list { #repo-create-owner-list {
top: 30px; top: 25px;
left: 0; left: 0;
width: auto; width: auto;
max-width: 300px; max-width: 300px;

11
routers/repo/pull.go

@ -33,10 +33,17 @@ func NewPullRequest(ctx *middleware.Context) {
} }
forkRepo := ctx.Repo.Repository.ForkRepo forkRepo := ctx.Repo.Repository.ForkRepo
if err := forkRepo.GetOwner(); err != nil { if err := forkRepo.GetBranches(); err != nil {
ctx.Handle(500, "GetOwner", err) ctx.Handle(500, "GetBranches", err)
return return
} }
ctx.Data["ForkRepo"] = forkRepo
ctx.Data["RequestTo"] = forkRepo.Owner.Name + "/" + forkRepo.Name ctx.Data["RequestTo"] = forkRepo.Owner.Name + "/" + forkRepo.Name
if len(forkRepo.DefaultBranch) == 0 {
forkRepo.DefaultBranch = forkRepo.Branches[0]
}
ctx.Data["DefaultBranch"] = forkRepo.DefaultBranch
ctx.HTML(200, NEW_PULL) ctx.HTML(200, NEW_PULL)
} }

38
templates/repo/pull_new.tmpl

@ -13,15 +13,15 @@
<span><a target="_blank" href="{{AppSubUrl}}/{{.RequestFrom}}">{{.RequestFrom}}</a></span> <span><a target="_blank" href="{{AppSubUrl}}/{{.RequestFrom}}">{{.RequestFrom}}</a></span>
</div> </div>
<div class="field"> <div class="field">
<label for="from_branch" class="req">{{.i18n.Tr "repo.pulls.from_branch"}}</label> <label for="from-branch" class="req">{{.i18n.Tr "repo.pulls.from_branch"}}</label>
<input id="from_branch_name" type="hidden" name="branch_name" value="{{.BranchName}}" /> <input id="from-branch" type="hidden" name="form_branch" value="{{.BranchName}}" />
<div class="inline-block drop"> <div class="inline-block drop">
<a class="drop-bottom"> <a class="drop-bottom">
<strong id="branch-name">{{.BranchName}}</strong> <strong id="from-branch-name">{{.BranchName}}</strong>
</a> </a>
<ul class="drop-down menu menu-vertical menu-radius switching-list" id="repo-create-owner-list"> <ul class="drop-down menu menu-vertical menu-radius switching-list repo-pull-branch-list" id="repo-pull-branch-list">
{{range .Branches}} {{range .Branches}}
<li {{if eq . $.BranchName}}class="checked"{{end}} data-branch-name="{{.}}"> <li {{if eq . $.BranchName}}class="checked"{{end}} data-branch-name="{{.}}" data-target="#from-branch" data-target-show="#from-branch-name">
<a> <a>
<i class="octicon octicon-check"></i> <i class="octicon octicon-check"></i>
<strong>{{.}}</strong> <strong>{{.}}</strong>
@ -35,6 +35,34 @@
<label>{{.i18n.Tr "repo.pulls.request_to"}}</label> <label>{{.i18n.Tr "repo.pulls.request_to"}}</label>
<span><a target="_blank" href="{{AppSubUrl}}/{{.RequestTo}}">{{.RequestTo}}</a></span> <span><a target="_blank" href="{{AppSubUrl}}/{{.RequestTo}}">{{.RequestTo}}</a></span>
</div> </div>
<div class="field">
<label for="to-branch" class="req">{{.i18n.Tr "repo.pulls.to_branch"}}</label>
<input id="to-branch" type="hidden" name="to_branch" value="{{.DefaultBranch}}" />
<div class="inline-block drop">
<a class="drop-bottom">
<strong id="to-branch-name">{{.DefaultBranch}}</strong>
</a>
<ul class="drop-down menu menu-vertical menu-radius switching-list repo-pull-branch-list" id="repo-pull-branch-list">
{{range .ForkRepo.Branches}}
<li {{if eq . $.DefaultBranch}}class="checked"{{end}} data-branch-name="{{.}}" data-target="#to-branch" data-target-show="#to-branch-name">
<a>
<i class="octicon octicon-check"></i>
<strong>{{.}}</strong>
</a>
</li>
{{end}}
</ul>
</div>
</div>
<div class="field clear">
<label class="left req" for="desc">{{.i18n.Tr "repo.repo_desc"}}</label>
<textarea class="ipt ipt-large ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc" required>{{.desc}}</textarea>
</div>
<div class="field">
<label></label>
<button class="btn btn-large btn-blue btn-radius">{{.i18n.Tr "repo.pulls.create"}}</button>
<a class="btn btn-small btn-gray btn-radius" id="repo-create-cancel" href="{{AppSubUrl}}{{.RepoLink}}"><strong>{{.i18n.Tr "cancel"}}</strong></a>
</div>
</div> </div>
</form> </form>
</div> </div>

Loading…
Cancel
Save