Browse Source

Refactor label.IsArchived() (#29750)

just some missed nits
tags/v1.22.0-rc0
6543 3 months ago
parent
commit
9a93b1816e
No account linked to committer's email address
3 changed files with 12 additions and 15 deletions
  1. 6
    6
      models/issues/label.go
  2. 1
    2
      modules/templates/util_render.go
  3. 5
    7
      routers/web/repo/issue_label.go

+ 6
- 6
models/issues/label.go View File

func (l *Label) SetArchived(isArchived bool) { func (l *Label) SetArchived(isArchived bool) {
if !isArchived { if !isArchived {
l.ArchivedUnix = timeutil.TimeStamp(0) l.ArchivedUnix = timeutil.TimeStamp(0)
} else if isArchived && l.ArchivedUnix.IsZero() {
} else if isArchived && !l.IsArchived() {
// Only change the date when it is newly archived. // Only change the date when it is newly archived.
l.ArchivedUnix = timeutil.TimeStampNow() l.ArchivedUnix = timeutil.TimeStampNow()
} }
} }


// IsArchived returns true if label is an archived
func (l *Label) IsArchived() bool {
return !l.ArchivedUnix.IsZero()
}

// CalOpenOrgIssues calculates the open issues of a label for a specific repo // CalOpenOrgIssues calculates the open issues of a label for a specific repo
func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) { func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{ counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{
return l.OrgID > 0 return l.OrgID > 0
} }


// IsArchived returns true if label is an archived
func (l *Label) IsArchived() bool {
return l.ArchivedUnix > 0
}

// BelongsToRepo returns true if label is a repository label // BelongsToRepo returns true if label is a repository label
func (l *Label) BelongsToRepo() bool { func (l *Label) BelongsToRepo() bool {
return l.RepoID > 0 return l.RepoID > 0

+ 1
- 2
modules/templates/util_render.go View File

var ( var (
archivedCSSClass string archivedCSSClass string
textColor = "#111" textColor = "#111"
isArchived = !label.ArchivedUnix.IsZero()
labelScope = label.ExclusiveScope() labelScope = label.ExclusiveScope()
) )




description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description)) description := emoji.ReplaceAliases(template.HTMLEscapeString(label.Description))


if isArchived {
if label.IsArchived() {
archivedCSSClass = "archived-label" archivedCSSClass = "archived-label"
description = fmt.Sprintf("(%s) %s", locale.TrString("archived"), description) description = fmt.Sprintf("(%s) %s", locale.TrString("archived"), description)
} }

+ 5
- 7
routers/web/repo/issue_label.go View File

"code.gitea.io/gitea/modules/label" "code.gitea.io/gitea/modules/label"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
} }


l := &issues_model.Label{ l := &issues_model.Label{
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Exclusive: form.Exclusive,
Description: form.Description,
Color: form.Color,
ArchivedUnix: timeutil.TimeStamp(0),
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Exclusive: form.Exclusive,
Description: form.Description,
Color: form.Color,
} }
if err := issues_model.NewLabel(ctx, l); err != nil { if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err) ctx.ServerError("NewLabel", err)

Loading…
Cancel
Save