From c4b1cd1e3ed6dd4e53fa629ded1ff49999a909df Mon Sep 17 00:00:00 2001 From: puni9869 Date: Wed, 2 Aug 2023 10:07:03 +0530 Subject: [PATCH 01/19] Adding in ui archive labels --- models/issues/label.go | 1 + options/locale/locale_en-US.ini | 1 + routers/web/org/org_labels.go | 3 +++ services/forms/repo_form.go | 1 + templates/repo/issue/labels/edit_delete_label.tmpl | 7 +++++++ 5 files changed, 13 insertions(+) diff --git a/models/issues/label.go b/models/issues/label.go index 8f2cf05a28d65..c951cbe6793cb 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -90,6 +90,7 @@ type Label struct { NumClosedIssues int CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + ArchivedUnix timeutil.TimeStamp `xorm:"INDEX created"` NumOpenIssues int `xorm:"-"` NumOpenRepoIssues int64 `xorm:"-"` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index cf04830cbb2a2..6ce013b87f92f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1486,6 +1486,7 @@ issues.label_title = Name issues.label_description = Description issues.label_color = Color issues.label_exclusive = Exclusive +issues.label_archive = Archive Label issues.label_exclusive_desc = Name the label scope/item to make it mutually exclusive with other scope/ labels. issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request. issues.label_count = %d labels diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index a9f9e963d4970..af7319541e7ea 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -4,6 +4,7 @@ package org import ( + "fmt" "net/http" "code.gitea.io/gitea/models/db" @@ -60,6 +61,8 @@ func NewLabel(ctx *context.Context) { // UpdateLabel update a label's name and color func UpdateLabel(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateLabelForm) + fmt.Println(form) + fmt.Println("$$$$$$$$$$$$") l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID) if err != nil { switch { diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index a26a2d89c5d65..333413fee6fd8 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -568,6 +568,7 @@ type CreateLabelForm struct { ID int64 Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"` Exclusive bool `form:"exclusive"` + IsArchived bool `form:"is_archived"` Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"` Color string `binding:"Required;MaxSize(7)" locale:"repo.issues.label_color"` } diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index b4eb6be7fcd1d..488071aa997ea 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -33,6 +33,13 @@
{{svg "octicon-alert"}} {{.locale.Tr "repo.issues.label_exclusive_warning" | Safe}}
+
+ +
+
+ + +
From 99fadb93926a84db302b589d724c8e1f1d4172ab Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 15:43:43 +0530 Subject: [PATCH 02/19] init label archive --- models/migrations/v1_21/v271.go | 1 + 1 file changed, 1 insertion(+) create mode 100644 models/migrations/v1_21/v271.go diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go new file mode 100644 index 0000000000000..1610db1f6f617 --- /dev/null +++ b/models/migrations/v1_21/v271.go @@ -0,0 +1 @@ +package v1_21 From 197a603883826ca645991509f9a95787fc702b98 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 21:55:51 +0530 Subject: [PATCH 03/19] Adding archive unix in api and repo and org level labels --- models/issues/label.go | 10 +++++++-- models/issues/label_test.go | 13 ++++++----- models/migrations/migrations.go | 2 ++ models/migrations/v1_21/v271.go | 33 +++++++++++++++++++++++++++- modules/structs/issue_label.go | 6 +++++ routers/api/v1/org/label.go | 6 +++++ routers/api/v1/repo/label.go | 12 +++++++++- routers/web/org/org_labels.go | 9 +++++--- routers/web/repo/issue_label.go | 7 +++++- routers/web/repo/issue_label_test.go | 7 +++--- services/convert/issue.go | 1 + templates/swagger/v1_json.tmpl | 15 +++++++++++++ 12 files changed, 105 insertions(+), 16 deletions(-) diff --git a/models/issues/label.go b/models/issues/label.go index d15de5f0f1d6d..5ef998c72836a 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -90,7 +90,6 @@ type Label struct { NumClosedIssues int CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - ArchivedUnix timeutil.TimeStamp `xorm:"INDEX created"` NumOpenIssues int `xorm:"-"` NumOpenRepoIssues int64 `xorm:"-"` @@ -98,6 +97,8 @@ type Label struct { QueryString string `xorm:"-"` IsSelected bool `xorm:"-"` IsExcluded bool `xorm:"-"` + + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` } func init() { @@ -154,6 +155,11 @@ func (l *Label) BelongsToOrg() bool { 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 func (l *Label) BelongsToRepo() bool { return l.RepoID > 0 @@ -212,7 +218,7 @@ func UpdateLabel(l *Label) error { } l.Color = color - return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive") + return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive", "archived_unix") } // DeleteLabel delete a label diff --git a/models/issues/label_test.go b/models/issues/label_test.go index 1bc5a1a93544f..a04e54c561974 100644 --- a/models/issues/label_test.go +++ b/models/issues/label_test.go @@ -4,6 +4,7 @@ package issues_test import ( + "code.gitea.io/gitea/modules/timeutil" "testing" "code.gitea.io/gitea/models/db" @@ -259,11 +260,12 @@ func TestUpdateLabel(t *testing.T) { label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}) // make sure update wont overwrite it update := &issues_model.Label{ - ID: label.ID, - Color: "#ffff00", - Name: "newLabelName", - Description: label.Description, - Exclusive: false, + ID: label.ID, + Color: "#ffff00", + Name: "newLabelName", + Description: label.Description, + Exclusive: false, + ArchivedUnix: timeutil.TimeStamp(0), } label.Color = update.Color label.Name = update.Name @@ -273,6 +275,7 @@ func TestUpdateLabel(t *testing.T) { assert.EqualValues(t, label.Color, newLabel.Color) assert.EqualValues(t, label.Name, newLabel.Name) assert.EqualValues(t, label.Description, newLabel.Description) + assert.EqualValues(t, newLabel.ArchivedUnix, 0) unittest.CheckConsistencyFor(t, &issues_model.Label{}, &repo_model.Repository{}) } diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index b2140a1eb1327..3faeac25d0c92 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -523,6 +523,8 @@ var migrations = []Migration{ NewMigration("Drop deleted branch table", v1_21.DropDeletedBranchTable), // v270 -> v271 NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo), + // v271 -> v272 + NewMigration("Fix PackageProperty typo", v1_21.AddArchivedUnixColumInLabelTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index 1610db1f6f617..521d111bc5809 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -1 +1,32 @@ -package v1_21 +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_21 //nolint +import ( + "code.gitea.io/gitea/modules/timeutil" + "fmt" + "xorm.io/xorm" +) + +func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { + type Label struct { + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` + } + + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + if err := sess.Sync2(new(Label)); err != nil { + return fmt.Errorf("Sync2: %w", err) + } + + _, err := sess.Exec(`UPDATE label SET archived_unix=0`) + if err != nil { + return err + } + return sess.Commit() +} diff --git a/modules/structs/issue_label.go b/modules/structs/issue_label.go index 2610d3e93f187..bf68726d79379 100644 --- a/modules/structs/issue_label.go +++ b/modules/structs/issue_label.go @@ -11,6 +11,8 @@ type Label struct { Name string `json:"name"` // example: false Exclusive bool `json:"exclusive"` + // example: false + IsArchived bool `json:"is_archived"` // example: 00aabb Color string `json:"color"` Description string `json:"description"` @@ -27,6 +29,8 @@ type CreateLabelOption struct { // example: #00aabb Color string `json:"color" binding:"Required"` Description string `json:"description"` + // example: false + IsArchived bool `json:"is_archived"` } // EditLabelOption options for editing a label @@ -37,6 +41,8 @@ type EditLabelOption struct { // example: #00aabb Color *string `json:"color"` Description *string `json:"description"` + // example: false + IsArchived *bool `json:"is_archived"` } // IssueLabelsOption a collection of labels diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index 183c1e6cc8a8c..e34b5a8754621 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -4,6 +4,7 @@ package org import ( + "code.gitea.io/gitea/modules/timeutil" "net/http" "strconv" "strings" @@ -209,6 +210,11 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } + if form.IsArchived != nil { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } if err := issues_model.UpdateLabel(l); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateLabel", err) return diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 6cb231f596c8b..cc58a5b6db602 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -5,6 +5,7 @@ package repo import ( + "code.gitea.io/gitea/modules/timeutil" "net/http" "strconv" @@ -151,7 +152,6 @@ func CreateLabel(ctx *context.APIContext) { return } form.Color = color - l := &issues_model.Label{ Name: form.Name, Exclusive: form.Exclusive, @@ -159,6 +159,11 @@ func CreateLabel(ctx *context.APIContext) { RepoID: ctx.Repo.Repository.ID, Description: form.Description, } + if form.IsArchived { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } if err := issues_model.NewLabel(ctx, l); err != nil { ctx.Error(http.StatusInternalServerError, "NewLabel", err) return @@ -231,6 +236,11 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } + if form.IsArchived != nil { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } if err := issues_model.UpdateLabel(l); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateLabel", err) return diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index af7319541e7ea..4170be8c77cab 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -4,7 +4,7 @@ package org import ( - "fmt" + "code.gitea.io/gitea/modules/timeutil" "net/http" "code.gitea.io/gitea/models/db" @@ -61,8 +61,6 @@ func NewLabel(ctx *context.Context) { // UpdateLabel update a label's name and color func UpdateLabel(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateLabelForm) - fmt.Println(form) - fmt.Println("$$$$$$$$$$$$") l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID) if err != nil { switch { @@ -78,6 +76,11 @@ func UpdateLabel(ctx *context.Context) { l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color + if form.IsArchived { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 5d326bab58084..889444a973cfe 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -4,6 +4,7 @@ package repo import ( + "code.gitea.io/gitea/modules/timeutil" "net/http" "code.gitea.io/gitea/models/db" @@ -137,11 +138,15 @@ func UpdateLabel(ctx *context.Context) { } return } - l.Name = form.Title l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color + if form.IsArchived { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index 4c9a359438015..e29582f9687ff 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -97,9 +97,10 @@ func TestUpdateLabel(t *testing.T) { test.LoadUser(t, ctx, 2) test.LoadRepo(t, ctx, 1) web.SetForm(ctx, &forms.CreateLabelForm{ - ID: 2, - Title: "newnameforlabel", - Color: "#abcdef", + ID: 2, + Title: "newnameforlabel", + Color: "#abcdef", + IsArchived: true, }) UpdateLabel(ctx) assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) diff --git a/services/convert/issue.go b/services/convert/issue.go index d81840f025210..33fad31d48ae1 100644 --- a/services/convert/issue.go +++ b/services/convert/issue.go @@ -208,6 +208,7 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m Exclusive: label.Exclusive, Color: strings.TrimLeft(label.Color, "#"), Description: label.Description, + IsArchived: label.IsArchived(), } // calculate URL diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 8cf5332bafc48..a5bea8a4cb941 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17057,6 +17057,11 @@ "x-go-name": "Exclusive", "example": false }, + "is_archived": { + "type": "boolean", + "x-go-name": "IsArchived", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -18001,6 +18006,11 @@ "x-go-name": "Exclusive", "example": false }, + "is_archived": { + "type": "boolean", + "x-go-name": "IsArchived", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -19479,6 +19489,11 @@ "format": "int64", "x-go-name": "ID" }, + "is_archived": { + "type": "boolean", + "x-go-name": "IsArchived", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" From c5447e5ebe6b8f851a5cd38cfb775ff5c178438d Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 22:05:00 +0530 Subject: [PATCH 04/19] Linting files --- models/issues/label_test.go | 2 +- models/migrations/v1_21/v271.go | 4 +++- routers/api/v1/org/label.go | 2 +- routers/api/v1/repo/label.go | 2 +- routers/web/org/org_labels.go | 2 +- routers/web/repo/issue_label.go | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/models/issues/label_test.go b/models/issues/label_test.go index a04e54c561974..3f0e980b318be 100644 --- a/models/issues/label_test.go +++ b/models/issues/label_test.go @@ -4,7 +4,6 @@ package issues_test import ( - "code.gitea.io/gitea/modules/timeutil" "testing" "code.gitea.io/gitea/models/db" @@ -12,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/timeutil" "github.com/stretchr/testify/assert" ) diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index 521d111bc5809..9378f5cc6f318 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -4,7 +4,9 @@ package v1_21 //nolint import ( "code.gitea.io/gitea/modules/timeutil" + "fmt" + "xorm.io/xorm" ) @@ -24,7 +26,7 @@ func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { return fmt.Errorf("Sync2: %w", err) } - _, err := sess.Exec(`UPDATE label SET archived_unix=0`) + _, err := sess.Exec("UPDATE label SET archived_unix=0") if err != nil { return err } diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index e34b5a8754621..96ec83d3942ce 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -4,7 +4,6 @@ package org import ( - "code.gitea.io/gitea/modules/timeutil" "net/http" "strconv" "strings" @@ -13,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index cc58a5b6db602..55b922cc54745 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -5,7 +5,6 @@ package repo import ( - "code.gitea.io/gitea/modules/timeutil" "net/http" "strconv" @@ -13,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index 4170be8c77cab..4fc7707b976b4 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -4,7 +4,6 @@ package org import ( - "code.gitea.io/gitea/modules/timeutil" "net/http" "code.gitea.io/gitea/models/db" @@ -12,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" repo_module "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" ) diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 889444a973cfe..956ab09182aaf 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -4,7 +4,6 @@ package repo import ( - "code.gitea.io/gitea/modules/timeutil" "net/http" "code.gitea.io/gitea/models/db" @@ -15,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/label" "code.gitea.io/gitea/modules/log" repo_module "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" issue_service "code.gitea.io/gitea/services/issue" From f0752e094fd6a7798207bb27f5fe3576f932c207 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 22:08:22 +0530 Subject: [PATCH 05/19] Adding to fixtures --- models/fixtures/label.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/models/fixtures/label.yml b/models/fixtures/label.yml index ab4d5ef944045..4b04445b02e0b 100644 --- a/models/fixtures/label.yml +++ b/models/fixtures/label.yml @@ -7,6 +7,7 @@ exclusive: false num_issues: 2 num_closed_issues: 0 + archive_unix: 0 - id: 2 @@ -17,6 +18,7 @@ exclusive: false num_issues: 1 num_closed_issues: 1 + archive_unix: 0 - id: 3 @@ -27,6 +29,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 + archive_unix: 0 - id: 4 @@ -37,6 +40,7 @@ exclusive: false num_issues: 1 num_closed_issues: 0 + archive_unix: 0 - id: 5 @@ -47,6 +51,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 + archive_unix: 0 - id: 6 @@ -57,6 +62,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 + archive_unix: 0 - id: 7 @@ -67,6 +73,7 @@ exclusive: true num_issues: 0 num_closed_issues: 0 + archive_unix: 0 - id: 8 @@ -77,6 +84,7 @@ exclusive: true num_issues: 0 num_closed_issues: 0 + archive_unix: 0 - id: 9 @@ -87,3 +95,4 @@ exclusive: true num_issues: 0 num_closed_issues: 0 + archive_unix: 0 From 44d24ace9656968a957cd7931c0c4cfb7fd6a628 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 23:17:05 +0530 Subject: [PATCH 06/19] Adding archived check in templates --- models/migrations/v1_21/v271.go | 2 -- routers/web/repo/issue_label.go | 11 ++++++----- templates/repo/issue/labels/edit_delete_label.tmpl | 4 ++-- templates/repo/issue/labels/label_list.tmpl | 4 ++-- web_src/js/features/comp/LabelEdit.js | 7 +++++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index 9378f5cc6f318..a45ea99063a50 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -4,9 +4,7 @@ package v1_21 //nolint import ( "code.gitea.io/gitea/modules/timeutil" - "fmt" - "xorm.io/xorm" ) diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 956ab09182aaf..982e06f6b0384 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -112,11 +112,12 @@ func NewLabel(ctx *context.Context) { } l := &issues_model.Label{ - RepoID: ctx.Repo.Repository.ID, - Name: form.Title, - Exclusive: form.Exclusive, - Description: form.Description, - Color: form.Color, + RepoID: ctx.Repo.Repository.ID, + Name: form.Title, + Exclusive: form.Exclusive, + Description: form.Description, + Color: form.Color, + ArchivedUnix: timeutil.TimeStamp(0), } if err := issues_model.NewLabel(ctx, l); err != nil { ctx.ServerError("NewLabel", err) diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index 488071aa997ea..5d155e2038be6 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -35,9 +35,9 @@

-
+
- +
diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index 9eee95be92369..4834c7d35c940 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -44,10 +44,10 @@
{{if and (not $.PageIsOrgSettingsLabels) (not $.Repository.IsArchived) (or $.CanWriteIssues $.CanWritePulls)}} - {{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}} + {{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}} {{svg "octicon-trash"}} {{$.locale.Tr "repo.issues.label_delete"}} {{else if $.PageIsOrgSettingsLabels}} - {{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}} + {{svg "octicon-pencil"}} {{$.locale.Tr "repo.issues.label_edit"}} {{svg "octicon-trash"}} {{$.locale.Tr "repo.issues.label_delete"}} {{end}}
diff --git a/web_src/js/features/comp/LabelEdit.js b/web_src/js/features/comp/LabelEdit.js index 18676d25e6cc9..156f202694869 100644 --- a/web_src/js/features/comp/LabelEdit.js +++ b/web_src/js/features/comp/LabelEdit.js @@ -36,7 +36,7 @@ export function initCompLabelEdit(selector) { $('.new-label.modal').modal({ onApprove() { $('.new-label.form').trigger('submit'); - } + }, }).modal('show'); return false; }); @@ -49,6 +49,9 @@ export function initCompLabelEdit(selector) { const nameInput = $('.edit-label .label-name-input'); nameInput.val($(this).data('title')); + const isArchivedCheckbox = $('.edit-label .label-is_archived-input'); + isArchivedCheckbox.prop('checked', this.hasAttribute('data-is_archived')); + const exclusiveCheckbox = $('.edit-label .label-exclusive-input'); exclusiveCheckbox.prop('checked', this.hasAttribute('data-exclusive')); // Warn when label was previously not exclusive and used in issues @@ -64,7 +67,7 @@ export function initCompLabelEdit(selector) { $('.edit-label.modal').modal({ onApprove() { $('.edit-label.form').trigger('submit'); - } + }, }).modal('show'); return false; }); From 903a7945649879028571a1017f3a592cc7d55452 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Fri, 4 Aug 2023 23:24:07 +0530 Subject: [PATCH 07/19] Fixing fixture for labels --- models/fixtures/label.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/models/fixtures/label.yml b/models/fixtures/label.yml index 4b04445b02e0b..2242b90dcdc23 100644 --- a/models/fixtures/label.yml +++ b/models/fixtures/label.yml @@ -7,7 +7,7 @@ exclusive: false num_issues: 2 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 2 @@ -18,7 +18,7 @@ exclusive: false num_issues: 1 num_closed_issues: 1 - archive_unix: 0 + archived_unix: 0 - id: 3 @@ -29,7 +29,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 4 @@ -40,7 +40,7 @@ exclusive: false num_issues: 1 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 5 @@ -51,7 +51,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 6 @@ -62,7 +62,7 @@ exclusive: false num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 7 @@ -73,7 +73,7 @@ exclusive: true num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 8 @@ -84,7 +84,7 @@ exclusive: true num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 - id: 9 @@ -95,4 +95,4 @@ exclusive: true num_issues: 0 num_closed_issues: 0 - archive_unix: 0 + archived_unix: 0 From 5a78bd9df886996656cfe5e3d5846527b22aea95 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Sun, 13 Aug 2023 15:22:54 +0530 Subject: [PATCH 08/19] Updating migrations --- models/migrations/migrations.go | 2 +- models/migrations/v1_21/v271.go | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 3faeac25d0c92..3b119787af03f 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -524,7 +524,7 @@ var migrations = []Migration{ // v270 -> v271 NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo), // v271 -> v272 - NewMigration("Fix PackageProperty typo", v1_21.AddArchivedUnixColumInLabelTable), + NewMigration("Add ArchivedUnix column in Label table", v1_21.AddArchivedUnixColumInLabelTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index a45ea99063a50..325e32f85f142 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -10,7 +10,7 @@ import ( func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { type Label struct { - ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"` } sess := x.NewSession() @@ -20,13 +20,9 @@ func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { return err } - if err := sess.Sync2(new(Label)); err != nil { - return fmt.Errorf("Sync2: %w", err) + if err := sess.Sync(new(Label)); err != nil { + return fmt.Errorf("sync: %w", err) } - _, err := sess.Exec("UPDATE label SET archived_unix=0") - if err != nil { - return err - } return sess.Commit() } From 20083778500f9d84de75bb6b82199558062cfe84 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Sun, 13 Aug 2023 22:10:49 +0530 Subject: [PATCH 09/19] Wrapping the archived function --- models/issues/label.go | 9 +++++++++ routers/api/v1/org/label.go | 2 +- routers/api/v1/repo/label.go | 8 ++------ routers/web/org/org_labels.go | 7 +------ routers/web/repo/issue_label.go | 7 ++----- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/models/issues/label.go b/models/issues/label.go index 5ef998c72836a..2c1fb0eff47d2 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -111,6 +111,15 @@ func (l *Label) CalOpenIssues() { l.NumOpenIssues = l.NumIssues - l.NumClosedIssues } +// Archived set the label as archived +func (l *Label) Archived(isArchived bool) { + if isArchived { + l.ArchivedUnix = timeutil.TimeStampNow() + } else { + l.ArchivedUnix = timeutil.TimeStamp(0) + } +} + // CalOpenOrgIssues calculates the open issues of a label for a specific repo func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) { counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{ diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index 96ec83d3942ce..f4c7c8edd50c2 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -210,7 +210,7 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - if form.IsArchived != nil { + if form.IsArchived != nil && *form.IsArchived == true { l.ArchivedUnix = timeutil.TimeStampNow() } else { l.ArchivedUnix = timeutil.TimeStamp(0) diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 55b922cc54745..1d2eed47bcd78 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -159,11 +159,7 @@ func CreateLabel(ctx *context.APIContext) { RepoID: ctx.Repo.Repository.ID, Description: form.Description, } - if form.IsArchived { - l.ArchivedUnix = timeutil.TimeStampNow() - } else { - l.ArchivedUnix = timeutil.TimeStamp(0) - } + l.Archived(form.IsArchived) if err := issues_model.NewLabel(ctx, l); err != nil { ctx.Error(http.StatusInternalServerError, "NewLabel", err) return @@ -236,7 +232,7 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - if form.IsArchived != nil { + if form.IsArchived != nil && *form.IsArchived == true { l.ArchivedUnix = timeutil.TimeStampNow() } else { l.ArchivedUnix = timeutil.TimeStamp(0) diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index 4fc7707b976b4..f5abb2555b7c3 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -11,7 +11,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" repo_module "code.gitea.io/gitea/modules/repository" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/forms" ) @@ -76,11 +75,7 @@ func UpdateLabel(ctx *context.Context) { l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color - if form.IsArchived { - l.ArchivedUnix = timeutil.TimeStampNow() - } else { - l.ArchivedUnix = timeutil.TimeStamp(0) - } + l.Archived(form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 982e06f6b0384..d2d940e2251a8 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -143,11 +143,8 @@ func UpdateLabel(ctx *context.Context) { l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color - if form.IsArchived { - l.ArchivedUnix = timeutil.TimeStampNow() - } else { - l.ArchivedUnix = timeutil.TimeStamp(0) - } + + l.Archived(form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return From 39b135bd2fabe41badb165263fa2bde80ff8a194 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Sun, 13 Aug 2023 22:15:50 +0530 Subject: [PATCH 10/19] Fixing migration --- models/migrations/v1_21/v271.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index 325e32f85f142..d9d196cf34cef 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -4,7 +4,6 @@ package v1_21 //nolint import ( "code.gitea.io/gitea/modules/timeutil" - "fmt" "xorm.io/xorm" ) @@ -12,17 +11,6 @@ func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { type Label struct { ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"` } + return x.Sync(new(Label)) - sess := x.NewSession() - defer sess.Close() - - if err := sess.Begin(); err != nil { - return err - } - - if err := sess.Sync(new(Label)); err != nil { - return fmt.Errorf("sync: %w", err) - } - - return sess.Commit() } From 0786a6f12a52dcdcd2499dbc26b385715d9db181 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Sun, 13 Aug 2023 23:48:33 +0530 Subject: [PATCH 11/19] Suggestions addressed --- models/issues/label.go | 8 ++++---- models/migrations/migrations.go | 2 +- options/locale/locale_en-US.ini | 1 + routers/api/v1/org/label.go | 7 +------ routers/api/v1/repo/label.go | 9 ++------- routers/web/org/org_labels.go | 2 +- routers/web/repo/issue_label.go | 2 +- templates/repo/issue/labels/edit_delete_label.tmpl | 9 ++++++--- templates/repo/issue/labels/label_list.tmpl | 4 ++-- web_src/js/features/comp/LabelEdit.js | 4 ++-- 10 files changed, 21 insertions(+), 27 deletions(-) diff --git a/models/issues/label.go b/models/issues/label.go index 2c1fb0eff47d2..70906efb47d75 100644 --- a/models/issues/label.go +++ b/models/issues/label.go @@ -98,7 +98,7 @@ type Label struct { IsSelected bool `xorm:"-"` IsExcluded bool `xorm:"-"` - ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"` } func init() { @@ -111,9 +111,9 @@ func (l *Label) CalOpenIssues() { l.NumOpenIssues = l.NumIssues - l.NumClosedIssues } -// Archived set the label as archived -func (l *Label) Archived(isArchived bool) { - if isArchived { +// SetArchived set the label as archived +func (l *Label) SetArchived(isArchived bool) { + if isArchived && l.ArchivedUnix.IsZero() { l.ArchivedUnix = timeutil.TimeStampNow() } else { l.ArchivedUnix = timeutil.TimeStamp(0) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index d56baadb7d428..7a126593d1458 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -523,7 +523,7 @@ var migrations = []Migration{ // v270 -> v271 NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo), // v271 -> v272 - NewMigration("Add ArchivedUnix column in Label table", v1_21.AddArchivedUnixColumInLabelTable), + NewMigration("Allow archiving labels", v1_21.AddArchivedUnixColumInLabelTable), } // GetCurrentDBVersion returns the current db version diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a2c75ab3f319e..daf22d9fea8e2 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1492,6 +1492,7 @@ issues.label_description = Description issues.label_color = Color issues.label_exclusive = Exclusive issues.label_archive = Archive Label +issues.label_archive_tooltip= Archived labels are excluded from the label search when applying labels to an issue. Existing labels on issues remain unaffected, allowing you to retire obsolete labels without losing information. issues.label_exclusive_desc = Name the label scope/item to make it mutually exclusive with other scope/ labels. issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request. issues.label_count = %d labels diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go index f4c7c8edd50c2..9ef28d4db9267 100644 --- a/routers/api/v1/org/label.go +++ b/routers/api/v1/org/label.go @@ -12,7 +12,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" @@ -210,11 +209,7 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - if form.IsArchived != nil && *form.IsArchived == true { - l.ArchivedUnix = timeutil.TimeStampNow() - } else { - l.ArchivedUnix = timeutil.TimeStamp(0) - } + l.SetArchived(form.IsArchived != nil && *form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateLabel", err) return diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 1d2eed47bcd78..fc9a16b58aa89 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -12,7 +12,6 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/label" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" @@ -159,7 +158,7 @@ func CreateLabel(ctx *context.APIContext) { RepoID: ctx.Repo.Repository.ID, Description: form.Description, } - l.Archived(form.IsArchived) + l.SetArchived(form.IsArchived) if err := issues_model.NewLabel(ctx, l); err != nil { ctx.Error(http.StatusInternalServerError, "NewLabel", err) return @@ -232,11 +231,7 @@ func EditLabel(ctx *context.APIContext) { if form.Description != nil { l.Description = *form.Description } - if form.IsArchived != nil && *form.IsArchived == true { - l.ArchivedUnix = timeutil.TimeStampNow() - } else { - l.ArchivedUnix = timeutil.TimeStamp(0) - } + l.SetArchived(form.IsArchived != nil && *form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateLabel", err) return diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go index f5abb2555b7c3..2c7725e38da5c 100644 --- a/routers/web/org/org_labels.go +++ b/routers/web/org/org_labels.go @@ -75,7 +75,7 @@ func UpdateLabel(ctx *context.Context) { l.Exclusive = form.Exclusive l.Description = form.Description l.Color = form.Color - l.Archived(form.IsArchived) + l.SetArchived(form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index d2d940e2251a8..257610d3af54b 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -144,7 +144,7 @@ func UpdateLabel(ctx *context.Context) { l.Description = form.Description l.Color = form.Color - l.Archived(form.IsArchived) + l.SetArchived(form.IsArchived) if err := issues_model.UpdateLabel(l); err != nil { ctx.ServerError("UpdateLabel", err) return diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index 5d155e2038be6..c700dc26f503c 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -35,11 +35,14 @@
-
+
- - + +
+ + {{svg "octicon-info" 13}} +
diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index 4834c7d35c940..c15833d952d9a 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -44,10 +44,10 @@
diff --git a/web_src/js/features/comp/LabelEdit.js b/web_src/js/features/comp/LabelEdit.js index 156f202694869..2a22190e10dd9 100644 --- a/web_src/js/features/comp/LabelEdit.js +++ b/web_src/js/features/comp/LabelEdit.js @@ -49,8 +49,8 @@ export function initCompLabelEdit(selector) { const nameInput = $('.edit-label .label-name-input'); nameInput.val($(this).data('title')); - const isArchivedCheckbox = $('.edit-label .label-is_archived-input'); - isArchivedCheckbox.prop('checked', this.hasAttribute('data-is_archived')); + const isArchivedCheckbox = $('.edit-label .label-is-archived-input'); + isArchivedCheckbox.prop('checked', this.hasAttribute('data-is-archived')); const exclusiveCheckbox = $('.edit-label .label-exclusive-input'); exclusiveCheckbox.prop('checked', this.hasAttribute('data-exclusive')); From 24fb5c89a9b2fb683952d1543cc4cbac12ac4f9b Mon Sep 17 00:00:00 2001 From: puni9869 Date: Mon, 14 Aug 2023 00:16:22 +0530 Subject: [PATCH 12/19] Linting the migration file --- models/migrations/v1_21/v271.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_21/v271.go b/models/migrations/v1_21/v271.go index d9d196cf34cef..098f6499d57e5 100644 --- a/models/migrations/v1_21/v271.go +++ b/models/migrations/v1_21/v271.go @@ -4,6 +4,7 @@ package v1_21 //nolint import ( "code.gitea.io/gitea/modules/timeutil" + "xorm.io/xorm" ) @@ -12,5 +13,4 @@ func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error { ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"` } return x.Sync(new(Label)) - } From d97c86e3009dbee1c11234131cf89b7724a77e16 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Mon, 14 Aug 2023 01:52:47 +0530 Subject: [PATCH 13/19] Adding archived labels route --- routers/web/repo/issue_label.go | 6 +++++- routers/web/web.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 257610d3af54b..443624b860d37 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -61,12 +61,16 @@ func RetrieveLabels(ctx *context.Context) { ctx.ServerError("RetrieveLabels.GetLabels", err) return } - + numArchivedLabels := 0 for _, l := range labels { l.CalOpenIssues() + if l.IsArchived() { + numArchivedLabels++ + } } ctx.Data["Labels"] = labels + ctx.Data["NumArchivedLabels"] = numArchivedLabels if ctx.Repo.Owner.IsOrganization() { orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}) diff --git a/routers/web/web.go b/routers/web/web.go index f857a36b04a8d..87ee22ea4331b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1165,6 +1165,7 @@ func registerRoutes(m *web.Route) { m.Get("/detail", repo.GetContentHistoryDetail) }) m.Get("/labels", reqRepoIssuesOrPullsReader, repo.RetrieveLabels, repo.Labels) + m.Get("/labels/archived", reqRepoIssuesOrPullsReader, repo.RetrieveLabels, repo.Labels) m.Get("/milestones", reqRepoIssuesOrPullsReader, repo.Milestones) }, context.RepoRef()) From 9502271915d2047834bb8d8b837bdf3e6f09f3f7 Mon Sep 17 00:00:00 2001 From: puni9869 <80308335+puni9869@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:22:13 +0530 Subject: [PATCH 14/19] Update templates/repo/issue/labels/edit_delete_label.tmpl Co-authored-by: wxiaoguang --- templates/repo/issue/labels/edit_delete_label.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index c700dc26f503c..83ed075873a4c 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -38,7 +38,7 @@
- +
{{svg "octicon-info" 13}} From c9e2b538893ca05d249959236a59c5a9f488d216 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Mon, 14 Aug 2023 12:29:22 +0530 Subject: [PATCH 15/19] Reverting original size of svg info --- templates/repo/issue/labels/edit_delete_label.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index 83ed075873a4c..d64782090cc84 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -40,8 +40,8 @@
- - {{svg "octicon-info" 13}} + + {{svg "octicon-info"}}
From 9f59b7408627f2c87ff490d25eeef427c230c447 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Tue, 15 Aug 2023 00:20:08 +0530 Subject: [PATCH 16/19] Adding archive ui on label page --- options/locale/locale_en-US.ini | 3 ++- routers/web/repo/issue_label.go | 24 ++++++++++++++++----- routers/web/web.go | 1 - templates/repo/issue/labels/label_list.tmpl | 16 +++++++++++++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index daf22d9fea8e2..8de1c150f54ff 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1495,7 +1495,8 @@ issues.label_archive = Archive Label issues.label_archive_tooltip= Archived labels are excluded from the label search when applying labels to an issue. Existing labels on issues remain unaffected, allowing you to retire obsolete labels without losing information. issues.label_exclusive_desc = Name the label scope/item to make it mutually exclusive with other scope/ labels. issues.label_exclusive_warning = Any conflicting scoped labels will be removed when editing the labels of an issue or pull request. -issues.label_count = %d labels +issues.label_count = %d active labels +issues.archived_label_count = %d archived issues.label_open_issues = %d open issues/pull requests issues.label_edit = Edit issues.label_delete = Delete diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go index 443624b860d37..47daca602b50e 100644 --- a/routers/web/repo/issue_label.go +++ b/routers/web/repo/issue_label.go @@ -61,16 +61,31 @@ func RetrieveLabels(ctx *context.Context) { ctx.ServerError("RetrieveLabels.GetLabels", err) return } - numArchivedLabels := 0 + // total number of labels + ctx.Data["NumLabels"] = len(labels) + + var archivedLabels []*issues_model.Label + var nonArchivedLabels []*issues_model.Label for _, l := range labels { l.CalOpenIssues() if l.IsArchived() { - numArchivedLabels++ + archivedLabels = append(archivedLabels, l) + } else { + nonArchivedLabels = append(nonArchivedLabels, l) } } + // archivedLabels + ctx.Data["NumArchivedLabels"] = len(archivedLabels) - ctx.Data["Labels"] = labels - ctx.Data["NumArchivedLabels"] = numArchivedLabels + // non archived label a.k.a. active labels + ctx.Data["NumNonArchivedLabels"] = len(nonArchivedLabels) + + includeArchivedLabel := ctx.FormOptionalBool("archived_label") + if includeArchivedLabel.IsTrue() { + ctx.Data["Labels"] = archivedLabels + } else { + ctx.Data["Labels"] = nonArchivedLabels + } if ctx.Repo.Owner.IsOrganization() { orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}) @@ -99,7 +114,6 @@ func RetrieveLabels(ctx *context.Context) { ctx.Data["OrganizationLink"] = ctx.Org.OrgLink } } - ctx.Data["NumLabels"] = len(labels) ctx.Data["SortType"] = ctx.FormString("sort") } diff --git a/routers/web/web.go b/routers/web/web.go index 87ee22ea4331b..f857a36b04a8d 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1165,7 +1165,6 @@ func registerRoutes(m *web.Route) { m.Get("/detail", repo.GetContentHistoryDetail) }) m.Get("/labels", reqRepoIssuesOrPullsReader, repo.RetrieveLabels, repo.Labels) - m.Get("/labels/archived", reqRepoIssuesOrPullsReader, repo.RetrieveLabels, repo.Labels) m.Get("/milestones", reqRepoIssuesOrPullsReader, repo.Milestones) }, context.RepoRef()) diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index c15833d952d9a..0bf0c605f6b17 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -1,5 +1,19 @@

- {{.locale.Tr "repo.issues.label_count" .NumLabels}} + {{if eq .NumLabels 0 }} + {{.locale.Tr "repo.issues.label_count" .NumLabels}} + {{else}} + + {{.locale.Tr "repo.issues.label_count" .NumNonArchivedLabels}} + + {{if gt .NumArchivedLabels 0}} + + {{.locale.Tr "repo.issues.archived_label_count" .NumArchivedLabels}} + + + {{svg "octicon-info" 12}} + + {{end}} + {{end}}