diff options
author | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-04-09 21:28:00 +0800 |
---|---|---|
committer | FuXiaoHei <fuxiaohei@hexiaz.com> | 2014-04-09 21:28:00 +0800 |
commit | c72e1b5c2ac8d2cbd123f3f53db7b4a125045725 (patch) | |
tree | 2f82785e8a1431189d5aeed3795bc77302caa7be | |
parent | 721834a2673fed7fc21988b8e91a88a26bcef051 (diff) | |
download | gitea-c72e1b5c2ac8d2cbd123f3f53db7b4a125045725.tar.gz gitea-c72e1b5c2ac8d2cbd123f3f53db7b4a125045725.zip |
repo-import page ui
-rwxr-xr-x | public/css/gogs.css | 12 | ||||
-rw-r--r-- | routers/repo/repo.go | 32 | ||||
-rw-r--r-- | templates/repo/import.tmpl | 112 | ||||
-rw-r--r-- | templates/user/dashboard.tmpl | 2 | ||||
-rw-r--r-- | web.go | 1 |
5 files changed, 158 insertions, 1 deletions
diff --git a/public/css/gogs.css b/public/css/gogs.css index bf39ea39ce..dcfb2758a0 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -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, diff --git a/routers/repo/repo.go b/routers/repo/repo.go index d223600c52..0ab1c9e420 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -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 diff --git a/templates/repo/import.tmpl b/templates/repo/import.tmpl new file mode 100644 index 0000000000..75d928d138 --- /dev/null +++ b/templates/repo/import.tmpl @@ -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" .}}
\ No newline at end of file diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl index 39e277e3c9..f0a0a0ccaa 100644 --- a/templates/user/dashboard.tmpl +++ b/templates/user/dashboard.tmpl @@ -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> @@ -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}) |