| @@ -24,6 +24,7 @@ type Attachment struct { | |||||
| ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
| UUID string `xorm:"uuid UNIQUE"` | UUID string `xorm:"uuid UNIQUE"` | ||||
| IssueID int64 `xorm:"INDEX"` | IssueID int64 `xorm:"INDEX"` | ||||
| DatasetID int64 `xorm:"INDEX DEFAULT 0"` | |||||
| ReleaseID int64 `xorm:"INDEX"` | ReleaseID int64 `xorm:"INDEX"` | ||||
| UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added | UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added | ||||
| CommentID int64 | CommentID int64 | ||||
| @@ -1,6 +1,8 @@ | |||||
| package models | package models | ||||
| import ( | import ( | ||||
| "fmt" | |||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| ) | ) | ||||
| @@ -29,3 +31,22 @@ func CreateDataset(dataset *Dataset) (err error) { | |||||
| return nil | 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 | |||||
| } | |||||
| @@ -13,6 +13,7 @@ type CreateDatasetForm struct { | |||||
| License string `binding:"Required;MaxSize(64)"` | License string `binding:"Required;MaxSize(64)"` | ||||
| Task string `binding:"Required;MaxSize(64)"` | Task string `binding:"Required;MaxSize(64)"` | ||||
| ReleaseID int64 `xorm:"INDEX"` | ReleaseID int64 `xorm:"INDEX"` | ||||
| Files []string | |||||
| } | } | ||||
| // Validate validates the fields | // Validate validates the fields | ||||
| @@ -621,7 +621,7 @@ email_notifications.disable = Disable Email Notifications | |||||
| email_notifications.submit = Set Email Preference | email_notifications.submit = Set Email Preference | ||||
| [dataset] | [dataset] | ||||
| title = Title | |||||
| title = Name | |||||
| description = Description | description = Description | ||||
| create_dataset = Create Dataset | create_dataset = Create Dataset | ||||
| category = Category | category = Category | ||||
| @@ -620,7 +620,7 @@ email_notifications.disable=停用邮件通知 | |||||
| email_notifications.submit=邮件通知设置 | email_notifications.submit=邮件通知设置 | ||||
| [dataset] | [dataset] | ||||
| title = 主题 | |||||
| title = 名称 | |||||
| description = 描述 | description = 描述 | ||||
| create_dataset = 创建数据集 | create_dataset = 创建数据集 | ||||
| category = 分类 | category = 分类 | ||||
| @@ -72,6 +72,17 @@ func CreatePost(ctx *context.Context, form auth.CreateDatasetForm) { | |||||
| log.Error("%v", err) | 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 { | if err == nil { | ||||
| log.Trace("Dataset created [%d]: %s/%s", opts.ID, ctxUser.Name, opts.Title) | log.Trace("Dataset created [%d]: %s/%s", opts.ID, ctxUser.Name, opts.Title) | ||||
| ctx.Redirect(setting.AppSubURL + "/datasets") | ctx.Redirect(setting.AppSubURL + "/datasets") | ||||