Browse Source

feat: add base dataset list

tags/v1.21.12.1
colorfulberry 6 years ago
parent
commit
f6bf3c723e
8 changed files with 378 additions and 0 deletions
  1. +81
    -0
      custom/templates/repo/datasets/dataset_list.tmpl
  2. +31
    -0
      custom/templates/repo/datasets/index.tmpl
  3. +153
    -0
      custom/templates/repo/header.tmpl
  4. +96
    -0
      routers/repo/dataset.go
  5. +3
    -0
      routers/routes/routes.go
  6. +0
    -0
      templates/repo/datasets/dataset_list.tmpl
  7. +0
    -0
      templates/repo/datasets/index.tmpl
  8. +14
    -0
      web_src/less/_dataset.less

+ 81
- 0
custom/templates/repo/datasets/dataset_list.tmpl View File

@@ -0,0 +1,81 @@
<div class="ui grid item">
<div class="row">
<div class="eight wide column">
<div class="title">
深度学习数据集视频1.1.0
</div>
</div>
<div class="one wide column">
12GB
</div>

<div class="three wide column">
<span>由 <a href="/berry">berry</a> 于 <span class="time-since poping up" title="" data-content="2020年05月23日 10时52分49秒" data-variation="inverted tiny">5 天前</span>创建</span>
</div>

<div class="two wide column">
<div class="ui buttons">
<button class="ui button">private</button>
<div class="or"></div>
<button class="ui positive button active">public</button>
</div>
</div>
<div class="two wide column right aligned">
<a class="delete-button ui red button" href="" data-url="{{.DeleteBranchLink}}">删除</a>
</div>
</div>
</div>
<div class="ui grid item">
<div class="row">
<div class="eight wide column">
<div class="title">
深度学习数据集视频1.1.0
</div>
</div>
<div class="one wide column">
12GB
</div>

<div class="three wide column">
<span>由 <a href="/berry">berry</a> 于 <span class="time-since poping up" title="" data-content="2020年05月23日 10时52分49秒" data-variation="inverted tiny">5 天前</span>创建</span>
</div>

<div class="two wide column">
<div class="ui buttons">
<button class="ui button">private</button>
<div class="or"></div>
<button class="ui positive button active">public</button>
</div>
</div>
<div class="two wide column right aligned">
<a class="delete-button ui red button" href="" data-url="{{.DeleteBranchLink}}">删除</a>
</div>
</div>
</div>
<div class="ui grid item">
<div class="row">
<div class="eight wide column">
<div class="title">
深度学习数据集视频1.1.0
</div>
</div>
<div class="one wide column">
12GB
</div>

<div class="three wide column">
<span>由 <a href="/berry">berry</a> 于 <span class="time-since poping up" title="" data-content="2020年05月23日 10时52分49秒" data-variation="inverted tiny">5 天前</span>创建</span>
</div>

<div class="two wide column">
<div class="ui buttons">
<button class="ui button">private</button>
<div class="or"></div>
<button class="ui positive button active">public</button>
</div>
</div>
<div class="two wide column right aligned">
<a class="delete-button ui red button" href="" data-url="{{.DeleteBranchLink}}">删除</a>
</div>
</div>
</div>

+ 31
- 0
custom/templates/repo/datasets/index.tmpl View File

@@ -0,0 +1,31 @@
{{template "base/head" .}}
<div class="repository release">
{{template "repo/header" .}}
<div class="ui container">
{{template "base/alert" .}}
<div class="ui two column stackable grid">
<div class="column">
<h2>{{.i18n.Tr "datasets"}}</h2>
</div>
<div class="column right aligned">
<div class="ui right dropdown type jump item">
<span class="text">
{{.i18n.Tr "repo.issues.filter_sort"}}<i class="dropdown icon"></i>
</span>
<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=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 class="ui divider"></div>
<div class="dataset list">
{{template "repo/datasets/dataset_list"}}
</div>
{{template "base/paginate" .}}
</div>
</div>
{{template "base/footer" .}}

