From f6bf3c723e486dca0338aad17f517d40cb6ef183 Mon Sep 17 00:00:00 2001 From: colorfulberry Date: Thu, 28 May 2020 15:55:24 +0800 Subject: [PATCH] feat: add base dataset list --- .../templates/repo/datasets/dataset_list.tmpl | 81 ++++++++++ custom/templates/repo/datasets/index.tmpl | 31 ++++ custom/templates/repo/header.tmpl | 153 ++++++++++++++++++ routers/repo/dataset.go | 96 +++++++++++ routers/routes/routes.go | 3 + templates/repo/datasets/dataset_list.tmpl | 0 templates/repo/datasets/index.tmpl | 0 web_src/less/_dataset.less | 14 ++ 8 files changed, 378 insertions(+) create mode 100644 custom/templates/repo/datasets/dataset_list.tmpl create mode 100644 custom/templates/repo/datasets/index.tmpl create mode 100644 custom/templates/repo/header.tmpl create mode 100644 routers/repo/dataset.go create mode 100644 templates/repo/datasets/dataset_list.tmpl create mode 100644 templates/repo/datasets/index.tmpl diff --git a/custom/templates/repo/datasets/dataset_list.tmpl b/custom/templates/repo/datasets/dataset_list.tmpl new file mode 100644 index 000000000..0dc7b8791 --- /dev/null +++ b/custom/templates/repo/datasets/dataset_list.tmpl @@ -0,0 +1,81 @@ +
+
+
+
+ 深度学习数据集视频1.1.0 +
+
+
+ 12GB +
+ +
+ berry5 天前创建 +
+ +
+
+ +
+ +
+
+
+ 删除 +
+
+
+
+
+
+
+ 深度学习数据集视频1.1.0 +
+
+
+ 12GB +
+ +
+ berry5 天前创建 +
+ +
+
+ +
+ +
+
+
+ 删除 +
+
+
+
+
+
+
+ 深度学习数据集视频1.1.0 +
+
+
+ 12GB +
+ +
+ berry5 天前创建 +
+ +
+
+ +
+ +
+
+
+ 删除 +
+
+
diff --git a/custom/templates/repo/datasets/index.tmpl b/custom/templates/repo/datasets/index.tmpl new file mode 100644 index 000000000..e6404f548 --- /dev/null +++ b/custom/templates/repo/datasets/index.tmpl @@ -0,0 +1,31 @@ +{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+ {{template "base/alert" .}} + +
+
+ {{template "repo/datasets/dataset_list"}} +
+ {{template "base/paginate" .}} +
+
+{{template "base/footer" .}} diff --git a/custom/templates/repo/header.tmpl b/custom/templates/repo/header.tmpl new file mode 100644 index 000000000..2ba9b31c8 --- /dev/null +++ b/custom/templates/repo/header.tmpl @@ -0,0 +1,153 @@ +
+{{with .Repository}} +
+
+ + {{if not .IsBeingCreated}} +
+
+ {{$.CsrfTokenHtml}} +
+ + + {{.NumWatches}} + +
+
+
+ {{$.CsrfTokenHtml}} +
+ + + {{.NumStars}} + +
+
+ {{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}} + + {{end}} +
+ {{end}} +
+
+{{end}} +
+ {{if not .Repository.IsBeingCreated}} + + {{end}} +
+
+
diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go new file mode 100644 index 000000000..0d2f93a91 --- /dev/null +++ b/routers/repo/dataset.go @@ -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)) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index f7d2f1d1e..ac3077995 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -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) diff --git a/templates/repo/datasets/dataset_list.tmpl b/templates/repo/datasets/dataset_list.tmpl new file mode 100644 index 000000000..e69de29bb diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl new file mode 100644 index 000000000..e69de29bb diff --git a/web_src/less/_dataset.less b/web_src/less/_dataset.less index e804e3d46..1c3f7ca26 100644 --- a/web_src/less/_dataset.less +++ b/web_src/less/_dataset.less @@ -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 {