Exemple #1
0
func (g Game) Owners() int {
	var retval string
	err := stmtGetOwners.QueryRow(g.ID).Scan(&retval)
	if err != nil {
		glog.Errorf("stmtGetOwners.QueryRow(%v): %s", g.ID, err)
	}
	return u.Toint(retval)
}
Exemple #2
0
//print the list of entries for the selected category, feed, or marked
func handleEntries(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	var loggedin bool
	var feedOrCat, id, mode, curID, modifier string
	loggedin, userName = auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	// format is /entries/{feed|category|marked}/<id>/{read|unread|marked|next|previous}[/{feed_id|cat_id}]
	u.PathVars(r, "/entries/", &feedOrCat, &id, &mode, &curID, &modifier)
	var el []feed.Entry
	switch feedOrCat {
	case "feed":
		f, err := feed.GetFeed(u.Toint(id))
		if err != nil {
			glog.Errorf("feed.GetFeed(%s): %s", id, err)
		}
		switch mode {
		case "read":
			el = f.ReadEntries()
		case "marked":
			el = f.MarkedEntries()
		case "all":
			el = f.AllEntries()
		case "search":
			el = f.SearchTitles(curID, modifier)
		default:
			el = f.UnreadEntries()
		}
	case "category":
		c := feed.GetCat(id)
		switch mode {
		case "read":
			el = c.ReadEntries()
		case "marked":
			el = c.MarkedEntries()
		case "all":
			el = c.AllEntries()
		case "search":
			el = c.SearchTitles(curID, modifier)
		default:
			el = c.UnreadEntries()
		}
	case "marked":
		el = feed.AllMarkedEntries(userName)
	}
	if len(el) == 0 {
		fmt.Fprintf(w, "No entries found")
	}
	if err := entriesListTmpl.Execute(w, &el); err != nil {
		glog.Errorf("entriesListTmpl.Execute: %s", err)
	}
	t1 := time.Now()
	fmt.Printf("handleEntries %v\n", t1.Sub(t0))
}
Exemple #3
0
func handleSelectMenu(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	var loggedin bool
	loggedin, userName = auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	var id string
	u.PathVars(r, "/menu/select/", &id)
	f, err := feed.GetFeed(u.Toint(id))
	if err != nil {
		glog.Errorf("feed.GetFeed(%s): %s", id, err)
	}
	setSelects(&f)
	if err := menuDropHtml.Execute(w, f); err != nil {
		glog.Errorf("menuDropHtml.Execute: %s", err)
	}
	fmt.Printf("handleSelectMenu %v\n", time.Now().Sub(t0))
}
Exemple #4
0
func handleMenu(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	var loggedin bool
	loggedin, userName = auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	var feedOrCat string
	var id string
	var mode string
	var curID string
	var modifier string
	u.PathVars(r, "/menu/", &feedOrCat, &id, &mode, &curID, &modifier)

	switch feedOrCat {
	case "category":
		cat := feed.GetCat(id)
		cat.SearchSelect = getSearchSelect(modifier)
		cat.Search = curID
		if err := catMenuHtml.Execute(w, cat); err != nil {
			glog.Errorf("catMenuHtml: %s", err)
		}
	case "feed":
		f, err := feed.GetFeed(u.Toint(id))
		if err != nil {
			glog.Errorf("feed.GetFeed(%s): %s", id, err)
		}
		f.SearchSelect = getSearchSelect(modifier)
		f.Search = curID
		setSelects(&f)
		if err := feedMenuHtml.Execute(w, f); err != nil {
			glog.Errorf("feedMenuHtml.Execute: %s", err)
		}
	case "marked":
		fmt.Fprintf(w, "&nbsp;")
	}
	fmt.Printf("handleMenu %v\n", time.Now().Sub(t0))
}
Exemple #5
0
func handleMarkEntry(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	var loggedin bool
	loggedin, userName = auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	var feedOrCat string
	var fcid string
	var retstr string
	var id string
	var tomark string
	u.PathVars(r, "/entry/mark/", &feedOrCat, &fcid, &id, &tomark)
	fmt.Printf("feedOrCat: %s, fcid: %s, id: %s, tomark: %s", feedOrCat, fcid, id, tomark)
	b := strings.Split(id, ",")
	// one thing can be marked whatever, but a list can only be marked read
	if len(b) == 1 {
		e := feed.GetEntry(id, userName)
		switch tomark {
		case "read":
			if err := e.MarkRead(); err != nil {
				glog.Errorf("e.MarkRead(): %s", err)
			}
		case "unread":
			if err := e.MarkUnread(); err != nil {
				glog.Errorf("e.MarkUnread(): %s", err)
			}
		case "marked":
			if err := e.Mark(); err != nil {
				glog.Errorf("e.Mark(): %s", err)
			}
			retstr = "<img src='static/mark_set.png' alt='Set mark' onclick='javascript:toggleMark(" + id + ");'>\n"
		case "unmarked":
			if err := e.UnMark(); err != nil {
				glog.Errorf("e.UnMark(): %s", err)
			}
			retstr = "<img src='static/mark_unset.png' alt='Set mark' onclick='javascript:toggleMark(" + id + ");'>\n"
		case "togglemarked":
			rsv, err := e.ToggleMark()
			if err != nil {
				glog.Errorf("e.ToggleMarked(): %s", err)
			}
			retstr = "<img src='static/mark_" + rsv + ".png' alt='Set mark' onclick='javascript:toggleMark(" + id + ");'>\n"
		}
	} else {
		switch feedOrCat {
		case "feed":
			f, err := feed.GetFeed(u.Toint(fcid))
			if err != nil {
				glog.Errorf("getFeed(%s): %s", fcid, err)
			}
			err = f.MarkEntriesRead(b)
			if err != nil {
				glog.Errorf("f.MarkEntriesread(): %s", err)
			}
		case "category":
			c := feed.GetCat(fcid)
			err := c.MarkEntriesRead(b)
			if err != nil {
				glog.Errorf("c.MarkEntriesRead(): %s", err)
			}
		}
	}
	fmt.Fprintf(w, retstr)
	t1 := time.Now()
	fmt.Printf("handleMarkEntry %v\n", t1.Sub(t0))
}
Exemple #6
0
func handleFeed(w http.ResponseWriter, r *http.Request) {
	var t0 = time.Now()
	var loggedin bool
	loggedin, userName = auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	var id string
	var todo string
	var val string
	u.PathVars(r, "/feed/", &id, &todo, &val)
	f, err := feed.GetFeed(u.Toint(id))
	if err != nil {
		glog.Errorf("feed.GetFeed(%s): %s", id, err)
	}
	if f.UserName != userName {
		fmt.Fprintf(w, "Auth err")
		return
	}
	switch todo {
	case "name":
		f.Title = val
		f.Save()
		fmt.Fprintf(w, "Name: "+val)
	case "link":
		url := r.FormValue("url")
		f.Url = url
		f.Save()
		fmt.Fprintf(w, f.Url)
	case "expirey":
		f.Expirey = val
		f.Save()
		fmt.Fprintf(w, "Expirey: "+val)
	case "autoscroll":
		f.AutoscrollPX = u.Toint(val)
		f.Save()
		fmt.Fprintf(w, "Autoscroll: "+val)
	case "exclude":
		f.Exclude = html.EscapeString(val)
		f.Save()
		fmt.Fprintf(w, "Exclude saved")
	case "excludedata":
		f.ExcludeData = html.EscapeString(val)
		f.Save()
		fmt.Fprintf(w, "Exclude Data Saved")
	case "category":
		f.CategoryID = u.Toint(val)
		f.Save()
		fmt.Fprintf(w, "Category: "+f.Category().Name)
	case "view_mode":
		f.ViewMode = val
		f.Save()
		fmt.Fprintf(w, "View Mode: "+val)
	case "delete":
		f.Delete()
		fmt.Fprintf(w, "Deleted")
	case "update":
		err = f.Update()
		if err != nil {
			glog.Errorf("f.Update() (url: %s): %s", f.Url, err)
			fmt.Fprintf(w, "Error updating")
		} else {
			fmt.Fprintf(w, "Updated")
		}
	case "unread":
		fmt.Fprintf(w, strconv.Itoa(f.Unread()))
	case "deleteexcludes":
		f.DeleteExcludes()
		fmt.Fprintf(w, "Deleted Excludes")
	case "clearcache":
		f.ClearCache()
		fmt.Fprintf(w, "Cleared Cache")
	}
	fmt.Printf("handleFeed /feed/%s/%s/%s %v\n", id, todo, val, time.Now().Sub(t0))
	return
}
Exemple #7
0
func handleSetGame(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	loggedin, user := auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	var id int
	if r.FormValue("id") == "" {
		glog.Errorf("No ID passed to SetGame")
		return
	}
	if r.FormValue("action") == "" {
		glog.Errorf("No action passed to SetGame")
		return
	}
	id = u.Toint(r.FormValue("id"))
	g, err := game.GetGame(id, user)
	if err != nil {
		glog.Errorf("GetGame(%v,%v): %s", id, user, err)
	}
	switch r.FormValue("action") {
	case "setrating":
		g.Rating = u.Toint(r.FormValue("rating"))
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
		fmt.Fprintf(w, "%s", g.StarContent())
	case "have":
		g.Has = true
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "have_not":
		g.Has = false
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "want":
		g.Want = true
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "wantnot":
		g.Want = false
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "has_manual":
		g.HasManual = true
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "hasnot_manual":
		g.HasManual = false
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "has_box":
		g.HasBox = true
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "hasnot_box":
		g.HasBox = false
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "set_review":
		g.Review = r.FormValue("review")
		err := g.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
		fmt.Fprintf(w, "%s", g.Review)
	default:
		glog.Errorf("Invalid action passed to set game: %s", r.FormValue("action"))
	}
	fmt.Printf("handleSetGame %v\n", time.Now().Sub(t0))
}
Exemple #8
0
func handleSetConsole(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	loggedin, user := auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	name := r.FormValue("name")
	if len(name) < 1 {
		glog.Errorf("Invalid Name passed to set/console: %s", name)
		return
	}
	if r.FormValue("action") == "" {
		glog.Errorf("No action passed to set/console/")
		return
	}
	c, err := game.GetConsole(name, user)
	if err != nil {
		glog.Errorf("GetConsole(%v,%v): %s", name, user, err)
	}
	fmt.Printf("in HandleSetConsole: Console: %sAction: %s--------\n", c, r.FormValue("action"))
	switch r.FormValue("action") {
	case "setrating":
		c.Rating = u.Toint(r.FormValue("rating"))
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
		fmt.Fprintf(w, "%s", c.StarContent())
		return
	case "have":
		c.Has = true
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "have_not":
		c.Has = false
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "has_manual":
		c.HasManual = true
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "hasnot_manual":
		c.HasManual = false
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "has_box":
		c.HasBox = true
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "hasnot_box":
		c.HasBox = false
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
	case "want":
		c.Want = true
		err := c.Save()
		if err != nil {
			glog.Error("g.Save(): %s", err)
		}
	case "wantnot":
		c.Want = false
		err := c.Save()
		if err != nil {
			glog.Error("g.Save(): %s", err)
		}
	case "wantgames":
		c.WantGames = true
		err := c.Save()
		if err != nil {
			glog.Error("g.Save(): %s", err)
		}
	case "wantnotgames":
		c.WantGames = false
		err := c.Save()
		if err != nil {
			glog.Error("g.Save(): %s", err)
		}
	case "set_review":
		c.Review = r.FormValue("review")
		err := c.Save()
		if err != nil {
			glog.Errorf("g.Save(): %s", err)
		}
		fmt.Fprintf(w, "%s", c.Review)
	default:
		glog.Errorf("Invalid action passed to set console: %s", r.FormValue("action"))
	}
	fmt.Printf("Updated Console: %s\n", c)
	fmt.Printf("handleSetConsole %v\n", time.Now().Sub(t0))
}
Exemple #9
0
func handleEdit(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	loggedin, user := auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	if !user.Admin {
		glog.Errorf("user %s attempting to add, not an admin", user)
		return
	}
	var cg string
	u.PathVars(r, "/edit/", &cg)
	switch cg {
	case "console":
		c, err := game.GetConsole(r.FormValue("name"), user)
		if err != nil {
			glog.Errorf("GetConsole(%s,user): %s", r.PostFormValue("name"), err)
		}
		type Meta struct {
			User         auth.User
			Message      template.HTML
			Console      game.Console
			CheapestGame game.Game
			Search       string
		}
		var meta Meta
		meta.User = user
		meta.Console = c
		wl, err := game.UserWantedGames(user)
		if err != nil {
			glog.Errorf("game.UserWantedGames(user): %s", err)
			return
		}
		meta.CheapestGame = game.Filter(wl).Cheapest()

		switch r.PostFormValue("action") {
		case "submit":
			c.Name = r.PostFormValue("name")
			c.Manufacturer = r.PostFormValue("manufacturer")
			c.Year = u.Toint(r.PostFormValue("year"))
			c.Picture = r.PostFormValue("picture")
			if err := c.Save(); err != nil {
				glog.Errorf("Saving console (%s): %s", c, err)
				meta.Message = template.HTML(err.Error())
			} else {
				meta.Message = template.HTML("Saved")
			}
			meta.Console = c
			if err := tmpl.ExecuteTemplate(w, "edit_console", meta); err != nil {
				glog.Errorf("ExecuteTemplate(w,edit_console,meta): %s", err)
			}
		case "delete":
			if err := tmpl.ExecuteTemplate(w, "really_delete_console", meta); err != nil {
				glog.Errorf("ExecuteTemplate(w,really_delete_console,meta): %s", err)
				return
			}
		case "reallydelete":
			err := c.Delete()
			if err != nil {
				glog.Errorf("c.Delete(): %s", err)
			}
			http.Redirect(w, r, "/", http.StatusFound)
		default:
			if err := tmpl.ExecuteTemplate(w, "edit_console", meta); err != nil {
				glog.Errorf("ExecuteTemplate(w,edit_console,meta): %s", err)
			}
		}
	case "game":
		id := u.Toint(r.FormValue("id"))
		g, err := game.GetGame(id, user)
		if err != nil {
			glog.Errorf("game.GetGame(%v,user): %s", id, err)
			return
		}
		type Meta struct {
			User         auth.User
			CheapestGame game.Game
			Game         game.Game
			Message      template.HTML
			Search       string
		}
		var meta Meta
		meta.User = user
		meta.Game = g
		wl, err := game.UserWantedGames(user)
		if err != nil {
			glog.Errorf("game.UserWantedGames(user): %s", err)
			return
		}
		meta.CheapestGame = game.Filter(wl).Cheapest()
		switch r.PostFormValue("action") {
		case "submit":
			g.Name = r.PostFormValue("name")
			g.Publisher = r.PostFormValue("publisher")
			g.Year = u.Toint(r.PostFormValue("year"))
			g.ConsoleName = r.PostFormValue("console")
			if err := g.Save(); err != nil {
				glog.Errorf("Saving game (%s): %s", g, err)
				meta.Message = "Error saving"
			} else {
				fmt.Printf("Saved game: %s", g)
				meta.Message = template.HTML("Saved: <a href='/game/" + u.Tostr(g.ID) + "'>Game</a>")
			}
			meta.Game = g
		case "delete":
			if err := tmpl.ExecuteTemplate(w, "really_delete_game", meta); err != nil {
				glog.Errorf("ExecuteTemplate(w,really_delete_game,meta): %s", err)
				return
			}
		case "reallydelete":
			err := g.Delete()
			if err != nil {
				glog.Errorf("g.Delete(): %s", err)
			}
			http.Redirect(w, r, "/", http.StatusFound)

		default:
			meta.Message = template.HTML("in default")
		}
		if err := tmpl.ExecuteTemplate(w, "edit_game", meta); err != nil {
			glog.Errorf("ExecuteTemplate(w,edit_game, meta): %s", err)
			return
		}
	}
	fmt.Printf("handleEdit %v\n", time.Now().Sub(t0))
}
Exemple #10
0
func handleAdd(w http.ResponseWriter, r *http.Request) {
	t0 := time.Now()
	loggedin, user := auth.LoggedIn(w, r)
	if !loggedin {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}
	if !user.Admin {
		glog.Errorf("user %s attempting to add, not an admin", user)
		return
	}
	var cg string
	u.PathVars(r, "/add/", &cg)
	type Meta struct {
		User     auth.User
		Message  template.HTML
		Consoles []game.Console
		Search   string
	}
	var meta Meta
	meta.User = user
	cl, err := game.GetConsoles(user)
	meta.Consoles = cl
	sort.Sort(game.ConsoleName(cl))
	if err != nil {
		glog.Errorf("game.GetConsoles(%s): %s", user, err)
	}
	switch cg {
	case "console":
		var c game.Console
		c.Name = r.PostFormValue("name")
		c.Manufacturer = r.PostFormValue("manufacturer")
		c.Year = u.Toint(r.PostFormValue("year"))
		c.User = user
		c.Picture = r.PostFormValue("picture")
		err := c.Save()
		if err != nil {
			glog.Errorf("Saving console (%s): %s", c, err)
			meta.Message = template.HTML(err.Error())
		} else {
			meta.Message = template.HTML("Saved")
		}
	case "game":
		var g game.Game
		g.Name = r.PostFormValue("name")
		g.Publisher = r.PostFormValue("publisher")
		g.Year = u.Toint(r.PostFormValue("year"))
		g.ConsoleName = r.PostFormValue("console")
		g.User = user
		g, err := game.InsertGame(g)
		if err != nil {
			glog.Errorf("Saving game (%s): %s", g, err)
			meta.Message = "Error saving"
		} else {
			meta.Message = template.HTML("Saved: <a href='/game/" + u.Tostr(g.ID) + "'>Game</a>")
		}
	}
	if err := tmpl.ExecuteTemplate(w, "add", meta); err != nil {
		glog.Errorf("ExecuteTemplate(w,add,meta): %s", err)
	}
	fmt.Printf("handleAdd %v\n", time.Now().Sub(t0))
}