Beispiel #1
0
func guestEntry(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)
	path := m["dir"].(string) + m["base"].(string)

	err := sc.Increment(c, path)
	util_err.Err_http(w, r, err, false)

	cntr, err := sc.Count(w, r, path)
	util_err.Err_http(w, r, err, false)

	tplAdder, tplExec := tpl_html.FuncTplBuilder(w, r)
	tplAdder("n_html_title", "New guest book entry", nil)
	tplAdder("n_cont_0", c_new_gbe, cntr)
	tplExec(w, r)

}
Beispiel #2
0
func guestView(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)
	path := m["dir"].(string) + m["base"].(string)

	err := sc.Increment(c, path)
	util_err.Err_http(w, r, err, false)

	cntr, err := sc.Count(w, r, path)
	util_err.Err_http(w, r, err, false)

	gbEntries, report := gbp.ListEntries(w, r)

	tplAdder, tplExec := tpl_html.FuncTplBuilder(w, r)
	tplAdder("n_html_title", "List of guest book entries", nil)
	tplAdder("n_cont_0", c_view_gbe, gbEntries)
	tplAdder("n_cont_1", "<pre>{{.}}</pre>", report)
	tplAdder("n_cont_2", "Visitors: {{.}}", cntr)
	tplExec(w, r)

}
Beispiel #3
0
func backend2(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	path := m["dir"].(string) + m["base"].(string)

	err := sc.Increment(c, path)
	util_err.Err_http(w, r, err, false)

	cntr, err := sc.Count(w, r, path)
	util_err.Err_http(w, r, err, false)

	add, tplExec := tpl_html.FuncTplBuilder(w, r)
	add("n_html_title", "Backend", nil)
	//add("n_cont_0", c_link, links)
	add("n_cont_0", tpl_html.PrefixLff+"backend_body", blocks2)
	add("tpl_legend", tpl_html.PrefixLff+"backend_body_embed01", "")

	//add("n_cont_1", "<pre>{{.}}</pre>", "pure text")
	add("n_cont_2", "<p>{{.}} views</p>", cntr)

	tplExec(w, r)

}
Beispiel #4
0
func backend3(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	c := appengine.NewContext(r)

	var nColsBlock = 4
	if r.FormValue("nColsBlock") != "" {
		nColsBlock = util.Stoi(r.FormValue("nColsBlock"))
	}
	var nColsViewport = 6
	if r.FormValue("nColsViewport") != "" {
		nColsViewport = util.Stoi(r.FormValue("nColsViewport"))
	}

	myB0.VB1 = ss.X
	myB0.NumB1 = len(myB0.VB1)
	myB0.NumB2 = 0
	myB0.NColsViewport = nColsViewport

	// compute basic meta data
	for i1, _ := range myB0.VB1 {
		myB0.NumB2 += len(myB0.VB1[i1].VB2)
		for i2, _ := range myB0.VB1[i1].VB2 {
			// number of chars
			ro := myB0.VB1[i1].VB2[i2] // read only
			myB0.VB1[i1].VB2[i2].Size = len(ro.Linktext) + len(ro.Description)
			myB0.VB1[i1].VB2[i2].EditorialIndex = i2
		}
	}

	// compute NCols - NRows for the block
	for i1, _ := range myB0.VB1 {
		myB0.VB1[i1].NCols = nColsBlock
		if myB0.VB1[i1].NColsEditorial > 0 {
			myB0.VB1[i1].NCols = myB0.VB1[i1].NColsEditorial
		}
		if len(myB0.VB1[i1].VB2) < nColsBlock && len(myB0.VB1[i1].VB2) > 0 {
			myB0.VB1[i1].NCols = len(myB0.VB1[i1].VB2)
		}
		myB0.VB1[i1].NRows = complementRowsOrCols(len(myB0.VB1[i1].VB2), myB0.VB1[i1].NCols)
		myB0.VB1[i1].Discrepancy = myB0.VB1[i1].NCols*myB0.VB1[i1].NRows - len(myB0.VB1[i1].VB2)

		myB0.MaxNCols = util.Max(myB0.MaxNCols, myB0.VB1[i1].NCols)
		myB0.MaxNRows = util.Max(myB0.MaxNRows, myB0.VB1[i1].NRows)
	}

	// compute NCols - NRows - sizeup to MaxNRows
	for i1, _ := range myB0.VB1 {
		if myB0.VB1[i1].NRows < myB0.MaxNRows {
			myB0.VB1[i1].NRows = myB0.MaxNRows
			myB0.VB1[i1].NCols = complementRowsOrCols(len(myB0.VB1[i1].VB2), myB0.VB1[i1].NRows)
			myB0.VB1[i1].Discrepancy = myB0.VB1[i1].NCols*myB0.VB1[i1].NRows - len(myB0.VB1[i1].VB2)
		}
	}

	// is first or last
	for i1, _ := range myB0.VB1 {
		for i2, _ := range myB0.VB1[i1].VB2 {
			myB0.VB1[i1].VB2[i2].IsFirst = false
			myB0.VB1[i1].VB2[i2].IsLast = false
			if i2%myB0.VB1[i1].NCols == 0 {
				myB0.VB1[i1].VB2[i2].IsFirst = true
			}
			if i2%myB0.VB1[i1].NCols == (myB0.VB1[i1].NCols - 1) {
				myB0.VB1[i1].VB2[i2].IsLast = true
			}
			//c.Infof("first-last %v %v \n", i2, i2%myB0.VB1[i1].NCols)
		}
	}

	// create slices with the data to be sorted
	for i1, _ := range myB0.VB1 {
		sh1 := make([]ss.Order, len(myB0.VB1[i1].VB2))
		myB0.VB1[i1].BySize = ss.ByInt(sh1)
		sh2 := make([]ss.Order, len(myB0.VB1[i1].VB2))
		myB0.VB1[i1].ByHeading = ss.ByStr(sh2)
		// fill in the data - to be sorted later
		for i2, _ := range myB0.VB1[i1].VB2 {
			ro := myB0.VB1[i1].VB2[i2] // read only
			myB0.VB1[i1].BySize[i2].IdxSrc = i2
			myB0.VB1[i1].BySize[i2].ByI = len(ro.Linktext) + len(ro.Description)
			myB0.VB1[i1].ByHeading[i2].IdxSrc = i2
			myB0.VB1[i1].ByHeading[i2].ByS = strings.ToLower(ro.Linktext)
		}
	}

	// actual rearranging of the sorting date
	for i1, _ := range myB0.VB1 {
		sort.Sort(myB0.VB1[i1].BySize)
		sort.Sort(myB0.VB1[i1].ByHeading)
		c.Infof("-- Sorting %v", myB0.VB1[i1].Heading)
		// for i, v := range myB0.VB1[i1].BySize {
		// 	c.Infof("---- %v %v %v", i, v.IdxSrc, v.ByI)
		// }
		// for i, v := range myB0.VB1[i1].ByHeading {
		// 	c.Infof("---- %v %v %v", i, v.IdxSrc, v.ByS)
		// }
	}

	path := m["dir"].(string) + m["base"].(string)

	err := sc.Increment(c, path)
	util_err.Err_http(w, r, err, false)

	cntr, err := sc.Count(w, r, path)
	util_err.Err_http(w, r, err, false)

	add, tplExec := tpl_html.FuncTplBuilder(w, r)
	add("n_html_title", "Backend", nil)

	add("n_cont_0", "<style>"+util.CSSColumnsWidth(nColsViewport)+"</style>", "")
	add("n_cont_1", tpl_html.PrefixLff+"backend3_body", myB0)
	add("tpl_legend", tpl_html.PrefixLff+"backend3_body_embed01", "")
	add("n_cont_2", "<p>{{.}} views</p>", cntr)

	sDumped := ""
	//sDumped = spew.Sdump(myB0)
	add("n_cont_3", "<pre>{{.}} </pre>", sDumped)

	tplExec(w, r)

}