Browse Source

feat: add dataset files

master
colorfulberry 5 years ago
parent
commit
f2ba80c271
6 changed files with 36 additions and 2 deletions
  1. +1
    -0
      models/attachment.go
  2. +21
    -0
      models/dataset.go
  3. +1
    -0
      modules/auth/dataset.go
  4. +1
    -1
      options/locale/locale_en-US.ini
  5. +1
    -1
      options/locale/locale_zh-CN.ini
  6. +11
    -0
      routers/dataset/dataset.go

+ 1
- 0
models/attachment.go View File

@@ -24,6 +24,7 @@ type Attachment struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
IssueID int64 `xorm:"INDEX"`
DatasetID int64 `xorm:"INDEX DEFAULT 0"`
ReleaseID int64 `xorm:"INDEX"`
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
CommentID int64


+ 21
- 0
models/dataset.go View File

@@ -1,6 +1,8 @@
package models

import (
"fmt"

"code.gitea.io/gitea/modules/timeutil"
)

@@ -29,3 +31,22 @@ func CreateDataset(dataset *Dataset) (err error) {

return nil
}

// AddReleaseAttachments adds a release attachments
func AddDatasetAttachments(DatasetID int64, attachmentUUIDs []string) (err error) {
// Check attachments
attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs)
if err != nil {
return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err)
}

for i := range attachments {
attachments[i].DatasetID = DatasetID
// No assign value could be 0, so ignore AllCols().
if _, err = x.ID(attachments[i].ID).Update(attachments[i]); err != nil {
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
}
}

return
}

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

@@ -13,6 +13,7 @@ type CreateDatasetForm struct {
License string `binding:"Required;MaxSize(64)"`
Task string `binding:"Required;MaxSize(64)"`
ReleaseID int64 `xorm:"INDEX"`
Files []string
}

// Validate validates the fields


+ 1
- 1
options/locale/locale_en-US.ini View File

@@ -621,7 +621,7 @@ email_notifications.disable = Disable Email Notifications
email_notifications.submit = Set Email Preference

[dataset]
title = Title
title = Name
description = Description
create_dataset = Create Dataset
category = Category


+ 1
- 1
options/locale/locale_zh-CN.ini View File

@@ -620,7 +620,7 @@ email_notifications.disable=停用邮件通知
email_notifications.submit=邮件通知设置

[dataset]
title = 主题
title = 名称
description = 描述
create_dataset = 创建数据集
category = 分类


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

@@ -72,6 +72,17 @@ func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) {
log.Error("%v", err)
}

var attachmentUUIDs []string
if setting.Attachment.Enabled {
attachmentUUIDs = form.Files
}

log.Error("%v", attachmentUUIDs)

if err = models.AddDatasetAttachments(opts.ID, attachmentUUIDs); err != nil {
log.Error("%v", err)
}

if err == nil {
log.Trace("Dataset created [%d]: %s/%s", opts.ID, ctxUser.Name, opts.Title)
ctx.Redirect(setting.AppSubURL + "/datasets")


Loading…
Cancel
Save