Example #1
0
func getConditions() []Condition {
	conditions := make([]Condition, 0)

	rows, err := common.DB.Query("SELECT field, operator, value FROM logictree.equality")
	common.CheckError(err, 2)

	var field, operator, value string

	i := 0

	for rows.Next() {
		rows.Scan(&field, &operator, &value)
		common.CheckError(err, 2)

		if i != 0 {
			conditions = append(conditions, Condition{
				Text: "AND",
				Type: "logic",
			})
		}

		conditions = append(conditions, Condition{
			Text:     fmt.Sprintf("%s %s %s", field, operator, value),
			Type:     "equality",
			Field:    field,
			Operator: operator,
			Value:    value,
		})

		i++
	}

	return conditions
}
Example #2
0
func Truncate(rw http.ResponseWriter, req *http.Request) {
	_, err := common.DB.Query("TRUNCATE TABLE logictree.equality")
	common.CheckError(err, 2)

	_, err = common.DB.Query("TRUNCATE TABLE logictree.logic")
	common.CheckError(err, 2)

	GetHomePage(rw, req)
}
Example #3
0
func GetHomePage(rw http.ResponseWriter, req *http.Request) {
	type Page struct {
		Title      string
		Conditions []Condition
	}

	p := Page{
		Title:      "home",
		Conditions: getConditions(),
	}

	common.Templates = template.Must(template.New("asd").ParseFiles("templates/home/home.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err, 2)
}