aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2020-11-25 12:20:40 +0100
committerGitHub <noreply@github.com>2020-11-25 13:20:40 +0200
commit6d93a3ab182d772543f449073bbea855c3bfb155 (patch)
tree2575e52175ef1cc2dcacaf54e0d68a104a0c05d8 /modules
parent00ec651270aca19cba9a82fa48e6f7137efdfe1f (diff)
downloadgitea-6d93a3ab182d772543f449073bbea855c3bfb155.tar.gz
gitea-6d93a3ab182d772543f449073bbea855c3bfb155.zip
Issue and Pulls lists rework (#13594)
* Issue and Pulls lists rework Reorganized and restyled the issue and pull request lists. * color and layout tweaks * use new issue list on dashboard as well * move pagination into template * misc tweaks * fix label hover * fix milestone list * fix discrepancies between issue and milestone list, add new 'merge' helper * fmt * simplify merge helper * remove whitespace * fix startIndex * further simplify dict merging * rename helper to 'mergeinto' for clarity * allow bottom-row to wrap Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules')
-rw-r--r--modules/templates/helper.go30
-rw-r--r--modules/util/util.go24
2 files changed, 37 insertions, 17 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index e1c5d5d86b..4e5c96cd0f 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -256,31 +256,27 @@ func NewFuncMap() []template.FuncMap {
"DefaultTheme": func() string {
return setting.UI.DefaultTheme
},
+ // pass key-value pairs to a partial template which receives them as a dict
"dict": func(values ...interface{}) (map[string]interface{}, error) {
if len(values) == 0 {
return nil, errors.New("invalid dict call")
}
dict := make(map[string]interface{})
+ return util.MergeInto(dict, values...)
+ },
+ /* like dict but merge key-value pairs into the first dict and return it */
+ "mergeinto": func(root map[string]interface{}, values ...interface{}) (map[string]interface{}, error) {
+ if len(values) == 0 {
+ return nil, errors.New("invalid mergeinto call")
+ }
- for i := 0; i < len(values); i++ {
- switch key := values[i].(type) {
- case string:
- i++
- if i == len(values) {
- return nil, errors.New("specify the key for non array values")
- }
- dict[key] = values[i]
- case map[string]interface{}:
- m := values[i].(map[string]interface{})
- for i, v := range m {
- dict[i] = v
- }
- default:
- return nil, errors.New("dict values must be maps")
- }
+ dict := make(map[string]interface{})
+ for key, value := range root {
+ dict[key] = value
}
- return dict, nil
+
+ return util.MergeInto(dict, values...)
},
"percentage": func(n int, values ...int) float32 {
var sum = 0
diff --git a/modules/util/util.go b/modules/util/util.go
index 6d02b5f52f..9de1710ac7 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -6,6 +6,7 @@ package util
import (
"bytes"
+ "errors"
"strings"
)
@@ -100,3 +101,26 @@ func NormalizeEOL(input []byte) []byte {
}
return tmp[:pos]
}
+
+// MergeInto merges pairs of values into a "dict"
+func MergeInto(dict map[string]interface{}, values ...interface{}) (map[string]interface{}, error) {
+ for i := 0; i < len(values); i++ {
+ switch key := values[i].(type) {
+ case string:
+ i++
+ if i == len(values) {
+ return nil, errors.New("specify the key for non array values")
+ }
+ dict[key] = values[i]
+ case map[string]interface{}:
+ m := values[i].(map[string]interface{})
+ for i, v := range m {
+ dict[i] = v
+ }
+ default:
+ return nil, errors.New("dict values must be maps")
+ }
+ }
+
+ return dict, nil
+}