| @@ -38,6 +38,7 @@ type Attachment struct { | |||
| UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added | |||
| CommentID int64 | |||
| Name string | |||
| Description string `xorm:"TEXT"` | |||
| DownloadCount int64 `xorm:"DEFAULT 0"` | |||
| Size int64 `xorm:"DEFAULT 0"` | |||
| IsPrivate bool `xorm:"DEFAULT false"` | |||
| @@ -92,6 +92,9 @@ type SearchDatasetOptions struct { | |||
| OwnerID int64 | |||
| RepoID int64 | |||
| IncludePublic bool | |||
| Category string | |||
| Task string | |||
| License string | |||
| ListOptions | |||
| SearchOrderBy | |||
| IsOwner bool | |||
| @@ -118,6 +121,17 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { | |||
| cond = cond.And(builder.Like{"dataset.title", opts.Keyword}) | |||
| } | |||
| if len(opts.Category) > 0 { | |||
| cond = cond.And(builder.Eq{"dataset.category": opts.Category}) | |||
| } | |||
| if len(opts.Task) > 0 { | |||
| cond = cond.And(builder.Eq{"dataset.task": opts.Task}) | |||
| } | |||
| if len(opts.License) > 0 { | |||
| cond = cond.And(builder.Eq{"dataset.license": opts.License}) | |||
| } | |||
| if opts.RepoID > 0 { | |||
| cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) | |||
| } | |||
| @@ -223,13 +237,23 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, isSigned bool, user *Us | |||
| sort.Sort(sortedRels) | |||
| // Select attachments | |||
| err = e. | |||
| Asc("dataset_id"). | |||
| In("dataset_id", sortedRels.ID). | |||
| And("type = ?", typeCloudBrain). | |||
| Find(&attachments, Attachment{}) | |||
| if err != nil { | |||
| return err | |||
| if typeCloudBrain == -1 { | |||
| err = e. | |||
| Asc("dataset_id"). | |||
| In("dataset_id", sortedRels.ID). | |||
| Find(&attachments, Attachment{}) | |||
| if err != nil { | |||
| return err | |||
| } | |||
| } else { | |||
| err = e. | |||
| Asc("dataset_id"). | |||
| In("dataset_id", sortedRels.ID). | |||
| And("type = ?", typeCloudBrain). | |||
| Find(&attachments, Attachment{}) | |||
| if err != nil { | |||
| return err | |||
| } | |||
| } | |||
| // merge join | |||
| @@ -312,6 +312,9 @@ func ExploreDatasets(ctx *context.Context) { | |||
| keyword := strings.Trim(ctx.Query("q"), " ") | |||
| category := ctx.Query("category") | |||
| task := ctx.Query("task") | |||
| license := ctx.Query("license") | |||
| var ownerID int64 | |||
| if ctx.User != nil && !ctx.User.IsAdmin { | |||
| ownerID = ctx.User.ID | |||
| @@ -320,6 +323,9 @@ func ExploreDatasets(ctx *context.Context) { | |||
| Keyword: keyword, | |||
| IncludePublic: true, | |||
| SearchOrderBy: orderBy, | |||
| Category: category, | |||
| Task: task, | |||
| License: license, | |||
| OwnerID: ownerID, | |||
| ListOptions: models.ListOptions{ | |||
| Page: page, | |||
| @@ -335,6 +341,9 @@ func ExploreDatasets(ctx *context.Context) { | |||
| pager := context.NewPagination(int(count), opts.PageSize, page, 5) | |||
| ctx.Data["Keyword"] = opts.Keyword | |||
| ctx.Data["Category"] = category | |||
| ctx.Data["Task"] = task | |||
| ctx.Data["License"] = license | |||
| pager.SetDefaultParams(ctx) | |||
| ctx.Data["Page"] = pager | |||
| @@ -15,6 +15,8 @@ import ( | |||
| "strconv" | |||
| "strings" | |||
| "code.gitea.io/gitea/modules/base" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/context" | |||
| "code.gitea.io/gitea/modules/labelmsg" | |||
| @@ -30,8 +32,9 @@ import ( | |||
| const ( | |||
| //result of decompress | |||
| DecompressSuccess = "0" | |||
| DecompressFailed = "1" | |||
| DecompressSuccess = "0" | |||
| DecompressFailed = "1" | |||
| tplAttachmentUpload base.TplName = "repo/attachment/upload" | |||
| ) | |||
| type CloudBrainDataset struct { | |||
| @@ -63,6 +66,12 @@ func renderAttachmentSettings(ctx *context.Context) { | |||
| ctx.Data["AttachmentMaxFiles"] = setting.Attachment.MaxFiles | |||
| } | |||
| func UploadAttachmentUI(ctx *context.Context) { | |||
| ctx.Data["datasetId"] = ctx.Query("datasetId") | |||
| ctx.HTML(200, tplAttachmentUpload) | |||
| } | |||
| // UploadAttachment response for uploading issue's attachment | |||
| func UploadAttachment(ctx *context.Context) { | |||
| if !setting.Attachment.Enabled { | |||
| @@ -836,22 +845,23 @@ func CompleteMultipart(ctx *context.Context) { | |||
| ctx.Error(500, fmt.Sprintf("UpdateFileChunk: %v", err)) | |||
| return | |||
| } | |||
| dataset, _ := models.GetDatasetByID(ctx.QueryInt64("dataset_id")) | |||
| attachment, err := models.InsertAttachment(&models.Attachment{ | |||
| UUID: uuid, | |||
| UploaderID: ctx.User.ID, | |||
| IsPrivate: true, | |||
| Name: fileName, | |||
| Size: ctx.QueryInt64("size"), | |||
| DatasetID: ctx.QueryInt64("dataset_id"), | |||
| Type: typeCloudBrain, | |||
| UUID: uuid, | |||
| UploaderID: ctx.User.ID, | |||
| IsPrivate: dataset.IsPrivate(), | |||
| Name: fileName, | |||
| Size: ctx.QueryInt64("size"), | |||
| DatasetID: ctx.QueryInt64("dataset_id"), | |||
| Description: ctx.Query("description"), | |||
| Type: typeCloudBrain, | |||
| }) | |||
| if err != nil { | |||
| ctx.Error(500, fmt.Sprintf("InsertAttachment: %v", err)) | |||
| return | |||
| } | |||
| dataset, _ := models.GetDatasetByID(attachment.DatasetID) | |||
| repository, _ := models.GetRepositoryByID(dataset.RepoID) | |||
| notification.NotifyOtherTask(ctx.User, repository, fmt.Sprint(attachment.Type), attachment.Name, models.ActionUploadAttachment) | |||
| @@ -91,21 +91,11 @@ func QueryDataSet(ctx *context.Context) []*models.Attachment { | |||
| attachments := newFilterPrivateAttachments(ctx, dataset.Attachments, repo) | |||
| ctx.Data["SortType"] = ctx.Query("sort") | |||
| switch ctx.Query("sort") { | |||
| case "newest": | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| case "oldest": | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix < attachments[j].CreatedUnix | |||
| }) | |||
| default: | |||
| ctx.Data["SortType"] = "newest" | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| } | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| return attachments | |||
| } | |||
| @@ -121,13 +111,12 @@ func DatasetIndex(ctx *context.Context) { | |||
| ctx.HTML(200, tplIndex) | |||
| return | |||
| } | |||
| cloudbrainType := -1 | |||
| if ctx.Query("type") != "" { | |||
| if ctx.Query("type") == "" { | |||
| log.Error("query dataset, not found param type") | |||
| ctx.NotFound("type error", nil) | |||
| return | |||
| cloudbrainType = ctx.QueryInt("type") | |||
| } | |||
| err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) | |||
| err = models.GetDatasetAttachments(cloudbrainType, ctx.IsSigned, ctx.User, dataset) | |||
| if err != nil { | |||
| ctx.ServerError("GetDatasetAttachments", err) | |||
| return | |||
| @@ -135,37 +124,52 @@ func DatasetIndex(ctx *context.Context) { | |||
| attachments := newFilterPrivateAttachments(ctx, dataset.Attachments, repo) | |||
| ctx.Data["SortType"] = ctx.Query("sort") | |||
| switch ctx.Query("sort") { | |||
| case "newest": | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| case "oldest": | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix < attachments[j].CreatedUnix | |||
| }) | |||
| default: | |||
| ctx.Data["SortType"] = "newest" | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| sort.Slice(attachments, func(i, j int) bool { | |||
| return attachments[i].CreatedUnix > attachments[j].CreatedUnix | |||
| }) | |||
| page := ctx.QueryInt("page") | |||
| if page <= 0 { | |||
| page = 1 | |||
| } | |||
| pagesize := ctx.QueryInt("pagesize") | |||
| if pagesize <= 0 { | |||
| pagesize = setting.UI.ExplorePagingNum | |||
| } | |||
| pager := context.NewPagination(len(attachments), pagesize, page, 5) | |||
| pageAttachments := getPageAttachments(attachments, page, pagesize) | |||
| ctx.Data["Page"] = pager | |||
| ctx.Data["PageIsDataset"] = true | |||
| ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") | |||
| ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets" | |||
| ctx.Data["dataset"] = dataset | |||
| ctx.Data["Attachments"] = attachments | |||
| ctx.Data["Attachments"] = pageAttachments | |||
| ctx.Data["IsOwner"] = true | |||
| ctx.Data["StoreType"] = setting.Attachment.StoreType | |||
| ctx.Data["Type"] = ctx.QueryInt("type") | |||
| ctx.Data["Type"] = cloudbrainType | |||
| renderAttachmentSettings(ctx) | |||
| ctx.HTML(200, tplIndex) | |||
| } | |||
| func getPageAttachments(attachments []*models.Attachment, page int, pagesize int) []*models.Attachment { | |||
| begin := (page - 1) * pagesize | |||
| end := (page) * pagesize | |||
| if begin > len(attachments)-1 { | |||
| return nil | |||
| } | |||
| if end > len(attachments)-1 { | |||
| return attachments[begin:] | |||
| } else { | |||
| return attachments[begin:end] | |||
| } | |||
| } | |||
| func CreateDataset(ctx *context.Context) { | |||
| MustEnableDataset(ctx) | |||
| @@ -586,6 +586,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Post("/delete", repo.DeleteAttachment) | |||
| m.Get("/get_pre_url", repo.GetPresignedPutObjectURL) | |||
| m.Post("/add", repo.AddAttachment) | |||
| m.Get("/upload", repo.UploadAttachmentUI) | |||
| m.Post("/private", repo.UpdatePublicAttachment) | |||
| m.Get("/get_chunks", repo.GetSuccessChunks) | |||
| m.Get("/new_multipart", repo.NewMultipart) | |||