func (this *Handler) ShowBlank(id string) { base := new(models.ModelManager) blanks := base.Blanks() columns := blanks.Select(map[string]interface{}{"contest_id": id}, "columns") cl := columns[0].(map[string]interface{}) colNames := blanks.Select(map[string]interface{}{"contest_id": id}, "colnames") cln := colNames[0].(map[string]interface{}) types := blanks.Select(map[string]interface{}{"contest_id": id}, "types") t := types[0].(map[string]interface{}) caption := blanks.Select(map[string]interface{}{"contest_id": id}, "name")[0].(map[string]interface{})["name"].(string) tmp, err := template.ParseFiles( "../uas/view/show_blank.html", "../uas/view/header.html", "../uas/view/footer.html") utils.HandleErr("[Handler.BlankShow] template.ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "show_blank", Model{ Id: id, Caption: caption, Columns: utils.ArrayStringToInterface(strings.Split(cl["columns"].(string), ",")), ColNames: utils.ArrayStringToInterface(strings.Split(cln["colnames"].(string), ",")), Types: utils.ArrayStringToInterface(strings.Split(t["types"].(string), ","))}) utils.HandleErr("[Handler.BlankShow] tmp.Execute: ", err) }
func (this *Handler) Select(tableName string) { sess := this.Session.SessionStart(this.Response, this.Request) createTime := sess.Get("createTime") life := this.Session.Maxlifetime if createTime == nil || createTime.(int64)+life < time.Now().Unix() { this.Session.SessionDestroy(this.Response, this.Request) fmt.Println("Select - Destroy") tmp, err := template.ParseFiles( "view/index.html", "view/header.html", "view/footer.html") utils.HandleErr("[handler.select] ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "index", nil) utils.HandleErr("[handler.select] ExecuteTemplate: ", err) return } sess.Set("createTime", time.Now().Unix()) base := new(models.ModelManager) var model models.Entity switch tableName { case "Users": model = base.Users().Entity break case "Contests": model = base.Contests().Entity break case "Blanks": model = base.Blanks().Entity break } answer := model.Select(nil, model.Columns...) tmp, err := template.ParseFiles( "../uas/view/table.html", "../uas/view/header.html", "../uas/view/footer.html") utils.HandleErr("[Handler.Select] template.ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "edit", Model{ Table: answer, TableName: model.TableName, ColNames: utils.ArrayStringToInterface(model.ColNames), Columns: utils.ArrayStringToInterface(model.Columns), Caption: model.Caption}) utils.HandleErr("[Handler.Select] tmp.Execute: ", err) }
func (this *Handler) SelectById(tableName string) { sess := this.Session.SessionStart(this.Response, this.Request) createTime := sess.Get("createTime") life := this.Session.Maxlifetime if createTime == nil || createTime.(int64)+life < time.Now().Unix() { this.Session.SessionDestroy(this.Response, this.Request) fmt.Println("SelectById - Destroy") tmp, err := template.ParseFiles( "view/index.html", "view/header.html", "view/footer.html") utils.HandleErr("[handler.select] ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "index", nil) utils.HandleErr("[handler.select] ExecuteTemplate: ", err) return } sess.Set("createTime", time.Now().Unix()) id := sess.Get("id") base := new(models.ModelManager) var answer []interface{} switch tableName { case "Users": model := base.Users() answer = model.Select(map[string]interface{}{"id": id}, model.UserColumns...) tmp, err := template.ParseFiles( "../uas/view/card.html", "../uas/view/header.html", "../uas/view/footer.html") utils.HandleErr("[Handler.SelectById] template.ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "card", Model{ Table: answer, ColNames: utils.ArrayStringToInterface(model.UserColNames), Columns: utils.ArrayStringToInterface(model.UserColumns)}) utils.HandleErr("[Handler.SelectById] tmp.Execute: ", err) break } }