/
content_type.go
71 lines (56 loc) · 1.42 KB
/
content_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package entity
import (
"sort"
"github.com/bitwormhole/wpm/server/data/dxo"
)
// ContentType ...
type ContentType struct {
ID dxo.ContentTypeID `gorm:"primaryKey"`
URN dxo.ContentTypeURN `gorm:"index:,unique"`
Base
Name dxo.ContentTypeName
Patterns dxo.StringList
Label string
Icon string
Description string
Priority int // 优先级,数值越高越先处理
AsFile bool
AsDir bool
AsProject bool // true 表示这是一个项目类型
}
////////////////////////////////////////////////////////////////////////////////
// ContentTypeLessFn ...
type ContentTypeLessFn func(o1, o2 *ContentType) bool
type myContentTypeSorter struct {
list []*ContentType
fn ContentTypeLessFn
}
func (inst *myContentTypeSorter) Len() int {
return len(inst.list)
}
func (inst *myContentTypeSorter) Less(i1, i2 int) bool {
o1 := inst.list[i1]
o2 := inst.list[i2]
if o1 == nil || o2 == nil {
return false
}
return inst.fn(o1, o2)
}
func (inst *myContentTypeSorter) Swap(i1, i2 int) {
o1 := inst.list[i1]
o2 := inst.list[i2]
inst.list[i1] = o2
inst.list[i2] = o1
}
// SortContentTypeArray 对 ContentType 数组进行排序
func SortContentTypeArray(list []*ContentType, fn ContentTypeLessFn) {
if list == nil || fn == nil {
return
}
sorter := &myContentTypeSorter{
list: list,
fn: fn,
}
sort.Sort(sorter)
}
////////////////////////////////////////////////////////////////////////////////