예제 #1
0
func (this *API_GetPlan) Get() {

	// Get TestPlans
	sprintname := make(map[int]string)
	res := models.GetAllSprintNames()
	for key, item := range res {
		sprintname[key] = string(item["SprintName"])
	}

	var tp []interface{}
	for i := 0; i < len(sprintname); i++ {
		temp := models.GetAllPlansBySprintName(sprintname[i])
		tp = append(tp, temp)
	}

	// p := new(plan)
	// p.SprintName = "sprint 4"
	// p.infos = make(info_m)

	// var ia []info
	// for i := 0; i < 5; i++ {
	// 	var i info
	// 	i.RegressionDetail = "access the file."
	// 	i.TotalTime = 10
	// 	ia = append(ia, i)
	// }
	// p2 := make(plan2)
	// p2["sprint4"] = ia
	// p2["sprint5"] = ia

	this.Data["json"] = &tp
	this.ServeJson()
	// this.TplNames = "alert.tpl"
}
예제 #2
0
func (this *ApiController) GetPlan() {

	expiration := int64(60 * 60)
	spec := redis.DefaultSpec().Db(0)
	client, err := redis.NewSynchClientWithSpec(spec)
	if err != nil {
		fmt.Println("Failed to create the client: ", err)
		return
	}

	key := "plan"
	value, err := client.Get(key)
	if err != nil {
		fmt.Println("Failed to get value: ", err)
		return
	}

	// Get TestPlans
	sprintname := make(map[int]string)
	var tp []interface{}
	if value == nil {
		fmt.Println("The plan is not exists. We will query it from mysql and then store them in redis.")

		res := models.GetAllSprintNames()
		for key, item := range res {
			sprintname[key] = string(item["SprintName"])
		}

		for i := 0; i < len(sprintname); i++ {
			temp := models.GetAllPlansBySprintName(sprintname[i])
			tp = append(tp, temp)
		}

		value, err := json.Marshal(tp)
		if err != nil {
			fmt.Println("Failed to marshal: ", err)
		}
		client.Set(key, value)
		client.Expire(key, expiration)
	} else {
		fmt.Println("The plan is exists. We will unmarshal them.")
		// var temp planinfo
		err := json.Unmarshal(value, &tp)
		if err != nil {
			fmt.Println("Failed to unmarshal: ", err)
			return
		}
	}

	this.Data["json"] = &tp
	this.ServeJson()
	// this.TplNames = "alert.tpl"
}
예제 #3
0
func (this *PlanController) Get() {

	expiration := int64(12 * 60 * 60)
	spec := redis.DefaultSpec().Db(0)
	client, err := redis.NewSynchClientWithSpec(spec)
	if err != nil {
		fmt.Println("Failed to create the client: ", err)
		return
	}

	key1 := "sprintname"
	key2 := "sp-plan"

	value1, err := client.Get(key1)
	if err != nil {
		fmt.Println("Failed to get value: ", err)
		return
	}
	value2, err := client.Get(key2)
	if err != nil {
		fmt.Println("Failed to get value: ", err)
		return
	}

	// Get TestPlans
	var sp []interface{}
	var tp []interface{}
	if value1 == nil || value2 == nil {
		fmt.Println("The plan is not exists. We will query it from mysql and then store them in redis.")

		res := models.GetAllSprintNames()
		for _, item := range res {
			sp = append(sp, string(item["SprintName"]))

			temp := models.GetAllPlansBySprintName(string(item["SprintName"]))
			tp = append(tp, temp)
		}
		value1, err := json.Marshal(sp)
		if err != nil {
			fmt.Println("Failed to marshal: ", err)
		}
		client.Set(key1, value1)
		client.Expire(key1, expiration)

		value2, err := json.Marshal(tp)
		if err != nil {
			fmt.Println("Failed to marshal: ", err)
		}
		client.Set(key2, value2)
		client.Expire(key2, expiration)
	} else {
		fmt.Println("The plan is exists. We will unmarshal them.")
		// var temp planinfo
		err := json.Unmarshal(value1, &sp)
		if err != nil {
			fmt.Println("Failed to unmarshal: ", err)
			return
		}
		err2 := json.Unmarshal(value2, &tp)
		if err2 != nil {
			fmt.Println("Failed to unmarshal: ", err2)
			return
		}
	}

	this.Data["TableHeader"] = sp
	this.Data["TestPlanTree"] = tp
	this.Data["Website"] = "goTestLinkReport.org"
	this.Data["Email"] = "*****@*****.**"

	this.TplNames = "plan.tpl"
}