diff --git a/models/dataset.go b/models/dataset.go index 0f0e83b56..b2a6c9665 100644 --- a/models/dataset.go +++ b/models/dataset.go @@ -21,3 +21,11 @@ type Dataset struct { Attachments []*Attachment `xorm:"-"` } + +func CreateDataset(dataset *Dataset) (err error) { + if _, err = x.Insert(dataset); err != nil { + return err + } + + return nil +} diff --git a/modules/auth/dataset.go b/modules/auth/dataset.go new file mode 100644 index 000000000..110d4e137 --- /dev/null +++ b/modules/auth/dataset.go @@ -0,0 +1,21 @@ +package auth + +import ( + "gitea.com/macaron/binding" + "gitea.com/macaron/macaron" +) + +// CreateDatasetForm form for dataset page +type CreateDatasetForm struct { + Title string `binding:"Required"` + Category string `binding:"Required"` + Description string `binding:"Required;MaxSize(254)"` + License string `binding:"OmitEmpty;MaxSize(64)"` + Task string + Release_id int64 `xorm:"INDEX"` +} + +// Validate validates the fields +func (f *CreateDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4b788993d..465a71f14 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -626,7 +626,7 @@ description = Description create_dataset = Create Dataset category = Category task = Task -licience = Licience +Licenses = Licenses file = Dataset File [repo] diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 674256a89..5c774f240 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -625,7 +625,7 @@ description = 描述 create_dataset = 创建数据集 category = 分类 task = 针对的具体任务 -licience = Licience +Licenses = Licenses file = 数据集文件 [repo] diff --git a/routers/dataset/dataset.go b/routers/dataset/dataset.go index 56d8a4122..1abb5665a 100644 --- a/routers/dataset/dataset.go +++ b/routers/dataset/dataset.go @@ -1,6 +1,8 @@ package dataset import ( + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" @@ -20,6 +22,62 @@ func Create(ctx *context.Context) { log.Debug("[dataset] Create...\n") ctx.HTML(200, tplCreate) } + +// func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) { +// switch { +// case models.IsErrReachLimitOfRepo(err): +// ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form) +// case models.IsErrRepoAlreadyExist(err): +// ctx.Data["Err_RepoName"] = true +// ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form) +// case models.IsErrNameReserved(err): +// ctx.Data["Err_RepoName"] = true +// ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form) +// case models.IsErrNamePatternNotAllowed(err): +// ctx.Data["Err_RepoName"] = true +// ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form) +// default: +// ctx.ServerError(name, err) +// } +// } + +func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) { + ctx.Data["Title"] = ctx.Tr("new_dataset") + + ctxUser := ctx.User + + if ctx.HasError() { + ctx.HTML(200, tplCreate) + return + } + + var err error + opts := models.Dataset{ + Title: form.Title, + Category: form.Category, + Description: form.Description, + License: form.License, + Task: form.Task, + Release_id: form.Release_id, + User_id: ctxUser.ID, + Status: 0, + } + log.Debug("======================================") + log.Debug("%#v", opts) + log.Debug("======================================") + // if !opts.IsValid() { + // ctx.RenderWithErr(ctx.Tr("repo.template.one_item"), tplCreate, form) + // return + + // } + + if err = models.CreateDataset(&opts); err != nil { + log.Error("%v", err) + } + + // handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) +} + func Delete(ctx *context.Context) { log.Debug("[dataset] Delete...\n") } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 17974aa3f..aca964d9f 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1004,6 +1004,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/datasets", func() { m.Get("", dataset.MyList) m.Get("/create", dataset.Create) + m.Post("/create", bindIgnErr(auth.CreateDatasetForm{}), dataset.CreatePost) m.Post("/delete", dataset.Delete) }, ignSignIn) // ***** END: DataSet***** diff --git a/templates/datasets/create.tmpl b/templates/datasets/create.tmpl index cfb1ad33e..04e642377 100644 --- a/templates/datasets/create.tmpl +++ b/templates/datasets/create.tmpl @@ -11,7 +11,7 @@ {{template "base/alert" .}}
- +
@@ -35,12 +35,10 @@
-