1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-23 01:33:09 +00:00

Finish new migrate page

This commit is contained in:
Unknwon 2014-08-01 00:06:19 -04:00
parent 7bbf644dd5
commit dabf5b057c
10 changed files with 153 additions and 150 deletions

View file

@ -60,6 +60,7 @@ Email = E-mail address
Password = Password
Retype = Re-type password
SSHTitle = SSH key name
HttpsUrl = HTTPS URL
require_error = ` cannot be empty.`
alpha_dash_error = ` must be valid alpha or numeric or dash(-_) characters.`
@ -83,6 +84,7 @@ illegal_org_name = Organization name contains illegal characters.
username_password_incorrect = Username or password is not correct.
invalid_ssh_key = Sorry, we're not able to verify your SSH key: %s
auth_failed = Authentication failed: %v
still_own_repo = Your account still have ownership of repository, you have to delete or transfer them first.
@ -142,6 +144,11 @@ license_helper = Select a license file
init_readme = Initialize this repository with a README.md
create_repo = Create Repository
need_auth = Need Authorization
migrate_type = Migration Type
migrate_type_helper = This repository will be a <span class="label label-blue label-radius">Mirror</span>
migrate_repo = Migrate Repository
[org]
org_name_holder = Organization Name
org_name_helper = Great organization names are short and memorable.

View file

@ -60,6 +60,7 @@ Email = 邮箱地址
Password = 密码
Retype = 确认密码
SSHTitle = SSH 密钥名称
HttpsUrl = HTTPS URL 地址
require_error = 不能为空。
alpha_dash_error = 必须为英文字母、阿拉伯数字或横线(-_
@ -83,6 +84,7 @@ illegal_org_name = 组织名称包含非法字符。
username_password_incorrect = 用户名或密码不正确。
invalid_ssh_key = 很抱歉,我们无法验证您输入的 SSH 密钥:%s
auth_failed = 授权验证失败:%v
still_own_repo = 您的帐户仍然是某些仓库的拥有者,您必须先转移或删除它们才能执行删除帐户操作!
@ -142,6 +144,11 @@ license_helper = 请选择授权许可文件
init_readme = 使用 README.md 文件初始化仓库
create_repo = 创建仓库
need_auth = 需要授权验证
migrate_type = 迁移类型
migrate_type_helper = 本仓库将是 <span class="label label-blue label-radius">镜像</span>
migrate_repo = 迁移仓库
[org]
org_name_holder = 组织名称
org_name_helper = 伟大的组织都有一个简短而寓意深刻的名字。

View file

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.4.7.0731 Alpha"
const APP_VER = "0.4.7.0801 Alpha"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())

View file

@ -33,11 +33,11 @@ func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs *binding.Errors, l
}
type MigrateRepoForm struct {
Url string `form:"url" binding:"Url"`
HttpsUrl string `form:"url" binding:"Url"`
AuthUserName string `form:"auth_username"`
AuthPasswd string `form:"auth_password"`
Uid int64 `form:"uid" binding:"Required"`
RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
RepoName string `form:"repo_name" binding:"Required;AlphaDash;MaxSize(100)"`
Mirror bool `form:"mirror"`
Private bool `form:"private"`
Description string `form:"desc" binding:"MaxSize(255)"`

View file

@ -294,6 +294,8 @@ img.avatar-30 {
border: 1px solid #ddd;
border-radius: .25em;
margin: 5px 0;
padding: 10px;
background-color: #f8f8f8;
}
.markdown > pre.linenums {
padding: 0;
@ -836,6 +838,9 @@ The register and sign-in page style
margin-left: -15px;
}
/* repository main */
#repo-wrapper {
padding-bottom: 100px;
}
#repo-header {
height: 69px;
border-bottom: 1px solid #d6d6d6;
@ -1100,29 +1105,36 @@ The register and sign-in page style
width: 520px;
}
/* repository create */
#repo-migrate-form,
#repo-create-form {
width: 800px;
margin: 60px auto 150px auto;
margin: 60px auto auto auto;
background: white;
}
#repo-migrate-form h2,
#repo-create-form h2 {
margin: .5em 1em;
}
#repo-migrate-form .field,
#repo-create-form .field {
margin: 1.2em 0 2em 0;
}
#repo-migrate-form .ipt,
#repo-create-form .ipt {
width: 540px;
}
#repo-migrate-form textarea,
#repo-create-form textarea {
height: 120px;
}
#repo-migrate-form .avatar,
#repo-create-form .avatar {
vertical-align: middle;
margin-right: .6em;
width: 28px;
height: 28px;
}
#repo-migrate-form:hover,
#repo-create-form:hover {
box-shadow: 0px 0px 6px #CCC;
}

