From 83e61aad76b8121b5cb10ea9b45d6fd3b4428b96 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Mon, 6 Jun 2022 15:15:12 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/attachment.go | 5 +++-- models/dataset.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index ea8f1645f..a93082bf0 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -41,8 +41,9 @@ 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"` + Description string `xorm:"TEXT"` + DownloadCount int64 `xorm:"DEFAULT 0"` + UseCount int64 Size int64 `xorm:"DEFAULT 0"` IsPrivate bool `xorm:"DEFAULT false"` DecompressState int32 `xorm:"DEFAULT 0"` diff --git a/models/dataset.go b/models/dataset.go index d4a7748d3..baf7731e4 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -25,6 +25,7 @@ type Dataset struct { Category string Description string `xorm:"TEXT"` DownloadTimes int64 + UseCount int64 NumStars int `xorm:"INDEX NOT NULL DEFAULT 0"` Recommend bool `xorm:"INDEX NOT NULL DEFAULT false"` License string From 7315dd24e251e5ca235d4602d5a7042f0958c7d9 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 7 Jun 2022 11:52:21 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/attachment.go | 15 ++++++++++++--- models/cloudbrain.go | 4 ++++ models/dataset.go | 17 ++++++++++++++--- models/repo_list.go | 2 ++ routers/admin/dataset.go | 4 ++++ routers/home.go | 4 ++++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index a93082bf0..fdf930ecf 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -41,9 +41,9 @@ 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"` - UseCount int64 + Description string `xorm:"TEXT"` + DownloadCount int64 `xorm:"DEFAULT 0"` + UseCount int64 `xorm:"DEFAULT 0"` Size int64 `xorm:"DEFAULT 0"` IsPrivate bool `xorm:"DEFAULT false"` DecompressState int32 `xorm:"DEFAULT 0"` @@ -108,6 +108,15 @@ func (a *Attachment) IncreaseDownloadCount() error { return nil } +func IncreaseAttachmentUseCount(uuid string) error { + // Update use count. + if _, err := x.Exec("UPDATE `attachment` SET use_count=use_count+1 WHERE uuid=?", uuid); err != nil { + return fmt.Errorf("increase attachment use count: %v", err) + } + + return nil +} + func (a *Attachment) UpdateDatasetUpdateUnix() error { // Update download count. if _, err := x.Exec("UPDATE `dataset` SET updated_unix="+fmt.Sprint(time.Now().Unix())+" WHERE id=?", a.DatasetID); err != nil { diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 810e68d30..451a36c81 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1395,6 +1395,8 @@ func CreateCloudbrain(cloudbrain *Cloudbrain) (err error) { if _, err = x.NoAutoTime().Insert(cloudbrain); err != nil { return err } + + go IncreaseDatasetUseCount(cloudbrain.Uuid) return nil } @@ -1629,6 +1631,8 @@ func RestartCloudbrain(old *Cloudbrain, new *Cloudbrain) (err error) { return err } + go IncreaseDatasetUseCount(new.Uuid) + return nil } func CloudbrainAll(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { diff --git a/models/dataset.go b/models/dataset.go index baf7731e4..aa29984f0 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -25,9 +25,9 @@ type Dataset struct { Category string Description string `xorm:"TEXT"` DownloadTimes int64 - UseCount int64 - NumStars int `xorm:"INDEX NOT NULL DEFAULT 0"` - Recommend bool `xorm:"INDEX NOT NULL DEFAULT false"` + UseCount int64 `xorm:"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"` @@ -351,6 +351,17 @@ func UpdateDataset(ctx DBContext, rel *Dataset) error { return err } +func IncreaseDatasetUseCount(uuid string) { + + IncreaseAttachmentUseCount(uuid) + + attachment, _ := GetAttachmentByUUID(uuid) + if attachment != nil { + x.Exec("UPDATE `dataset` SET use_count=use_count+1 WHERE id=?", attachment.DatasetID) + } + +} + // GetDatasetByID returns Dataset with given ID. func GetDatasetByID(id int64) (*Dataset, error) { rel := new(Dataset) diff --git a/models/repo_list.go b/models/repo_list.go index 253cc968c..92654c11c 100755 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -218,6 +218,8 @@ const ( SearchOrderByForks SearchOrderBy = "num_forks ASC" SearchOrderByForksReverse SearchOrderBy = "num_forks DESC" SearchOrderByDownloadTimes SearchOrderBy = "download_times DESC" + SearchOrderByUseCount SearchOrderBy = "use_count ASC" + SearchOrderByUseCountReverse SearchOrderBy = "use_count DESC" SearchOrderByHot SearchOrderBy = "(num_watches + num_stars + num_forks + clone_cnt) DESC" SearchOrderByActive SearchOrderBy = "(num_issues + num_pulls + num_commit) DESC" SearchOrderByWatches SearchOrderBy = "num_watches DESC" diff --git a/routers/admin/dataset.go b/routers/admin/dataset.go index 6b29b06ff..d1a8f2780 100644 --- a/routers/admin/dataset.go +++ b/routers/admin/dataset.go @@ -61,6 +61,10 @@ func Datasets(ctx *context.Context) { orderBy = models.SearchOrderByForksReverse case "fewestforks": orderBy = models.SearchOrderByForks + case "mostusecount": + orderBy = models.SearchOrderByUseCountReverse + case "fewestusecount": + orderBy = models.SearchOrderByUseCount default: ctx.Data["SortType"] = "recentupdate" orderBy = models.SearchOrderByRecentUpdated diff --git a/routers/home.go b/routers/home.go index 38acffb2f..a34302876 100755 --- a/routers/home.go +++ b/routers/home.go @@ -322,6 +322,10 @@ func ExploreDatasets(ctx *context.Context) { orderBy = models.SearchOrderByStarsReverse case "feweststars": orderBy = models.SearchOrderByStars + case "mostusecount": + orderBy = models.SearchOrderByUseCountReverse + case "fewestusecount": + orderBy = models.SearchOrderByUseCount case "default": orderBy = models.SearchOrderByDefault default: From 007b224ab6fdd85fbc57b285c50ca4b9048fa004 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Wed, 8 Jun 2022 15:32:58 +0800 Subject: [PATCH 3/8] fix issue --- options/locale/locale_en-US.ini | 3 +- options/locale/locale_zh-CN.ini | 3 +- templates/explore/datasets.tmpl | 342 +++++++++++++++++------------ templates/repo/datasets/index.tmpl | 4 +- 4 files changed, 207 insertions(+), 145 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c52a369ce..0b33879a2 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1446,7 +1446,8 @@ issues.filter_sort.feweststars = Fewest stars issues.filter_sort.mostforks = Most forks issues.filter_sort.fewestforks = Fewest forks issues.filter_sort.downloadtimes = Most downloaded -issues.filter_sort.moststars = Most star +issues.filter_sort.mostusecount = Most Quote +issues.filter_sort.fewestusecount=Fewest Quote issues.action_open = Open issues.action_close = Close issues.action_label = Label diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index cb1c7565a..3402de834 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1452,12 +1452,13 @@ issues.filter_sort.mostcomment=最多评论 issues.filter_sort.leastcomment=最少评论 issues.filter_sort.nearduedate=到期日从近到远 issues.filter_sort.farduedate=到期日从远到近 -issues.filter_sort.moststars=点赞由多到少 issues.filter_sort.feweststars=点赞由少到多 issues.filter_sort.mostforks=派生由多到少 issues.filter_sort.fewestforks=派生由少到多 issues.filter_sort.downloadtimes=下载次数 issues.filter_sort.moststars=收藏数量 +issues.filter_sort.mostusecount=最多引用 +issues.filter_sort.fewestusecount=最少引用 issues.action_open=开启 issues.action_close=关闭 issues.action_label=标签 diff --git a/templates/explore/datasets.tmpl b/templates/explore/datasets.tmpl index 5739ebb10..57942c24a 100644 --- a/templates/explore/datasets.tmpl +++ b/templates/explore/datasets.tmpl @@ -1,133 +1,164 @@ {{template "base/head" .}}
{{template "explore/dataset_search" .}}
- + {{template "explore/dataset_left" .}} - +

- {{.i18n.Tr "datasets"}} + {{.i18n.Tr "datasets"}}

@@ -141,85 +172,114 @@ {{end}}
- 仅显示平台推荐 + + 仅显示平台推荐
{{range $k, $v :=.Datasets}} -
+
-
- {{.Repo.OwnerName}} / {{.Repo.Alias}} +
+ {{.Title}}{{if .Recommend}}{{end}} {{if $.IsSigned}} - - - {{.DownloadTimes}} + +
- + + + +
${starItems[{{$k}}]}
{{else}} - - - {{.DownloadTimes}} + +
- + + + +
${starItems[{{$k}}]}
{{end}} +
-
{{.Title}}{{if .Recommend}}{{end}}
{{if or (.Category) (.Task) (.License)}} {{end}} -
+

{{.Description}}

- +
{{if eq .UserID 0}} - + {{else}} - + {{end}} - 创建于:{{TimeSinceUnix1 .CreatedUnix}} + {{TimeSinceUnixShort .CreatedUnix}} + + + {{.UseCount}} + + + + {{.DownloadTimes}} +
{{end}} - +
- +
diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 74448406f..88e9ff149 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -105,7 +105,7 @@ } .heart-stroke { - stroke: #666; + stroke: #FA8C16; stroke-width: 2; fill: #fff } @@ -148,7 +148,7 @@
-

{{.dataset.Title}}

+

{{.dataset.Title}}

From 8f12d315d4f2d9787e0e65fc07fba333c2e4216b Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 8 Jun 2022 16:03:39 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/attachment.go | 8 ++++---- models/dataset.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index fdf930ecf..bb99ba467 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -43,7 +43,7 @@ type Attachment struct { Name string Description string `xorm:"TEXT"` DownloadCount int64 `xorm:"DEFAULT 0"` - UseCount int64 `xorm:"DEFAULT 0"` + UseNumber int64 `xorm:"DEFAULT 0"` Size int64 `xorm:"DEFAULT 0"` IsPrivate bool `xorm:"DEFAULT false"` DecompressState int32 `xorm:"DEFAULT 0"` @@ -108,9 +108,9 @@ func (a *Attachment) IncreaseDownloadCount() error { return nil } -func IncreaseAttachmentUseCount(uuid string) error { - // Update use count. - if _, err := x.Exec("UPDATE `attachment` SET use_count=use_count+1 WHERE uuid=?", uuid); err != nil { +func IncreaseAttachmentUseNumber(uuid string) error { + // Update use number. + if _, err := x.Exec("UPDATE `attachment` SET use_number=use_number+1 WHERE uuid=?", uuid); err != nil { return fmt.Errorf("increase attachment use count: %v", err) } diff --git a/models/dataset.go b/models/dataset.go index aa29984f0..726a5010f 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -213,7 +213,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,dataset.recommend" + 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,dataset.use_count" count, err := sess.Distinct("dataset.id").Join("INNER", "repository", "repository.id = dataset.repo_id"). Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). @@ -353,7 +353,7 @@ func UpdateDataset(ctx DBContext, rel *Dataset) error { func IncreaseDatasetUseCount(uuid string) { - IncreaseAttachmentUseCount(uuid) + IncreaseAttachmentUseNumber(uuid) attachment, _ := GetAttachmentByUUID(uuid) if attachment != nil { From e38fa7a7bc10ade10c5a397d74b9a9f1fafeb26f Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Wed, 8 Jun 2022 17:02:11 +0800 Subject: [PATCH 5/8] fix issue --- options/locale/locale_en-US.ini | 4 +++ options/locale/locale_zh-CN.ini | 4 +++ templates/repo/datasets/index.tmpl | 43 +++++++++++++++++------------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0b33879a2..7cc0ed00f 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -898,6 +898,10 @@ search_dataset = Search Dataset Files unzip_tooltips = If it has not been decompressed for a long time, please check whether the compressed package has encrypted files or file errors zip_failed = Decompression failed, please check whether the compressed package is encrypted or contact technical support dataset_desc = The description should not exceed 1024 characters +unzip_successed=Unzip Successed +unzip_failed=Unzip Failed +unzip_stared=Unzipping +unzip_status=Unzip Status [repo] owner = Owner repo_name = Repository Name diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 3402de834..1c24dceab 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -903,6 +903,10 @@ search_dataset = 搜索数据集文件 unzip_tooltips = 如果长时间未解压,请检查压缩包是否有加密文件或者文件错误 zip_failed = 解压失败,请检查压缩包是否有加密或者联系技术支持人员。 dataset_desc = 描述字数不超过1024个字符 +unzip_successed=解压成功 +unzip_failed=解压失败 +unzip_stared=解压中 +unzip_status=解压状态 [repo] owner=拥有者 diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 88e9ff149..8e2c98a4e 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -276,27 +276,32 @@
- {{if .Description}} -
{{.Description}}
{{$.i18n.Tr "dataset.download"}}:{{.DownloadCount}}
- - {{.Name}} - -
- {{else}} - -
{{$.i18n.Tr "dataset.download"}}:{{.DownloadCount}}
- - {{.Name}} - +
+ + {{$.i18n.Tr "dataset.unzip_status"}}:{{if eq .DecompressState 1}}{{$.i18n.Tr "dataset.unzip_successed"}}{{else if eq .DecompressState 0}}{{$.i18n.Tr "dataset.unzip_stared"}}{{else}}{{$.i18n.Tr "dataset.unzip_failed"}}{{end}} +   {{$.i18n.Tr "dataset.download"}}:{{.DownloadCount}} + {{if .Description}}  {{$.i18n.Tr "dataset.description"}}:{{.Description}}{{end}} +
+ +
+ {{.DecompressState}} + {{if eq .DecompressState 1}} + + {{else if eq .DecompressState 0}} + + {{else}} + + {{end}} + + {{.Name}} + + +
- {{end}} - -
{{.Size | FileSize}} From 6473f414c21800308b1db46844a62e0dfc6da80c Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 8 Jun 2022 17:22:57 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/repo/dataset.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 0e57fe1a0..9d7f4a4d7 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -172,6 +172,10 @@ func DatasetIndex(ctx *context.Context) { for _, attachment := range pageAttachments { uploader, _ := models.GetUserByID(attachment.UploaderID) attachment.Uploader = uploader + if !strings.HasSuffix(attachment.Name, ".zip") { + attachment.DecompressState = 3 //非zip文件 + } + } ctx.Data["Page"] = pager From 13fe2ad4b299e5cd0f42d18fd34480914017a732 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 9 Jun 2022 10:20:02 +0800 Subject: [PATCH 7/8] fix issue --- templates/repo/datasets/index.tmpl | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 8e2c98a4e..a1feb4310 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -283,18 +283,19 @@   {{$.i18n.Tr "dataset.download"}}:{{.DownloadCount}} {{if .Description}}  {{$.i18n.Tr "dataset.description"}}:{{.Description}}{{end}}
-
- {{.DecompressState}} {{if eq .DecompressState 1}} {{else if eq .DecompressState 0}} - {{else}} + {{else if eq .DecompressState 2}} + {{else}} + {{end}} {{.Name}} @@ -327,18 +328,6 @@ {{.CreatedUnix | TimeSinceUnix1}}