mirror of
1
Fork 0

repo-import page ui

This commit is contained in:
FuXiaoHei 2014-04-09 21:28:00 +08:00
parent 721834a267
commit c72e1b5c2a
5 changed files with 158 additions and 1 deletions

View File

@ -309,6 +309,18 @@ html, body {
height: 8em;
}
#repo-import-auth{
width: 100%;
margin-top: 48px;
box-sizing: border-box;
}
#repo-import-auth .form-group{
box-sizing: border-box;
margin-left: 0;
margin-right: 0;
}
/* gogits user setting */
#user-setting-nav > h4, #user-setting-container > h4, #user-setting-container > div > h4,

View File

@ -55,6 +55,38 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Handle(200, "repo.Create", err)
}
func Import(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = "Import repository"
ctx.Data["PageIsNewRepo"] = true // For navbar arrow.
ctx.Data["LanguageIgns"] = models.LanguageIgns
ctx.Data["Licenses"] = models.Licenses
if ctx.Req.Method == "GET" {
ctx.HTML(200, "repo/import")
return
}
if ctx.HasError() {
ctx.HTML(200, "repo/import")
return
}
_, err := models.CreateRepository(ctx.User, form.RepoName, form.Description,
form.Language, form.License, form.Visibility == "private", form.InitReadme == "on")
if err == nil {
log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName)
ctx.Redirect("/" + ctx.User.Name + "/" + form.RepoName)
return
} else if err == models.ErrRepoAlreadyExist {
ctx.RenderWithErr("Repository name has already been used", "repo/import", &form)
return
} else if err == models.ErrRepoNameIllegal {
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/import", &form)
return
}
ctx.Handle(200, "repo.Import", err)
}
func Single(ctx *middleware.Context, params martini.Params) {
branchName := ctx.Repo.BranchName
commitId := ctx.Repo.CommitId

112
templates/repo/import.tmpl Normal file
View File

@ -0,0 +1,112 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div class="container" id="body">
<form action="/repo/create" method="post" class="form-horizontal card" id="repo-create">
{{.CsrfTokenHtml}}
<h3>Import Repository</h3>
<div class="alert alert-danger form-error{{if .HasError}}{{else}} hidden{{end}}">{{.ErrorMsg}}</div>
<div class="form-group">
<label class="col-md-2 control-label">From<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<select class="form-control" name="from">
<option value="">GitHub</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">URL<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<input name="url" type="text" class="form-control" placeholder="Type your imported repository url link" required="required">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<a class="btn btn-default" data-toggle="collapse" data-target="#repo-import-auth">Need Authorization</a>
</div>
<div id="repo-import-auth" class="collapse">
<div class="form-group">
<label class="col-md-2 control-label">Username</label>
<div class="col-md-8">
<input name="auth-username" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Password</label>
<div class="col-md-8">
<input name="auth-password" type="text" class="form-control">
</div>
</div>
</div>
</div>
<hr/>
<div class="form-group">
<label class="col-md-2 control-label">Owner<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<p class="form-control-static">{{.SignedUserName}}</p>
<input type="hidden" value="{{.SignedUserId}}" name="userId"/>
</div>
</div>
<div class="form-group {{if .Err_RepoName}}has-error has-feedback{{end}}">
<label class="col-md-2 control-label">Repository<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<input name="repo" type="text" class="form-control" placeholder="Type your repository name" value="{{.repo}}" required="required">
<span class="help-block">Great repository names are short and memorable. </span>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Visibility<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<p class="form-control-static">Public</p>
<input type="hidden" value="public" name="visibility"/>
</div>
</div>
<div class="form-group {{if .Err_Description}}has-error has-feedback{{end}}">
<label class="col-md-2 control-label">Description</label>
<div class="col-md-8">
<textarea name="desc" class="form-control" placeholder="Type your repository description">{{.desc}}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Language</label>
<div class="col-md-8">
<select class="form-control" name="language">
<option value="">Select a language</option>
{{range .LanguageIgns}}<option value="{{.}}">{{.}}</option>{{end}}
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">License</label>
<div class="col-md-8">
<select class="form-control" name="license">
<option value="">Select a license</option>
{{range .Licenses}}<option value="{{.}}">{{.}}</option>{{end}}
</select>
</div>
</div>
<!--<div class="form-group">
<div class="col-md-8 col-md-offset-2">
<div class="checkbox">
<label>
<input type="checkbox" name="initReadme" {{if .initReadme}}checked{{end}}>
<strong>Initialize this repository with a README</strong>
</label>
</div>
</div>
</div>-->
<div class="form-group">
<div class="col-md-offset-2 col-md-8">
<button type="submit" class="btn btn-lg btn-primary">Import repository</button>
<a href="/" class="text-danger">Cancel</a>
</div>
</div>
</form>
</div>
{{template "base/footer" .}}

View File

@ -37,7 +37,7 @@
<div class="dropdown-menu dropdown-menu-right">
<ul class="list-unstyled">
<li><a href="/repo/create"><i class="fa fa-book"></i>Repository</a></li>
<li><a href="#"><i class="fa fa-clipboard"></i>Mirror</a></li>
<li><a href="/repo/import"><i class="fa fa-clipboard"></i>Mirror</a></li>
<li><a href="#"><i class="fa fa-users"></i>Organization</a></li>
</ul>

1
web.go
View File

@ -116,6 +116,7 @@ func runWeb(*cli.Context) {
m.Get("/user/:username", ignSignIn, user.Profile)
m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create)
m.Any("/repo/import", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Import)
adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true})