Ejemplo n.º 1
0
//Handles event and creates DOM patch
func (c *connection) handleExecute(handle router.Handle, paramsFromRequest router.Params) ([]byte, error) {
	dropsResponse := &protocol.DropsResponse{}
	activeDOM := session.GetSessionActiveDOM(c.sessionId)
	// fmt.Printf("\nGetting activeDOM on websocket connection: %+v\n", pretty.Formatter(activeDOM))
	if handle != nil {
		sessionParam := router.Param{Key: "session", Value: c.sessionId}

		paramsFromRequest = append(paramsFromRequest, sessionParam)
		// fmt.Printf("Routing success: %v\n", paramsFromRequest)

		dropsResponse = handle(nil, nil, paramsFromRequest)
		dropsResponse.ActiveDom = activeDOM
		// PrintDOM(ActiveDOM, "1")

		// fmt.Printf("ActiveDOM: %+v\n", activeDOM)
		// fmt.Printf("New DOM: %+v\n", dom)
		// fmt.Printf("Active dom is the same to new DOM: %v\n", *ActiveDOM == *dom)
		// PrintDOM(dom, "2")
	} else {
		log.Println("Routing failure, no handler")

		dropsResponse.Dom = activeDOM
	}
	var message []byte
	// var err error
	session.SetSessionActiveDOM(c.sessionId, dropsResponse.Dom)

	message = protocol.GenerateMessage(dropsResponse)

	fmt.Printf("Drops response: %+v\n", string(message))
	return message, nil

}
Ejemplo n.º 2
0
func AddHandler(w http.ResponseWriter, r *http.Request, params router.Params) *protocol.DropsResponse {
	data := params.ByName("data").(map[string]interface{})
	modelname := data["model"].(string)

	fmt.Printf("%# v", pretty.Formatter(data))

	store.AddModel(modelname, data)
	sessionId := session.GetSessionId(r, params.ByName("session").(string))

	message.NewMessage(sessionId, modelname+" saved")

	dom := session.GetSessionActiveDOM(sessionId)
	message.ProcessMessages(sessionId, dom)

	response := &protocol.DropsResponse{}
	response.Dom = dom
	response.Route = "/" + strings.ToLower(modelname) + "/"
	return response
}
Ejemplo n.º 3
0
func SaveHandler(w http.ResponseWriter, r *http.Request, params router.Params) *protocol.DropsResponse {
	data := params.ByName("data").(map[string]interface{})
	modelname := data["model"].(string)
	id, err := strconv.ParseInt(data["id"].(string), 0, 64)
	if err != nil {
		log.Printf("Error parsing id %v", err)
	}
	data["id"] = id
	fmt.Printf("%# v", pretty.Formatter(data))

	store.SaveModel(modelname, data)

	sessionId := session.GetSessionId(r, params.ByName("session").(string))
	message.NewMessage(sessionId, modelname+" saved")

	dom := session.GetSessionActiveDOM(sessionId)
	message.ProcessMessages(sessionId, dom)

	response := &protocol.DropsResponse{}
	response.Dom = dom
	return response
}