View file

@ -59,7 +59,7 @@ var Gogs = {};
Gogs.renderMarkdown = function () {
var $md = $('.markdown');
var $pre = $md.find('pre > code').parent();
$pre.addClass('prettyprint linenums');
$pre.addClass('prettyprint');
prettyPrint();
// Set anchor.
@ -166,11 +166,17 @@ function initRepoCreate() {
console.log("set repo owner to uid :", uid, $(this).text().trim());
}
});
$('#auth-button').click(function (e) {
$('#repo-migrate-auth').slideToggle('fast');
e.preventDefault();
})
console.log('initRepoCreate');
}
$(document).ready(function () {
initCore();
if ($('#repo-create-form').length) {
if ($('#repo-create-form').length || $('#repo-migrate-form').length) {
initRepoCreate();
}

View file

@ -27,7 +27,6 @@ const (
func Create(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo")
ctx.Data["PageIsRepoCreate"] = true
// Give default value for template to render.
ctx.Data["gitignore"] = "0"
@ -57,7 +56,6 @@ func Create(ctx *middleware.Context) {
func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Data["Title"] = ctx.Tr("new_repo")
ctx.Data["PageIsRepoCreate"] = true
ctx.Data["Gitignores"] = models.Gitignores
ctx.Data["Licenses"] = models.Licenses
@ -100,9 +98,11 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName)
return
} else if err == models.ErrRepoAlreadyExist {
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), CREATE, &form)
return
} else if err == models.ErrRepoNameIllegal {
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), CREATE, &form)
return
}
@ -112,12 +112,22 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
ctx.Handle(500, "CreateRepository", err)
ctx.Handle(500, "CreatePost", err)
}
func Migrate(ctx *middleware.Context) {
ctx.Data["Title"] = "Migrate repository"
ctx.Data["PageIsNewRepo"] = true
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctxUser := ctx.User
if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 {
org, err := models.GetUserById(orgId)
if err != nil && err != models.ErrUserNotExist {
ctx.Handle(500, "GetUserById", err)
return
}
ctxUser = org
}
ctx.Data["ContextUser"] = ctxUser
if err := ctx.User.GetOrganizations(); err != nil {
ctx.Handle(500, "GetOrganizations", err)
@ -129,8 +139,18 @@ func Migrate(ctx *middleware.Context) {
}
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
ctx.Data["Title"] = "Migrate repository"
ctx.Data["PageIsNewRepo"] = true
ctx.Data["Title"] = ctx.Tr("new_migrate")
ctxUser := ctx.User
if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 {
org, err := models.GetUserById(orgId)
if err != nil && err != models.ErrUserNotExist {
ctx.Handle(500, "GetUserById", err)
return
}
ctxUser = org
}
ctx.Data["ContextUser"] = ctxUser
if err := ctx.User.GetOrganizations(); err != nil {
ctx.Handle(500, "GetOrganizations", err)
@ -143,49 +163,45 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
return
}
u := ctx.User
// Not equal means current user is an organization.
if u.Id != form.Uid {
var err error
u, err = models.GetUserById(form.Uid)
if err != nil {
if err == models.ErrUserNotExist {
ctx.Handle(404, "GetUserById", err)
} else {
ctx.Handle(500, "GetUserById", err)
}
if ctxUser.IsOrganization() {
// Check ownership of organization.
if !ctxUser.IsOrgOwner(ctx.User.Id) {
ctx.Error(403)
return
}
}
authStr := strings.Replace(fmt.Sprintf("://%s:%s",
form.AuthUserName, form.AuthPasswd), "@", "%40", -1)
url := strings.Replace(form.Url, "://", authStr+"@", 1)
repo, err := models.MigrateRepository(u, form.RepoName, form.Description, form.Private,
url := strings.Replace(form.HttpsUrl, "://", authStr+"@", 1)
repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private,
form.Mirror, url)
if err == nil {
log.Trace("%s Repository migrated: %s/%s", ctx.Req.RequestURI, u.LowerName, form.RepoName)
ctx.Redirect("/" + u.Name + "/" + form.RepoName)
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
ctx.Redirect("/" + ctxUser.Name + "/" + form.RepoName)
return
} else if err == models.ErrRepoAlreadyExist {
ctx.RenderWithErr("Repository name has already been used", MIGRATE, &form)
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), MIGRATE, &form)
return
} else if err == models.ErrRepoNameIllegal {
ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), MIGRATE, &form)
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), MIGRATE, &form)
return
}
if repo != nil {
if errDelete := models.DeleteRepository(u.Id, repo.Id, u.Name); errDelete != nil {
if errDelete := models.DeleteRepository(ctxUser.Id, repo.Id, ctxUser.Name); errDelete != nil {
log.Error(4, "DeleteRepository: %v", errDelete)
}
}
if strings.Contains(err.Error(), "Authentication failed") {
ctx.RenderWithErr(err.Error(), MIGRATE, &form)
ctx.Data["Err_Auth"] = true
ctx.RenderWithErr(ctx.Tr("form.auth_failed", err), MIGRATE, &form)
return
}
ctx.Handle(500, "MigrateRepository", err)
ctx.Handle(500, "MigratePost", err)
}
// func Action(ctx *middleware.Context, params martini.Params) {

