usabilit changes
This commit is contained in:
parent
cfc2edeaff
commit
7679b45092
|
@ -8,4 +8,10 @@ $(document).ready( function () {
|
||||||
window.location = "/export";
|
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)
|
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")
|
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 {
|
if err != nil {
|
||||||
fmt.Println("DB errpr reading unexported news: ", err)
|
fmt.Println("DB errpr reading unexported news: ", err)
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
newsTree := map[int]*NewsContainer{}
|
newsTree := map[int]*NewsContainer{}
|
||||||
newsFlat := map[int]*NewsContainer{}
|
newsFlat := map[int]*NewsContainer{}
|
||||||
|
count := 0
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
news := News{}
|
news := News{}
|
||||||
var url, title, notes sql.NullString
|
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)
|
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())
|
||||||
return nil, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
news.Url = nullStringToString(&url)
|
news.Url = nullStringToString(&url)
|
||||||
|
@ -98,9 +99,10 @@ func Unexported(db *sql.DB) (map[int]*NewsContainer, error) {
|
||||||
}
|
}
|
||||||
container := newsFlat[cid]
|
container := newsFlat[cid]
|
||||||
container.News = append(container.News, news)
|
container.News = append(container.News, news)
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
return newsTree, nil
|
return newsTree, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *NewsContainer) HeaderDepth(start int) int {
|
func (this *NewsContainer) HeaderDepth(start int) int {
|
||||||
|
|
|
@ -14,7 +14,8 @@ import (
|
||||||
"github.com/dballard/transmet/categories"
|
"github.com/dballard/transmet/categories"
|
||||||
"github.com/dballard/transmet/news"
|
"github.com/dballard/transmet/news"
|
||||||
"bytes"
|
"bytes"
|
||||||
"html/template"
|
txtTemplate "text/template"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
||||||
|
@ -139,6 +140,8 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
|
||||||
session, _ := store.Get(r, "c_user")
|
session, _ := store.Get(r, "c_user")
|
||||||
flashes := GetFlashes(session)
|
flashes := GetFlashes(session)
|
||||||
|
popup := session.Values["popup"]
|
||||||
|
delete(session.Values, "popup")
|
||||||
title := session.Values["title"]
|
title := session.Values["title"]
|
||||||
delete(session.Values, "title")
|
delete(session.Values, "title")
|
||||||
link := session.Values["link"]
|
link := session.Values["link"]
|
||||||
|
@ -150,7 +153,7 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
if link != nil {
|
if link != nil {
|
||||||
fmt.Println("link: '" + link.(string) + "'")
|
fmt.Println("link: '" + link.(string) + "'")
|
||||||
//TODO category_id
|
//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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,15 +168,19 @@ func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
title = getUrlTitle(url)
|
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) {
|
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
session, _ := store.Get(r, "c_user")
|
session, _ := store.Get(r, "c_user")
|
||||||
var news news.News
|
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")
|
news.Url = r.FormValue("link")
|
||||||
|
popup := r.FormValue("popup")
|
||||||
category_id, err := strconv.Atoi(r.FormValue("category"))
|
category_id, err := strconv.Atoi(r.FormValue("category"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
category_id = -1
|
category_id = -1
|
||||||
|
@ -186,14 +193,19 @@ func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
session.Values["title"] = news.Title
|
session.Values["title"] = news.Title
|
||||||
session.Values["link"] = news.Url
|
session.Values["link"] = news.Url
|
||||||
session.Values["notes"] = news.Notes
|
session.Values["notes"] = news.Notes
|
||||||
|
session.Values["popup"] = popup
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
http.Redirect(w, r, "/add", http.StatusFound)
|
http.Redirect(w, r, "/add", http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
// TODO auto close? redirect
|
// TODO auto close? redirect
|
||||||
session.AddFlash("Added news \""+news.Title+"\"", flash_info)
|
session.AddFlash("Added news \""+news.Title+"\"", flash_info)
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
|
if popup == "1" {
|
||||||
|
http.Redirect(w, r, "/added", http.StatusFound)
|
||||||
|
} else {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
@ -201,13 +213,13 @@ func templateFormHandler(w http.ResponseWriter, r *http.Request, user *user.User
|
||||||
flashes := GetFlashes(session)
|
flashes := GetFlashes(session)
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
|
|
||||||
news, err := news.Unexported(db)
|
news, count, err := news.Unexported(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var templateBuf bytes.Buffer
|
var templateBuf bytes.Buffer
|
||||||
template, err := template.ParseFiles("templates/html_template.html")
|
template, err := txtTemplate.ParseFiles("templates/html_template.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error processing html_tempalte:" , err)
|
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)
|
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) {
|
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)
|
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() {
|
func init_route_handlers() {
|
||||||
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("js/"))))
|
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("/add", getPostHandler(userHandler(addFormHandler), userHandler(addPostHandler)))
|
||||||
r.HandleFunc("/", userHandler(templateFormHandler))
|
r.HandleFunc("/", userHandler(templateFormHandler))
|
||||||
r.HandleFunc("/export", userHandler(exportHandler))
|
r.HandleFunc("/export", userHandler(exportHandler))
|
||||||
|
r.HandleFunc("/added", userHandler(addedHandler))
|
||||||
|
|
||||||
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
<h2 class="form-add-heading">Add Link</h2>
|
<h2 class="form-add-heading">Add Link</h2>
|
||||||
{{template "flashes" .}}
|
{{template "flashes" .}}
|
||||||
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
<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="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">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>
|
<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}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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 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>
|
</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>
|
<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}}
|
{{end}}
|
||||||
|
|
||||||
{{define "launch-add"}}
|
{{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}}
|
{{end}}
|
|
@ -24,7 +24,7 @@ func UsernameExists(db *sql.DB, username string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserFromAuth(db *sql.DB, username, password string) *User {
|
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)
|
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 {
|
if err != nil {
|
||||||
fmt.Println("Username or auth fail: ", err)
|
fmt.Println("Username or auth fail: ", err)
|
||||||
|
|
Loading…
Reference in New Issue