Work on news list page
TODO: - fix category path printer (only prints last if there is a parent) - dates are all NOW
This commit is contained in:
		
							parent
							
								
									72a17784ff
								
							
						
					
					
						commit
						6438250ef7
					
				|  | @ -9,3 +9,11 @@ body { | ||||||
| .col-form .row .col-xs-2 { | .col-form .row .col-xs-2 { | ||||||
|   text-align: right; |   text-align: right; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | .news-posts h3 { | ||||||
|  |     display: inline; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .news-row { | ||||||
|  |     margin-bottom: 1em; | ||||||
|  | } | ||||||
|  | @ -337,7 +337,7 @@ func newsFormHandler(w http.ResponseWriter, r *http.Request, user *user.User, se | ||||||
| 	    session.AddFlash("Error loading news", flash_err) | 	    session.AddFlash("Error loading news", flash_err) | ||||||
| 	} | 	} | ||||||
|      |      | ||||||
|     ShowTemplate("news", w, map[string]interface{}{"user": user, "flashes": flashes, "news": news, "count": count}) |     ShowTemplate("news", w, map[string]interface{}{"user": user, "flashes": flashes, "news": news, "count": count, "categories": categories.CategoriesFlat}) | ||||||
|    	 |    	 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -358,7 +358,7 @@ func init_route_handlers() { | ||||||
| 	r.HandleFunc("/logout", userHandler(LogoutHandler)) | 	r.HandleFunc("/logout", userHandler(LogoutHandler)) | ||||||
| 
 | 
 | ||||||
| 	r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler))) | 	r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler))) | ||||||
| 	r.HandleFunc("/", userHandler(templateFormHandler)) | 	r.HandleFunc("/", userHandler(newsFormHandler)) | ||||||
| 	r.HandleFunc("/news", userHandler(newsFormHandler)) | 	r.HandleFunc("/news", userHandler(newsFormHandler)) | ||||||
| 	r.HandleFunc("/export", userHandler(templateFormHandler)) | 	r.HandleFunc("/export", userHandler(templateFormHandler)) | ||||||
| 	r.HandleFunc("/export-commit", userHandler(exportHandler)) | 	r.HandleFunc("/export-commit", userHandler(exportHandler)) | ||||||
|  |  | ||||||
							
								
								
									
										24
									
								
								templates.go
								
								
								
								
							
							
						
						
									
										24
									
								
								templates.go
								
								
								
								
							|  | @ -7,6 +7,9 @@ import ( | ||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"time" | ||||||
|  | 	"strings" | ||||||
|  | 	"github.com/dballard/transmet/categories" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
|  | @ -29,6 +32,8 @@ func dict (values ...interface{}) (map[string]interface{}, error) { | ||||||
|     return dict, nil |     return dict, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // string multiplication
 | ||||||
|  | // stringTimes(3, "Foo") => "FooFooFoo"
 | ||||||
| func stringTimes(times int, str string) string { | func stringTimes(times int, str string) string { | ||||||
|     result := "" |     result := "" | ||||||
|     for i := 0; i < times; i ++ { |     for i := 0; i < times; i ++ { | ||||||
|  | @ -37,12 +42,31 @@ func stringTimes(times int, str string) string { | ||||||
|     return result |     return result | ||||||
| }  | }  | ||||||
| 
 | 
 | ||||||
|  | // Turns a Time into a formated string
 | ||||||
|  | func dateFormat(t time.Time) string { | ||||||
|  |     return t.Format(time.ANSIC) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // takes a category_id and returns "Root / Parent / Category"
 | ||||||
|  | func fullCategoryPath(categoriesFlat map[int]*categories.Category, category_id int) string { | ||||||
|  |     fmt.Println("fullCategoryPath: ", category_id) | ||||||
|  |     var categoryNames []string = nil | ||||||
|  |     var category *categories.Category = categoriesFlat[category_id] | ||||||
|  |     for ; category.Parent.Valid; category = categoriesFlat[int(category.Parent.Int64)] { | ||||||
|  |         fmt.Println("fullCategoryPath LOOP: ", category.Name) | ||||||
|  |         categoryNames = append(categoryNames, category.Name) | ||||||
|  |     } | ||||||
|  |     return strings.Join(categoryNames, " / ") | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // Tempalte helper functions
 | // Tempalte helper functions
 | ||||||
| var funcMap = template.FuncMap { | var funcMap = template.FuncMap { | ||||||
|     "add": func (x, y int) int { return x + y }, |     "add": func (x, y int) int { return x + y }, | ||||||
|     "minus": func (x, y int) int { return x - y }, |     "minus": func (x, y int) int { return x - y }, | ||||||
|     "dict": dict, |     "dict": dict, | ||||||
|     "stringTimes": stringTimes, |     "stringTimes": stringTimes, | ||||||
|  |     "dateFormat": dateFormat, | ||||||
|  |     "fullCategoryPath": fullCategoryPath, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,14 +1,31 @@ | ||||||
| {{define "body"}} | {{define "body"}} | ||||||
|     <h2 class="news-heading">News</h2> |     <h2 class="news-heading">News</h2> | ||||||
|     {{template "flashes" .}} |     {{template "flashes" .}} | ||||||
|  |     <div class="news-posts"> | ||||||
|     {{range $news_post := .news}} |     {{range $news_post := .news}} | ||||||
|                 {{template "row-news" $news_post}} |                 {{template "row-news" dict "post" $news_post "categories" $.categories}} | ||||||
|     {{end}} |     {{end}} | ||||||
|  |     </div> | ||||||
| 
 | 
 | ||||||
| {{end}} | {{end}} | ||||||
| 
 | 
 | ||||||
| <!-- print a news row --> | <!-- print a news row --> | ||||||
| {{define "row-news"}} | {{define "row-news"}} | ||||||
| <h2> -- {{.Title}}</h2> |     <div class="news-row"> | ||||||
| 
 |         <div class="row"> | ||||||
|  |             <div class="col-xs-12"> | ||||||
|  |                 <h3>{{.post.Title}}</h3> | ||||||
|  |             </div> | ||||||
|  |             <div class="col-xs-12"> | ||||||
|  |                 {{dateFormat .post.Date}} | ||||||
|  |             </div> | ||||||
|  |             <div class="col-xs-12"> | ||||||
|  |                 <a href="{{.post.Url}}">{{.post.Url}}</a> | ||||||
|  |             </div> | ||||||
|  |             <div class="col-xs-12"> | ||||||
|  |                 Category: {{fullCategoryPath .categories .post.Category_id}} | ||||||
|  |             </div> | ||||||
|  |         </div> | ||||||
|  |         <div>{{.post.Notes}}</div> | ||||||
|  |     </div> | ||||||
| {{end}} | {{end}} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue