Add Discussion frontend
* Discussion 프론트엔드 기능 추가.. * remove verbose log
This commit is contained in:
parent
882144d133
commit
8f0af1d889
|
@ -36,6 +36,7 @@ type IssuesOptions struct { //nolint
|
||||||
ProjectBoardID int64
|
ProjectBoardID int64
|
||||||
IsClosed optional.Option[bool]
|
IsClosed optional.Option[bool]
|
||||||
IsPull optional.Option[bool]
|
IsPull optional.Option[bool]
|
||||||
|
IsDiscussion optional.Option[bool]
|
||||||
LabelIDs []int64
|
LabelIDs []int64
|
||||||
IncludedLabelNames []string
|
IncludedLabelNames []string
|
||||||
ExcludedLabelNames []string
|
ExcludedLabelNames []string
|
||||||
|
|
|
@ -10,12 +10,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOptions {
|
func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOptions {
|
||||||
|
|
||||||
searchOpt := &SearchOptions{
|
searchOpt := &SearchOptions{
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
RepoIDs: opts.RepoIDs,
|
RepoIDs: opts.RepoIDs,
|
||||||
AllPublic: opts.AllPublic,
|
AllPublic: opts.AllPublic,
|
||||||
IsPull: opts.IsPull,
|
IsPull: opts.IsPull,
|
||||||
IsClosed: opts.IsClosed,
|
IsDiscussion: opts.IsDiscussion,
|
||||||
|
IsClosed: opts.IsClosed,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.LabelIDs) == 1 && opts.LabelIDs[0] == 0 {
|
if len(opts.LabelIDs) == 1 && opts.LabelIDs[0] == 0 {
|
||||||
|
|
|
@ -79,8 +79,9 @@ type SearchOptions struct {
|
||||||
RepoIDs []int64 // repository IDs which the issues belong to
|
RepoIDs []int64 // repository IDs which the issues belong to
|
||||||
AllPublic bool // if include all public repositories
|
AllPublic bool // if include all public repositories
|
||||||
|
|
||||||
IsPull optional.Option[bool] // if the issues is a pull request
|
IsPull optional.Option[bool] // if the issues is a pull request
|
||||||
IsClosed optional.Option[bool] // if the issues is closed
|
IsDiscussion optional.Option[bool] // if the issues is a discussion
|
||||||
|
IsClosed optional.Option[bool] // if the issues is closed
|
||||||
|
|
||||||
IncludedLabelIDs []int64 // labels the issues have
|
IncludedLabelIDs []int64 // labels the issues have
|
||||||
ExcludedLabelIDs []int64 // labels the issues don't have
|
ExcludedLabelIDs []int64 // labels the issues don't have
|
||||||
|
|
|
@ -1214,6 +1214,7 @@ find_tag = Find tag
|
||||||
branches = Branches
|
branches = Branches
|
||||||
tags = Tags
|
tags = Tags
|
||||||
issues = Issues
|
issues = Issues
|
||||||
|
discussions=Discussions
|
||||||
pulls = Pull Requests
|
pulls = Pull Requests
|
||||||
project_board = Projects
|
project_board = Projects
|
||||||
packages = Packages
|
packages = Packages
|
||||||
|
|
|
@ -141,7 +141,17 @@ func MustAllowPulls(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption optional.Option[bool]) {
|
func MustAllowDiscussions(ctx *context.Context) {
|
||||||
|
// var repositoryId = ctx.Repo.Repository.ID
|
||||||
|
// TODO: check enable discussions && check enable Read
|
||||||
|
var check = true
|
||||||
|
if !check {
|
||||||
|
ctx.NotFound("MustAllowDiscussions", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption optional.Option[bool], isDiscussionOption optional.Option[bool]) {
|
||||||
var err error
|
var err error
|
||||||
viewType := ctx.FormString("type")
|
viewType := ctx.FormString("type")
|
||||||
sortType := ctx.FormString("sort")
|
sortType := ctx.FormString("sort")
|
||||||
|
@ -213,6 +223,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||||
ReviewRequestedID: reviewRequestedID,
|
ReviewRequestedID: reviewRequestedID,
|
||||||
ReviewedID: reviewedID,
|
ReviewedID: reviewedID,
|
||||||
IsPull: isPullOption,
|
IsPull: isPullOption,
|
||||||
|
IsDiscussion: isDiscussionOption,
|
||||||
IssueIDs: nil,
|
IssueIDs: nil,
|
||||||
}
|
}
|
||||||
if keyword != "" {
|
if keyword != "" {
|
||||||
|
@ -299,6 +310,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
IsClosed: isShowClosed,
|
IsClosed: isShowClosed,
|
||||||
IsPull: isPullOption,
|
IsPull: isPullOption,
|
||||||
|
IsDiscussion: isDiscussionOption,
|
||||||
LabelIDs: labelIDs,
|
LabelIDs: labelIDs,
|
||||||
SortType: sortType,
|
SortType: sortType,
|
||||||
})
|
})
|
||||||
|
@ -310,6 +322,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||||
ctx.Data["IssueIndexerUnavailable"] = true
|
ctx.Data["IssueIndexerUnavailable"] = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: GetIssuesByIDs를 디스커션도 조회하도록 만들기
|
||||||
issues, err = issues_model.GetIssuesByIDs(ctx, ids, true)
|
issues, err = issues_model.GetIssuesByIDs(ctx, ids, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetIssuesByIDs", err)
|
ctx.ServerError("GetIssuesByIDs", err)
|
||||||
|
@ -486,9 +500,19 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
||||||
}
|
}
|
||||||
|
|
||||||
func issueIDsFromSearch(ctx *context.Context, keyword string, opts *issues_model.IssuesOptions) ([]int64, error) {
|
func issueIDsFromSearch(ctx *context.Context, keyword string, opts *issues_model.IssuesOptions) ([]int64, error) {
|
||||||
ids, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts))
|
|
||||||
if err != nil {
|
var searchOptions = issue_indexer.ToSearchOptions(keyword, opts)
|
||||||
return nil, fmt.Errorf("SearchIssues: %w", err)
|
var ids []int64
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if !searchOptions.IsDiscussion.ValueOrDefault(false) {
|
||||||
|
ids, _, err = issue_indexer.SearchIssues(ctx, searchOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("SearchIssues: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ids = []int64{1, 2}
|
||||||
|
// TODO: 특정 레포지토리의 디스커션의 아이디들을 반환할수 있도록 로직 작성
|
||||||
}
|
}
|
||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
@ -496,14 +520,26 @@ func issueIDsFromSearch(ctx *context.Context, keyword string, opts *issues_model
|
||||||
// Issues render issues page
|
// Issues render issues page
|
||||||
func Issues(ctx *context.Context) {
|
func Issues(ctx *context.Context) {
|
||||||
isPullList := ctx.Params(":type") == "pulls"
|
isPullList := ctx.Params(":type") == "pulls"
|
||||||
|
isDiscussion := ctx.Params(":type") == "discussions"
|
||||||
|
|
||||||
if isPullList {
|
if isPullList {
|
||||||
|
// handle pull requests
|
||||||
MustAllowPulls(ctx)
|
MustAllowPulls(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["Title"] = ctx.Tr("repo.pulls")
|
ctx.Data["Title"] = ctx.Tr("repo.pulls")
|
||||||
ctx.Data["PageIsPullList"] = true
|
ctx.Data["PageIsPullList"] = true
|
||||||
|
} else if isDiscussion {
|
||||||
|
// handle discussions
|
||||||
|
MustAllowDiscussions(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Data["Title"] = ctx.Tr("repo.discussions")
|
||||||
|
ctx.Data["PageIsDiscussionList"] = true
|
||||||
} else {
|
} else {
|
||||||
|
// handle issuses
|
||||||
MustEnableIssues(ctx)
|
MustEnableIssues(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
|
@ -513,7 +549,7 @@ func Issues(ctx *context.Context) {
|
||||||
ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
issues(ctx, ctx.FormInt64("milestone"), ctx.FormInt64("project"), optional.Some(isPullList))
|
issues(ctx, ctx.FormInt64("milestone"), ctx.FormInt64("project"), optional.Some(isPullList), optional.Some(isDiscussion))
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = milestone.Name
|
ctx.Data["Title"] = milestone.Name
|
||||||
ctx.Data["Milestone"] = milestone
|
ctx.Data["Milestone"] = milestone
|
||||||
|
|
||||||
issues(ctx, milestoneID, projectID, optional.None[bool]())
|
issues(ctx, milestoneID, projectID, optional.None[bool](), optional.None[bool]())
|
||||||
|
|
||||||
ret := issue.ParseTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
ret := issue.ParseTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
||||||
ctx.Data["NewIssueChooseTemplate"] = len(ret.IssueTemplates) > 0
|
ctx.Data["NewIssueChooseTemplate"] = len(ret.IssueTemplates) > 0
|
||||||
|
|
|
@ -1162,7 +1162,7 @@ func registerRoutes(m *web.Route) {
|
||||||
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
|
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
|
||||||
|
|
||||||
m.Group("/{username}/{reponame}", func() {
|
m.Group("/{username}/{reponame}", func() {
|
||||||
m.Group("/{type:issues|pulls}", func() {
|
m.Group("/{type:issues|pulls|discussions}", func() {
|
||||||
m.Get("", repo.Issues)
|
m.Get("", repo.Issues)
|
||||||
m.Group("/{index}", func() {
|
m.Group("/{index}", func() {
|
||||||
m.Get("", repo.ViewIssue)
|
m.Get("", repo.ViewIssue)
|
||||||
|
|
|
@ -152,6 +152,11 @@
|
||||||
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues"}}
|
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues"}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<!-- discussions -->
|
||||||
|
<a class="{{if .PageIsDiscussionList}}active {{end}}item" href="{{.RepoLink}}/discussions" >
|
||||||
|
{{ svg "octicon-comment-discussion" }} {{ctx.Locale.Tr "repo.discussions"}}
|
||||||
|
</a>
|
||||||
|
|
||||||
{{if and .Repository.CanEnablePulls (.Permission.CanRead ctx.Consts.RepoUnitTypePullRequests)}}
|
{{if and .Repository.CanEnablePulls (.Permission.CanRead ctx.Consts.RepoUnitTypePullRequests)}}
|
||||||
<a class="{{if .PageIsPullList}}active {{end}}item" href="{{.RepoLink}}/pulls">
|
<a class="{{if .PageIsPullList}}active {{end}}item" href="{{.RepoLink}}/pulls">
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
{{svg "octicon-milestone" 16 "tw-mr-2"}}
|
{{svg "octicon-milestone" 16 "tw-mr-2"}}
|
||||||
{{else if .PageIsPullList}}
|
{{else if .PageIsPullList}}
|
||||||
{{svg "octicon-git-pull-request" 16 "tw-mr-2"}}
|
{{svg "octicon-git-pull-request" 16 "tw-mr-2"}}
|
||||||
|
{{else if .PageIsDiscussionList}}
|
||||||
|
{{svg "octicon-comment-discussion" 16 "tw-mr-2"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{svg "octicon-issue-opened" 16 "tw-mr-2"}}
|
{{svg "octicon-issue-opened" 16 "tw-mr-2"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user