+ 153
- 0
custom/templates/repo/header.tmpl View File

@@ -0,0 +1,153 @@
<div class="header-wrapper">
{{with .Repository}}
<div class="ui container">
<div class="repo-header">
<div class="ui huge breadcrumb repo-title">
{{if .RelAvatarLink}}
<img class="ui avatar image" src="{{.RelAvatarLink}}">
{{else if .IsTemplate}}
{{if .IsPrivate}}
{{svg "octicon-repo-template-private" 32}}
{{else}}
{{svg "octicon-repo-template" 32}}
{{end}}
{{else}}
{{if .IsPrivate}}
{{svg "octicon-lock" 32}}
{{else if .IsMirror}}
{{svg "octicon-repo-clone" 32}}
{{else if .IsFork}}
{{svg "octicon-repo-forked" 32}}
{{else}}
{{svg "octicon-repo" 32}}
{{end}}
{{end}}
<a href="{{AppSubUrl}}/{{.Owner.Name}}">{{.Owner.Name}}</a>
<div class="divider"> / </div>
<a href="{{$.RepoLink}}">{{.Name}}</a>
{{if .RelAvatarLink}}
{{if .IsTemplate}}
{{if .IsPrivate}}
{{svg "octicon-repo-template-private" 32}}
{{else}}
{{svg "octicon-repo-template" 32}}
{{end}}
{{else}}
{{if .IsPrivate}}
{{svg "octicon-lock" 32}}
{{else if .IsMirror}}
{{svg "octicon-repo-clone" 32}}
{{else if .IsFork}}
{{svg "octicon-repo-forked" 32}}
{{else}}
{{svg "octicon-repo" 32}}
{{end}}
{{end}}
{{end}}
{{if .IsArchived}}<i class="archive icon archived-icon"></i>{{end}}
{{if .IsMirror}}<div class="fork-flag">{{$.i18n.Tr "repo.mirror_from"}} <a target="_blank" rel="noopener noreferrer" href="{{if .SanitizedOriginalURL}}{{.SanitizedOriginalURL}}{{else}}{{MirrorAddress $.Mirror}}{{end}}">{{if .SanitizedOriginalURL}}{{.SanitizedOriginalURL}}{{else}}{{MirrorAddress $.Mirror}}{{end}}</a></div>{{end}}
{{if .IsFork}}<div class="fork-flag">{{$.i18n.Tr "repo.forked_from"}} <a href="{{.BaseRepo.Link}}">{{SubStr .BaseRepo.RelLink 1 -1}}</a></div>{{end}}
{{if .IsGenerated}}<div class="fork-flag">{{$.i18n.Tr "repo.generated_from"}} <a href="{{.TemplateRepo.Link}}">{{SubStr .TemplateRepo.RelLink 1 -1}}</a></div>{{end}}
</div>
{{if not .IsBeingCreated}}
<div class="repo-buttons">
<form method="post" action="{{$.RepoLink}}/action/{{if $.IsWatchingRepo}}un{{end}}watch?redirect_to={{$.Link}}">
{{$.CsrfTokenHtml}}
<div class="ui labeled button" tabindex="0">
<button type="submit" class="ui compact basic button">
<i class="icon fa-eye{{if not $.IsWatchingRepo}}-slash{{end}}"></i>{{if $.IsWatchingRepo}}{{$.i18n.Tr "repo.unwatch"}}{{else}}{{$.i18n.Tr "repo.watch"}}{{end}}
</button>
<a class="ui basic label" href="{{.Link}}/watchers">
{{.NumWatches}}
</a>
</div>
</form>
<form method="post" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star?redirect_to={{$.Link}}">
{{$.CsrfTokenHtml}}
<div class="ui labeled button" tabindex="0">
<button type="submit" class="ui compact basic button">
<i class="icon star{{if not $.IsStaringRepo}} outline{{end}}"></i>{{if $.IsStaringRepo}}{{$.i18n.Tr "repo.unstar"}}{{else}}{{$.i18n.Tr "repo.star"}}{{end}}
</button>
<a class="ui basic label" href="{{.Link}}/stars">
{{.NumStars}}
</a>
</div>
</form>
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
<div class="ui labeled button {{if and ($.IsSigned) (not $.CanSignedUserFork)}}disabled-repo-button{{end}}" tabindex="0">
<a class="ui compact basic button {{if or (not $.IsSigned) (not $.CanSignedUserFork)}}poping up{{end}}" {{if $.CanSignedUserFork}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else if $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" {{ else }} data-content="{{$.i18n.Tr "repo.fork_guest_user" }}" rel="nofollow" href="{{AppSubUrl}}/user/login?redirect_to={{AppSubUrl}}/repo/fork/{{.ID}}" {{end}} data-position="top center" data-variation="tiny">
{{svg "octicon-repo-forked" 15}}{{$.i18n.Tr "repo.fork"}}
</a>
<a class="ui basic label" href="{{.Link}}/forks">
{{.NumForks}}
</a>
</div>
{{end}}
</div>
{{end}}
</div><!-- end grid -->
</div><!-- end container -->
{{end}}
<div class="ui tabs container">
{{if not .Repository.IsBeingCreated}}
<div class="ui tabular stackable menu navbar">
{{if .Permission.CanRead $.UnitTypeCode}}
<a class="{{if .PageIsViewCode}}active{{end}} item" href="{{.RepoLink}}{{if (ne .BranchName .Repository.DefaultBranch)}}/src/{{.BranchNameSubURL | EscapePound}}{{end}}">
{{svg "octicon-code" 16}} {{.i18n.Tr "repo.code"}}
</a>
{{end}}

<a class="{{if.PageIsDataset}}active{{end}} item" href="{{.RepoLink}}/datasets">
{{svg "octicon-file-submodule" 16}} {{.i18n.Tr "datasets"}}
</a>

{{if .Permission.CanRead $.UnitTypeIssues}}
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
{{svg "octicon-issue-opened" 16}} {{.i18n.Tr "repo.issues"}} <span class="ui {{if not .Repository.NumOpenIssues}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenIssues}}</span>
</a>
{{end}}

{{if .Permission.CanRead $.UnitTypeExternalTracker}}
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoExternalIssuesLink}}" target="_blank" rel="noopener noreferrer">
{{svg "octicon-link-external" 16}} {{.i18n.Tr "repo.issues"}} </span>
</a>
{{end}}

