Simplified grouping by advancing/declining

master
Michael Dvorkin 11 years ago
parent fd1e3b9089
commit af77896323
  1. 4
      column_editor.go
  2. 3
      mop/mop.go
  3. 18
      profile.go
  4. 20
      yahoo_quotes.go

@ -72,9 +72,7 @@ func (self *ColumnEditor) select_right_column() *ColumnEditor {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *ColumnEditor) execute() *ColumnEditor { func (self *ColumnEditor) execute() *ColumnEditor {
if updated,_ := self.quotes.UpdateSortOrder(); updated { self.screen.Draw(self.quotes.Reorder())
self.screen.Draw(self.quotes)
}
return self return self
} }

@ -58,8 +58,7 @@ loop:
} else if event.Ch == 'o' || event.Ch == 'O' { } else if event.Ch == 'o' || event.Ch == 'O' {
column_editor = new(mop.ColumnEditor).Initialize(screen, quotes) column_editor = new(mop.ColumnEditor).Initialize(screen, quotes)
} else if event.Ch == 'g' || event.Ch == 'G' { } else if event.Ch == 'g' || event.Ch == 'G' {
profile.Regroup() screen.Draw(quotes.Regroup())
screen.Draw(quotes)
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' { } else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' {
showing_help = true showing_help = true
screen.Clear().Draw(help) screen.Clear().Draw(help)

@ -56,12 +56,6 @@ func (self *Profile) ListOfTickers() string {
return strings.Join(self.Tickers, `+`) return strings.Join(self.Tickers, `+`)
} }
//-----------------------------------------------------------------------------
func (self *Profile) Regroup() error {
self.Grouped = !self.Grouped
return self.Save()
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Profile) AddTickers(tickers []string) (added int, err error) { func (self *Profile) AddTickers(tickers []string) (added int, err error) {
added = 0 added = 0
@ -98,15 +92,19 @@ func (self *Profile) RemoveTickers(tickers []string) (removed int, err error) {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Profile) UpdateSortOrder() (updated bool, err error) { func (self *Profile) Reorder() error {
if self.selected_column == self.SortColumn { if self.selected_column == self.SortColumn {
self.Ascending = !self.Ascending self.Ascending = !self.Ascending
} else { } else {
self.SortColumn = self.selected_column self.SortColumn = self.selected_column
} }
err = self.Save() return self.Save()
updated = (err == nil) }
return
//-----------------------------------------------------------------------------
func (self *Profile) Regroup() error {
self.Grouped = !self.Grouped
return self.Save()
} }
// private // private

@ -109,7 +109,7 @@ func (self *Quotes) Format() string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Quotes) AddTickers(tickers []string) (added int, err error) { func (self *Quotes) AddTickers(tickers []string) (added int, err error) {
if added, err = self.profile.AddTickers(tickers); added > 0 { if added, err = self.profile.AddTickers(tickers); err == nil && added > 0 {
self.stocks = nil // Force fetch. self.stocks = nil // Force fetch.
} }
return return
@ -117,18 +117,28 @@ func (self *Quotes) AddTickers(tickers []string) (added int, err error) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Quotes) RemoveTickers(tickers []string) (removed int, err error) { func (self *Quotes) RemoveTickers(tickers []string) (removed int, err error) {
if removed, err = self.profile.RemoveTickers(tickers); removed > 0 { if removed, err = self.profile.RemoveTickers(tickers); err == nil && removed > 0 {
self.stocks = nil // Force fetch. self.stocks = nil // Force fetch.
} }
return return
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Quotes) UpdateSortOrder() (updated bool, err error) { func (self *Quotes) Reorder() *Quotes {
if updated, err = self.profile.UpdateSortOrder(); updated { if self.profile.Reorder() == nil {
self.stocks = nil // Force fetch. self.stocks = nil // Force fetch.
} }
return
return self
}
//-----------------------------------------------------------------------------
func (self *Quotes) Regroup() *Quotes {
if self.profile.Regroup() == nil {
self.stocks = nil // Force fetch.
}
return self
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

Loading…
Cancel
Save