Beispiel #1
0
func (us *Users) GET(c *kocha.Context) error {
	var n int
	var users []model.User

	num, _ := GetPerItem(c)
	currentPage, _ := GetPageNum(c)
	page := currentPage
	if page > 0 {
		page--
	}

	dbInst := db.Get("default")
	condition := dbInst.OrderBy("id", genmai.DESC).Limit(num).Offset(page * num)
	err := dbInst.Select(&users, condition)
	if err == nil {
		if page > 0 && len(users) == 0 {
			c.Redirect("/users", false)
		}
		err = dbInst.Select(&n, dbInst.Count(), dbInst.From(&model.User{}))
	}

	if err != nil {
		c.RenderError(500, err, nil)
	}

	pagination, _ := simpagin.New(currentPage, n, num, DEFAULT_PER_PAGE)
	return c.Render(map[string]interface{}{
		"ControllerName": "Users",
		"users":          users,
		"totalPage":      int(math.Ceil(float64(n) / float64(num))),
		"pagination":     pagination,
	})
}
Beispiel #2
0
func (qu *Queues) GET(c *kocha.Context) error {
	var n int
	var queues []Queue

	num, _ := GetPerItem(c)
	currentPage, _ := GetPageNum(c)
	page := currentPage
	if page > 0 {
		page--
	}

	dbInst := db.Get("default")
	rows, err := dbInst.DB().Query(`
		SELECT queues.id, status, screen_name, tweet_id,
		action, execute_time, fail_count, queues.created_at, queues.updated_at
		FROM queues JOIN users ON user_id = users.id
		ORDER BY id DESC LIMIT ? OFFSET ?
	`, num, page*num)

	if err == nil {
		defer rows.Close()
		for rows.Next() {
			var queue Queue
			if err := rows.Scan(
				&queue.Id,
				&queue.Status,
				&queue.ScreenName,
				&queue.TweetId,
				&queue.Action,
				&queue.ExecuteTime,
				&queue.FailCount,
				&queue.CreatedAt,
				&queue.UpdatedAt,
			); err != nil {
				panic(err)
			}
			queues = append(queues, queue)
		}

		if page > 0 && len(queues) == 0 {
			c.Redirect("/queues", false)
		}
		err = dbInst.Select(&n, dbInst.Count(), dbInst.From(&model.Queue{}))
	}

	if err != nil {
		c.RenderError(500, err, nil)
	}

	pagination, _ := simpagin.New(currentPage, n, num, DEFAULT_PER_PAGE)
	return c.Render(map[string]interface{}{
		"ControllerName": "Queues",
		"queues":         queues,
		"totalPage":      int(math.Ceil(float64(n) / float64(num))),
		"pagination":     pagination,
	})
}
Beispiel #3
0
func (r *Root) GET(c *kocha.Context) error {
	data := c.Data.(map[string]interface{})
	selectedVocaloids := data["SelectedVocaloids"].([]*model.Vocaloid)
	count, err := model.Songs.Count(selectedVocaloids...)
	if err != nil {
		return c.RenderError(500, err, nil)
	}
	p, err := strconv.Atoi(c.Params.Get("p"))
	if err != nil {
		p = 1
	}
	offset := int(math.Max(itemsPerPage, 0) * math.Max(float64(p-1), 0))
	songs, err := model.Songs.FindByVocaloid(selectedVocaloids, offset, itemsPerPage)
	if err != nil {
		return c.RenderError(500, err, nil)
	}
	if len(selectedVocaloids) == 0 {
		selectedVocaloids = append(selectedVocaloids, &model.Vocaloid{Key: "vocaloid", Name: "VOCALOID"})
		data["SelectedVocaloids"] = selectedVocaloids
	}
	paginationLength := int(count / itemsPerPage)
	if count%itemsPerPage > 0 {
		paginationLength++
	}
	plength := paginationLength
	if plength < 1 {
		plength = 1
	}
	if plength > maxPaginationLength {
		plength = maxPaginationLength
	}
	paginator := pagination.NewPaginator(count, itemsPerPage, plength, paginationThreshold)
	page := paginator.Page(p)
	pages := paginator.Pages(p)
	return c.Render(map[string]interface{}{
		"Songs":            songs,
		"SelectedVocaloid": selectedVocaloids[0],
		"Pages":            pages,
		"Page":             page,
	})
}
Beispiel #4
0
func (r *Root) GET(c *kocha.Context) error {
	return c.Render(map[string]interface{}{
		"ControllerName": "Root",
	})
}
Beispiel #5
0
func (ab *About) GET(c *kocha.Context) error {
	return c.Render(nil)
}
Beispiel #6
0
func (ro *Root) GET(c *kocha.Context) error {
	return c.Render(nil)
}