{{if and .Repository.CanEnablePulls (.Permission.CanRead $.UnitTypePullRequests)}}
<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls">
{{svg "octicon-git-pull-request" 16}} {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span>
</a>
{{end}}

{{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsEmptyRepo) }}
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
{{svg "octicon-tag" 16}} {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .NumReleases}}gray{{else}}blue{{end}} small label">{{.NumReleases}}</span>
</a>
{{end}}

{{if or (.Permission.CanRead $.UnitTypeWiki) (.Permission.CanRead $.UnitTypeExternalWiki)}}
<a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki" {{if (.Permission.CanRead $.UnitTypeExternalWiki)}} target="_blank" rel="noopener noreferrer" {{end}}>
{{svg "octicon-book" 16}} {{.i18n.Tr "repo.wiki"}}
</a>
{{end}}

{{if and (.Permission.CanReadAny $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) (not .IsEmptyRepo)}}
<a class="{{if .PageIsActivity}}active{{end}} item" href="{{.RepoLink}}/activity">
{{svg "octicon-pulse" 16}} {{.i18n.Tr "repo.activity"}}
</a>
{{end}}

{{template "custom/extra_tabs" .}}

{{if .Permission.IsAdmin}}
<div class="right menu">
<a class="{{if .PageIsSettings}}active{{end}} item" href="{{.RepoLink}}/settings">
{{svg "octicon-tools" 16}} {{.i18n.Tr "repo.settings"}}
</a>
</div>
{{end}}
</div>
{{end}}
</div>
<div class="ui tabs divider"></div>
</div>

