usabilit changes
This commit is contained in:
parent
cfc2edeaff
commit
7679b45092
|
@ -8,4 +8,10 @@ $(document).ready( function () {
|
|||
window.location = "/export";
|
||||
},
|
||||
});
|
||||
|
||||
if( $('.addedLink').length > 0) {
|
||||
setTimeout(function (){
|
||||
window.close();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
|
12
news/news.go
12
news/news.go
|
@ -57,17 +57,18 @@ func addContainer(category_id int, flat, tree map[int]*NewsContainer) {
|
|||
}
|
||||
}
|
||||
|
||||
func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
|
||||
// returns a tree of news items, the total count, and error
|
||||
func Unexported(db *sql.DB) (map[int]*NewsContainer, int, error) {
|
||||
categories.LoadCategories(db)
|
||||
|
||||
rows, err := db.Query("SELECT url, title, category_id, timestamp, notes FROM news WHERE exported is null order by category_id ASC")
|
||||
if err != nil {
|
||||
fmt.Println("DB errpr reading unexported news: ", err)
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
newsTree := map[int]*NewsContainer{}
|
||||
newsFlat := map[int]*NewsContainer{}
|
||||
|
||||
count := 0
|
||||
for rows.Next() {
|
||||
news := News{}
|
||||
var url, title, notes sql.NullString
|
||||
|
@ -75,7 +76,7 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
|
|||
err := rows.Scan(&url, &title, &category_id, &news.Date, ¬es)
|
||||
if err != nil {
|
||||
fmt.Println("Error reading news from DB: " + err.Error())
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
news.Url = nullStringToString(&url)
|
||||
|
@ -98,9 +99,10 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
|
|||
}
|
||||
container := newsFlat[cid]
|
||||
container.News = append(container.News, news)
|
||||
count++
|
||||
}
|
||||
|
||||
return newsTree, nil
|
||||
return newsTree, count, nil
|
||||
}
|
||||
|
||||
func (this *NewsContainer) HeaderDepth(start int) int {
|
||||
|
|
|
@ -14,7 +14,8 @@ import (
|
|||
"github.com/dballard/transmet/categories"
|
||||
"github.com/dballard/transmet/news"
|
||||
"bytes"
|
||||
"html/template"
|
||||
txtTemplate "text/template"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
||||
|
@ -139,18 +140,20 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
|||
|
||||
session, _ := store.Get(r, "c_user")
|
||||
flashes := GetFlashes(session)
|
||||
popup := session.Values["popup"]
|
||||
delete(session.Values, "popup")
|
||||
title := session.Values["title"]
|
||||
delete(session.Values, "title")
|
||||
link := session.Values["link"]
|
||||
delete(session.Values, "link")
|
||||
description := session.Values["description"]
|
||||
delete(session.Values, "description")
|
||||
delete(session.Values, "description")
|
||||
session.Save(r, w)
|
||||
|
||||
if link != nil {
|
||||
fmt.Println("link: '" + link.(string) + "'")
|
||||
//TODO category_id
|
||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "flashes": flashes, "categories": categories.CategoriesTree, "link": link, "title": title, "description": description})
|
||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "flashes": flashes, "categories": categories.CategoriesTree, "link": link, "title": title, "description": description, "popup": popup})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -165,15 +168,19 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
|||
title = getUrlTitle(url)
|
||||
}
|
||||
|
||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "flashes": flashes, "link": url, "categories": categories.CategoriesTree, "title": title})
|
||||
popup = r.URL.Query().Get("popup")
|
||||
|
||||
ShowTemplate("add", w, map[string]interface{}{"user": user, "flashes": flashes, "link": url, "categories": categories.CategoriesTree, "title": title, "popup": popup})
|
||||
}
|
||||
|
||||
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||
session, _ := store.Get(r, "c_user")
|
||||
var news news.News
|
||||
news.Title = r.FormValue("title")
|
||||
news.Notes = r.FormValue("notes")
|
||||
|
||||
news.Title, _ = url.QueryUnescape(r.FormValue("title"))
|
||||
news.Notes, _ = url.QueryUnescape(r.FormValue("notes"))
|
||||
news.Url = r.FormValue("link")
|
||||
popup := r.FormValue("popup")
|
||||
category_id, err := strconv.Atoi(r.FormValue("category"))
|
||||
if err != nil {
|
||||
category_id = -1
|
||||
|
@ -186,13 +193,18 @@ func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
|||
session.Values["title"] = news.Title
|
||||
session.Values["link"] = news.Url
|
||||
session.Values["notes"] = news.Notes
|
||||
session.Values["popup"] = popup
|
||||
session.Save(r, w)
|
||||
http.Redirect(w, r, "/add", http.StatusFound)
|
||||
} else {
|
||||
// TODO auto close? redirect
|
||||
session.AddFlash("Added news \""+news.Title+"\"", flash_info)
|
||||
session.Save(r, w)
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
if popup == "1" {
|
||||
http.Redirect(w, r, "/added", http.StatusFound)
|
||||
} else {
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,13 +213,13 @@ func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User
|
|||
flashes := GetFlashes(session)
|
||||
session.Save(r, w)
|
||||
|
||||
news, err := news.Unexported(db)
|
||||
news, count, err := news.Unexported(db)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var templateBuf bytes.Buffer
|
||||
template, err := template.ParseFiles("templates/html_template.html")
|
||||
template, err := txtTemplate.ParseFiles("templates/html_template.txt")
|
||||
if err != nil {
|
||||
fmt.Println("Error processing html_tempalte:" , err)
|
||||
}
|
||||
|
@ -216,7 +228,7 @@ func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User
|
|||
fmt.Println("Exec err: ", err)
|
||||
}
|
||||
|
||||
ShowTemplate("list", w, map[string]interface{}{"user": user, "flashes": flashes, "template": &templateBuf, "url": config.Url})
|
||||
ShowTemplate("list", w, map[string]interface{}{"user": user, "flashes": flashes, "template": &templateBuf, "count": count, "url": config.Url})
|
||||
}
|
||||
|
||||
func exportHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||
|
@ -233,6 +245,12 @@ func exportHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
|||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
|
||||
func addedHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||
session, _ := store.Get(r, "c_user")
|
||||
flashes := GetFlashes(session)
|
||||
session.Save(r, w)
|
||||
ShowTemplate("added", w, map[string]interface{}{"user": user, "flashes": flashes})
|
||||
}
|
||||
|
||||
func init_route_handlers() {
|
||||
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("js/"))))
|
||||
|
@ -247,6 +265,7 @@ func init_route_handlers() {
|
|||
r.HandleFunc("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler)))
|
||||
r.HandleFunc("/", userHandler(templateFormHandler))
|
||||
r.HandleFunc("/export", userHandler(exportHandler))
|
||||
r.HandleFunc("/added", userHandler(addedHandler))
|
||||
|
||||
|
||||
http.Handle("/", r)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<h2 class="form-add-heading">Add Link</h2>
|
||||
{{template "flashes" .}}
|
||||
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
||||
<input type="hidden" name="popup" value="{{.popup}}" />
|
||||
<div class="row">
|
||||
<div class="col-xs-2">Link:</div><div class="col-xs-10"><input type="text" class="form-control" name="link" placeholder="Link" value="{{.link}}"/></div>
|
||||
<div class="col-xs-2">Title:</div><div class="col-xs-10"><input type="text" class="form-control" name="title" placeholder="Title" value="{{.title}}"/></div>
|
||||
|
@ -12,7 +13,7 @@
|
|||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-xs-2">Notes:</div><div class="col-xs-10"><textarea class="form-control" name="notes" placeholder="Notes" rows="3" cols="80">{{.description}}</textarea></div>
|
||||
<div class="col-xs-2">Notes:</div><div class="col-xs-10"><textarea class="form-control" name="notes" placeholder="Notes" rows="5" cols="80">{{.description}}</textarea></div>
|
||||
<div class="col-xs-2"></div><div class="col-xs-10"><input class="btn btn-lg btn-primary btn-block" type="submit" value="Add Link" /></div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{{define "body"}}
|
||||
<h2 class="form-add-heading">Added Link</h2>
|
||||
{{template "flashes" .}}
|
||||
<div class="addedLink"></div>
|
||||
{{end}}
|
|
@ -27,8 +27,12 @@ Click this to mark the current queue of news items as exported (clearing them)
|
|||
|
||||
<textarea class="form-control" name="template" placeholder="Template" rows="16" cols="80">{{.template}}</textarea>
|
||||
|
||||
<div class="ros">
|
||||
<div class="col-xs-10"></div>
|
||||
<div class="col-xs-2"><b>{{.count}}</b> news items</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{define "launch-add"}}
|
||||
javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='{{.url}}add',l=d.location,e=encodeURIComponent,u=f+'?url='+e(l.href)+'&title='+e(d.title);a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();void(0)
|
||||
javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='{{.url}}add',l=d.location,e=encodeURIComponent,u=f+'?popup=1&url='+e(l.href)+'&title='+e(d.title);a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=410'))l.href=u;};if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();void(0)
|
||||
{{end}}
|
|
@ -24,7 +24,7 @@ func UsernameExists(db *sql.DB, username string) (bool, error) {
|
|||
}
|
||||
|
||||
func NewUserFromAuth(db *sql.DB, username, password string) *User {
|
||||
fmt.Println("NewUserFromAuth:", username, ":", password)
|
||||
fmt.Println("NewUserFromAuth:", username)
|
||||
rows, err := db.Query("SELECT username FROM users WHERE username = $1 AND password IS NOT NULL AND password = crypt($2 , password);", username, password)
|
||||
if err != nil {
|
||||
fmt.Println("Username or auth fail: ", err)
|
||||
|
|
Loading…
Reference in New Issue