Refactored updating sort order

master
Michael Dvorkin 11 years ago
parent a79b4605df
commit fd1e3b9089
  1. 9
      column_editor.go
  2. 35
      layout.go
  3. 4
      markup.go
  4. 12
      profile.go
  5. 8
      yahoo_quotes.go

@ -72,13 +72,10 @@ func (self *ColumnEditor) select_right_column() *ColumnEditor {
//-----------------------------------------------------------------------------
func (self *ColumnEditor) execute() *ColumnEditor {
if self.profile.selected_column == self.profile.SortColumn {
self.profile.Ascending = !self.profile.Ascending
} else {
self.profile.SortColumn = self.profile.selected_column
}
self.profile.Save()
if updated,_ := self.quotes.UpdateSortOrder(); updated {
self.screen.Draw(self.quotes)
}
return self
}

@ -36,9 +36,9 @@ func (self *Layout) Initialize() *Layout {
{ 10, `52w High` },
{ 11, `Volume` },
{ 11, `AvgVolume` },
{ 10, `P/E` },
{ 10, `Dividend` },
{ 10, `Yield` },
{ 9, `P/E` },
{ 9, `Dividend` },
{ 9, `Yield` },
{ 11, `MktCap` },
}
@ -186,9 +186,8 @@ func arrow_for(column int, profile *Profile) string {
if column == profile.SortColumn {
if profile.Ascending {
return string('\U00002191')
} else {
return string('\U00002193')
}
return string('\U00002193')
}
return ``
}
@ -197,50 +196,48 @@ func arrow_for(column int, profile *Profile) string {
func blank(str string) string {
if len(str) == 3 && str[0:3] == `N/A` {
return `-`
} else {
return str
}
return str
}
//-----------------------------------------------------------------------------
func blank_currency(str string) string {
if str == `0.00` {
return `-`
} else {
return currency(str)
}
return currency(str)
}
//-----------------------------------------------------------------------------
func last(str string) string {
if len(str) >= 6 && str[0:6] != `N/A - ` {
return str
} else {
return str[6:]
}
return str[6:]
}
//-----------------------------------------------------------------------------
func currency(str string) string {
if str == `N/A` {
return `-`
} else {
switch str[0:1] {
case `+`, `-`:
return str[0:1] + `$` + str[1:]
default:
return `$` + str
}
if sign := str[0:1]; sign == `+` || sign == `-` {
return sign + `$` + str[1:]
}
return `$` + str
}
//-----------------------------------------------------------------------------
func percent(str string) string {
if str == `N/A` {
return `-`
} else {
return str + `%`
}
return str + `%`
}
//-----------------------------------------------------------------------------

@ -132,7 +132,7 @@ func extract_tag_name(str string) string {
return str[1 : len(str)-1]
} else if len(str) > 3 {
return str[2 : len(str)-1]
} else {
return `/`
}
return `/`
}

@ -97,6 +97,18 @@ func (self *Profile) RemoveTickers(tickers []string) (removed int, err error) {
return
}
//-----------------------------------------------------------------------------
func (self *Profile) UpdateSortOrder() (updated bool, err error) {
if self.selected_column == self.SortColumn {
self.Ascending = !self.Ascending
} else {
self.SortColumn = self.selected_column
}
err = self.Save()
updated = (err == nil)
return
}
// private
//-----------------------------------------------------------------------------
func (self *Profile) default_file_name() string {

@ -123,6 +123,14 @@ func (self *Quotes) RemoveTickers(tickers []string) (removed int, err error) {
return
}
//-----------------------------------------------------------------------------
func (self *Quotes) UpdateSortOrder() (updated bool, err error) {
if updated, err = self.profile.UpdateSortOrder(); updated {
self.stocks = nil // Force fetch.
}
return
}
//-----------------------------------------------------------------------------
func (self *Quotes) parse(body []byte) *Quotes {
lines := bytes.Split(body, []byte{'\n'})

Loading…
Cancel
Save