@@ -35,6 +35,20 @@ type Attachment struct { | |||||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | CreatedUnix timeutil.TimeStamp `xorm:"created"` | ||||
} | } | ||||
func (a *Attachment) AfterUpdate() { | |||||
if a.DatasetID > 0 { | |||||
datasetIsPublicCount, err := x.Where("dataset_id = ? AND is_private = ?", a.DatasetID, false).Count(new(Attachment)) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if datasetIsPublicCount > 0 { | |||||
x.Table(new(Dataset)).ID(a.DatasetID).Update(map[string]interface{}{"status": DatasetStatusPublic}) | |||||
} else { | |||||
x.Table(new(Dataset)).ID(a.DatasetID).Update(map[string]interface{}{"status": DatasetStatusPrivate}) | |||||
} | |||||
} | |||||
} | |||||
// IncreaseDownloadCount is update download count + 1 | // IncreaseDownloadCount is update download count + 1 | ||||
func (a *Attachment) IncreaseDownloadCount() error { | func (a *Attachment) IncreaseDownloadCount() error { | ||||
// Update download count. | // Update download count. | ||||
@@ -1,6 +1,8 @@ | |||||
package repo | package repo | ||||
import ( | import ( | ||||
"sort" | |||||
"code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
"code.gitea.io/gitea/modules/auth" | "code.gitea.io/gitea/modules/auth" | ||||
"code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
@@ -35,31 +37,30 @@ func DatasetIndex(ctx *context.Context) { | |||||
ctx.ServerError("GetDatasetAttachments", err) | ctx.ServerError("GetDatasetAttachments", err) | ||||
return | return | ||||
} | } | ||||
attachments := dataset.Attachments | |||||
// var orderBy models.SearchOrderBy | |||||
// page := ctx.QueryInt("page") | |||||
// if page <= 0 { | |||||
// page = 1 | |||||
// } | |||||
// ctx.Data["SortType"] = ctx.Query("sort") | |||||
// switch ctx.Query("sort") { | |||||
// case "newest": | |||||
// orderBy = models.SearchOrderByNewest | |||||
// case "oldest": | |||||
// orderBy = models.SearchOrderByOldest | |||||
// case "recentupdate": | |||||
// orderBy = models.SearchOrderByRecentUpdated | |||||
// case "leastupdate": | |||||
// orderBy = models.SearchOrderByLeastUpdated | |||||
// default: | |||||
// ctx.Data["SortType"] = "recentupdate" | |||||
// orderBy = models.SearchOrderByRecentUpdated | |||||
// } | |||||
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 | |||||
}) | |||||
} | |||||
ctx.Data["PageIsDataset"] = true | ctx.Data["PageIsDataset"] = true | ||||
ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") | ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") | ||||
ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets" | ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets" | ||||
ctx.Data["dataset"] = dataset | ctx.Data["dataset"] = dataset | ||||
ctx.Data["Attachments"] = attachments | |||||
ctx.Data["IsOwner"] = true | ctx.Data["IsOwner"] = true | ||||
ctx.HTML(200, tplIndex) | ctx.HTML(200, tplIndex) | ||||
@@ -1,5 +1,5 @@ | |||||
{{if .dataset.Attachments}} | |||||
{{range .dataset.Attachments}} | |||||
{{if .Attachments}} | |||||
{{range .Attachments}} | |||||
<div class="ui grid item" id="{{.UUID}}"> | <div class="ui grid item" id="{{.UUID}}"> | ||||
<div class="row"> | <div class="row"> | ||||
<div class="six wide column"> | <div class="six wide column"> | ||||
@@ -53,8 +53,6 @@ | |||||
<div class="menu"> | <div class="menu"> | ||||
<a class="item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a> | <a class="item" href="{{$.Link}}?sort=newest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.latest"}}</a> | ||||
<a class="item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a> | <a class="item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.oldest"}}</a> | ||||
<a class="item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.recentupdate"}}</a> | |||||
<a class="item" href="{{$.Link}}?sort=oldest&q={{$.Keyword}}&tab={{$.TabName}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||