| @@ -50,6 +50,7 @@ type Attachment struct { | |||||
| FileChunk *FileChunk `xorm:"-"` | FileChunk *FileChunk `xorm:"-"` | ||||
| CanDel bool `xorm:"-"` | CanDel bool `xorm:"-"` | ||||
| Uploader *User `xorm:"-"` | |||||
| } | } | ||||
| type AttachmentUsername struct { | type AttachmentUsername struct { | ||||
| @@ -355,7 +356,7 @@ func updateAttachment(e Engine, atta *Attachment) error { | |||||
| // Use uuid only if id is not set and uuid is set | // Use uuid only if id is not set and uuid is set | ||||
| sess = e.Where("uuid = ?", atta.UUID) | sess = e.Where("uuid = ?", atta.UUID) | ||||
| } | } | ||||
| _, err := sess.Cols("name", "issue_id", "release_id", "comment_id", "download_count", "is_private", "decompress_state").Update(atta) | |||||
| _, err := sess.Cols("name", "description", "issue_id", "release_id", "comment_id", "download_count", "is_private", "decompress_state").Update(atta) | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -31,3 +31,16 @@ type EditDatasetForm struct { | |||||
| Files []string | Files []string | ||||
| Type string `binding:"Required"` | Type string `binding:"Required"` | ||||
| } | } | ||||
| func (f *EditDatasetForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | |||||
| return validate(errs, ctx.Data, f, ctx.Locale) | |||||
| } | |||||
| type EditAttachmentForm struct { | |||||
| ID int64 `binding:"Required"` | |||||
| Description string | |||||
| } | |||||
| func (f *EditAttachmentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | |||||
| return validate(errs, ctx.Data, f, ctx.Locale) | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package dataset | |||||
| func GetResourceType(cloudbrainType int) string { | |||||
| if cloudbrainType == 0 { | |||||
| return "CPU/GPU" | |||||
| } else { | |||||
| return "NPU" | |||||
| } | |||||
| } | |||||
| func GetStatusText(isPrivate bool) string { | |||||
| if isPrivate { | |||||
| return "dataset.private" | |||||
| } else { | |||||
| return "dataset.public" | |||||
| } | |||||
| } | |||||
| @@ -23,6 +23,8 @@ import ( | |||||
| "time" | "time" | ||||
| "unicode" | "unicode" | ||||
| "code.gitea.io/gitea/modules/dataset" | |||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| "code.gitea.io/gitea/modules/emoji" | "code.gitea.io/gitea/modules/emoji" | ||||
| @@ -86,20 +88,22 @@ func NewFuncMap() []template.FuncMap { | |||||
| "AllowedReactions": func() []string { | "AllowedReactions": func() []string { | ||||
| return setting.UI.Reactions | return setting.UI.Reactions | ||||
| }, | }, | ||||
| "AvatarLink": models.AvatarLink, | |||||
| "Safe": Safe, | |||||
| "SafeJS": SafeJS, | |||||
| "Str2html": Str2html, | |||||
| "TimeSince": timeutil.TimeSince, | |||||
| "TimeSinceUnix": timeutil.TimeSinceUnix, | |||||
| "TimeSinceUnix1": timeutil.TimeSinceUnix1, | |||||
| "TimeSinceUnixShort": timeutil.TimeSinceUnixShort, | |||||
| "RawTimeSince": timeutil.RawTimeSince, | |||||
| "FileSize": base.FileSize, | |||||
| "PrettyNumber": base.PrettyNumber, | |||||
| "Subtract": base.Subtract, | |||||
| "EntryIcon": base.EntryIcon, | |||||
| "MigrationIcon": MigrationIcon, | |||||
| "AvatarLink": models.AvatarLink, | |||||
| "Safe": Safe, | |||||
| "SafeJS": SafeJS, | |||||
| "Str2html": Str2html, | |||||
| "TimeSince": timeutil.TimeSince, | |||||
| "TimeSinceUnix": timeutil.TimeSinceUnix, | |||||
| "TimeSinceUnix1": timeutil.TimeSinceUnix1, | |||||
| "AttachmentResourceType": dataset.GetResourceType, | |||||
| "AttachmentStatus": dataset.GetStatusText, | |||||
| "TimeSinceUnixShort": timeutil.TimeSinceUnixShort, | |||||
| "RawTimeSince": timeutil.RawTimeSince, | |||||
| "FileSize": base.FileSize, | |||||
| "PrettyNumber": base.PrettyNumber, | |||||
| "Subtract": base.Subtract, | |||||
| "EntryIcon": base.EntryIcon, | |||||
| "MigrationIcon": MigrationIcon, | |||||
| "Add": func(a, b int) int { | "Add": func(a, b int) int { | ||||
| return a + b | return a + b | ||||
| }, | }, | ||||
| @@ -340,11 +344,13 @@ func NewTextFuncMap() []texttmpl.FuncMap { | |||||
| "AppDomain": func() string { | "AppDomain": func() string { | ||||
| return setting.Domain | return setting.Domain | ||||
| }, | }, | ||||
| "TimeSince": timeutil.TimeSince, | |||||
| "TimeSinceUnix": timeutil.TimeSinceUnix, | |||||
| "TimeSinceUnix1": timeutil.TimeSinceUnix1, | |||||
| "TimeSinceUnixShort": timeutil.TimeSinceUnixShort, | |||||
| "RawTimeSince": timeutil.RawTimeSince, | |||||
| "TimeSince": timeutil.TimeSince, | |||||
| "TimeSinceUnix": timeutil.TimeSinceUnix, | |||||
| "TimeSinceUnix1": timeutil.TimeSinceUnix1, | |||||
| "TimeSinceUnixShort": timeutil.TimeSinceUnixShort, | |||||
| "RawTimeSince": timeutil.RawTimeSince, | |||||
| "AttachmentResourceType": dataset.GetResourceType, | |||||
| "AttachmentStatus": dataset.GetStatusText, | |||||
| "DateFmtLong": func(t time.Time) string { | "DateFmtLong": func(t time.Time) string { | ||||
| return t.Format(time.RFC1123Z) | return t.Format(time.RFC1123Z) | ||||
| }, | }, | ||||
| @@ -715,6 +715,7 @@ description_format_err=Description's length can be up to 1024 characters long. | |||||
| create_dataset = Create Dataset | create_dataset = Create Dataset | ||||
| create_dataset_fail=Failed to create dataset. | create_dataset_fail=Failed to create dataset. | ||||
| query_dataset_fail=Failed to query dataset. | query_dataset_fail=Failed to query dataset. | ||||
| edit_attachment_fail=Failed to update description. | |||||
| show_dataset= Dataset | show_dataset= Dataset | ||||
| edit_dataset= Edit Dataset | edit_dataset= Edit Dataset | ||||
| update_dataset= Update Dataset | update_dataset= Update Dataset | ||||
| @@ -717,7 +717,8 @@ description=描述 | |||||
| description_format_err=描述最多允许输入1024个字符。 | description_format_err=描述最多允许输入1024个字符。 | ||||
| create_dataset=创建数据集 | create_dataset=创建数据集 | ||||
| create_dataset_fail=创建数据集失败。 | create_dataset_fail=创建数据集失败。 | ||||
| query_dataset_fail=查询数据集失败 | |||||
| query_dataset_fail=查询数据集失败。 | |||||
| edit_attachment_fail=修改描述失败。 | |||||
| show_dataset=数据集 | show_dataset=数据集 | ||||
| edit_dataset=编辑数据集 | edit_dataset=编辑数据集 | ||||
| @@ -15,6 +15,8 @@ import ( | |||||
| "strconv" | "strconv" | ||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/modules/auth" | |||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| @@ -35,6 +37,7 @@ const ( | |||||
| DecompressSuccess = "0" | DecompressSuccess = "0" | ||||
| DecompressFailed = "1" | DecompressFailed = "1" | ||||
| tplAttachmentUpload base.TplName = "repo/attachment/upload" | tplAttachmentUpload base.TplName = "repo/attachment/upload" | ||||
| tplAttachmentEdit base.TplName = "repo/attachment/edit" | |||||
| ) | ) | ||||
| type CloudBrainDataset struct { | type CloudBrainDataset struct { | ||||
| @@ -78,6 +81,31 @@ func UploadAttachmentUI(ctx *context.Context) { | |||||
| } | } | ||||
| func EditAttachmentUI(ctx *context.Context) { | |||||
| id := ctx.QueryInt64(":id") | |||||
| attachment, _ := models.GetAttachmentByID(id) | |||||
| if attachment == nil { | |||||
| ctx.Error(404, "The attachment does not exits.") | |||||
| } | |||||
| ctx.Data["Attachment"] = attachment | |||||
| ctx.HTML(200, tplAttachmentEdit) | |||||
| } | |||||
| func EditAttachment(ctx *context.Context, form auth.EditAttachmentForm) { | |||||
| err := models.UpdateAttachment(&models.Attachment{ | |||||
| ID: form.ID, | |||||
| Description: form.Description, | |||||
| }) | |||||
| if err != nil { | |||||
| ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.edit_attachment_fail"))) | |||||
| } | |||||
| ctx.JSON(http.StatusOK, models.BaseOKMessage) | |||||
| } | |||||
| // UploadAttachment response for uploading issue's attachment | // UploadAttachment response for uploading issue's attachment | ||||
| func UploadAttachment(ctx *context.Context) { | func UploadAttachment(ctx *context.Context) { | ||||
| if !setting.Attachment.Enabled { | if !setting.Attachment.Enabled { | ||||
| @@ -144,6 +144,12 @@ func DatasetIndex(ctx *context.Context) { | |||||
| pageAttachments := getPageAttachments(attachments, page, pagesize) | pageAttachments := getPageAttachments(attachments, page, pagesize) | ||||
| //load attachment creator | |||||
| for _, attachment := range pageAttachments { | |||||
| uploader, _ := models.GetUserByID(attachment.UploaderID) | |||||
| attachment.Uploader = uploader | |||||
| } | |||||
| ctx.Data["Page"] = pager | ctx.Data["Page"] = pager | ||||
| ctx.Data["PageIsDataset"] = true | ctx.Data["PageIsDataset"] = true | ||||
| ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") | ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") | ||||
| @@ -588,6 +588,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Get("/get_pre_url", repo.GetPresignedPutObjectURL) | m.Get("/get_pre_url", repo.GetPresignedPutObjectURL) | ||||
| m.Post("/add", repo.AddAttachment) | m.Post("/add", repo.AddAttachment) | ||||
| m.Get("/upload", repo.UploadAttachmentUI) | m.Get("/upload", repo.UploadAttachmentUI) | ||||
| m.Get("/edit/:id", repo.EditAttachmentUI) | |||||
| m.Post("/edit", bindIgnErr(auth.EditAttachmentForm{}), repo.EditAttachment) | |||||
| m.Post("/private", repo.UpdatePublicAttachment) | m.Post("/private", repo.UpdatePublicAttachment) | ||||
| m.Get("/get_chunks", repo.GetSuccessChunks) | m.Get("/get_chunks", repo.GetSuccessChunks) | ||||
| m.Get("/new_multipart", repo.NewMultipart) | m.Get("/new_multipart", repo.NewMultipart) | ||||