fix news page listing bugs
This commit is contained in:
parent
6438250ef7
commit
a4abe1424a
|
@ -1,5 +1,6 @@
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
transmet
|
transmet
|
||||||
|
db/dbconf.yml
|
||||||
.project
|
.project
|
||||||
*~
|
*~
|
||||||
*.o
|
*.o
|
||||||
|
|
20
news/news.go
20
news/news.go
|
@ -69,7 +69,7 @@ func addContainer(category_id int, flat, tree map[int]*NewsContainer) {
|
||||||
func LoadPage(db *sql.DB, offset, amount int) ([]News, int, error) {
|
func LoadPage(db *sql.DB, offset, amount int) ([]News, int, error) {
|
||||||
categories.LoadCategories(db) // required by addContainer
|
categories.LoadCategories(db) // required by addContainer
|
||||||
|
|
||||||
rows, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported is null order by category_id ASC")
|
rows, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported is null order by timestamp DESC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("DB errpr reading LoadPage news: ", err)
|
fmt.Println("DB errpr reading LoadPage news: ", err)
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -99,7 +99,7 @@ func convertSqlToNews(rows *sql.Rows) ([]News, int, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
newsItem := News{}
|
newsItem := News{}
|
||||||
var url, title, notes sql.NullString
|
var url, title, notes sql.NullString
|
||||||
var date, category_id sql.NullInt64
|
var category_id sql.NullInt64
|
||||||
err := rows.Scan(&url, &title, &category_id, &newsItem.Date, ¬es)
|
err := rows.Scan(&url, &title, &category_id, &newsItem.Date, ¬es)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error reading news from DB: " + err.Error())
|
fmt.Println("Error reading news from DB: " + err.Error())
|
||||||
|
@ -109,13 +109,7 @@ func convertSqlToNews(rows *sql.Rows) ([]News, int, error) {
|
||||||
newsItem.Url = nullStringToString(&url)
|
newsItem.Url = nullStringToString(&url)
|
||||||
newsItem.Title = nullStringToString(&title)
|
newsItem.Title = nullStringToString(&title)
|
||||||
newsItem.Notes = nullStringToString(¬es)
|
newsItem.Notes = nullStringToString(¬es)
|
||||||
|
|
||||||
if date.Valid {
|
|
||||||
newsItem.Date = time.Unix(date.Int64, 0)
|
|
||||||
} else {
|
|
||||||
newsItem.Date = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
if category_id.Valid {
|
if category_id.Valid {
|
||||||
newsItem.Category_id = int(category_id.Int64)
|
newsItem.Category_id = int(category_id.Int64)
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,7 +131,7 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
news := News{}
|
news := News{}
|
||||||
var url, title, notes sql.NullString
|
var url, title, notes sql.NullString
|
||||||
var date, category_id sql.NullInt64
|
var category_id sql.NullInt64
|
||||||
err := rows.Scan(&url, &title, &category_id, &news.Date, ¬es)
|
err := rows.Scan(&url, &title, &category_id, &news.Date, ¬es)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error reading news from DB: " + err.Error())
|
fmt.Println("Error reading news from DB: " + err.Error())
|
||||||
|
@ -148,12 +142,6 @@ func convertSqlToNewsContainer(rows *sql.Rows) (map[int]*NewsContainer, int, err
|
||||||
news.Title = nullStringToString(&title)
|
news.Title = nullStringToString(&title)
|
||||||
news.Notes = nullStringToString(¬es)
|
news.Notes = nullStringToString(¬es)
|
||||||
|
|
||||||
if date.Valid {
|
|
||||||
news.Date = time.Unix(date.Int64, 0)
|
|
||||||
} else {
|
|
||||||
news.Date = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
if category_id.Valid {
|
if category_id.Valid {
|
||||||
news.Category_id = int(category_id.Int64)
|
news.Category_id = int(category_id.Int64)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -49,12 +49,9 @@ func dateFormat(t time.Time) string {
|
||||||
|
|
||||||
// takes a category_id and returns "Root / Parent / Category"
|
// takes a category_id and returns "Root / Parent / Category"
|
||||||
func fullCategoryPath(categoriesFlat map[int]*categories.Category, category_id int) string {
|
func fullCategoryPath(categoriesFlat map[int]*categories.Category, category_id int) string {
|
||||||
fmt.Println("fullCategoryPath: ", category_id)
|
|
||||||
var categoryNames []string = nil
|
var categoryNames []string = nil
|
||||||
var category *categories.Category = categoriesFlat[category_id]
|
for category := categoriesFlat[category_id]; category != nil; category = categoriesFlat[int(category.Parent.Int64)] {
|
||||||
for ; category.Parent.Valid; category = categoriesFlat[int(category.Parent.Int64)] {
|
categoryNames = append([]string{category.Name}, categoryNames...)
|
||||||
fmt.Println("fullCategoryPath LOOP: ", category.Name)
|
|
||||||
categoryNames = append(categoryNames, category.Name)
|
|
||||||
}
|
}
|
||||||
return strings.Join(categoryNames, " / ")
|
return strings.Join(categoryNames, " / ")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue