Updated TimerList struct
This commit is contained in:
14
sort.go
14
sort.go
@@ -13,6 +13,7 @@ const (
|
||||
SORT_START_DATE_DESC
|
||||
SORT_FINISH_DATE_ASC
|
||||
SORT_FINISH_DATE_DESC
|
||||
SORT_ERROR
|
||||
)
|
||||
|
||||
// Sort allows a TimerList to be sorted by certain predefined fields.
|
||||
@@ -28,8 +29,15 @@ func (timerlist *TimerList) Sort(sortFlag int) error {
|
||||
default:
|
||||
return errors.New("Unrecognized sort option")
|
||||
}
|
||||
timerlist.sortFlag = sortFlag
|
||||
return nil
|
||||
}
|
||||
func (timerlist *TimerList) refresh() {
|
||||
timerlist.Sort(timerlist.sortFlag)
|
||||
for i, t := range timerlist.timers {
|
||||
t.Id = i
|
||||
}
|
||||
}
|
||||
|
||||
type timerlistSort struct {
|
||||
timerlists TimerList
|
||||
@@ -37,15 +45,15 @@ type timerlistSort struct {
|
||||
}
|
||||
|
||||
func (ts *timerlistSort) Len() int {
|
||||
return len(ts.timerlists)
|
||||
return len(ts.timerlists.timers)
|
||||
}
|
||||
|
||||
func (ts *timerlistSort) Swap(l, r int) {
|
||||
ts.timerlists[l], ts.timerlists[r] = ts.timerlists[r], ts.timerlists[l]
|
||||
ts.timerlists.timers[l], ts.timerlists.timers[r] = ts.timerlists.timers[r], ts.timerlists.timers[l]
|
||||
}
|
||||
|
||||
func (ts *timerlistSort) Less(l, r int) bool {
|
||||
return ts.by(ts.timerlists[l], ts.timerlists[r])
|
||||
return ts.by(ts.timerlists.timers[l], ts.timerlists.timers[r])
|
||||
}
|
||||
|
||||
func (timerlist *TimerList) sortBy(by func(t1, t2 *Timer) bool) *TimerList {
|
||||
|
||||
Reference in New Issue
Block a user