From 447ce2e1d4f7f376273d3bdfa41e53f62eb3805a Mon Sep 17 00:00:00 2001 From: colorfulberry Date: Fri, 29 May 2020 16:06:35 +0800 Subject: [PATCH] feat: add right side update --- options/locale/locale_en-US.ini | 3 ++ options/locale/locale_zh-CN.ini | 5 ++- routers/repo/dataset.go | 11 +++--- routers/routes/routes.go | 2 +- templates/repo/datasets/index.tmpl | 2 +- templates/repo/datasets/right_side.tmpl | 47 ++++++++++++++----------- web_src/js/index.js | 15 ++++++++ 7 files changed, 57 insertions(+), 28 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index ca44a8685..aba21c11d 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -632,8 +632,11 @@ show_dataset= Dataset edit_dataset= Edit Dataset update_dataset= Update Dataset category = Category +no_category = No Category task = Task +no_task = No Task license = License +no_license = No License file = Dataset File download = download edit = edit diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index eaedc0e9b..0eaf888e3 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -632,8 +632,11 @@ show_dataset=数据集 edit_dataset=编辑数据集 update_dataset=更新数据集 category=分类 -task=针对的具体任务 +no_category=未设置分类 +task=研究方向/应用领域 +no_task=未设置研究方向/应用领域 license=license +no_license=没有设置license file=数据集文件 download=下载附件 edit=编辑 diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 90cc80b6a..11ee247bc 100644 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -15,7 +15,7 @@ const ( func DatasetIndex(ctx *context.Context) { ctx.Data["PageIsDataset"] = true ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") - ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets/5/edit" + ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets" user := ctx.User dataset, err := models.GetDatasetByID(5) if err != nil { @@ -38,13 +38,14 @@ func DatasetIndex(ctx *context.Context) { } func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { + ctx.Data["PageIsDataset"] = true + ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset") - rel, err := models.GetDatasetByID(ctx.ParamsInt64(":id")) + rel, err := models.GetDatasetByID(5) ctx.Data["dataset"] = rel if err != nil { - ctx.Data["Error"] = true ctx.ServerError("GetDataset", err) return } @@ -61,7 +62,9 @@ func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { rel.Task = form.Task rel.License = form.License if err = models.UpdateDataset(models.DefaultDBContext(), rel); err != nil { + ctx.Data["Error"] = true + ctx.HTML(200, tplIndex) log.Error("%v", err) } - ctx.HTML(200, tplIndex) + ctx.Redirect(ctx.Repo.RepoLink + "/datasets") } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index adad35804..c48011ca9 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -764,7 +764,7 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoMustNotBeArchived()) m.Group("/datasets", func() { m.Get("", repo.DatasetIndex) - m.Post("/:id/edit", bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) + m.Post("", bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) }, context.RepoMustNotBeArchived()) m.Group("/comments/:id", func() { m.Post("", repo.UpdateCommentContent) diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index b5ebc90ba..4235e3f28 100644 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -29,7 +29,7 @@
{{.i18n.Tr "cancel"}} - +
diff --git a/templates/repo/datasets/right_side.tmpl b/templates/repo/datasets/right_side.tmpl index 1ec0b734b..8ee7fc716 100644 --- a/templates/repo/datasets/right_side.tmpl +++ b/templates/repo/datasets/right_side.tmpl @@ -9,18 +9,23 @@ {{svg "octicon-gear" 16}}
- {{.i18n.Tr "repo.issues.new.no_milestone"}} -
- {{if .dataset.Category}} - {{$.i18n.Tr (printf "dataset.category.%s" .dataset.Category)}} - {{end}} -
+ {{if .dataset.Category}} + {{$.i18n.Tr (printf "dataset.category.%s" .dataset.Category)}} + {{else}} + {{.i18n.Tr "dataset.no_category"}} + {{end}}
- {{.i18n.Tr "repo.issues.new.no_milestone"}} - + {{if .dataset.Task}} + {{$.i18n.Tr (printf "dataset.task.%s" .dataset.Task)}} + {{else}} + {{.i18n.Tr "dataset.no_task"}} + {{end}}
- {{.i18n.Tr "repo.issues.new.no_milestone"}} -
- {{if .dataset.License}} - {{.dataset.License}} - {{end}} -
+ {{if .dataset.License}} + {{.dataset.License}} + {{else}} + {{.i18n.Tr "dataset.no_license"}} + {{end}}
\ No newline at end of file diff --git a/web_src/js/index.js b/web_src/js/index.js index 63d04699c..3dd0bd0c2 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1094,6 +1094,21 @@ async function initRepository() { $('#dataset-content input').focus(); return false; }; + $('[data-category-id]').on('click', function () { + const category = $(this).data('category-id'); + $('#category').val(category); + $('#submit').click(); + }); + $('[data-task-id]').on('click', function () { + const task = $(this).data('task-id'); + $('#task').val(task); + $('#submit').click(); + }); + $('[data-license-id]').on('click', function () { + const license = $(this).data('license-id'); + $('#license').val(license); + $('#submit').click(); + }); $('#dataset-edit').on('click', editContentToggle); $('#cancel').on('click', editContentToggle); }