func ChangeCollaborationAccessMode(ctx *context.Context) { if err := ctx.Repo.Repository.ChangeCollaborationAccessMode( ctx.QueryInt64("uid"), models.AccessMode(ctx.QueryInt("mode"))); err != nil { log.Error(4, "ChangeCollaborationAccessMode: %v", err) } }
func Commits(ctx *context.Context) { ctx.Data["PageIsCommits"] = true commitsCount, err := ctx.Repo.Commit.CommitsCount() if err != nil { ctx.Handle(500, "GetCommitsCount", err) return } page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5) // Both `git log branchName` and `git log commitId` work. commits, err := ctx.Repo.Commit.CommitsByRange(page) if err != nil { ctx.Handle(500, "CommitsByRange", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commitsCount ctx.Data["Branch"] = ctx.Repo.BranchName ctx.HTML(200, COMMITS) }
func showOrgProfile(ctx *context.Context) { ctx.SetParams(":org", ctx.Params(":username")) context.HandleOrgAssignment(ctx) if ctx.Written() { return } org := ctx.Org.Organization ctx.Data["Title"] = org.FullName page := ctx.QueryInt("page") if page <= 0 { page = 1 } var ( repos []*models.Repository count int64 err error ) if ctx.IsSigned && !ctx.User.IsAdmin { repos, count, err = org.GetUserRepositories(ctx.User.ID, page, setting.UI.User.RepoPagingNum) if err != nil { ctx.Handle(500, "GetUserRepositories", err) return } ctx.Data["Repos"] = repos } else { showPrivate := ctx.IsSigned && ctx.User.IsAdmin repos, err = models.GetUserRepositories(org.ID, showPrivate, page, setting.UI.User.RepoPagingNum) if err != nil { ctx.Handle(500, "GetRepositories", err) return } ctx.Data["Repos"] = repos count = models.CountUserRepositories(org.ID, showPrivate) } ctx.Data["Page"] = paginater.New(int(count), setting.UI.User.RepoPagingNum, page, 5) if err := org.GetMembers(); err != nil { ctx.Handle(500, "GetMembers", err) return } ctx.Data["Members"] = org.Members ctx.Data["Teams"] = org.Teams ctx.HTML(200, ORG_HOME) }
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { page := ctx.QueryInt("page") if page <= 0 { page = 1 } var ( repos []*models.Repository count int64 err error ) keyword := ctx.Query("q") if len(keyword) == 0 { repos, err = opts.Ranger(page, opts.PageSize) if err != nil { ctx.Handle(500, "opts.Ranger", err) return } count = opts.Counter(opts.Private) } else { repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ Keyword: keyword, OrderBy: opts.OrderBy, Private: opts.Private, Page: page, PageSize: opts.PageSize, }) if err != nil { ctx.Handle(500, "SearchRepositoryByName", err) return } } ctx.Data["Keyword"] = keyword ctx.Data["Total"] = count ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) for _, repo := range repos { if err = repo.GetOwner(); err != nil { ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err)) return } } ctx.Data["Repos"] = repos ctx.HTML(200, opts.TplName) }
func RenderUserCards(ctx *context.Context, total int, getter func(page int) ([]*models.User, error), tpl base.TplName) { page := ctx.QueryInt("page") if page <= 0 { page = 1 } pager := paginater.New(total, models.ItemsPerPage, page, 5) ctx.Data["Page"] = pager items, err := getter(pager.Current()) if err != nil { ctx.Handle(500, "getter", err) return } ctx.Data["Cards"] = items ctx.HTML(200, tpl) }
func FileHistory(ctx *context.Context) { ctx.Data["IsRepoToolbarCommits"] = true fileName := ctx.Repo.TreePath if len(fileName) == 0 { Commits(ctx) return } branchName := ctx.Repo.BranchName commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) if err != nil { ctx.Handle(500, "FileCommitsCount", err) return } else if commitsCount == 0 { ctx.Handle(404, "FileCommitsCount", nil) return } page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5) commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page) if err != nil { ctx.Handle(500, "CommitsByFileAndRange", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["FileName"] = fileName ctx.Data["CommitCount"] = commitsCount ctx.Data["Branch"] = branchName ctx.HTML(200, COMMITS) }
func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { page := ctx.QueryInt("page") if page <= 1 { page = 1 } var ( users []*models.User count int64 err error ) keyword := ctx.Query("q") if len(keyword) == 0 { users, err = opts.Ranger(page, opts.PageSize) if err != nil { ctx.Handle(500, "opts.Ranger", err) return } count = opts.Counter() } else { users, count, err = models.SearchUserByName(&models.SearchUserOptions{ Keyword: keyword, Type: opts.Type, OrderBy: opts.OrderBy, Page: page, PageSize: opts.PageSize, }) if err != nil { ctx.Handle(500, "SearchUserByName", err) return } } ctx.Data["Keyword"] = keyword ctx.Data["Total"] = count ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) ctx.Data["Users"] = users ctx.HTML(200, opts.TplName) }
func Notices(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.notices") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminNotices"] = true total := models.CountNotices() page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(total), setting.UI.Admin.NoticePagingNum, page, 5) notices, err := models.Notices(page, setting.UI.Admin.NoticePagingNum) if err != nil { ctx.Handle(500, "Notices", err) return } ctx.Data["Notices"] = notices ctx.Data["Total"] = total ctx.HTML(200, NOTICES) }
func Issues(ctx *context.Context) { isPullList := ctx.Params(":type") == "pulls" if isPullList { ctx.Data["Title"] = ctx.Tr("pull_requests") ctx.Data["PageIsPulls"] = true } else { ctx.Data["Title"] = ctx.Tr("issues") ctx.Data["PageIsIssues"] = true } ctxUser := getDashboardContextUser(ctx) if ctx.Written() { return } // Organization does not have view type and filter mode. var ( viewType string sortType = ctx.Query("sort") filterMode = models.FM_ALL assigneeID int64 posterID int64 ) if ctxUser.IsOrganization() { viewType = "all" } else { viewType = ctx.Query("type") types := []string{"assigned", "created_by"} if !com.IsSliceContainsStr(types, viewType) { viewType = "all" } switch viewType { case "assigned": filterMode = models.FM_ASSIGN assigneeID = ctxUser.ID case "created_by": filterMode = models.FM_CREATE posterID = ctxUser.ID } } repoID := ctx.QueryInt64("repo") isShowClosed := ctx.Query("state") == "closed" // Get repositories. var err error var repos []*models.Repository if ctxUser.IsOrganization() { repos, _, err = ctxUser.GetUserRepositories(ctx.User.ID, 1, ctxUser.NumRepos) if err != nil { ctx.Handle(500, "GetRepositories", err) return } } else { if err := ctxUser.GetRepositories(1, ctx.User.NumRepos); err != nil { ctx.Handle(500, "GetRepositories", err) return } repos = ctxUser.Repos } allCount := 0 repoIDs := make([]int64, 0, len(repos)) showRepos := make([]*models.Repository, 0, len(repos)) for _, repo := range repos { if (isPullList && repo.NumPulls == 0) || (!isPullList && (!repo.EnableIssues || repo.EnableExternalTracker || repo.NumIssues == 0)) { continue } repoIDs = append(repoIDs, repo.ID) if isPullList { allCount += repo.NumOpenPulls repo.NumOpenIssues = repo.NumOpenPulls repo.NumClosedIssues = repo.NumClosedPulls } else { allCount += repo.NumOpenIssues } if filterMode != models.FM_ALL { // Calculate repository issue count with filter mode. numOpen, numClosed := repo.IssueStats(ctxUser.ID, filterMode, isPullList) repo.NumOpenIssues, repo.NumClosedIssues = int(numOpen), int(numClosed) } if repo.ID == repoID || (isShowClosed && repo.NumClosedIssues > 0) || (!isShowClosed && repo.NumOpenIssues > 0) { showRepos = append(showRepos, repo) } } ctx.Data["Repos"] = showRepos issueStats := models.GetUserIssueStats(repoID, ctxUser.ID, repoIDs, filterMode, isPullList) issueStats.AllCount = int64(allCount) page := ctx.QueryInt("page") if page <= 1 { page = 1 } var total int if !isShowClosed { total = int(issueStats.OpenCount) } else { total = int(issueStats.ClosedCount) } ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5) // Get issues. issues, err := models.Issues(&models.IssuesOptions{ UserID: ctxUser.ID, AssigneeID: assigneeID, RepoID: repoID, PosterID: posterID, RepoIDs: repoIDs, Page: page, IsClosed: isShowClosed, IsPull: isPullList, SortType: sortType, }) if err != nil { ctx.Handle(500, "Issues", err) return } // Get posters and repository. for i := range issues { issues[i].Repo, err = models.GetRepositoryByID(issues[i].RepoID) if err != nil { ctx.Handle(500, "GetRepositoryByID", fmt.Errorf("[#%d]%v", issues[i].ID, err)) return } if err = issues[i].Repo.GetOwner(); err != nil { ctx.Handle(500, "GetOwner", fmt.Errorf("[#%d]%v", issues[i].ID, err)) return } } ctx.Data["Issues"] = issues ctx.Data["IssueStats"] = issueStats ctx.Data["ViewType"] = viewType ctx.Data["SortType"] = sortType ctx.Data["RepoID"] = repoID ctx.Data["IsShowClosed"] = isShowClosed if isShowClosed { ctx.Data["State"] = "closed" } else { ctx.Data["State"] = "open" } ctx.HTML(200, ISSUES) }