From ab34d3f14446b8a3c8452f333ed7b64685703e49 Mon Sep 17 00:00:00 2001 From: chenshihai Date: Mon, 14 Nov 2022 16:40:12 +0800 Subject: [PATCH 1/7] =?UTF-8?q?#3180=20=E8=AE=AD=E7=BB=83=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=AF=A6=E6=83=85=E9=A1=B5=E6=B2=A1=E6=9C=89=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E4=BB=A3=E7=A0=81=E4=BB=93=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=8C=E5=8F=AA=E6=9C=89=E5=88=86=E6=94=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/repo/cloudbrain/inference/show.tmpl | 1 + templates/repo/cloudbrain/show.tmpl | 1 + templates/repo/cloudbrain/trainjob/show.tmpl | 1 + templates/repo/grampus/trainjob/show.tmpl | 1 + templates/repo/modelarts/inferencejob/show.tmpl | 1 + templates/repo/modelarts/trainjob/show.tmpl | 1 + templates/repo/modelsafety/show.tmpl | 1 + 7 files changed, 7 insertions(+) diff --git a/templates/repo/cloudbrain/inference/show.tmpl b/templates/repo/cloudbrain/inference/show.tmpl index 3154b8ac6..11ed2f0c5 100644 --- a/templates/repo/cloudbrain/inference/show.tmpl +++ b/templates/repo/cloudbrain/inference/show.tmpl @@ -446,6 +446,7 @@
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index cca85fb32..27c3cc556 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -337,6 +337,7 @@
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/cloudbrain/trainjob/show.tmpl b/templates/repo/cloudbrain/trainjob/show.tmpl index ab6c40ead..c06df57c2 100644 --- a/templates/repo/cloudbrain/trainjob/show.tmpl +++ b/templates/repo/cloudbrain/trainjob/show.tmpl @@ -412,6 +412,7 @@
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/grampus/trainjob/show.tmpl b/templates/repo/grampus/trainjob/show.tmpl index e8d4082f4..9d46a5256 100755 --- a/templates/repo/grampus/trainjob/show.tmpl +++ b/templates/repo/grampus/trainjob/show.tmpl @@ -422,6 +422,7 @@
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/modelarts/inferencejob/show.tmpl b/templates/repo/modelarts/inferencejob/show.tmpl index 29bd1aaf3..5fa07f067 100644 --- a/templates/repo/modelarts/inferencejob/show.tmpl +++ b/templates/repo/modelarts/inferencejob/show.tmpl @@ -388,6 +388,7 @@ td, th {
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/modelarts/trainjob/show.tmpl b/templates/repo/modelarts/trainjob/show.tmpl index d615f90a8..bbe2d52e7 100755 --- a/templates/repo/modelarts/trainjob/show.tmpl +++ b/templates/repo/modelarts/trainjob/show.tmpl @@ -442,6 +442,7 @@
{{.BranchName}} + {{SubStr .CommitID 0 10}}
diff --git a/templates/repo/modelsafety/show.tmpl b/templates/repo/modelsafety/show.tmpl index a46077443..2090441c9 100644 --- a/templates/repo/modelsafety/show.tmpl +++ b/templates/repo/modelsafety/show.tmpl @@ -833,6 +833,7 @@ $(`[vfield="Description"]`).text(res['Description'] || '--'); $(`[vfield="Parameters"]`).text(res['Parameters'] || '--'); + $(`[vfield="BranchName"]`).html(res['BranchName'] + '' + res['CommitID'].slice(0, 10) + ''); var imageName = res['Image'] || res['EngineName']; $(`[vimagetitle="Image"] span`).hide(); From 4be102021bfd556d1ce0218ad7e9d3babce3ef6b Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 16 Nov 2022 16:03:32 +0800 Subject: [PATCH 2/7] #3027 add repo watch notify type --- models/repo.go | 2 +- models/repo_watch.go | 33 ++++++++++++++++++++++++++++++--- modules/context/repo.go | 1 + routers/repo/repo.go | 4 +++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/models/repo.go b/models/repo.go index f0760108b..832e3fc37 100755 --- a/models/repo.go +++ b/models/repo.go @@ -1279,7 +1279,7 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, opts ...Cr } if setting.Service.AutoWatchNewRepos { - if err = watchRepo(ctx.e, doer.ID, repo.ID, true); err != nil { + if err = watchRepo(ctx.e, doer.ID, repo.ID, true, ReceiveAllNotification); err != nil { return fmt.Errorf("watchRepo: %v", err) } } diff --git a/models/repo_watch.go b/models/repo_watch.go index 573a2d78a..7c43ee352 100644 --- a/models/repo_watch.go +++ b/models/repo_watch.go @@ -24,6 +24,14 @@ const ( RepoWatchModeAuto // 3 ) +// NotifyType specifies what kind of watch the user has on a repository +type NotifyType int8 + +const ( + RejectAllNotification NotifyType = 0 + ReceiveAllNotification NotifyType = 9 +) + var ActionChan = make(chan *Action, 200) var ActionChan4Task = make(chan Action, 200) @@ -34,6 +42,7 @@ type Watch struct { RepoID int64 `xorm:"UNIQUE(watch)"` Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"` CreatedUnix int64 `xorm:"created"` + NotifyType NotifyType `xorm:"SMALLINT NOT NULL DEFAULT 0"` } // getWatch gets what kind of subscription a user has on a given repository; returns dummy record if none found @@ -60,8 +69,20 @@ func IsWatching(userID, repoID int64) bool { return err == nil && isWatchMode(watch.Mode) } +// GetWatchNotifyType +func GetWatchNotifyType(userID, repoID int64) NotifyType { + watch, err := getWatch(x, userID, repoID) + if err != nil { + return RejectAllNotification + } + return watch.NotifyType +} + func watchRepoMode(e Engine, watch Watch, mode RepoWatchMode) (err error) { if watch.Mode == mode { + if _, err := e.ID(watch.ID).Cols("notify_type").Update(watch); err != nil { + return err + } return nil } if mode == RepoWatchModeAuto && (watch.Mode == RepoWatchModeDont || isWatchMode(watch.Mode)) { @@ -109,7 +130,7 @@ func WatchRepoMode(userID, repoID int64, mode RepoWatchMode) (err error) { return watchRepoMode(x, watch, mode) } -func watchRepo(e Engine, userID, repoID int64, doWatch bool) (err error) { +func watchRepo(e Engine, userID, repoID int64, doWatch bool, notifyTypes ...NotifyType) (err error) { var watch Watch if watch, err = getWatch(e, userID, repoID); err != nil { return err @@ -119,14 +140,19 @@ func watchRepo(e Engine, userID, repoID int64, doWatch bool) (err error) { } else if !doWatch { err = watchRepoMode(e, watch, RepoWatchModeNone) } else { + notifyType := RejectAllNotification + if len(notifyTypes) > 0 { + notifyType = notifyTypes[0] + } + watch.NotifyType = notifyType err = watchRepoMode(e, watch, RepoWatchModeNormal) } return err } // WatchRepo watch or unwatch repository. -func WatchRepo(userID, repoID int64, watch bool) (err error) { - return watchRepo(x, userID, repoID, watch) +func WatchRepo(userID, repoID int64, watch bool, notifyType ...NotifyType) (err error) { + return watchRepo(x, userID, repoID, watch, notifyType...) } func getWatchers(e Engine, repoID int64) ([]*Watch, error) { @@ -156,6 +182,7 @@ func getRepoWatchersIDs(e Engine, repoID int64) ([]int64, error) { return ids, e.Table("watch"). Where("watch.repo_id=?", repoID). And("watch.mode<>?", RepoWatchModeDont). + And("watch.notify_type > ?", RejectAllNotification). Select("user_id"). Find(&ids) } diff --git a/modules/context/repo.go b/modules/context/repo.go index 7c425c8c0..3bdc34f0d 100755 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -474,6 +474,7 @@ func RepoAssignment() macaron.Handler { if ctx.IsSigned { ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.ID, repo.ID) + ctx.Data["WatchNotifyType"] = models.GetWatchNotifyType(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) diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 2c8c2f45b..4919b2487 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -414,7 +414,9 @@ func Action(ctx *context.Context) { var err error switch ctx.Params(":action") { case "watch": - err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) + err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true, models.ReceiveAllNotification) + case "watch_but_reject": + err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true, models.RejectAllNotification) case "unwatch": err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) case "star": From 39e63e9c8e13b9481226fcc3dff22ab253a6d424 Mon Sep 17 00:00:00 2001 From: chenshihai Date: Thu, 17 Nov 2022 11:21:06 +0800 Subject: [PATCH 3/7] =?UTF-8?q?#3027=20=E3=80=90=E6=98=93=E7=94=A8?= =?UTF-8?q?=E6=80=A7=E5=BB=BA=E8=AE=AE=E3=80=91=E5=85=B3=E4=BA=8E=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=98=93=E7=94=A8=E6=80=A7=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_en-US.ini | 5 +++++ options/locale/locale_zh-CN.ini | 5 +++++ templates/repo/header.tmpl | 45 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e8e8722e2..5a05b93be 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1392,6 +1392,11 @@ star = Star fork = Fork download_archive = Download Repository star_fail=Failed to %s the dataset. +watched=Watched +notWatched=Not watched +un_watch=Unwatch +watch_all=Watch all +watch_no_notify=Watch but not notify 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 d13c99443..de2155232 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1409,6 +1409,11 @@ star=点赞 fork=派生 download_archive=下载此项目 star_fail=%s失败。 +watched=已关注 +notWatched=未关注 +un_watch=不关注 +watch_all=关注所有动态 +watch_no_notify=关注但不提醒动态 no_desc=暂无描述 diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index cb83bebe7..465429975 100755 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -51,6 +51,49 @@ {{if not .IsBeingCreated}}
+
+
+ {{if $.IsWatchingRepo}}{{$.i18n.Tr "repo.watched"}}{{else}}{{$.i18n.Tr "repo.notWatched"}}{{end}} + +
+ + {{.NumWatches}} + +
+
{{$.CsrfTokenHtml}}
From b85d3d00f72b9105735a34a1c19acb912cc4e0e1 Mon Sep 17 00:00:00 2001 From: chenshihai Date: Thu, 17 Nov 2022 12:08:08 +0800 Subject: [PATCH 4/7] #3027 --- templates/repo/header.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 465429975..f501fafa4 100755 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -52,11 +52,11 @@ {{if not .IsBeingCreated}}
-
+
{{if $.IsWatchingRepo}}{{$.i18n.Tr "repo.watched"}}{{else}}{{$.i18n.Tr "repo.notWatched"}}{{end}} -