| @@ -64,6 +64,7 @@ type AttachmentInfo struct { | |||
| Repo *Repository `xorm:"extends"` | |||
| RelAvatarLink string `xorm:"extends"` | |||
| UserName string `xorm:"extends"` | |||
| Recommend bool `xorm:"-"` | |||
| } | |||
| type AttachmentsOptions struct { | |||
| @@ -78,6 +79,7 @@ type AttachmentsOptions struct { | |||
| JustNeedZipFile bool | |||
| NeedRepoInfo bool | |||
| Keyword string | |||
| RecommendOnly bool | |||
| } | |||
| func (a *Attachment) AfterUpdate() { | |||
| @@ -570,6 +572,11 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { | |||
| builder.Eq{"attachment.is_private": opts.IsPrivate}, | |||
| ) | |||
| } | |||
| if opts.RecommendOnly { | |||
| cond = cond.And(builder.In("attachment.id", builder.Select("attachment.id"). | |||
| From("attachment"). | |||
| Join("INNER", "dataset", "attachment.dataset_id = dataset.id and dataset.recommend=true"))) | |||
| } | |||
| if opts.JustNeedZipFile { | |||
| var DecompressState []int32 | |||
| @@ -618,6 +625,7 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { | |||
| if err != nil { | |||
| return nil, 0, fmt.Errorf("GetDatasetByID failed error: %v", err) | |||
| } | |||
| attachment.Recommend = dataset.Recommend | |||
| repo, err := GetRepositoryByID(dataset.RepoID) | |||
| if err == nil { | |||
| attachment.Repo = repo | |||
| @@ -23,7 +23,8 @@ type Dataset struct { | |||
| Category string | |||
| Description string `xorm:"TEXT"` | |||
| DownloadTimes int64 | |||
| NumStars int `xorm:"INDEX NOT NULL DEFAULT 0"` | |||
| NumStars int `xorm:"INDEX NOT NULL DEFAULT 0"` | |||
| Recommend bool `xorm:"INDEX NOT NULL DEFAULT false"` | |||
| License string | |||
| Task string | |||
| ReleaseID int64 `xorm:"INDEX"` | |||
| @@ -99,6 +100,7 @@ type SearchDatasetOptions struct { | |||
| OwnerID int64 | |||
| RepoID int64 | |||
| IncludePublic bool | |||
| RecommendOnly bool | |||
| Category string | |||
| Task string | |||
| License string | |||
| @@ -132,6 +134,13 @@ func CreateDataset(dataset *Dataset) (err error) { | |||
| } | |||
| func RecommendDataset(dataSetId int64, recommend bool) error { | |||
| dataset := Dataset{Recommend: recommend} | |||
| _, err := x.ID(dataSetId).Cols("recommend").Update(dataset) | |||
| return err | |||
| } | |||
| func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) { | |||
| cond := SearchDatasetCondition(opts) | |||
| return SearchDatasetByCondition(opts, cond) | |||
| @@ -146,6 +155,9 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { | |||
| if opts.RepoID > 0 { | |||
| cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) | |||
| } | |||
| if opts.RecommendOnly { | |||
| cond = cond.And(builder.Eq{"dataset.recommend": opts.RecommendOnly}) | |||
| } | |||
| if opts.IncludePublic { | |||
| cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) | |||
| @@ -198,7 +210,7 @@ func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (Da | |||
| defer sess.Close() | |||
| datasets := make(DatasetList, 0, opts.PageSize) | |||
| selectColumnsSql := "distinct dataset.id,dataset.title, dataset.status, dataset.category, dataset.description, dataset.download_times, dataset.license, dataset.task, dataset.release_id, dataset.user_id, dataset.repo_id, dataset.created_unix,dataset.updated_unix,dataset.num_stars" | |||
| selectColumnsSql := "distinct dataset.id,dataset.title, dataset.status, dataset.category, dataset.description, dataset.download_times, dataset.license, dataset.task, dataset.release_id, dataset.user_id, dataset.repo_id, dataset.created_unix,dataset.updated_unix,dataset.num_stars,dataset.recommend" | |||
| count, err := sess.Distinct("dataset.id").Join("INNER", "repository", "repository.id = dataset.repo_id"). | |||
| Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). | |||
| @@ -1,6 +1,8 @@ | |||
| package admin | |||
| import ( | |||
| "net/http" | |||
| "strconv" | |||
| "strings" | |||
| "code.gitea.io/gitea/models" | |||
| @@ -88,6 +90,23 @@ func Datasets(ctx *context.Context) { | |||
| ctx.HTML(200, tplDatasets) | |||
| } | |||
| func DatasetAction(ctx *context.Context) { | |||
| var err error | |||
| datasetId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) | |||
| switch ctx.Params(":action") { | |||
| case "recommend": | |||
| err = models.RecommendDataset(datasetId, true) | |||
| case "unrecommend": | |||
| err = models.RecommendDataset(datasetId, false) | |||
| } | |||
| if err != nil { | |||
| ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.star_fail", ctx.Params(":action")))) | |||
| } else { | |||
| ctx.JSON(http.StatusOK, models.BaseOKMessage) | |||
| } | |||
| } | |||
| func DeleteDataset(ctx *context.Context) { | |||
| dataset, err := models.GetDatasetByID(ctx.QueryInt64("id")) | |||
| if err != nil { | |||
| @@ -331,6 +331,7 @@ func ExploreDatasets(ctx *context.Context) { | |||
| Task: task, | |||
| License: license, | |||
| OwnerID: ownerID, | |||
| RecommendOnly: ctx.QueryBool("recommend"), | |||
| ListOptions: models.ListOptions{ | |||
| Page: page, | |||
| PageSize: 30, | |||
| @@ -358,6 +358,7 @@ func MyDatasets(ctx *context.Context) { | |||
| NeedIsPrivate: false, | |||
| JustNeedZipFile: true, | |||
| NeedRepoInfo: true, | |||
| RecommendOnly: ctx.QueryBool("recommend"), | |||
| }) | |||
| if err != nil { | |||
| ctx.ServerError("datasets", err) | |||
| @@ -398,6 +399,7 @@ func PublicDataset(ctx *context.Context) { | |||
| Type: cloudbrainType, | |||
| JustNeedZipFile: true, | |||
| NeedRepoInfo: true, | |||
| RecommendOnly: ctx.QueryBool("recommend"), | |||
| }) | |||
| if err != nil { | |||
| ctx.ServerError("datasets", err) | |||
| @@ -454,6 +456,7 @@ func MyFavoriteDataset(ctx *context.Context) { | |||
| Type: cloudbrainType, | |||
| JustNeedZipFile: true, | |||
| NeedRepoInfo: true, | |||
| RecommendOnly: ctx.QueryBool("recommend"), | |||
| }) | |||
| if err != nil { | |||
| ctx.ServerError("datasets", err) | |||
| @@ -525,6 +525,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
| m.Group("/datasets", func() { | |||
| m.Get("", admin.Datasets) | |||
| m.Put(":id/action/:action", admin.DatasetAction) | |||
| // m.Post("/delete", admin.DeleteDataset) | |||
| }) | |||
| m.Group("/cloudbrains", func() { | |||
| @@ -106,9 +106,9 @@ func Profile(ctx *context.Context) { | |||
| for _, org := range orgs { | |||
| _, repoCount, err := models.SearchRepository(&models.SearchRepoOptions{ | |||
| OwnerID: org.ID, | |||
| Private: ctx.IsSigned, | |||
| Actor: ctx.User, | |||
| OwnerID: org.ID, | |||
| Private: ctx.IsSigned, | |||
| Actor: ctx.User, | |||
| }) | |||
| if err != nil { | |||
| ctx.ServerError("SearchRepository", err) | |||
| @@ -175,6 +175,8 @@ func Profile(ctx *context.Context) { | |||
| orderBy = models.SearchOrderByAlphabeticallyReverse | |||
| case "alphabetically": | |||
| orderBy = models.SearchOrderByAlphabetically | |||
| case "downloadtimes": | |||
| orderBy = models.SearchOrderByDownloadTimes | |||
| case "moststars": | |||
| orderBy = models.SearchOrderByStarsReverse | |||
| case "feweststars": | |||