diff options
author | Oscar Costa <oscarcosta@gmail.com> | 2019-12-06 18:13:19 -0800 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-12-06 21:13:19 -0500 |
commit | 1583c48e3a89fcb9aeb81a57295982ee64d5859f (patch) | |
tree | 00018c9c4ad684572b923d3750773fa12f0cd17a | |
parent | eba816e8269b6a4ad141da0d399a5613796a348e (diff) | |
download | gitea-1583c48e3a89fcb9aeb81a57295982ee64d5859f.tar.gz gitea-1583c48e3a89fcb9aeb81a57295982ee64d5859f.zip |
Show label list on label set (#9251)
* Showing the list of labels of template files #7812
* Returning and logging errors when loading labels
* Commenting public method
* Change log level in case of error loading labels.
-rw-r--r-- | models/issue_label.go | 19 | ||||
-rw-r--r-- | models/repo.go | 18 | ||||
-rw-r--r-- | templates/repo/create.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/issue/labels.tmpl | 4 |
4 files changed, 37 insertions, 8 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index 4318406af7..1ea0ed85cc 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -132,6 +132,25 @@ func (label *Label) ForegroundColor() template.CSS { return template.CSS("#000") } +func loadLabels(labelTemplate string) ([]string, error) { + list, err := GetLabelTemplateFile(labelTemplate) + if err != nil { + return nil, ErrIssueLabelTemplateLoad{labelTemplate, err} + } + + labels := make([]string, len(list)) + for i := 0; i < len(list); i++ { + labels[i] = list[i][0] + } + return labels, nil +} + +// LoadLabelsFormatted loads the labels' list of a template file as a string separated by comma +func LoadLabelsFormatted(labelTemplate string) (string, error) { + labels, err := loadLabels(labelTemplate) + return strings.Join(labels, ", "), err +} + func initalizeLabels(e Engine, repoID int64, labelTemplate string) error { list, err := GetLabelTemplateFile(labelTemplate) if err != nil { diff --git a/models/repo.go b/models/repo.go index 6a260d393c..2fd4df9206 100644 --- a/models/repo.go +++ b/models/repo.go @@ -64,8 +64,8 @@ var ( // Readmes contains the readme files Readmes []string - // LabelTemplates contains the label template files - LabelTemplates []string + // LabelTemplates contains the label template files and the list of labels for each file + LabelTemplates map[string]string // ItemsPerPage maximum items per page in forks, watchers and stars of a repo ItemsPerPage = 40 @@ -100,11 +100,21 @@ func loadRepoConfig() { Gitignores = typeFiles[0] Licenses = typeFiles[1] Readmes = typeFiles[2] - LabelTemplates = typeFiles[3] + LabelTemplatesFiles := typeFiles[3] sort.Strings(Gitignores) sort.Strings(Licenses) sort.Strings(Readmes) - sort.Strings(LabelTemplates) + sort.Strings(LabelTemplatesFiles) + + // Load label templates + LabelTemplates = make(map[string]string) + for _, templateFile := range LabelTemplatesFiles { + labels, err := LoadLabelsFormatted(templateFile) + if err != nil { + log.Error("Failed to load labels: %v", err) + } + LabelTemplates[templateFile] = labels + } // Filter out invalid names and promote preferred licenses. sortedLicenses := make([]string, 0, len(Licenses)) diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index c71c3ab5a6..b63af09cec 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -109,8 +109,8 @@ <div class="default text">{{.i18n.Tr "repo.issue_labels_helper"}}</div> <div class="menu"> <div class="item" data-value="">{{.i18n.Tr "repo.issue_labels_helper"}}</div> - {{range .LabelTemplates}} - <div class="item" data-value="{{.}}">{{.}}</div> + {{range $template, $labels := .LabelTemplates}} + <div class="item" data-value="{{$template}}">{{$template}}<br/><i>({{$labels}})</i></div> {{end}} </div> </div> diff --git a/templates/repo/issue/labels.tmpl b/templates/repo/issue/labels.tmpl index c3bfc9ccc6..32a5c2a4ef 100644 --- a/templates/repo/issue/labels.tmpl +++ b/templates/repo/issue/labels.tmpl @@ -79,8 +79,8 @@ <input type="hidden" name="template_name" value="Default"> <div class="default text">{{.i18n.Tr "repo.issues.label_templates.helper"}}</div> <div class="menu"> - {{range .LabelTemplates}} - <div class="item" data-value="{{.}}">{{.}}</div> + {{range $template, $labels := .LabelTemplates}} + <div class="item" data-value="{{$template}}">{{$template}}<br/><i>({{$labels}})</i></div> {{end}} </div> </div> |