| @@ -32,7 +32,7 @@ func CreateDataset(dataset *Dataset) (err error) { | |||||
| return nil | return nil | ||||
| } | } | ||||
| // AddReleaseAttachments adds a release attachments | |||||
| // AddDatasetAttachments adds a Dataset attachments | |||||
| func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error) { | func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error) { | ||||
| // Check attachments | // Check attachments | ||||
| attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs) | attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs) | ||||
| @@ -50,3 +50,23 @@ func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error | |||||
| return | return | ||||
| } | } | ||||
| // GetDatasetByID returns Dataset with given ID. | |||||
| func GetDatasetByID(id int64) (*Dataset, error) { | |||||
| rel := new(Dataset) | |||||
| has, err := x. | |||||
| ID(id). | |||||
| Get(rel) | |||||
| if err != nil { | |||||
| return nil, err | |||||
| } else if !has { | |||||
| return nil, ErrDatasetNotExist{id} | |||||
| } | |||||
| return rel, nil | |||||
| } | |||||
| func UpdateDataset(ctx DBContext, rel *Dataset) error { | |||||
| _, err := ctx.e.ID(rel.ID).AllCols().Update(rel) | |||||
| return err | |||||
| } | |||||
| @@ -851,6 +851,14 @@ func IsErrInvalidTagName(err error) bool { | |||||
| return ok | return ok | ||||
| } | } | ||||
| type ErrDatasetNotExist struct { | |||||
| ID int64 | |||||
| } | |||||
| func (err ErrDatasetNotExist) Error() string { | |||||
| return fmt.Sprintf("Dataset does not exist [id: %d]", err.ID) | |||||
| } | |||||
| func (err ErrInvalidTagName) Error() string { | func (err ErrInvalidTagName) Error() string { | ||||
| return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName) | return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName) | ||||
| } | } | ||||
| @@ -16,6 +16,17 @@ type CreateDatasetForm struct { | |||||
| Files []string | Files []string | ||||
| } | } | ||||
| type EditDatasetForm struct { | |||||
| ID int64 `binding:"Required"` | |||||
| Title string `binding:"Required"` | |||||
| Category string `binding:"Required"` | |||||
| Description string `binding:"Required;MaxSize(254)"` | |||||
| License string `binding:"Required;MaxSize(64)"` | |||||
| Task string `binding:"Required;MaxSize(64)"` | |||||
| ReleaseID int64 `xorm:"INDEX"` | |||||
| Files []string | |||||
| } | |||||
| // Validate validates the fields | // Validate validates the fields | ||||
| func (f *CreateDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | func (f *CreateDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | ||||
| return validate(errs, ctx.Data, f, ctx.Locale) | return validate(errs, ctx.Data, f, ctx.Locale) | ||||
| @@ -7,6 +7,7 @@ import ( | |||||
| "code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| "code.gitea.io/gitea/modules/setting" | "code.gitea.io/gitea/modules/setting" | ||||
| "code.gitea.io/gitea/routers/repo" | |||||
| ) | ) | ||||
| const ( | const ( | ||||
| @@ -92,6 +93,68 @@ func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) { | |||||
| // handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) | // handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form) | ||||
| } | } | ||||
| // EditRelease render release edit page | |||||
| func EditDataset(ctx *context.Context) { | |||||
| ctx.Data["Title"] = ctx.Tr("repo.dataset.edit_release") | |||||
| ctx.Data["PageIsEditDataset"] = true | |||||
| repo.RenderAttachmentSettings(ctx) | |||||
| rel, err := models.GetDatasetByID(ctx.ParamsInt64(":id")) | |||||
| if err != nil { | |||||
| ctx.ServerError("GetDataset", err) | |||||
| return | |||||
| } | |||||
| ctx.Data["ID"] = rel.ID | |||||
| ctx.Data["title"] = rel.Title | |||||
| ctx.Data["description"] = rel.Description | |||||
| ctx.Data["category"] = rel.Category | |||||
| ctx.Data["task"] = rel.Task | |||||
| ctx.Data["license"] = rel.License | |||||
| ctx.HTML(200, tplCreate) | |||||
| } | |||||
| func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { | |||||
| ctx.Data["Title"] = ctx.Tr("repo.dataset.edit_release") | |||||
| ctx.Data["PageIsEditDataset"] = true | |||||
| rel, err := models.GetDatasetByID(ctx.ParamsInt64(":id")) | |||||
| if err != nil { | |||||
| ctx.ServerError("GetDataset", err) | |||||
| return | |||||
| } | |||||
| ctx.Data["ID"] = rel.ID | |||||
| ctx.Data["title"] = rel.Title | |||||
| ctx.Data["description"] = rel.Description | |||||
| ctx.Data["category"] = rel.Category | |||||
| ctx.Data["task"] = rel.Task | |||||
| ctx.Data["license"] = rel.License | |||||
| if ctx.HasError() { | |||||
| ctx.HTML(200, tplCreate) | |||||
| return | |||||
| } | |||||
| var attachmentUUIDs []string | |||||
| if setting.Attachment.Enabled { | |||||
| attachmentUUIDs = form.Files | |||||
| } | |||||
| rel.Title = form.Title | |||||
| rel.Description = form.Description | |||||
| rel.Category = form.Category | |||||
| rel.Task = form.Task | |||||
| rel.License = form.License | |||||
| if err = models.UpdateDataset(models.DefaultDBContext(), rel); err != nil { | |||||
| log.Error("%v", err) | |||||
| } | |||||
| if err = models.AddDatasetAttachments(rel.ID, attachmentUUIDs); err != nil { | |||||
| log.Error("%v", err) | |||||
| } | |||||
| ctx.Redirect(setting.AppSubURL + "/datasets") | |||||
| } | |||||
| func Delete(ctx *context.Context) { | func Delete(ctx *context.Context) { | ||||
| log.Debug("[dataset] Delete...\n") | log.Debug("[dataset] Delete...\n") | ||||
| } | } | ||||
| @@ -17,6 +17,10 @@ import ( | |||||
| "code.gitea.io/gitea/modules/upload" | "code.gitea.io/gitea/modules/upload" | ||||
| ) | ) | ||||
| func RenderAttachmentSettings(ctx *context.Context) { | |||||
| renderAttachmentSettings(ctx) | |||||
| } | |||||
| func renderAttachmentSettings(ctx *context.Context) { | func renderAttachmentSettings(ctx *context.Context) { | ||||
| ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled | ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled | ||||
| ctx.Data["AttachmentStoreType"] = setting.Attachment.StoreType | ctx.Data["AttachmentStoreType"] = setting.Attachment.StoreType | ||||
| @@ -1006,6 +1006,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Get("/create", dataset.Create) | m.Get("/create", dataset.Create) | ||||
| m.Post("/create", bindIgnErr(auth.CreateDatasetForm{}), dataset.CreatePost) | m.Post("/create", bindIgnErr(auth.CreateDatasetForm{}), dataset.CreatePost) | ||||
| m.Post("/delete", dataset.Delete) | m.Post("/delete", dataset.Delete) | ||||
| m.Get("/edit/:id", dataset.EditDataset) | |||||
| m.Post("/edit/:id", bindIgnErr(auth.EditDatasetForm{}), dataset.EditDatasetPost) | |||||
| }, ignSignIn) | }, ignSignIn) | ||||
| // ***** END: DataSet***** | // ***** END: DataSet***** | ||||
| m.Group("/notifications", func() { | m.Group("/notifications", func() { | ||||