Skip to content

Commit 12fe44c

Browse files
committed
Use repository headers extension point instead of sidemenus
1 parent ab24a72 commit 12fe44c

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/main/scala/Plugin.scala

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import gitbucket.core.controller.Context
22
import gitbucket.core.model.Issue
3-
import gitbucket.core.plugin.Link
3+
import gitbucket.core.service.{AccountService, IssuesService, RepositoryService}
44
import gitbucket.core.service.RepositoryService.RepositoryInfo
55
import gitbucket.core.util.Implicits.request2Session
66
import gitbucket.notifications._
7+
import gitbucket.notifications.model.Watch
8+
import gitbucket.notifications.service.NotificationsService
79
import io.github.gitbucket.solidbase.migration.LiquibaseMigration
810
import io.github.gitbucket.solidbase.model.Version
911

10-
class Plugin extends gitbucket.core.plugin.Plugin {
12+
class Plugin extends gitbucket.core.plugin.Plugin
13+
with NotificationsService with RepositoryService with AccountService with IssuesService {
1114

1215
override val pluginId = "notifications"
1316

@@ -30,14 +33,16 @@ class Plugin extends gitbucket.core.plugin.Plugin {
3033
override val issueHooks = Seq(new service.IssueHook)
3134
override val pullRequestHooks = Seq(new service.PullRequestHook)
3235

33-
override val repositoryMenus = Seq(
34-
(repository: RepositoryInfo, context: Context) =>
35-
Some(Link(
36-
id = "watch",
37-
label = "Watch",
38-
path = "/watch",
39-
icon = Some("menu-icon octicon octicon-eye")
40-
))
36+
override val repositoryHeaders = Seq(
37+
(repository: RepositoryInfo, context: Context) => {
38+
context.loginAccount.map { loginAccount =>
39+
implicit val session = request2Session(context.request)
40+
41+
html.watch(getWatch(repository.owner, repository.name, loginAccount.userName).map(_.notification) getOrElse {
42+
if (autoSubscribeUsersForRepository(repository.owner, repository.name) contains loginAccount.userName) Watch.Watching else Watch.NotWatching
43+
}, repository)(context)
44+
}
45+
}
4146
)
4247

4348
override val issueSidebars = Seq(

src/main/twirl/gitbucket/notifications/watch.scala.html

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
@(notification: gitbucket.notifications.model.Watch.Notification,
22
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
33
@import gitbucket.core.view.helpers
4-
@gitbucket.core.html.main("Watch", Some(repository)){
5-
@gitbucket.core.html.menu("watch", repository){
6-
7-
@gitbucket.core.helper.html.dropdown("Notifications"){
8-
@gitbucket.notifications.model.Watch.Notification.values.map { n =>
9-
<li>
10-
<a href="#" class="watch" data-id="@n.id">
11-
@gitbucket.core.helper.html.checkicon(notification.id == n.id) @n.name
12-
</a>
13-
</li>
14-
}
15-
}
16-
4+
@gitbucket.core.helper.html.dropdown("Notifications"){
5+
@gitbucket.notifications.model.Watch.Notification.values.map { n =>
6+
<li>
7+
<a href="#" class="watch" data-id="@n.id">
8+
@gitbucket.core.helper.html.checkicon(notification.id == n.id) @n.name
9+
</a>
10+
</li>
1711
}
1812
}
1913
<script>

0 commit comments

Comments
 (0)