+ 96
- 0
routers/repo/dataset.go View File

@@ -0,0 +1,96 @@
package repo

import (
"errors"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/unknwon/com"
)

const (
tplIndex base.TplName = "repo/datasets/index"
)

func DatasetIndex(ctx *context.Context) {
ctx.Data["PageIsDataset"] = true
// ctx.Data["Title"] = ctx.Tr("dataset.show_dataset")

// user := ctx.User
// dataset, err := models.GetOwnerDatasetByID(ctx.ParamsInt64((":id")), user)
// if err != nil {
// ctx.NotFound("GetDataset", err)
// return
// }

// err = models.GeDatasetAttachments(dataset)
// if err != nil {
// ctx.ServerError("GetDatasetAttachments", err)
// return
// }

// isOwner := (ctx.User != nil && dataset.UserID == user.ID)

// ctx.Data["dataset"] = dataset
// ctx.Data["IsOwner"] = isOwner

ctx.HTML(200, tplIndex)
}

func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) {
ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset")

rel, err := models.GetDatasetByID(ctx.ParamsInt64(":id"))
if err != nil {
ctx.ServerError("GetDataset", err)
return
}
isOwner := (ctx.User != nil && rel.UserID == ctx.User.ID)
if !isOwner {
ctx.NotFound("403", errors.New("not owner"))
return
}
ctx.Data["ID"] = rel.ID
ctx.Data["title"] = rel.Title
ctx.Data["description"] = rel.Description
ctx.Data["category"] = rel.Category
ctx.Data["task"] = rel.Task
ctx.Data["license"] = rel.License
ctx.Data["private"] = rel.IsPrivate()

if ctx.HasError() {
ctx.HTML(200, tplCreate)
return
}

var attachmentUUIDs []string
if setting.Attachment.Enabled {
attachmentUUIDs = form.Files
}

status := models.DatasetStatusPublic
if form.Private {
status = models.DatasetStatusPrivate
}

rel.Title = form.Title
rel.Status = status
rel.Description = form.Description
rel.Category = form.Category
rel.Task = form.Task
rel.License = form.License
if err = models.UpdateDataset(models.DefaultDBContext(), rel); err != nil {
log.Error("%v", err)
}

if err = models.AddDatasetAttachments(rel.ID, attachmentUUIDs); err != nil {
log.Error("%v", err)
}
log.Trace("Dataset updated: %d", rel.ID)

ctx.Redirect(setting.AppSubURL + "/datasets/" + com.ToStr(rel.ID))
}

+ 3
- 0
routers/routes/routes.go View File

@@ -762,6 +762,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus)
m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation)
}, context.RepoMustNotBeArchived())
m.Group("/datasets", func() {
m.Get("", repo.DatasetIndex)
}, context.RepoMustNotBeArchived())
m.Group("/comments/:id", func() {
m.Post("", repo.UpdateCommentContent)
m.Post("/delete", repo.DeleteComment)


+ 0
- 0
templates/repo/datasets/dataset_list.tmpl View File


+ 0
- 0
templates/repo/datasets/index.tmpl View File


+ 14
- 0
web_src/less/_dataset.less View File

@@ -136,6 +136,20 @@
}
}
}
.item {
padding-top: 15px;
padding-bottom: 10px;
border-bottom: 1px dashed #aaaaaa;
}
.ui.grid>.row {
align-items: center;
}
.title {
color: #444444;
font-size: 16px;
font-weight: bold;
margin: 0 6px;
}
}
.ui.dataset.list {
.item {


Loading…
Cancel
Save