Browse Source

feat: add the pages

tags/v1.21.12.1
colorfulberry 5 years ago
parent
commit
471a7420d5
6 changed files with 109 additions and 1 deletions
  1. +21
    -1
      models/dataset.go
  2. +8
    -0
      models/error.go
  3. +11
    -0
      modules/auth/dataset.go
  4. +63
    -0
      routers/dataset/dataset.go
  5. +4
    -0
      routers/repo/attachment.go
  6. +2
    -0
      routers/routes/routes.go

+ 21
- 1
models/dataset.go View File

@@ -32,7 +32,7 @@ func CreateDataset(dataset *Dataset) (err error) {
return nil
}

// AddReleaseAttachments adds a release attachments
// AddDatasetAttachments adds a Dataset attachments
func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error) {
// Check attachments
attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs)
@@ -50,3 +50,23 @@ func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error

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
}

+ 8
- 0
models/error.go View File

@@ -851,6 +851,14 @@ func IsErrInvalidTagName(err error) bool {
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 {
return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
}


+ 11
- 0
modules/auth/dataset.go View File

@@ -16,6 +16,17 @@ type CreateDatasetForm struct {
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
func (f *CreateDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)


+ 63
- 0
routers/dataset/dataset.go View File

@@ -7,6 +7,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/repo"
)

const (
@@ -92,6 +93,68 @@ func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) {
// 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) {
log.Debug("[dataset] Delete...\n")
}

+ 4
- 0
routers/repo/attachment.go View File

@@ -17,6 +17,10 @@ import (
"code.gitea.io/gitea/modules/upload"
)

func RenderAttachmentSettings(ctx *context.Context) {
renderAttachmentSettings(ctx)
}

func renderAttachmentSettings(ctx *context.Context) {
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
ctx.Data["AttachmentStoreType"] = setting.Attachment.StoreType


+ 2
- 0
routers/routes/routes.go View File

@@ -1006,6 +1006,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/create", dataset.Create)
m.Post("/create", bindIgnErr(auth.CreateDatasetForm{}), dataset.CreatePost)
m.Post("/delete", dataset.Delete)
m.Get("/edit/:id", dataset.EditDataset)
m.Post("/edit/:id", bindIgnErr(auth.EditDatasetForm{}), dataset.EditDatasetPost)
}, ignSignIn)
// ***** END: DataSet*****
m.Group("/notifications", func() {


Loading…
Cancel
Save