Ejemplo n.º 1
0
// Run New
func (c *New) Run(w http.ResponseWriter, r *http.Request) {

	if r.Method == "GET" {
		data := map[string]bool{
			"Error": false,
		}
		query := r.URL.Query()
		if query["error"] != nil {
			data["Error"] = true
		}

		t, _ := template.ParseFiles("./src/wardrobe/views/_layout/header.tmpl", "./src/wardrobe/views/_layout/footer.tmpl", "./src/wardrobe/views/new.tmpl")
		t.ExecuteTemplate(w, "header", nil)
		t.ExecuteTemplate(w, "content", data)
		t.ExecuteTemplate(w, "footer", nil)
		t.Execute(w, nil)
	} else {
		r.ParseForm()
		if r.FormValue("name") == "" || len(r.Form["types[]"]) == 0 {
			http.Redirect(w, r, "/new?error=1", 302)
		} else {
			d := model.LoadWardrobe()
			d.Create(r.FormValue("name"), r.Form["types[]"])

			http.Redirect(w, r, "/?new=1", 302)
		}
	}
}
Ejemplo n.º 2
0
// Run Clean
func (c *Clean) Run(w http.ResponseWriter, r *http.Request) {

	d := model.LoadWardrobe()
	c.Params[0] = strings.Replace(c.Params[0], "/clean", "", 1)
	c.Params[0] = strings.Replace(c.Params[0], "/", "", 1)
	i := d.Find(c.Params[0])
	if i.Name == "" {
		e := Error{}
		e.Run(w, r)
	} else {
		i.In = true
		d.Update(i)
		http.Redirect(w, r, "/?cleaned=1", 302)
	}

}
Ejemplo n.º 3
0
// Run Wear
func (c *Wear) Run(w http.ResponseWriter, r *http.Request) {

	d := model.LoadWardrobe()
	c.Data = make(map[string]interface{})

	// Check for a query
	params := r.URL.Query()
	wearType := params.Get("type")
	if wearType == "" {
		c.Data["typed"] = false
	} else {
		c.Data["typed"] = true
		if wearType == "both" {
			c.Data["typeBoth"] = true
		} else {
			c.Data["typeBoth"] = false
		}
		d.Shuffle()
		var Clothing0, Clothing1 = "", ""
		for _, item := range d {
			if wearType == "both" {
				if item.Types[0] == "Under" && item.In && Clothing0 == "" {
					Clothing0 = item.PrintName()
				} else if len(item.Types) == 2 && item.Types[1] == "Over" && item.In && Clothing1 == "" {
					Clothing1 = item.PrintName()
				} else if item.Types[0] == "Over" && item.In && Clothing1 == "" {
					Clothing1 = item.PrintName()
				}
			} else {
				if len(item.Types) == 2 && item.Types[1] == wearType && item.In && Clothing0 == "" {
					Clothing0 = item.PrintName()
				} else if item.Types[0] == wearType && item.In && Clothing0 == "" {
					Clothing0 = item.PrintName()
				}
			}
		}
		c.Data["Clothing0"] = Clothing0
		c.Data["Clothing1"] = Clothing1

	}

	t, _ := template.ParseFiles("./src/wardrobe/views/_layout/header.tmpl", "./src/wardrobe/views/_layout/footer.tmpl", "./src/wardrobe/views/wear.tmpl")
	t.ExecuteTemplate(w, "header", nil)
	t.ExecuteTemplate(w, "content", c)
	t.ExecuteTemplate(w, "footer", nil)
	t.Execute(w, nil)
}
Ejemplo n.º 4
0
// Run Index
func (c *Index) Run(w http.ResponseWriter, r *http.Request) {

	d := model.LoadWardrobe()
	sort.Sort(d)
	c.Data = make(map[string]interface{})
	c.Data["Wardrobe"] = d

	// Sessions
	c.Data["cleaned"] = false
	c.Data["dirtied"] = false
	query := r.URL.Query()
	if query["cleaned"] != nil {
		c.Data["cleaned"] = true
	}
	if query["dirtied"] != nil {
		c.Data["dirtied"] = true
	}

	t, _ := template.ParseFiles("./src/wardrobe/views/_layout/header.tmpl", "./src/wardrobe/views/_layout/footer.tmpl", "./src/wardrobe/views/index.tmpl")
	t.ExecuteTemplate(w, "header", nil)
	t.ExecuteTemplate(w, "content", c)
	t.ExecuteTemplate(w, "footer", nil)
	t.Execute(w, nil)
}