コード例 #1
0
ファイル: issue.go プロジェクト: JREAMLU/gogs
func Issues(ctx *middleware.Context) {
	ctx.Data["Title"] = "Issues"
	ctx.Data["IsRepoToolbarIssues"] = true
	ctx.Data["IsRepoToolbarIssuesList"] = true
	ctx.Data["ViewType"] = "all"

	milestoneId, _ := base.StrTo(ctx.Query("milestone")).Int()
	page, _ := base.StrTo(ctx.Query("page")).Int()

	ctx.Data["IssueCreatedCount"] = 0

	var posterId int64 = 0
	if ctx.Query("type") == "created_by" {
		if !ctx.IsSigned {
			ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
			ctx.Redirect("/user/login/", 302)
			return
		}
		ctx.Data["ViewType"] = "created_by"
	}

	// Get issues.
	issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, posterId, int64(milestoneId), page,
		ctx.Query("state") == "closed", false, ctx.Query("labels"), ctx.Query("sortType"))
	if err != nil {
		ctx.Handle(200, "issue.Issues: %v", err)
		return
	}

	if ctx.IsSigned {
		posterId = ctx.User.Id
	}
	var createdByCount int

	// Get posters.
	for i := range issues {
		u, err := models.GetUserById(issues[i].PosterId)
		if err != nil {
			ctx.Handle(200, "issue.Issues(get poster): %v", err)
			return
		}
		issues[i].Poster = u
		if u.Id == posterId {
			createdByCount++
		}
	}

	ctx.Data["Issues"] = issues
	ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues
	ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues
	ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues
	ctx.Data["IssueCreatedCount"] = createdByCount
	ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed"
	ctx.HTML(200, "issue/list")
}
コード例 #2
0
ファイル: issue.go プロジェクト: josephyzhou/gogs
func Issues(ctx *middleware.Context, params martini.Params) {
	ctx.Data["Title"] = "Issues"
	ctx.Data["IsRepoToolbarIssues"] = true

	milestoneId, _ := base.StrTo(params["milestone"]).Int()
	page, _ := base.StrTo(params["page"]).Int()

	var err error
	ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0,
		int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"])
	if err != nil {
		ctx.Handle(200, "issue.Issues: %v", err)
		return
	}

	if len(params["branchname"]) == 0 {
		params["branchname"] = "master"
	}
	ctx.Data["Branchname"] = params["branchname"]
	ctx.HTML(200, "repo/issues")
}
コード例 #3
0
ファイル: issue.go プロジェクト: swallowcamel/gogs
func Issues(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("repo.issues")
	ctx.Data["PageIsIssueList"] = true

	viewType := ctx.Query("type")
	types := []string{"assigned", "created_by", "mentioned"}
	if !com.IsSliceContainsStr(types, viewType) {
		viewType = "all"
	}

	isShowClosed := ctx.Query("state") == "closed"

	// Must sign in to see issues about you.
	if viewType != "all" && !ctx.IsSigned {
		ctx.SetCookie("redirect_to", "/"+url.QueryEscape(setting.AppSubUrl+ctx.Req.RequestURI), 0, setting.AppSubUrl)
		ctx.Redirect(setting.AppSubUrl + "/user/login")
		return
	}

	var assigneeID, posterID int64
	filterMode := models.FM_ALL
	switch viewType {
	case "assigned":
		assigneeID = ctx.User.Id
		filterMode = models.FM_ASSIGN
	case "created_by":
		posterID = ctx.User.Id
		filterMode = models.FM_CREATE
	case "mentioned":
		filterMode = models.FM_MENTION
	}

	var uid int64 = -1
	if ctx.IsSigned {
		uid = ctx.User.Id
	}

	repo := ctx.Repo.Repository
	selectLabels := ctx.Query("labels")
	milestoneID := ctx.QueryInt64("milestone")
	issueStats := models.GetIssueStats(repo.Id, uid, com.StrTo(selectLabels).MustInt64(), isShowClosed, filterMode)

	page := ctx.QueryInt("page")
	if page <= 1 {
		page = 1
	} else {
		ctx.Data["PreviousPage"] = page - 1
	}
	if (!isShowClosed && int(issueStats.OpenCount) > setting.IssuePagingNum*page) ||
		(isShowClosed && int(issueStats.ClosedCount) > setting.IssuePagingNum*page) {
		ctx.Data["NextPage"] = page + 1
	}

	// Get issues.
	issues, err := models.GetIssues(uid, assigneeID, repo.Id, posterID, milestoneID,
		page, isShowClosed, filterMode == models.FM_MENTION, selectLabels, ctx.Query("sortType"))
	if err != nil {
		ctx.Handle(500, "GetIssues: %v", err)
		return
	}

	// Get issue-user pairs.
	pairs, err := models.GetIssueUserPairs(repo.Id, posterID, isShowClosed)
	if err != nil {
		ctx.Handle(500, "GetIssueUserPairs: %v", err)
		return
	}

	// Get posters.
	for i := range issues {
		if err = issues[i].GetPoster(); err != nil {
			ctx.Handle(500, "GetPoster", fmt.Errorf("[#%d]%v", issues[i].ID, err))
			return
		}

		if err = issues[i].GetLabels(); err != nil {
			ctx.Handle(500, "GetLabels", fmt.Errorf("[#%d]%v", issues[i].ID, err))
			return
		}

		if !ctx.IsSigned {
			issues[i].IsRead = true
			continue
		}

		// Check read status.
		idx := models.PairsContains(pairs, issues[i].ID, ctx.User.Id)
		if idx > -1 {
			issues[i].IsRead = pairs[idx].IsRead
		} else {
			issues[i].IsRead = true
		}
	}

	ctx.Data["IssueStats"] = issueStats
	ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64()
	ctx.Data["ViewType"] = viewType
	ctx.Data["Issues"] = issues
	ctx.Data["IsShowClosed"] = isShowClosed
	if isShowClosed {
		ctx.Data["State"] = "closed"
		ctx.Data["ShowCount"] = issueStats.ClosedCount
	} else {
		ctx.Data["State"] = "open"
		ctx.Data["ShowCount"] = issueStats.OpenCount
	}

	ctx.HTML(200, ISSUES)
}
コード例 #4
0
ファイル: issue.go プロジェクト: JustStone/gogs
func Issues(ctx *middleware.Context) {
	ctx.Data["Title"] = "Issues"
	ctx.Data["IsRepoToolbarIssues"] = true
	ctx.Data["IsRepoToolbarIssuesList"] = true

	viewType := ctx.Query("type")
	types := []string{"assigned", "created_by", "mentioned"}
	if !com.IsSliceContainsStr(types, viewType) {
		viewType = "all"
	}

	isShowClosed := ctx.Query("state") == "closed"

	if viewType != "all" && !ctx.IsSigned {
		ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
		ctx.Redirect("/user/login")
		return
	}

	var assigneeId, posterId int64
	var filterMode int
	switch viewType {
	case "assigned":
		assigneeId = ctx.User.Id
		filterMode = models.FM_ASSIGN
	case "created_by":
		posterId = ctx.User.Id
		filterMode = models.FM_CREATE
	case "mentioned":
		filterMode = models.FM_MENTION
	}

	var mid int64
	midx, _ := base.StrTo(ctx.Query("milestone")).Int64()
	if midx > 0 {
		mile, err := models.GetMilestoneByIndex(ctx.Repo.Repository.Id, midx)
		if err != nil {
			ctx.Handle(500, "issue.Issues(GetMilestoneByIndex): %v", err)
			return
		}
		mid = mile.Id
	}

	selectLabels := ctx.Query("labels")
	labels, err := models.GetLabels(ctx.Repo.Repository.Id)
	if err != nil {
		ctx.Handle(500, "issue.Issues(GetLabels): %v", err)
		return
	}
	for _, l := range labels {
		l.CalOpenIssues()
	}
	ctx.Data["Labels"] = labels

	page, _ := base.StrTo(ctx.Query("page")).Int()

	// Get issues.
	issues, err := models.GetIssues(assigneeId, ctx.Repo.Repository.Id, posterId, mid, page,
		isShowClosed, selectLabels, ctx.Query("sortType"))
	if err != nil {
		ctx.Handle(500, "issue.Issues(GetIssues): %v", err)
		return
	}

	// Get issue-user pairs.
	pairs, err := models.GetIssueUserPairs(ctx.Repo.Repository.Id, posterId, isShowClosed)
	if err != nil {
		ctx.Handle(500, "issue.Issues(GetIssueUserPairs): %v", err)
		return
	}

	// Get posters.
	for i := range issues {
		if err = issues[i].GetLabels(); err != nil {
			ctx.Handle(500, "issue.Issues(GetLabels)", fmt.Errorf("[#%d]%v", issues[i].Id, err))
			return
		}

		idx := models.PairsContains(pairs, issues[i].Id)

		if filterMode == models.FM_MENTION && (idx == -1 || !pairs[idx].IsMentioned) {
			continue
		}

		if idx > -1 {
			issues[i].IsRead = pairs[idx].IsRead
		} else {
			issues[i].IsRead = true
		}

		if err = issues[i].GetPoster(); err != nil {
			ctx.Handle(500, "issue.Issues(GetPoster)", fmt.Errorf("[#%d]%v", issues[i].Id, err))
			return
		}
	}

	var uid int64 = -1
	if ctx.User != nil {
		uid = ctx.User.Id
	}
	issueStats := models.GetIssueStats(ctx.Repo.Repository.Id, uid, isShowClosed, filterMode)
	ctx.Data["IssueStats"] = issueStats
	ctx.Data["SelectLabels"], _ = base.StrTo(selectLabels).Int64()
	ctx.Data["ViewType"] = viewType
	ctx.Data["Issues"] = issues
	ctx.Data["IsShowClosed"] = isShowClosed
	if isShowClosed {
		ctx.Data["State"] = "closed"
		ctx.Data["ShowCount"] = issueStats.ClosedCount
	} else {
		ctx.Data["ShowCount"] = issueStats.OpenCount
	}
	ctx.HTML(200, ISSUES)
}
コード例 #5
0
ファイル: user.go プロジェクト: JREAMLU/gogs
func Issues(ctx *middleware.Context) {
	ctx.Data["Title"] = "Your Issues"
	ctx.Data["ViewType"] = "all"

	page, _ := base.StrTo(ctx.Query("page")).Int()
	repoId, _ := base.StrTo(ctx.Query("repoid")).Int64()

	ctx.Data["RepoId"] = repoId

	var posterId int64 = 0
	if ctx.Query("type") == "created_by" {
		posterId = ctx.User.Id
		ctx.Data["ViewType"] = "created_by"
	}

	// Get all repositories.
	repos, err := models.GetRepositories(ctx.User)
	if err != nil {
		ctx.Handle(200, "user.Issues(get repositories)", err)
		return
	}

	showRepos := make([]models.Repository, 0, len(repos))

	isShowClosed := ctx.Query("state") == "closed"
	var closedIssueCount, createdByCount, allIssueCount int

	// Get all issues.
	allIssues := make([]models.Issue, 0, 5*len(repos))
	for i, repo := range repos {
		issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, false, "", "")
		if err != nil {
			ctx.Handle(200, "user.Issues(get issues)", err)
			return
		}

		allIssueCount += repo.NumIssues
		closedIssueCount += repo.NumClosedIssues

		// Set repository information to issues.
		for j := range issues {
			issues[j].Repo = &repos[i]
		}
		allIssues = append(allIssues, issues...)

		repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
		if repos[i].NumOpenIssues > 0 {
			showRepos = append(showRepos, repos[i])
		}
	}

	showIssues := make([]models.Issue, 0, len(allIssues))
	ctx.Data["IsShowClosed"] = isShowClosed

	// Get posters and filter issues.
	for i := range allIssues {
		u, err := models.GetUserById(allIssues[i].PosterId)
		if err != nil {
			ctx.Handle(200, "user.Issues(get poster): %v", err)
			return
		}
		allIssues[i].Poster = u
		if u.Id == ctx.User.Id {
			createdByCount++
		}

		if repoId > 0 && repoId != allIssues[i].Repo.Id {
			continue
		}

		if isShowClosed == allIssues[i].IsClosed {
			showIssues = append(showIssues, allIssues[i])
		}
	}

	ctx.Data["Repos"] = showRepos
	ctx.Data["Issues"] = showIssues
	ctx.Data["AllIssueCount"] = allIssueCount
	ctx.Data["ClosedIssueCount"] = closedIssueCount
	ctx.Data["OpenIssueCount"] = allIssueCount - closedIssueCount
	ctx.Data["CreatedByCount"] = createdByCount
	ctx.HTML(200, "issue/user")
}