MCPcopy
hub / github.com/filebrowser/filebrowser / ApplySort

Method ApplySort

files/listing.go:19–46  ·  view source on GitHub ↗

ApplySort applies the sort order using .Order and .Sort

()

Source from the content-addressed store, hash-verified

17
18// ApplySort applies the sort order using .Order and .Sort
19func (l Listing) ApplySort() {
20 // Check '.Order' to know how to sort
21 if !l.Sorting.Asc {
22 switch l.Sorting.By {
23 case "name":
24 sort.Sort(sort.Reverse(byName(l)))
25 case "size":
26 sort.Sort(sort.Reverse(bySize(l)))
27 case "modified":
28 sort.Sort(sort.Reverse(byModified(l)))
29 default:
30 // If not one of the above, do nothing
31 return
32 }
33 } else { // If we had more Orderings we could add them here
34 switch l.Sorting.By {
35 case "name":
36 sort.Sort(byName(l))
37 case "size":
38 sort.Sort(bySize(l))
39 case "modified":
40 sort.Sort(byModified(l))
41 default:
42 sort.Sort(byName(l))
43 return
44 }
45 }
46}
47
48// Implement sorting for Listing
49type byName Listing

Callers 2

public.goFile · 0.80
resource.goFile · 0.80

Calls 3

byNameTypeAlias · 0.85
bySizeTypeAlias · 0.85
byModifiedTypeAlias · 0.85

Tested by

no test coverage detected