From 6931dc07ff6eef673050df6d6c431be5f674306c Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 2 Mar 2022 09:43:34 +0800 Subject: [PATCH 01/78] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E7=82=B9?= =?UTF-8?q?=E8=B5=9E=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/base_message.go | 10 ++++++ models/dataset.go | 1 + models/dataset_star.go | 62 +++++++++++++++++++++++++++++++++ models/user.go | 9 ++--- options/locale/locale_en-US.ini | 1 + options/locale/locale_zh-CN.ini | 2 ++ routers/repo/dataset.go | 19 ++++++++++ routers/routes/routes.go | 1 + 8 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 models/base_message.go create mode 100644 models/dataset_star.go diff --git a/models/base_message.go b/models/base_message.go new file mode 100644 index 000000000..d20650463 --- /dev/null +++ b/models/base_message.go @@ -0,0 +1,10 @@ +package models + +type BaseMessage struct { + Code int + Message string +} + +var BaseMessageOK = BaseMessage{ + 0, "", +} diff --git a/models/dataset.go b/models/dataset.go index 2b3de752b..00b45d48f 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -22,6 +22,7 @@ type Dataset struct { Category string Description string `xorm:"TEXT"` DownloadTimes int64 + NumStars int License string Task string ReleaseID int64 `xorm:"INDEX"` diff --git a/models/dataset_star.go b/models/dataset_star.go new file mode 100644 index 000000000..fac08caee --- /dev/null +++ b/models/dataset_star.go @@ -0,0 +1,62 @@ +package models + +import "code.gitea.io/gitea/modules/timeutil" + +type DatasetStar struct { + ID int64 `xorm:"pk autoincr"` + UID int64 `xorm:"UNIQUE(s)"` + DatasetID int64 `xorm:"UNIQUE(s)"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` +} + +// StarRepo or unstar repository. +func StarDataset(userID, datasetID int64, star bool) error { + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + if star { + if isDatasetStaring(sess, userID, datasetID) { + return nil + } + + if _, err := sess.Insert(&DatasetStar{UID: userID, DatasetID: datasetID}); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `dataset` SET num_stars = num_stars + 1 WHERE id = ?", datasetID); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `user` SET num_dataset_stars = num_dataset_stars + 1 WHERE id = ?", userID); err != nil { + return err + } + } else { + if !isDatasetStaring(sess, userID, datasetID) { + return nil + } + + if _, err := sess.Delete(&DatasetStar{0, userID, datasetID, 0}); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `dataset` SET num_stars = num_stars - 1 WHERE id = ?", datasetID); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `user` SET num_dataset_stars = num_dataset_stars - 1 WHERE id = ?", userID); err != nil { + return err + } + } + + return sess.Commit() +} + +func IsDatasetStaring(userID, datasetID int64) bool { + + return isDatasetStaring(x, userID, datasetID) +} + +func isDatasetStaring(e Engine, userID, datasetID int64) bool { + has, _ := e.Get(&DatasetStar{0, userID, datasetID, 0}) + return has +} diff --git a/models/user.go b/models/user.go index f7857248b..bbbe9359e 100755 --- a/models/user.go +++ b/models/user.go @@ -153,10 +153,11 @@ type User struct { UseCustomAvatar bool // Counters - NumFollowers int - NumFollowing int `xorm:"NOT NULL DEFAULT 0"` - NumStars int - NumRepos int + NumFollowers int + NumFollowing int `xorm:"NOT NULL DEFAULT 0"` + NumStars int + NumDatasetStars int + NumRepos int // For organization NumTeams int diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0787e6ce6..a4331b3d7 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1061,6 +1061,7 @@ unstar = Unstar star = Star fork = Fork download_archive = Download Repository +star_fail=Failed to %s the dataset. no_desc = No Description no_label = No labels diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 2eeb72735..a09bafc89 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1070,6 +1070,8 @@ unstar=取消点赞 star=点赞 fork=派生 download_archive=下载此项目 +star_fail=%s失败。 + no_desc=暂无描述 no_label = 暂无标签 diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 7d59ab486..fcbf2894d 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -1,6 +1,7 @@ package repo import ( + "net/http" "sort" "code.gitea.io/gitea/models" @@ -190,3 +191,21 @@ func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { } ctx.Redirect(ctx.Repo.RepoLink + "/datasets?type=" + form.Type) } + +func DatasetAction(ctx *context.Context) { + var err error + datasetId := ctx.QueryInt64(":id") + switch ctx.Params(":action") { + case "star": + err = models.StarDataset(ctx.User.ID, datasetId, true) + case "unstar": + err = models.StarDataset(ctx.User.ID, datasetId, false) + + } + if err != nil { + ctx.JSON(http.StatusOK, models.BaseMessage{1, ctx.Tr("repo.star_fail", ctx.Params(":action"))}) + } else { + ctx.JSON(http.StatusOK, models.BaseMessageOK) + } + +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 7fa06fa3b..d97c22a2d 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -978,6 +978,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/datasets", func() { m.Get("", reqRepoDatasetReader, repo.DatasetIndex) + m.Put("/:id/:action", reqRepoDatasetReader, repo.DatasetAction) m.Post("", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) m.Group("/dirs", func() { From 7a3cd6b1cd15556db0b0dd46b60355b8233bb022 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 2 Mar 2022 10:42:10 +0800 Subject: [PATCH 02/78] =?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/dataset.go | 2 +- models/user.go | 2 +- routers/repo/dataset.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index 00b45d48f..54feb0f96 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -22,7 +22,7 @@ type Dataset struct { Category string Description string `xorm:"TEXT"` DownloadTimes int64 - NumStars int + NumStars int `xorm:"NOT NULL DEFAULT 0"` License string Task string ReleaseID int64 `xorm:"INDEX"` diff --git a/models/user.go b/models/user.go index bbbe9359e..f72462051 100755 --- a/models/user.go +++ b/models/user.go @@ -156,7 +156,7 @@ type User struct { NumFollowers int NumFollowing int `xorm:"NOT NULL DEFAULT 0"` NumStars int - NumDatasetStars int + NumDatasetStars int `xorm:"NOT NULL DEFAULT 0"` NumRepos int // For organization diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index fcbf2894d..0e5cf2182 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -3,6 +3,7 @@ package repo import ( "net/http" "sort" + "strconv" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" @@ -194,7 +195,7 @@ func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { func DatasetAction(ctx *context.Context) { var err error - datasetId := ctx.QueryInt64(":id") + datasetId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) switch ctx.Params(":action") { case "star": err = models.StarDataset(ctx.User.ID, datasetId, true) From b2cb55734b57611f7ba7f34791c1e9cbf94a7f3b Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 2 Mar 2022 17:38:44 +0800 Subject: [PATCH 03/78] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=8D=E5=88=9B=E5=BB=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=20=E9=A1=B9=E7=9B=AE=E6=94=B9=E4=B8=BA=E7=A7=81?= =?UTF-8?q?=E6=9C=89=EF=BC=8C=E6=8A=8A=E6=95=B0=E6=8D=AE=E9=9B=86=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8B=E6=89=80=E6=9C=89=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=B9=E4=B8=BA=E7=A7=81=E6=9C=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dataset.go | 3 --- models/repo.go | 23 +++++++++++++++++++---- routers/repo/attachment.go | 8 +++++++- routers/repo/dataset.go | 4 ++-- routers/repo/setting.go | 4 ---- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index 54feb0f96..87b99589d 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -302,9 +302,6 @@ func GetDatasetByID(id int64) (*Dataset, error) { } func GetDatasetByRepo(repo *Repository) (*Dataset, error) { - if err := CreateDefaultDatasetToRepo(repo); err != nil { - return nil, err - } dataset := &Dataset{RepoID: repo.ID} has, err := x.Get(dataset) if err != nil { diff --git a/models/repo.go b/models/repo.go index 6b3df9fe0..9bb4b9d03 100755 --- a/models/repo.go +++ b/models/repo.go @@ -1280,10 +1280,6 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, opts ...Cr return fmt.Errorf("copyDefaultWebhooksToRepo: %v", err) } - if err = CreateDefaultDatasetToRepo(repo); err != nil { - return fmt.Errorf("models.CreateDefaultDatasetToRepo: %v", err) - } - return nil } @@ -1586,6 +1582,25 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e if err != nil { return err } + //If repo has become private, we need set dataset and dataset_file to private + _, err = e.Where("repo_id = ?", repo.ID).Cols("status").Update(&Dataset{ + Status: 0, + }) + if err != nil { + return err + } + + dataset, err := GetDatasetByRepo(repo) + if err != nil { + return err + } + _, err = e.Where("dataset_id = ?", dataset.ID).Cols("is_private").Update(&Attachment{ + IsPrivate: true, + }) + if err != nil { + return err + } + } // Create/Remove git-daemon-export-ok for git-daemon... diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index bc843c555..13ce62aa9 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -387,11 +387,17 @@ func AddAttachment(ctx *context.Context) { ctx.Error(404, "attachment has not been uploaded") return } + datasetId := ctx.QueryInt64("dataset_id") + dataset, err := models.GetDatasetByID(datasetId) + if err != nil { + ctx.Error(404, "dataset does not exist.") + return + } attachment, err := models.InsertAttachment(&models.Attachment{ UUID: uuid, UploaderID: ctx.User.ID, - IsPrivate: true, + IsPrivate: dataset.IsPrivate(), Name: fileName, Size: ctx.QueryInt64("size"), DatasetID: ctx.QueryInt64("dataset_id"), diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 0e5cf2182..f7e5415f4 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -112,8 +112,8 @@ func DatasetIndex(ctx *context.Context) { dataset, err := models.GetDatasetByRepo(repo) if err != nil { - log.Error("query dataset, not found repo.") - ctx.NotFound("GetDatasetByRepo", err) + log.Warn("query dataset, not found.") + ctx.HTML(200, tplIndex) return } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 5b057dbe5..af28f3290 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -245,10 +245,6 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { // This section doesn't require repo_name/RepoName to be set in the form, don't show it // as an error on the UI for this action ctx.Data["Err_RepoName"] = nil - if err := models.CreateDefaultDatasetToRepo(repo); err != nil { - ctx.ServerError("CreateDefaultDatasetToRepo", err) - return - } if form.EnableDataset && !models.UnitTypeDatasets.UnitGlobalDisabled() { units = append(units, models.RepoUnit{ From a5c49c30ba23c6c4ca5cc6c6df18db1e4a687ebd Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 3 Mar 2022 15:31:28 +0800 Subject: [PATCH 04/78] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/base_message.go | 8 +++- models/dataset.go | 29 +++++------- modules/auth/dataset.go | 10 ++--- options/locale/locale_en-US.ini | 4 ++ options/locale/locale_zh-CN.ini | 5 +++ routers/home.go | 4 ++ routers/repo/dataset.go | 78 +++++++++++++++++++++++++++------ routers/routes/routes.go | 3 ++ 8 files changed, 101 insertions(+), 40 deletions(-) diff --git a/models/base_message.go b/models/base_message.go index d20650463..37f7668ad 100644 --- a/models/base_message.go +++ b/models/base_message.go @@ -5,6 +5,12 @@ type BaseMessage struct { Message string } -var BaseMessageOK = BaseMessage{ +var BaseOKMessage = BaseMessage{ 0, "", } + +func BaseErrorMessage(message string) BaseMessage { + return BaseMessage{ + 1, message, + } +} diff --git a/models/dataset.go b/models/dataset.go index 87b99589d..b64b00eb6 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -22,7 +22,7 @@ type Dataset struct { Category string Description string `xorm:"TEXT"` DownloadTimes int64 - NumStars int `xorm:"NOT NULL DEFAULT 0"` + NumStars int `xorm:"INDEX NOT NULL DEFAULT 0"` License string Task string ReleaseID int64 `xorm:"INDEX"` @@ -105,22 +105,6 @@ func CreateDataset(dataset *Dataset) (err error) { return nil } -func CreateDefaultDatasetToRepo(repo *Repository) (err error) { - dataset := &Dataset{RepoID: repo.ID} - has, err := x.Get(dataset) - if err != nil { - return err - } - if !has { - dataset.Status = DatasetStatusPrivate - dataset.Title = repo.Name - if err = CreateDataset(dataset); err != nil { - return err - } - } - return nil -} - func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) { cond := SearchDatasetCondition(opts) return SearchDatasetByCondition(opts, cond) @@ -140,6 +124,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { if opts.IncludePublic { cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) + cond = cond.And(builder.Eq{"attachment.is_private": false}) if opts.OwnerID > 0 { if len(opts.Keyword) == 0 { cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) @@ -154,6 +139,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) if !opts.IsOwner { cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) + cond = cond.And(builder.Eq{"attachment.is_private": false}) } } @@ -170,14 +156,19 @@ 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" - count, err := sess.Join("INNER", "repository", "repository.id = dataset.repo_id").Where(cond).Count(new(Dataset)) + count, err := sess.Select(selectColumnsSql).Join("INNER", "repository", "repository.id = dataset.repo_id"). + Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). + Where(cond).Count(new(Dataset)) if err != nil { return nil, 0, fmt.Errorf("Count: %v", err) } - sess.Select("dataset.*").Join("INNER", "repository", "repository.id = dataset.repo_id").Where(cond).OrderBy(opts.SearchOrderBy.String()) + sess.Select(selectColumnsSql).Join("INNER", "repository", "repository.id = dataset.repo_id"). + Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). + Where(cond).OrderBy(opts.SearchOrderBy.String()) if opts.PageSize > 0 { sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } diff --git a/modules/auth/dataset.go b/modules/auth/dataset.go index 577637273..4a6dbbd7d 100755 --- a/modules/auth/dataset.go +++ b/modules/auth/dataset.go @@ -9,11 +9,10 @@ import ( type CreateDatasetForm struct { Title string `binding:"Required"` Category string `binding:"Required"` - Description string `binding:"Required;MaxSize(254)"` + Description string `binding:"Required"` License string `binding:"Required;MaxSize(64)"` Task string `binding:"Required;MaxSize(64)"` ReleaseID int64 `xorm:"INDEX"` - Private bool Files []string } @@ -25,11 +24,10 @@ type EditDatasetForm struct { ID int64 `binding:"Required"` Title string `binding:"Required"` Category string `binding:"Required"` - Description string `binding:"Required;MaxSize(254)"` + Description string `binding:"Required"` License string `binding:"Required;MaxSize(64)"` Task string `binding:"Required;MaxSize(64)"` - Private bool - ReleaseID int64 `xorm:"INDEX"` + ReleaseID int64 `xorm:"INDEX"` Files []string - Type string `binding:"Required"` + Type string `binding:"Required"` } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a4331b3d7..5b07b6b4d 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -709,8 +709,12 @@ alert = To initiate a cloud brain task, please upload the dataset in zip format. dataset = Dataset dataset_setting= Dataset Setting title = Name +title_format_err=Name can only contain number,letter,'-','_' or '.', and can be up to 100 characters long. description = Description +description_format_err=Description's length can be up to 1024 characters long. create_dataset = Create Dataset +create_dataset_fail=Failed to create dataset. +query_dataset_fail=Failed to query dataset. show_dataset= Dataset edit_dataset= Edit Dataset update_dataset= Update Dataset diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index a09bafc89..7609437d6 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -712,8 +712,13 @@ alert=如果要发起云脑任务,请上传zip格式的数据集 dataset=数据集 dataset_setting=数据集设置 title=名称 +title_format_err=名称最多允许输入100个字符,只允许字母,数字,中划线 (‘-’),下划线 (‘_’) 和点 (‘.’) 。 description=描述 +description_format_err=描述最多允许输入1024个字符。 create_dataset=创建数据集 +create_dataset_fail=创建数据集失败。 +query_dataset_fail=查询数据集失败 + show_dataset=数据集 edit_dataset=编辑数据集 update_dataset=更新数据集 diff --git a/routers/home.go b/routers/home.go index 2db8d2112..93e6f8461 100755 --- a/routers/home.go +++ b/routers/home.go @@ -301,6 +301,10 @@ func ExploreDatasets(ctx *context.Context) { orderBy = models.SearchOrderBySizeReverse case "downloadtimes": orderBy = models.SearchOrderByDownloadTimes + case "moststars": + orderBy = models.SearchOrderByStarsReverse + case "feweststars": + orderBy = models.SearchOrderByStars default: ctx.Data["SortType"] = "recentupdate" orderBy = models.SearchOrderByRecentUpdated diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index f7e5415f4..8ad83654b 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -2,8 +2,10 @@ package repo import ( "net/http" + "regexp" "sort" "strconv" + "unicode/utf8" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" @@ -14,9 +16,12 @@ import ( ) const ( - tplIndex base.TplName = "repo/datasets/index" + tplIndex base.TplName = "repo/datasets/index" + tplDatasetCreate base.TplName = "repo/datasets/create" ) +var titlePattern = regexp.MustCompile(`^[A-Za-z0-9-_\\.]{1,100}$`) + // MustEnableDataset check if repository enable internal dataset func MustEnableDataset(ctx *context.Context) { if !ctx.Repo.CanRead(models.UnitTypeDatasets) { @@ -161,22 +166,69 @@ func DatasetIndex(ctx *context.Context) { ctx.HTML(200, tplIndex) } +func CreateDataset(ctx *context.Context) { + + MustEnableDataset(ctx) + + ctx.HTML(200, tplDatasetCreate) +} + +func CreateDatasetPost(ctx *context.Context, form auth.CreateDatasetForm) { + + dataset := &models.Dataset{} + + if !titlePattern.MatchString(form.Title) { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err"))) + return + } + if utf8.RuneCountInString(form.Description) > 1024 { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err"))) + return + } + + dataset.RepoID = ctx.Repo.Repository.ID + dataset.UserID = ctx.User.ID + dataset.Category = form.Category + dataset.Task = form.Task + dataset.Title = form.Title + dataset.License = form.License + dataset.Description = form.Description + dataset.DownloadTimes = 0 + if ctx.Repo.Repository.IsPrivate { + dataset.Status = 0 + } else { + dataset.Status = 1 + } + err := models.CreateDataset(dataset) + if err != nil { + log.Error("fail to create dataset", err) + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.create_dataset_fail"))) + } else { + ctx.JSON(http.StatusOK, models.BaseOKMessage) + } + +} + func EditDatasetPost(ctx *context.Context, form auth.EditDatasetForm) { ctx.Data["PageIsDataset"] = true ctx.Data["Title"] = ctx.Tr("dataset.edit_dataset") + if !titlePattern.MatchString(form.Title) { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.title_format_err"))) + return + } + if utf8.RuneCountInString(form.Description) > 1024 { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.description_format_err"))) + return + } + rel, err := models.GetDatasetByID(form.ID) ctx.Data["dataset"] = rel if err != nil { - ctx.ServerError("GetDataset", err) - return - } - - if ctx.HasError() { - ctx.Data["Error"] = true - ctx.HTML(200, tplIndex) + log.Error("failed to query dataset", err) + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.query_dataset_fail"))) return } @@ -186,11 +238,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.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("dataset.query_dataset_fail"))) } - ctx.Redirect(ctx.Repo.RepoLink + "/datasets?type=" + form.Type) + ctx.JSON(http.StatusOK, models.BaseOKMessage) } func DatasetAction(ctx *context.Context) { @@ -204,9 +254,9 @@ func DatasetAction(ctx *context.Context) { } if err != nil { - ctx.JSON(http.StatusOK, models.BaseMessage{1, ctx.Tr("repo.star_fail", ctx.Params(":action"))}) + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.star_fail", ctx.Params(":action")))) } else { - ctx.JSON(http.StatusOK, models.BaseMessageOK) + ctx.JSON(http.StatusOK, models.BaseOKMessage) } } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index d97c22a2d..50da9ad23 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -979,6 +979,9 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/datasets", func() { m.Get("", reqRepoDatasetReader, repo.DatasetIndex) m.Put("/:id/:action", reqRepoDatasetReader, repo.DatasetAction) + m.Get("/create", reqRepoDatasetWriter, repo.CreateDataset) + m.Post("/create", reqRepoDatasetWriter, bindIgnErr(auth.CreateDatasetForm{}), repo.CreateDatasetPost) + m.Post("", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) m.Group("/dirs", func() { From 68b39af5e5cc811f38842b07ebba0c5f3c3b195e Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Fri, 4 Mar 2022 11:34:20 +0800 Subject: [PATCH 05/78] =?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 | 1 + models/dataset.go | 38 +++++++++++++++---- routers/home.go | 9 +++++ routers/repo/attachment.go | 32 ++++++++++------ routers/repo/dataset.go | 78 ++++++++++++++++++++------------------ routers/routes/routes.go | 1 + 6 files changed, 104 insertions(+), 55 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index c322d391b..af7cafe53 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -38,6 +38,7 @@ 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"` Size int64 `xorm:"DEFAULT 0"` IsPrivate bool `xorm:"DEFAULT false"` diff --git a/models/dataset.go b/models/dataset.go index b64b00eb6..efc610630 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -92,6 +92,9 @@ type SearchDatasetOptions struct { OwnerID int64 RepoID int64 IncludePublic bool + Category string + Task string + License string ListOptions SearchOrderBy IsOwner bool @@ -118,6 +121,17 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { cond = cond.And(builder.Like{"dataset.title", opts.Keyword}) } + if len(opts.Category) > 0 { + cond = cond.And(builder.Eq{"dataset.category": opts.Category}) + } + + if len(opts.Task) > 0 { + cond = cond.And(builder.Eq{"dataset.task": opts.Task}) + } + if len(opts.License) > 0 { + cond = cond.And(builder.Eq{"dataset.license": opts.License}) + } + if opts.RepoID > 0 { cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) } @@ -223,13 +237,23 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, isSigned bool, user *Us sort.Sort(sortedRels) // Select attachments - err = e. - Asc("dataset_id"). - In("dataset_id", sortedRels.ID). - And("type = ?", typeCloudBrain). - Find(&attachments, Attachment{}) - if err != nil { - return err + if typeCloudBrain == -1 { + err = e. + Asc("dataset_id"). + In("dataset_id", sortedRels.ID). + Find(&attachments, Attachment{}) + if err != nil { + return err + } + } else { + err = e. + Asc("dataset_id"). + In("dataset_id", sortedRels.ID). + And("type = ?", typeCloudBrain). + Find(&attachments, Attachment{}) + if err != nil { + return err + } } // merge join diff --git a/routers/home.go b/routers/home.go index 93e6f8461..c59e9576a 100755 --- a/routers/home.go +++ b/routers/home.go @@ -312,6 +312,9 @@ func ExploreDatasets(ctx *context.Context) { keyword := strings.Trim(ctx.Query("q"), " ") + category := ctx.Query("category") + task := ctx.Query("task") + license := ctx.Query("license") var ownerID int64 if ctx.User != nil && !ctx.User.IsAdmin { ownerID = ctx.User.ID @@ -320,6 +323,9 @@ func ExploreDatasets(ctx *context.Context) { Keyword: keyword, IncludePublic: true, SearchOrderBy: orderBy, + Category: category, + Task: task, + License: license, OwnerID: ownerID, ListOptions: models.ListOptions{ Page: page, @@ -335,6 +341,9 @@ func ExploreDatasets(ctx *context.Context) { pager := context.NewPagination(int(count), opts.PageSize, page, 5) ctx.Data["Keyword"] = opts.Keyword + ctx.Data["Category"] = category + ctx.Data["Task"] = task + ctx.Data["License"] = license pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 13ce62aa9..481d0900b 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -15,6 +15,8 @@ import ( "strconv" "strings" + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/labelmsg" @@ -30,8 +32,9 @@ import ( const ( //result of decompress - DecompressSuccess = "0" - DecompressFailed = "1" + DecompressSuccess = "0" + DecompressFailed = "1" + tplAttachmentUpload base.TplName = "repo/attachment/upload" ) type CloudBrainDataset struct { @@ -63,6 +66,12 @@ func renderAttachmentSettings(ctx *context.Context) { ctx.Data["AttachmentMaxFiles"] = setting.Attachment.MaxFiles } +func UploadAttachmentUI(ctx *context.Context) { + ctx.Data["datasetId"] = ctx.Query("datasetId") + ctx.HTML(200, tplAttachmentUpload) + +} + // UploadAttachment response for uploading issue's attachment func UploadAttachment(ctx *context.Context) { if !setting.Attachment.Enabled { @@ -836,22 +845,23 @@ func CompleteMultipart(ctx *context.Context) { ctx.Error(500, fmt.Sprintf("UpdateFileChunk: %v", err)) return } - + dataset, _ := models.GetDatasetByID(ctx.QueryInt64("dataset_id")) attachment, err := models.InsertAttachment(&models.Attachment{ - UUID: uuid, - UploaderID: ctx.User.ID, - IsPrivate: true, - Name: fileName, - Size: ctx.QueryInt64("size"), - DatasetID: ctx.QueryInt64("dataset_id"), - Type: typeCloudBrain, + UUID: uuid, + UploaderID: ctx.User.ID, + IsPrivate: dataset.IsPrivate(), + Name: fileName, + Size: ctx.QueryInt64("size"), + DatasetID: ctx.QueryInt64("dataset_id"), + Description: ctx.Query("description"), + Type: typeCloudBrain, }) if err != nil { ctx.Error(500, fmt.Sprintf("InsertAttachment: %v", err)) return } - dataset, _ := models.GetDatasetByID(attachment.DatasetID) + repository, _ := models.GetRepositoryByID(dataset.RepoID) notification.NotifyOtherTask(ctx.User, repository, fmt.Sprint(attachment.Type), attachment.Name, models.ActionUploadAttachment) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 8ad83654b..413ec6951 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -91,21 +91,11 @@ func QueryDataSet(ctx *context.Context) []*models.Attachment { attachments := newFilterPrivateAttachments(ctx, dataset.Attachments, repo) 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 - }) - } + + sort.Slice(attachments, func(i, j int) bool { + return attachments[i].CreatedUnix > attachments[j].CreatedUnix + }) + return attachments } @@ -121,13 +111,12 @@ func DatasetIndex(ctx *context.Context) { ctx.HTML(200, tplIndex) return } + cloudbrainType := -1 + if ctx.Query("type") != "" { - if ctx.Query("type") == "" { - log.Error("query dataset, not found param type") - ctx.NotFound("type error", nil) - return + cloudbrainType = ctx.QueryInt("type") } - err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) + err = models.GetDatasetAttachments(cloudbrainType, ctx.IsSigned, ctx.User, dataset) if err != nil { ctx.ServerError("GetDatasetAttachments", err) return @@ -135,37 +124,52 @@ func DatasetIndex(ctx *context.Context) { attachments := newFilterPrivateAttachments(ctx, dataset.Attachments, repo) - 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 - }) + sort.Slice(attachments, func(i, j int) bool { + return attachments[i].CreatedUnix > attachments[j].CreatedUnix + }) + + page := ctx.QueryInt("page") + if page <= 0 { + page = 1 + } + pagesize := ctx.QueryInt("pagesize") + if pagesize <= 0 { + pagesize = setting.UI.ExplorePagingNum } + pager := context.NewPagination(len(attachments), pagesize, page, 5) + pageAttachments := getPageAttachments(attachments, page, pagesize) + + ctx.Data["Page"] = pager ctx.Data["PageIsDataset"] = true ctx.Data["Title"] = ctx.Tr("dataset.show_dataset") ctx.Data["Link"] = ctx.Repo.RepoLink + "/datasets" ctx.Data["dataset"] = dataset - ctx.Data["Attachments"] = attachments + ctx.Data["Attachments"] = pageAttachments ctx.Data["IsOwner"] = true ctx.Data["StoreType"] = setting.Attachment.StoreType - ctx.Data["Type"] = ctx.QueryInt("type") + ctx.Data["Type"] = cloudbrainType renderAttachmentSettings(ctx) ctx.HTML(200, tplIndex) } +func getPageAttachments(attachments []*models.Attachment, page int, pagesize int) []*models.Attachment { + begin := (page - 1) * pagesize + end := (page) * pagesize + + if begin > len(attachments)-1 { + return nil + } + if end > len(attachments)-1 { + return attachments[begin:] + } else { + return attachments[begin:end] + } + +} + func CreateDataset(ctx *context.Context) { MustEnableDataset(ctx) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 50da9ad23..c260ca686 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -586,6 +586,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/delete", repo.DeleteAttachment) m.Get("/get_pre_url", repo.GetPresignedPutObjectURL) m.Post("/add", repo.AddAttachment) + m.Get("/upload", repo.UploadAttachmentUI) m.Post("/private", repo.UpdatePublicAttachment) m.Get("/get_chunks", repo.GetSuccessChunks) m.Get("/new_multipart", repo.NewMultipart) From aa1347a63359c469f79f9f923b1c4cb327c99023 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Fri, 4 Mar 2022 15:35:19 +0800 Subject: [PATCH 06/78] =?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 | 16 ++++++++++++++++ routers/routes/routes.go | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 413ec6951..c3f4de52a 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -18,6 +18,7 @@ import ( const ( tplIndex base.TplName = "repo/datasets/index" tplDatasetCreate base.TplName = "repo/datasets/create" + tplDatasetEdit base.TplName = "repo/datasets/edit" ) var titlePattern = regexp.MustCompile(`^[A-Za-z0-9-_\\.]{1,100}$`) @@ -177,6 +178,21 @@ func CreateDataset(ctx *context.Context) { ctx.HTML(200, tplDatasetCreate) } +func EditDataset(ctx *context.Context) { + + MustEnableDataset(ctx) + datasetId, _ := strconv.ParseInt(ctx.Params(":id"), 10, 64) + + dataset, _ := models.GetDatasetByID(datasetId) + if dataset == nil { + ctx.Error(http.StatusNotFound, "") + return + } + ctx.Data["Dataset"] = dataset + + ctx.HTML(200, tplDatasetEdit) +} + func CreateDatasetPost(ctx *context.Context, form auth.CreateDatasetForm) { dataset := &models.Dataset{} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index c260ca686..1bf80ec82 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -982,8 +982,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Put("/:id/:action", reqRepoDatasetReader, repo.DatasetAction) m.Get("/create", reqRepoDatasetWriter, repo.CreateDataset) m.Post("/create", reqRepoDatasetWriter, bindIgnErr(auth.CreateDatasetForm{}), repo.CreateDatasetPost) - - m.Post("", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) + m.Get("/edit/:id", reqRepoDatasetWriter, repo.EditDataset) + m.Post("/edit", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) m.Group("/dirs", func() { m.Get("/:uuid", reqRepoDatasetReader, repo.DirIndex) From 6077d4fe6521740413ad22c142b5dda564a2c2df Mon Sep 17 00:00:00 2001 From: liuzx Date: Tue, 8 Mar 2022 11:13:18 +0800 Subject: [PATCH 07/78] update --- models/attachment.go | 82 ++++++++++++++++++++++++ routers/repo/dataset.go | 34 ++++++++++ routers/routes/routes.go | 4 +- templates/repo/datasets/tasks/index.tmpl | 0 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 templates/repo/datasets/tasks/index.tmpl diff --git a/models/attachment.go b/models/attachment.go index af7cafe53..d482a9018 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/timeutil" gouuid "github.com/satori/go.uuid" + "xorm.io/builder" "xorm.io/xorm" ) @@ -55,6 +56,19 @@ type AttachmentUsername struct { Name string } +type AttachmentInfo struct { + Attachment `xorm:"extends"` + Repo *Repository `xorm:"extends"` +} + +type AttachmentsOptions struct { + ListOptions + DatasetID int8 + DecompressState int + Type int + NeedRepoInfo bool +} + func (a *Attachment) AfterUpdate() { if a.DatasetID > 0 { datasetIsPublicCount, err := x.Where("dataset_id = ? AND is_private = ?", a.DatasetID, false).Count(new(Attachment)) @@ -504,3 +518,71 @@ func GetAttachmentSizeByDatasetID(datasetID int64) (int64, error) { func GetAllAttachmentSize() (int64, error) { return x.SumInt(&Attachment{}, "size") } + +func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { + sess := x.NewSession() + defer sess.Close() + + var cond = builder.NewCond() + if opts.DatasetID > 0 { + cond = cond.And( + builder.Eq{"attachment.dataset_id": opts.DatasetID}, + ) + } + + if opts.DecompressState > 0 { + cond = cond.And( + builder.Eq{"attachment.decompress_state": opts.DecompressState}, + ) + } + + if (opts.Type) >= 0 { + cond = cond.And( + builder.Eq{"cloudbrain.type": opts.Type}, + ) + } + + var count int64 + var err error + if opts.DatasetID > 0 { + count, err = sess.Where(cond).Count(new(Attachment)) + } + + if err != nil { + return nil, 0, fmt.Errorf("Count: %v", err) + } + + if opts.Page >= 0 && opts.PageSize > 0 { + var start int + if opts.Page == 0 { + start = 0 + } else { + start = (opts.Page - 1) * opts.PageSize + } + sess.Limit(opts.PageSize, start) + } + + sess.OrderBy("attachment.created_unix DESC") + attachments := make([]*AttachmentInfo, 0, setting.UI.IssuePagingNum) + if err := sess.Table(&Attachment{}).Where(cond). + Find(&attachments); err != nil { + return nil, 0, fmt.Errorf("Find: %v", err) + } + + if opts.NeedRepoInfo { + for _, attachment := range attachments { + dataset, err := GetDatasetByID(attachment.DatasetID) + if err != nil { + return nil, 0, fmt.Errorf("GetDatasetByID failed error: %v", err) + } + repo, err := GetRepositoryByID(dataset.RepoID) + if err == nil { + attachment.Repo = repo + } else { + return nil, 0, fmt.Errorf("GetRepositoryByID failed error: %v", err) + } + } + } + + return attachments, count, nil +} diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index c3f4de52a..7b3625d49 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -1,6 +1,7 @@ package repo import ( + "encoding/json" "net/http" "regexp" "sort" @@ -19,6 +20,7 @@ const ( tplIndex base.TplName = "repo/datasets/index" tplDatasetCreate base.TplName = "repo/datasets/create" tplDatasetEdit base.TplName = "repo/datasets/edit" + taskstplIndex base.TplName = "repo/datasets/tasks/index" ) var titlePattern = regexp.MustCompile(`^[A-Za-z0-9-_\\.]{1,100}$`) @@ -280,3 +282,35 @@ func DatasetAction(ctx *context.Context) { } } + +func TasksDatasetIndex(ctx *context.Context) { + page := ctx.QueryInt("page") + // repo := ctx.Repo.Repository + + datasets, count, err := models.Attachments(&models.AttachmentsOptions{ + ListOptions: models.ListOptions{ + Page: page, + PageSize: setting.UI.IssuePagingNum, + }, + Type: models.TypeCloudBrainTwo, + }) + if err != nil { + ctx.ServerError("datasets", err) + return + } + + data, err := json.Marshal(datasets) + if err != nil { + log.Error("json.Marshal failed:", err.Error()) + ctx.JSON(200, map[string]string{ + "result_code": "-1", + "error_msg": err.Error(), + "data": "", + }) + return + } + ctx.JSON(200, map[string]string{ + "data": string(data), + "count": strconv.FormatInt(count, 10), + }) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 1bf80ec82..84d01cdb1 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -6,13 +6,14 @@ package routes import ( "bytes" - "code.gitea.io/gitea/routers/authentication" "encoding/gob" "net/http" "path" "text/template" "time" + "code.gitea.io/gitea/routers/authentication" + "code.gitea.io/gitea/modules/cloudbrain" "code.gitea.io/gitea/routers/operation" @@ -984,6 +985,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/create", reqRepoDatasetWriter, bindIgnErr(auth.CreateDatasetForm{}), repo.CreateDatasetPost) m.Get("/edit/:id", reqRepoDatasetWriter, repo.EditDataset) m.Post("/edit", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) + m.Get("/tasks", reqRepoDatasetReader, repo.TasksDatasetIndex) m.Group("/dirs", func() { m.Get("/:uuid", reqRepoDatasetReader, repo.DirIndex) diff --git a/templates/repo/datasets/tasks/index.tmpl b/templates/repo/datasets/tasks/index.tmpl new file mode 100644 index 000000000..e69de29bb From 5737eac68213a31b54828873987845780f199f5a Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 8 Mar 2022 11:30:42 +0800 Subject: [PATCH 08/78] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E5=B9=BF?= =?UTF-8?q?=E5=9C=BA=E6=90=9C=E7=B4=A2=E6=94=AF=E6=8C=81=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dataset.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index efc610630..096ab291c 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -118,7 +118,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { cond = cond.And(builder.Neq{"dataset.status": DatasetStatusDeleted}) if len(opts.Keyword) > 0 { - cond = cond.And(builder.Like{"dataset.title", opts.Keyword}) + cond = cond.And(builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) } if len(opts.Category) > 0 { @@ -144,7 +144,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) } else { subCon := builder.NewCond() - subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}, builder.Like{"dataset.title", opts.Keyword}) + subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}, builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) cond = cond.Or(subCon) } From bfdd694ad225236ace0a82a231cfe89c304b3c0a Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 8 Mar 2022 16:06:48 +0800 Subject: [PATCH 09/78] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=88=9B=E5=BB=BA=E5=A4=9A=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dataset.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index 096ab291c..e5b252ce6 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -101,11 +101,28 @@ type SearchDatasetOptions struct { } func CreateDataset(dataset *Dataset) (err error) { - if _, err = x.Insert(dataset); err != nil { + + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { return err } - return nil + datasetByRepoId := &Dataset{RepoID: dataset.RepoID} + has, err := sess.Get(datasetByRepoId) + if err != nil { + return err + } + if has { + return fmt.Errorf("The dataset already exists.") + } + + if _, err = sess.Insert(dataset); err != nil { + return err + } + return sess.Commit() + } func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) { From ce1ff8e795151611582108b8930bdcd8cfcaef9e Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 8 Mar 2022 17:12:50 +0800 Subject: [PATCH 10/78] =?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/attachment.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 481d0900b..96cce5cd0 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -68,6 +68,12 @@ func renderAttachmentSettings(ctx *context.Context) { func UploadAttachmentUI(ctx *context.Context) { ctx.Data["datasetId"] = ctx.Query("datasetId") + dataset, _ := models.GetDatasetByID(ctx.QueryInt64("datasetId")) + if dataset == nil { + ctx.Error(404, "The dataset does not exits.") + } + r, _ := models.GetRepositoryByID(dataset.RepoID) + ctx.Data["Repo"] = r ctx.HTML(200, tplAttachmentUpload) } From 4d7323930eee1a670792902bbb160bbb1b64f507 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 8 Mar 2022 17:57:50 +0800 Subject: [PATCH 11/78] fix issue --- templates/repo/attachment/upload.tmpl | 98 +++++++++ templates/repo/datasets/create.tmpl | 65 ++++++ templates/repo/datasets/index.tmpl | 257 ++++++++++++------------ web_src/js/components/MinioUploader.vue | 122 +++++++---- web_src/js/components/ObsUploader.vue | 5 +- web_src/js/index.js | 96 +++++++++ web_src/less/openi.less | 4 + 7 files changed, 472 insertions(+), 175 deletions(-) create mode 100644 templates/repo/attachment/upload.tmpl create mode 100644 templates/repo/datasets/create.tmpl diff --git a/templates/repo/attachment/upload.tmpl b/templates/repo/attachment/upload.tmpl new file mode 100644 index 000000000..167a65aae --- /dev/null +++ b/templates/repo/attachment/upload.tmpl @@ -0,0 +1,98 @@ + +{{template "base/head" .}} +
+{{template "repo/header" .}} +
+ +
+

+ 上传数据集文件 +

+
+
+ + {{.CsrfTokenHtml}} + + CPU/GPU + NPU + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ +

说明:

+

只有zip格式的数据集才能发起云脑任务;
+ 云脑1提供CPU / GPU资源,云脑2提供Ascend NPU资源;调试使用的数据集也需要上传到对应的环境;

+ +
+
+
+{{template "base/footer" .}} + \ No newline at end of file diff --git a/templates/repo/datasets/create.tmpl b/templates/repo/datasets/create.tmpl new file mode 100644 index 000000000..ea935c345 --- /dev/null +++ b/templates/repo/datasets/create.tmpl @@ -0,0 +1,65 @@ + +
+
+
+
+
+
+
+
+
+{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+ +
+

+ {{.i18n.Tr "repo.modelarts.train_job.new_infer"}} +

+
+
+ + {{.CsrfTokenHtml}} + + + 请输入字母、数字、_和-,最长64个字符,且不能以中划线(-)结尾。 + + + + + + + + + + + + + + + + + + + + + + + + + 确定 + 取消 + + +
+
+
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 65ba2bb6e..9074e62c4 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -6,145 +6,142 @@ margin: -1px; background: #FFF !important; } +.wrapper { + display: flex; + overflow: hidden; + padding: 0 1rem; + } + .exp{ + display: none; + } + .exp:checked+.text{ + max-height: none; + } + .exp:checked+.text::after{ + visibility: hidden; + } + .exp:checked+.text .btn::before{ + visibility: hidden; + } + .exp:checked+.text .btn::after{ + content:'收起' + } + + .wrapper>.text { + font-family: SourceHanSansSC-regular; + font-size: 14px; + color: #101010; + overflow: hidden; + text-overflow: ellipsis; + text-align: justify; + position: relative; + line-height: 1.5; + max-height: 3em; + transition: .3s max-height; + } + .wrapper>.text::before { + content: ''; + height: calc(100% - 20px); + float: right; + } + .wrapper>.text::after { + content: ''; + width: 999vw; + height: 999vw; + position: absolute; + box-shadow: inset calc(100px - 999vw) calc(30px - 999vw) 0 0 #fff; + margin-left: -100px; + } + .btn{ + position: relative; + float: right; + clear: both; + margin-left: 20px; + font-size: 14px; + padding: 0 8px; + background: #3F51B5; + line-height: 20px; + border-radius: 4px; + color: #fff; + cursor: pointer; + /* margin-top: -30px; */ + } + .btn::after{ + content:'展开' + } + .btn::before{ + content: '...'; + position: absolute; + left: -5px; + color: #333; + transform: translateX(-100%) + } -
+
{{template "repo/header" .}} - -
- - -
- {{.CsrfTokenHtml}} - {{template "base/alert" .}} -
-
-
-

{{.dataset.Title}}

-
- {{if .Permission.CanWrite $.UnitTypeDatasets}} - - {{end}} -
-
-
- {{if .dataset.Description }} - {{.dataset.Description}} - {{else}} - {{.Repository.DescriptionHTML}} - {{end}} -
-
-
- -
- -
- -
- -
- -
- -
- {{.i18n.Tr "cancel"}} - -
-
- - - -
-
-
-
-
- {{if eq .Type 0}}{{.i18n.Tr "repo.cloudbrain1"}}{{else}}{{.i18n.Tr "repo.cloudbrain2"}}{{end}}-{{.i18n.Tr "datasets"}} -
-
-
- {{.dataset.Title}} - {{.dataset.Category}} - {{.dataset.License}} + {{if .dataset.Title}} + {{.dataset.Title}} + {{end}} + {{if .dataset.Category}} + {{.dataset.Category}} + {{end}} + {{if .dataset.License}} + {{.dataset.License}} + {{end}}
From fbe28851c1688912fee75b0637a5b09eafefb4ce Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 9 Mar 2022 09:27:13 +0800 Subject: [PATCH 14/78] =?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/attachment.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 96cce5cd0..8254ccc67 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -814,6 +814,9 @@ func CompleteMultipart(ctx *context.Context) { typeCloudBrain := ctx.QueryInt("type") fileName := ctx.Query("file_name") + log.Warn("uuid:" + uuid) + log.Warn("typeCloudBrain:" + strconv.Itoa(typeCloudBrain)) + err := checkTypeCloudBrain(typeCloudBrain) if err != nil { ctx.ServerError("checkTypeCloudBrain failed", err) @@ -852,6 +855,7 @@ func CompleteMultipart(ctx *context.Context) { return } dataset, _ := models.GetDatasetByID(ctx.QueryInt64("dataset_id")) + log.Warn("insert attachment to datasetId:" + strconv.FormatInt(dataset.ID, 10)) attachment, err := models.InsertAttachment(&models.Attachment{ UUID: uuid, UploaderID: ctx.User.ID, From e3004c488c30a40e85a46839baf6c359df47017b Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 9 Mar 2022 17:04:12 +0800 Subject: [PATCH 15/78] fix-bug --- models/attachment.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index 5179c0170..6214567ef 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "path" + "strings" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/obs" @@ -70,6 +71,7 @@ type AttachmentsOptions struct { NeedIsPrivate bool IsPrivate bool NeedRepoInfo bool + Keyword string } func (a *Attachment) AfterUpdate() { @@ -554,8 +556,14 @@ func Attachments(opts *AttachmentsOptions) ([]*AttachmentInfo, int64, error) { var count int64 var err error - if (opts.Type) >= 0 { + if len(opts.Keyword) == 0 { count, err = sess.Where(cond).Count(new(Attachment)) + } else { + lowerKeyWord := strings.ToLower(opts.Keyword) + + cond = cond.And(builder.Or(builder.Like{"LOWER(attachment.name)", lowerKeyWord})) + count, err = sess.Table(&Attachment{}).Where(cond).Count(new(AttachmentInfo)) + } if err != nil { From 8497e5b0591350eae0e5c7ab1a3274aa805f0abb Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 10 Mar 2022 09:31:53 +0800 Subject: [PATCH 16/78] fix-bug --- routers/repo/dataset.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index d4e12ab8f..e73a942f8 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -6,6 +6,7 @@ import ( "regexp" "sort" "strconv" + "strings" "unicode/utf8" "code.gitea.io/gitea/models" @@ -286,6 +287,8 @@ func DatasetAction(ctx *context.Context) { func CurrentRepoDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") + repo := ctx.Repo.Repository var datasetIDs []int64 dataset, err := models.GetDatasetByRepo(repo) @@ -299,6 +302,7 @@ func CurrentRepoDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, DatasetIDs: datasetIDs, UploaderID: uploaderID, Type: cloudbrainType, @@ -329,6 +333,7 @@ func CurrentRepoDataset(ctx *context.Context) { func MyDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") uploaderID := ctx.User.ID datasets, count, err := models.Attachments(&models.AttachmentsOptions{ @@ -336,6 +341,7 @@ func MyDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, UploaderID: uploaderID, Type: cloudbrainType, NeedIsPrivate: false, @@ -365,12 +371,14 @@ func MyDataset(ctx *context.Context) { func PublicDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") datasets, count, err := models.Attachments(&models.AttachmentsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, NeedIsPrivate: true, IsPrivate: false, Type: cloudbrainType, @@ -400,6 +408,7 @@ func PublicDataset(ctx *context.Context) { func MyFavoriteDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") + keyword := strings.Trim(ctx.Query("search"), " ") var datasetIDs []int64 @@ -416,6 +425,7 @@ func MyFavoriteDataset(ctx *context.Context) { Page: page, PageSize: setting.UI.IssuePagingNum, }, + Keyword: keyword, DatasetIDs: datasetIDs, NeedIsPrivate: true, IsPrivate: false, From 1ad707670f5de54eadd9197ff614221b1f555dc2 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 10 Mar 2022 10:10:30 +0800 Subject: [PATCH 17/78] =?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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index e73a942f8..9c3efb3a4 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -138,7 +138,7 @@ func DatasetIndex(ctx *context.Context) { } pagesize := ctx.QueryInt("pagesize") if pagesize <= 0 { - pagesize = setting.UI.ExplorePagingNum + pagesize = 10 } pager := context.NewPagination(len(attachments), pagesize, page, 5) From c7eb80ac3681e1d23196670ff6b5a594e08e50e8 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 10 Mar 2022 15:25:10 +0800 Subject: [PATCH 18/78] fix bug --- routers/repo/dataset.go | 10 +++++----- routers/routes/routes.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 9c3efb3a4..5ef9f30bf 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -287,7 +287,7 @@ func DatasetAction(ctx *context.Context) { func CurrentRepoDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") - keyword := strings.Trim(ctx.Query("search"), " ") + keyword := strings.Trim(ctx.Query("q"), " ") repo := ctx.Repo.Repository var datasetIDs []int64 @@ -330,10 +330,10 @@ func CurrentRepoDataset(ctx *context.Context) { }) } -func MyDataset(ctx *context.Context) { +func MyDatasets(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") - keyword := strings.Trim(ctx.Query("search"), " ") + keyword := strings.Trim(ctx.Query("q"), " ") uploaderID := ctx.User.ID datasets, count, err := models.Attachments(&models.AttachmentsOptions{ @@ -371,7 +371,7 @@ func MyDataset(ctx *context.Context) { func PublicDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") - keyword := strings.Trim(ctx.Query("search"), " ") + keyword := strings.Trim(ctx.Query("q"), " ") datasets, count, err := models.Attachments(&models.AttachmentsOptions{ ListOptions: models.ListOptions{ @@ -408,7 +408,7 @@ func PublicDataset(ctx *context.Context) { func MyFavoriteDataset(ctx *context.Context) { page := ctx.QueryInt("page") cloudbrainType := ctx.QueryInt("type") - keyword := strings.Trim(ctx.Query("search"), " ") + keyword := strings.Trim(ctx.Query("q"), " ") var datasetIDs []int64 diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 8c03824e3..a7b7c61d7 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -986,7 +986,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/edit/:id", reqRepoDatasetWriter, repo.EditDataset) m.Post("/edit", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost) m.Get("/current_repo", reqRepoDatasetReader, repo.CurrentRepoDataset) - m.Get("/my_datasets", reqRepoDatasetReader, repo.MyDataset) + m.Get("/my_datasets", reqRepoDatasetReader, repo.MyDatasets) m.Get("/public_datasets", reqRepoDatasetReader, repo.PublicDataset) m.Get("/my_favorite", reqRepoDatasetReader, repo.MyFavoriteDataset) From c6f56a7226fb0be5299f016cac4e162bbf93f83e Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 10 Mar 2022 16:23:47 +0800 Subject: [PATCH 19/78] fix issue --- templates/repo/datasets/create.tmpl | 4 +- templates/repo/datasets/edit.tmpl | 72 ++++++++++++ templates/repo/datasets/index.tmpl | 164 +++++++++++++++++++++++++++- web_src/js/index.js | 101 ++++++++++++++++- 4 files changed, 330 insertions(+), 11 deletions(-) create mode 100644 templates/repo/datasets/edit.tmpl diff --git a/templates/repo/datasets/create.tmpl b/templates/repo/datasets/create.tmpl index ea935c345..e7a2a4f8e 100644 --- a/templates/repo/datasets/create.tmpl +++ b/templates/repo/datasets/create.tmpl @@ -54,12 +54,12 @@ 确定 - 取消 + 取消
-
+
{{template "base/footer" .}} diff --git a/templates/repo/datasets/edit.tmpl b/templates/repo/datasets/edit.tmpl new file mode 100644 index 000000000..d44e8765c --- /dev/null +++ b/templates/repo/datasets/edit.tmpl @@ -0,0 +1,72 @@ + +
+
+
+
+
+
+
+
+
+{{template "base/head" .}} +
+ {{template "repo/header" .}} +
+ +
+

+ {{.i18n.Tr "repo.modelarts.train_job.new_infer"}} +

+ + +
+
+ + {{.CsrfTokenHtml}} + + + 请输入字母、数字、_和-,最长64个字符,且不能以中划线(-)结尾。 + + + + + + + + + + + + + + + + + + + + + + + + + 确定 + 取消 + + +
+
+
+
+
+{{template "base/footer" .}} + \ No newline at end of file diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 289e6525a..73f153c04 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -6,6 +6,14 @@ margin: -1px; background: #FFF !important; } + +.dataset_title{ + font-size: 14px; + max-width: 80%; + display: inline-block !important; + margin-left: 6px !important; + padding-right: 0 !important; +} .wrapper { display: flex; overflow: hidden; @@ -76,10 +84,26 @@ color: #333; transform: translateX(-100%) } + + .el-button--text{color:#0366d6 ;} + .heart-stroke{ + stroke: #666; + stroke-width: 2; + fill: #fff + } + .stars_active{ + fill: #FA8C16 !important; + }
{{template "repo/header" .}} {{if .dataset}} + +
@@ -87,11 +111,12 @@

{{.dataset.Title}}

-
+
-
- {{.dataset.NumStars}} - 修改 + +
+ + 修改
@@ -130,10 +155,122 @@ 上传
+
+
+
+
+ +
+ 文件名称 +
+
+ 大小 +
+
+ 存储位置 +
+
+ 状态 +
+
+ 创建者 +
+
+ 上传时间 +
+
+ 操作 +
+
+
+ {{range $k, $v :=.dataset.Attachments}} +
+
+ + + +
+ {{.Size | FileSize}} +
+
+ {{.Type}} +
+
+ {{.IsPrivate}} +
+
+ 创建者 +
+
+ {{.CreatedUnix | TimeSinceUnix1}} +
+ +
+
+ {{end}} + +
+ +
+
- +
+
+ + +
+
{{else}}
@@ -146,8 +283,25 @@
{{end}}
+ + {{template "base/footer" .}} \ No newline at end of file diff --git a/web_src/js/index.js b/web_src/js/index.js index 0663cb3f2..fdcc617c2 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -43,7 +43,7 @@ import Contributors from './components/Contributors.vue' import Model from './components/Model.vue'; import WxAutorize from './components/WxAutorize.vue' import initCloudrain from './features/cloudrbanin.js' - +// import $ from 'jquery.js' Vue.use(ElementUI); Vue.prototype.$axios = axios; @@ -3664,6 +3664,11 @@ function initVueDataset() { if (!el) { return; } + const items = [] + $('#dataset-range-value').find('.item').each(function(){ + items.push($(this).data('private')) + }) + let num_stars = $('#dataset-range-value').data('num-stars') new Vue({ delimiters: ['${', '}'], el, @@ -3673,13 +3678,17 @@ function initVueDataset() { type:0, desc:'', datasetType:'全部', + privates:[], + star_active:false, + num_stars:0, ruleForm:{ title:'', description:'', category:'', task:'', license:'', - _csrf:csrf + _csrf:csrf, + id:'', }, rules: { title: [ @@ -3716,6 +3725,10 @@ function initVueDataset() { if(document.getElementById('postPath')){ this.url = document.getElementById('postPath').value } + this.privates = items + this.num_stars = num_stars + this.getEditInit() + }, methods:{ createDataset(formName){ @@ -3730,6 +3743,9 @@ function initVueDataset() { }else{ console.log(res.data.Message) } + document.getElementById("mask").style.display = "none" + }).catch(error=>{ + console.log(error) }) } else{ @@ -3737,8 +3753,15 @@ function initVueDataset() { } }) }, - cancelDataset(){ - location.href = this.url.split('/create')[0]+'?type=-1' + cancelDataset(getpage){ + if(getpage==='create'){ + location.href = this.url.split('/create')[0]+'?type=-1' + }else if(getpage==='edit'){ + location.href = this.url.split('/edit')[0]+'?type=-1' + }else{ + location.href='/' + } + }, gotoUpload(datsetId){ location.href = `${AppSubUrl}/attachments/upload?datasetId=${datsetId}` @@ -3748,8 +3771,78 @@ function initVueDataset() { }, uploadNpu(){ this.type=1 + }, + setPrivate(uuid,privateFlag,index){ + const params = {_csrf:csrf,file:uuid,is_private:privateFlag} + this.$axios.post('/attachments/private',this.qs.stringify(params)).then((res)=>{ + console.log(res) + this.$set(this.privates,index,privateFlag) + }).catch(error=>{ + console.log(error) + }) + }, + delDataset(uuid){ + let _this = this + const params = {_csrf:csrf,file:uuid} + $('#data-dataset-delete-modal') + .modal({ + closable: false, + onApprove() { + _this.$axios.post('/attachments/delete',_this.qs.stringify(params)).then((res)=>{ + console.log(res) + $('#'+uuid).hide() + }).catch(error=>{ + console.log(error) + }) + } + }) + .modal('show'); + }, + getEditInit(){ + console.log(this.ruleForm) + if($('#dataset-edit-value')){ + console.log("==========") + let $this = $('#dataset-edit-value') + this.ruleForm.title = $this.data('edit-title') || '' + this.ruleForm.description = $this.data('edit-description') || '' + this.ruleForm.category = $this.data('edit-category') || '' + this.ruleForm.task = $this.data('edit-task') || '' + this.ruleForm.license = $this.data('edit-license') || '' + this.ruleForm.id = $this.data('edit-id') || '' + } + console.log(this.ruleForm) + }, + editDataset(formName,id){ + let _this = this + console.log(this.url) + this.url = this.url.split(`/${id}`)[0] + console.log(this.url) + this.$refs[formName].validate((valid)=>{ + if(valid){ + document.getElementById("mask").style.display = "block" + _this.$axios.post(_this.url,_this.qs.stringify(_this.ruleForm)).then((res)=>{ + if(res.data.Code===0){ + document.getElementById("mask").style.display = "none" + location.href = _this.url.split('/edit')[0]+'?type=-1' + }else{ + console.log(res.data.Message) + } + document.getElementById("mask").style.display = "none" + }).catch((err)=>{ + console.log(err) + }) + } + else{ + return false + } + }) + + }, + postStar(id,link){ + console.log(id,link) } + } }); From 8cf36fcc3173bc543beb0e1c97e87dbcbd8141c1 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 10 Mar 2022 16:30:45 +0800 Subject: [PATCH 20/78] fix-bug --- routers/repo/dataset.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 5ef9f30bf..3f5209918 100755 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -325,8 +325,9 @@ func CurrentRepoDataset(ctx *context.Context) { return } ctx.JSON(200, map[string]string{ - "data": string(data), - "count": strconv.FormatInt(count, 10), + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), }) } @@ -363,8 +364,9 @@ func MyDatasets(ctx *context.Context) { return } ctx.JSON(200, map[string]string{ - "data": string(data), - "count": strconv.FormatInt(count, 10), + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), }) } @@ -400,8 +402,9 @@ func PublicDataset(ctx *context.Context) { return } ctx.JSON(200, map[string]string{ - "data": string(data), - "count": strconv.FormatInt(count, 10), + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), }) } @@ -448,7 +451,8 @@ func MyFavoriteDataset(ctx *context.Context) { return } ctx.JSON(200, map[string]string{ - "data": string(data), - "count": strconv.FormatInt(count, 10), + "result_code": "0", + "data": string(data), + "count": strconv.FormatInt(count, 10), }) } From 915b3a6d94a294906628be64e33a7b95d732d67e Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 10 Mar 2022 17:12:38 +0800 Subject: [PATCH 21/78] =?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/dataset_star.go | 9 ++++++--- modules/context/repo.go | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/models/dataset_star.go b/models/dataset_star.go index fac08caee..5dedb2ba4 100644 --- a/models/dataset_star.go +++ b/models/dataset_star.go @@ -51,9 +51,12 @@ func StarDataset(userID, datasetID int64, star bool) error { return sess.Commit() } -func IsDatasetStaring(userID, datasetID int64) bool { - - return isDatasetStaring(x, userID, datasetID) +func IsDatasetStaringByRepoId(userID, repoID int64) bool { + dataset, _ := GetDatasetByRepo(&Repository{ID: repoID}) + if dataset == nil { + return false + } + return isDatasetStaring(x, userID, dataset.ID) } func isDatasetStaring(e Engine, userID, datasetID int64) bool { diff --git a/modules/context/repo.go b/modules/context/repo.go index 64f02c921..7c425c8c0 100755 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -475,6 +475,8 @@ func RepoAssignment() macaron.Handler { if ctx.IsSigned { ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID) ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.ID, repo.ID) + + ctx.Data["IsStaringDataset"] = models.IsDatasetStaringByRepoId(ctx.User.ID, repo.ID) } if repo.IsFork { From 4786375ab93285bb79c38f32f809af9c770fa9f9 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 10 Mar 2022 17:34:32 +0800 Subject: [PATCH 22/78] fix issue --- web_src/js/index.js | 50 +++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index fdcc617c2..5c595b47a 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3669,6 +3669,28 @@ function initVueDataset() { items.push($(this).data('private')) }) let num_stars = $('#dataset-range-value').data('num-stars') + const ruleForm = {} + if(document.getElementById('dataset-edit-value')){ + let $this = $('#dataset-edit-value') + ruleForm.title = $this.data('edit-title') || '' + ruleForm.description = $this.data('edit-description') || '' + ruleForm.category = $this.data('edit-category') || '' + ruleForm.task = $this.data('edit-task') || '' + ruleForm.license = $this.data('edit-license') || '' + ruleForm.id = $this.data('edit-id')|| '' + } + console.log(ruleForm) + // getEditInit(){ + // if($('#dataset-edit-value')){ + // $this = $('#dataset-edit-value') + // this.ruleForm.title = $this.data('edit-title') || '' + // this.ruleForm.description = $this.data('edit-description') || '' + // this.ruleForm.category = $this.data('edit-category') || '' + // this.ruleForm.task = $this.data('edit-task') || '' + // this.ruleForm.license = $this.data('edit-license') || '' + // this.ruleForm.id = $this.data('edit-id')|| '' + // } + // }, new Vue({ delimiters: ['${', '}'], el, @@ -3727,7 +3749,8 @@ function initVueDataset() { } this.privates = items this.num_stars = num_stars - this.getEditInit() + this.ruleForm = ruleForm + // this.getEditInit() }, methods:{ @@ -3798,20 +3821,17 @@ function initVueDataset() { }) .modal('show'); }, - getEditInit(){ - console.log(this.ruleForm) - if($('#dataset-edit-value')){ - console.log("==========") - let $this = $('#dataset-edit-value') - this.ruleForm.title = $this.data('edit-title') || '' - this.ruleForm.description = $this.data('edit-description') || '' - this.ruleForm.category = $this.data('edit-category') || '' - this.ruleForm.task = $this.data('edit-task') || '' - this.ruleForm.license = $this.data('edit-license') || '' - this.ruleForm.id = $this.data('edit-id') || '' - } - console.log(this.ruleForm) - }, + // getEditInit(){ + // if($('#dataset-edit-value')){ + // $this = $('#dataset-edit-value') + // this.ruleForm.title = $this.data('edit-title') || '' + // this.ruleForm.description = $this.data('edit-description') || '' + // this.ruleForm.category = $this.data('edit-category') || '' + // this.ruleForm.task = $this.data('edit-task') || '' + // this.ruleForm.license = $this.data('edit-license') || '' + // this.ruleForm.id = $this.data('edit-id')|| '' + // } + // }, editDataset(formName,id){ let _this = this console.log(this.url) From 95b2613cdaa98210410ba8f93aa322a53dd58728 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Fri, 11 Mar 2022 10:00:26 +0800 Subject: [PATCH 23/78] fix issue --- templates/repo/datasets/edit.tmpl | 14 ++++----- templates/repo/datasets/index.tmpl | 14 +++++---- web_src/js/components/MinioUploader.vue | 20 +++++++----- web_src/js/index.js | 42 ++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/templates/repo/datasets/edit.tmpl b/templates/repo/datasets/edit.tmpl index d44e8765c..d198d1666 100644 --- a/templates/repo/datasets/edit.tmpl +++ b/templates/repo/datasets/edit.tmpl @@ -28,36 +28,36 @@
- + {{.CsrfTokenHtml}} - + 请输入字母、数字、_和-,最长64个字符,且不能以中划线(-)结尾。 - + - + - + - + - 确定 + 确定 取消 diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 73f153c04..656f22a75 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -93,12 +93,13 @@ } .stars_active{ fill: #FA8C16 !important; + stroke:#FA8C16 !important }
{{template "repo/header" .}} {{if .dataset}} -