Skip to content

Commit

Permalink
make multi selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Dec 14, 2019
1 parent 3220b65 commit eb674fc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 49 deletions.
87 changes: 51 additions & 36 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func Milestones(ctx *context.Context) {
page = 1
}

repoID := ctx.QueryInt64("repo")
reposQuery := ctx.Query("repos")
isShowClosed := ctx.Query("state") == "closed"

// Get repositories.
Expand Down Expand Up @@ -199,17 +199,34 @@ func Milestones(ctx *context.Context) {
}

var repoIDs []int64
if repoID > 0 {
repoIDs = []int64{repoID}
if !com.IsSliceContainsInt64(userRepoIDs, repoID) {
if issueReposQueryPattern.MatchString(reposQuery) {
// remove "[" and "]" from string
reposQuery = reposQuery[1 : len(reposQuery)-1]
//for each ID (delimiter ",") add to int to repoIDs
reposSet := false
for _, rID := range strings.Split(reposQuery, ",") {
// Ensure nonempty string entries
if rID != "" && rID != "0" {
reposSet = true
rIDint64, err := strconv.ParseInt(rID, 10, 64)
if err == nil && com.IsSliceContainsInt64(userRepoIDs, rIDint64) {
repoIDs = append(repoIDs, rIDint64)
}
}
}
if reposSet && len(repoIDs) == 0 {
// force an empty result
repoIDs = []int64{-1}
}
} else {
log.Error("issueReposQueryPattern not match with query")
}

if len(repoIDs) == 0 {
repoIDs = userRepoIDs
}

counts, err := models.CountMilestonesByRepoIDs(repoIDs, isShowClosed)
counts, err := models.CountMilestonesByRepoIDs(userRepoIDs, isShowClosed)
if err != nil {
ctx.ServerError("CountMilestonesByRepoIDs", err)
return
Expand All @@ -222,36 +239,29 @@ func Milestones(ctx *context.Context) {
}

showReposMap := make(map[int64]*models.Repository, len(counts))
for repoID := range counts {
repo, err := models.GetRepositoryByID(repoID)
if err != nil {
ctx.ServerError("GetRepositoryByID", err)
return
for rID := range counts {
if rID == -1 {
break
}
showReposMap[repoID] = repo
}

if repoID > 0 {
if _, ok := showReposMap[repoID]; !ok {
repo, err := models.GetRepositoryByID(repoID)
repo, err := models.GetRepositoryByID(rID)
if err != nil {
if models.IsErrRepoNotExist(err) {
ctx.NotFound("GetRepositoryByID", err)
return
} else if err != nil {
ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err))
ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", rID, err))
return
}
showReposMap[repoID] = repo
}

repo := showReposMap[repoID]
showReposMap[rID] = repo

// Check if user has access to given repository.
perm, err := models.GetUserRepoPermission(repo, ctxUser)
if err != nil {
ctx.ServerError("GetUserRepoPermission", fmt.Errorf("[%d]%v", repoID, err))
ctx.ServerError("GetUserRepoPermission", fmt.Errorf("[%d]%v", rID, err))
return
}

if !perm.CanRead(models.UnitTypeIssues) {
if log.IsTrace() {
log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
Expand Down Expand Up @@ -285,36 +295,41 @@ func Milestones(ctx *context.Context) {
}
}

milestoneStats, err := models.GetMilestonesStats(userRepoIDs)
milestoneStats, err := models.GetMilestonesStats(repoIDs)
if err != nil {
ctx.ServerError("GetMilestoneStats", err)
return
}

var total int
if !isShowClosed {
total = int(milestoneStats.OpenCount)
totalMilestoneStats, err := models.GetMilestonesStats(userRepoIDs)
if err != nil {
ctx.ServerError("GetMilestoneStats", err)
return
}

var pagerCount int
if isShowClosed {
ctx.Data["State"] = "closed"
ctx.Data["Total"] = totalMilestoneStats.ClosedCount
pagerCount = int(milestoneStats.ClosedCount)
} else {
total = int(milestoneStats.ClosedCount)
ctx.Data["State"] = "open"
ctx.Data["Total"] = totalMilestoneStats.OpenCount
pagerCount = int(milestoneStats.OpenCount)
}

ctx.Data["Milestones"] = milestones
ctx.Data["Repos"] = showRepos
ctx.Data["Counts"] = counts
ctx.Data["MilestoneStats"] = milestoneStats
ctx.Data["Total"] = total
ctx.Data["SortType"] = sortType
ctx.Data["RepoID"] = repoID
ctx.Data["IsShowClosed"] = isShowClosed

if isShowClosed {
ctx.Data["State"] = "closed"
} else {
ctx.Data["State"] = "open"
if len(repoIDs) != len(userRepoIDs) {
ctx.Data["RepoIDs"] = repoIDs
}
ctx.Data["IsShowClosed"] = isShowClosed

pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5)
pager.AddParam(ctx, "repo", "RepoID")
pager := context.NewPagination(pagerCount, setting.UI.IssuePagingNum, page, 5)
pager.AddParam(ctx, "repos", "RepoIDs")
pager.AddParam(ctx, "sort", "SortType")
pager.AddParam(ctx, "state", "State")
ctx.Data["Page"] = pager
Expand Down
41 changes: 28 additions & 13 deletions templates/user/dashboard/milestones.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,35 @@
</a>
<div class="ui divider"></div>
{{range .Repos}}
<a class="{{if eq $.RepoID .ID}}ui basic blue button{{end}} repo name item" href="{{$.Link}}?sort={{$.SortType}}{{if not (eq $.RepoID .ID)}}&repo={{.ID}}{{end}}&state={{$.State}}" title="{{.FullName}}">
<span class="text truncate">{{.FullName}}</span>
<div class="floating ui {{if $.IsShowClosed}}red{{else}}green{{end}} label">{{index $.Counts .ID}}</div>
</a>
{{with $Repo := .}}
<a class="{{range $.RepoIDs}}{{if eq . $Repo.ID}}ui basic blue button{{end}}{{end}} repo name item" href="{{$.Link}}?repos=[
{{with $include := true}}
{{range $.RepoIDs}}
{{if eq . $Repo.ID}}
{{$include = false}}
{{else}}
{{.}}%2C
{{end}}
{{end}}
{{if eq $include true}}
{{$Repo.ID}}%2C
{{end}}
{{end}}
]&sort={{$.SortType}}&state={{$.State}}" title="{{.FullName}}">
<span class="text truncate">{{$Repo.FullName}}</span>
<div class="floating ui {{if $.IsShowClosed}}red{{else}}green{{end}} label">{{index $.Counts $Repo.ID}}</div>
</a>
{{end}}
{{end}}
</div>
</div>
<div class="twelve wide column content">
<div class="ui tiny basic status buttons">
<a class="ui {{if not .IsShowClosed}}green active{{end}} basic button" href="{{.Link}}?repo={{.RepoID}}&sort={{$.SortType}}&state=open">
<a class="ui {{if not .IsShowClosed}}green active{{end}} basic button" href="{{.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort={{$.SortType}}&state=open">
<i class="octicon octicon-issue-opened"></i>
{{.i18n.Tr "repo.milestones.open_tab" .MilestoneStats.OpenCount}}
</a>
<a class="ui {{if .IsShowClosed}}red active{{end}} basic button" href="{{.Link}}?repo={{.RepoID}}&sort={{$.SortType}}&state=closed">
<a class="ui {{if .IsShowClosed}}red active{{end}} basic button" href="{{.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort={{$.SortType}}&state=closed">
<i class="octicon octicon-issue-closed"></i>
{{.i18n.Tr "repo.milestones.close_tab" .MilestoneStats.ClosedCount}}
</a>
Expand All @@ -37,20 +52,20 @@
<i class="dropdown icon"></i>
</span>
<div class="menu">
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=closestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.closest_due_date"}}</a>
<a class="{{if eq .SortType "furthestduedate"}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=furthestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.furthest_due_date"}}</a>
<a class="{{if eq .SortType "leastcomplete"}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=leastcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_complete"}}</a>
<a class="{{if eq .SortType "mostcomplete"}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=mostcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_complete"}}</a>
<a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a>
<a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?repo={{.RepoID}}&sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a>
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=closestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.closest_due_date"}}</a>
<a class="{{if eq .SortType "furthestduedate"}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=furthestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.furthest_due_date"}}</a>
<a class="{{if eq .SortType "leastcomplete"}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=leastcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_complete"}}</a>
<a class="{{if eq .SortType "mostcomplete"}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=mostcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_complete"}}</a>
<a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a>
<a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a>
</div>
</div>
</div>

<div class="milestone list">
{{range .Milestones}}
<li class="item">
<div class="ui label">{{if not $.RepoID}}{{.Repo.FullName}}{{end}}</div>
<div class="ui label">{{if not $.RepoIDs}}{{.Repo.FullName}}{{end}}</div>
<i class="octicon octicon-milestone"></i> <a href="{{.Repo.Link }}/milestone/{{.ID}}">{{.Name}}</a>
<div class="ui right green progress" data-percent="{{.Completeness}}">
<div class="bar" {{if not .Completeness}}style="background-color: transparent"{{end}}>
Expand Down

0 comments on commit eb674fc

Please sign in to comment.