View file

@ -1 +1 @@
0.4.7.0731 Alpha
0.4.7.0801 Alpha

View file

@ -36,7 +36,7 @@
</div>
<div class="field">
<label class="req" for="repo-name">{{.i18n.Tr "repo.repo_name"}}</label>
<input class="ipt ipt-radius" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required />
<input class="ipt ipt-radius {{if .Err_RepoName}}ipt-error{{end}}" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required />
<span class="form-label"></span>
<span class="help">{{.i18n.Tr "repo.repo_name_helper" | Str2html}}</span>
</div>
@ -47,7 +47,7 @@
</p>
<div class="field clear">
<label class="left" for="desc">{{.i18n.Tr "repo.repo_desc"}}</label>
<textarea class="ipt ipt-radius" id="desc" name="desc">{{.desc}}</textarea>
<textarea class="ipt ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc">{{.desc}}</textarea>
</div>
<p class="field">
<label for="lang">{{.i18n.Tr "repo.repo_lang"}}</label>

View file

@ -1,127 +1,82 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div class="container" id="body">
<form action="/repo/migrate" method="post" class="form-horizontal card" id="repo-create">
{{template "ng/base/head" .}}
{{template "ng/base/header" .}}
<div id="repo-wrapper">
<form id="repo-migrate-form" class="form form-align panel panel-radius" action="/repo/migrate" method="post">
{{.CsrfTokenHtml}}
<h3>Repository Migration</h3>
{{template "base/alert" .}}
<!-- <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">GitHub</option>
</select>
<div class="panel-header"><h2>{{.i18n.Tr "new_migrate"}}</h2></div>
<div class="panel-content">
{{template "ng/base/alert" .}}
<div class="field">
<label class="req" for="url">HTTPS URL</label>
<input class="ipt ipt-radius {{if .Err_HttpsUrl}}ipt-error{{end}}" id="url" name="url" type="text" value="{{.url}}" required />
</div>
</div> -->
<div class="form-group">
<label class="col-md-2 control-label">HTTPS URL<strong class="text-danger">*</strong></label>
<div class="col-md-8">
<input name="url" type="text" class="form-control" placeholder="Type your migration repository HTTPS URL" value="{{.url}}" 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" placeholder="Type your user name" value="{{.auth_username}}" >
<div class="field">
<span class="form-label"></span>
<button class="btn btn-large btn-gray btn-radius" id="auth-button" data-toggle="collapse" data-target="#repo-import-auth">{{.i18n.Tr "repo.need_auth"}}</button>
<div id="repo-migrate-auth" {{if not .Err_Auth}}class="hide"{{end}}>
<div class="field">
<label for="auth_username">{{.i18n.Tr "username"}}</label>
<input class="ipt ipt-radius {{if .Err_Auth}}ipt-error{{end}}" id="auth_username" name="auth_username" type="text" value="{{.auth_username}}" />
</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="password" class="form-control" placeholder="Type your password" value="{{.auth_password}}" >
<div class="field">
<label for="auth_password">{{.i18n.Tr "password"}}</label>
<input class="ipt ipt-radius {{if .Err_Auth}}ipt-error{{end}}" id="auth_password" name="auth_password" type="text" value="{{.auth_password}}" />
</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">
<div class="btn-group" id="repo-owner-switch">
<button type="button" class="btn btn-default" id="repo-owner-current">
<img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username" id="repo-owner-avatar">
<span id="repo-owner-name">{{.SignedUser.Name}}</span>
</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<div class="dropdown-menu clone-group-btn no-propagation">
<ul id="dashboard-switch-menu" class="list-unstyled">
<li data-uid="{{.SignedUser.Id}}" class="checked">
<a>
<i class="fa fa-check"></i>
<img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username">
{{.SignedUser.Name}}
</a>
</li>
{{range .Orgs}}
<li data-uid="{{.Id}}">
<a>
<i class="fa fa-check"></i>
<img src="{{.AvatarLink}}?s=28" alt="user-avatar" title="username">
{{.Name}}
</a>
</li>
{{end}}
</ul>
</div>
<hr/>
<div class="field">
<label for="owner" class="req">{{.i18n.Tr "repo.owner"}}</label>
<input id="repo-owner-id" type="hidden" name="uid" value="{{.ContextUser.Id}}" />
<div class="inline-block drop">
<a href="#" class="drop-bottom">
<img class="avatar" src="{{.ContextUser.AvatarLink}}" id="repo-owner-avatar" alt="user-avatar">
<strong id="repo-owner-name">{{.ContextUser.Name}}</strong>
</a>
<ul class="drop-down menu menu-vertical menu-radius switching-list" id="repo-create-owner-list">
<li {{if eq $.ContextUser.Id .SignedUser.Id}}class="checked"{{end}} data-uid="{{.SignedUser.Id}}">
<a>
<i class="octicon octicon-check"></i>
<img class="avatar" src="{{.SignedUser.AvatarLink}}" alt="user-avatar">
<strong>{{.SignedUser.Name}}</strong>
</a>
</li>
{{range .Orgs}}
<li {{if eq $.ContextUser.Id .Id}}class="checked"{{end}} data-uid="{{.Id}}">
<a>
<i class="octicon octicon-check"></i>
<img class="avatar" src="{{.AvatarLink}}" alt="user-avatar">
<strong>{{.Name}}</strong>
</a>
</li>
{{end}}
</ul>
</div>
</div>
<input type="hidden" value="{{.SignedUserId}}" name="uid" id="repo-owner-id"/>
</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 class="field">
<label class="req" for="repo-name">{{.i18n.Tr "repo.repo_name"}}</label>
<input class="ipt ipt-radius {{if .Err_RepoName}}ipt-error{{end}}" id="repo-name" name="repo_name" type="text" value="{{.repo_name}}" required />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Migration Type</label>
<div class="col-md-8">
<div class="checkbox">
<label>
<input type="checkbox" name="mirror" {{if .mirror}}checked{{end}}>
<strong>This repository is a mirror</strong>
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Visibility</label>
<div class="col-md-8">
<div class="checkbox">
<label>
<input type="checkbox" name="private" {{if .private}}checked{{end}}>
<strong>This repository is private</strong>
</label>
</div>
</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">
<div class="col-md-offset-2 col-md-8">
<button type="submit" class="btn btn-lg btn-primary">Migrate repository</button>
<a href="/" class="text-danger">Cancel</a>
<p class="field">
<label for="visibility">{{.i18n.Tr "repo.visibility"}}</label>
<input class="ipt-chk" id="visibility" name="private" type="checkbox" {{if .private}}checked{{end}} />
<span>{{.i18n.Tr "repo.visiblity_helper" | Str2html}}</span>
</p>
<p class="field">
<label for="visibility">{{.i18n.Tr "repo.migrate_type"}}</label>
<input class="ipt-chk" id="visibility" name="mirror" type="checkbox" {{if .mirror}}checked{{end}} />
<span>{{.i18n.Tr "repo.migrate_type_helper" | Str2html}}</span>
</p>
<div class="field clear">
<label class="left" for="desc">{{.i18n.Tr "repo.repo_desc"}}</label>
<textarea class="ipt ipt-radius {{if .Err_Description}}ipt-error{{end}}" id="desc" name="desc">{{.desc}}</textarea>
</div>
<p class="field">
<label for="repo-create-submit"></label>
<button class="btn btn-large btn-blue btn-radius" id="repo-create-submit">{{.i18n.Tr "repo.migrate_repo"}}</button>
<a class="btn btn-small btn-gray btn-radius" id="repo-create-cancel" href="/"><strong>{{.i18n.Tr "cancel"}}</strong></a>
</p>
</div>
</form>
</div>
{{template "base/footer" .}}
{{template "ng/base/footer" .}}