Work on mirror repo

This commit is contained in:
Unknown 2014-04-09 14:20:02 -04:00
parent 5f6bd323f5
commit 9f7bd5007b
4 changed files with 12 additions and 45 deletions

View file

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

View file

@ -16,7 +16,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">URL<strong class="text-danger">*</strong></label> <label class="col-md-2 control-label">URL<strong class="text-danger">*</strong></label>
<div class="col-md-8"> <div class="col-md-8">
<input name="url" type="text" class="form-control" placeholder="Type your imported repository url link" required="required"> <input name="url" type="text" class="form-control" placeholder="Type your mirror repository url link" required="required">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -70,40 +70,9 @@
</div> </div>
</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="form-group">
<div class="col-md-offset-2 col-md-8"> <div class="col-md-offset-2 col-md-8">
<button type="submit" class="btn btn-lg btn-primary">Import repository</button> <button type="submit" class="btn btn-lg btn-primary">Mirror repository</button>
<a href="/" class="text-danger">Cancel</a> <a href="/" class="text-danger">Cancel</a>
</div> </div>
</div> </div>

View file

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

2
web.go
View file

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