158 lines
4.7 KiB
Go
158 lines
4.7 KiB
Go
package keyboard
|
||
|
||
import (
|
||
"bitrix_balancer_api/core/lib/external/tgkit"
|
||
"bitrix_balancer_api/core/typescore"
|
||
"bitrix_balancer_api/telegram_service/types"
|
||
"context"
|
||
"fmt"
|
||
)
|
||
|
||
func BuildAddApproverMainMenu() interface{} {
|
||
return tgkit.NewInlineKeyboard().
|
||
Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Добавить согласующего", "add_appr_create")).
|
||
Row(tgkit.Btn("📋 Ранее добавленные", "add_appr_list")).
|
||
Build()
|
||
}
|
||
|
||
func BuildAddApproverCategoryMenu(categories []*typescore.ApprovalTopicCategory, page int) interface{} {
|
||
const perPage = 6
|
||
total := len(categories)
|
||
totalPages := (total + perPage - 1) / perPage
|
||
if page < 0 {
|
||
page = 0
|
||
}
|
||
if page >= totalPages && totalPages > 0 {
|
||
page = totalPages - 1
|
||
}
|
||
start, end := page*perPage, page*perPage+perPage
|
||
if end > total {
|
||
end = total
|
||
}
|
||
|
||
kb := tgkit.NewInlineKeyboard()
|
||
for _, c := range categories[start:end] {
|
||
if c.ID == nil || c.Name == nil {
|
||
continue
|
||
}
|
||
kb.Row(tgkit.Btn(*c.Name, fmt.Sprintf("add_appr_category:%d", *c.ID)))
|
||
}
|
||
if totalPages > 1 {
|
||
kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "add_appr_category_page", "add_appr_page_noop"))
|
||
}
|
||
return kb.Build()
|
||
}
|
||
|
||
func BuildAddApproverApprovalMenu(approvals []*typescore.Approval, categoryID uint64, page int, ctx context.Context, ipc *types.InternalProviderControl) interface{} {
|
||
const perPage = 6
|
||
total := len(approvals)
|
||
totalPages := (total + perPage - 1) / perPage
|
||
if page < 0 {
|
||
page = 0
|
||
}
|
||
if page >= totalPages && totalPages > 0 {
|
||
page = totalPages - 1
|
||
}
|
||
start, end := page*perPage, page*perPage+perPage
|
||
if end > total {
|
||
end = total
|
||
}
|
||
|
||
kb := tgkit.NewInlineKeyboard()
|
||
for _, a := range approvals[start:end] {
|
||
if a.ID == nil {
|
||
continue
|
||
}
|
||
topicName := "—"
|
||
if a.TopicID != nil {
|
||
if t, _ := ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *a.TopicID); t != nil && t.Name != nil {
|
||
topicName = *t.Name
|
||
}
|
||
}
|
||
kb.Row(tgkit.Btn(fmt.Sprintf("#%d — %s", *a.ID, topicName), fmt.Sprintf("add_appr_approval:%d", *a.ID)))
|
||
}
|
||
if totalPages > 1 {
|
||
kb.Rows = append(kb.Rows, buildPageRow(page, totalPages,
|
||
fmt.Sprintf("add_appr_approval_page:%d", categoryID), "add_appr_page_noop"))
|
||
}
|
||
kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "К категориям", "add_appr_create"))
|
||
return kb.Build()
|
||
}
|
||
|
||
func BuildAddApproverUserMenu(users []*typescore.User, approvalID, categoryID uint64, page int) interface{} {
|
||
const perPage = 8
|
||
total := len(users)
|
||
totalPages := (total + perPage - 1) / perPage
|
||
if page < 0 {
|
||
page = 0
|
||
}
|
||
if page >= totalPages && totalPages > 0 {
|
||
page = totalPages - 1
|
||
}
|
||
start, end := page*perPage, page*perPage+perPage
|
||
if end > total {
|
||
end = total
|
||
}
|
||
|
||
kb := tgkit.NewInlineKeyboard()
|
||
for _, u := range users[start:end] {
|
||
if u.ID == nil || u.FullName == nil {
|
||
continue
|
||
}
|
||
kb.Row(tgkit.Btn(*u.FullName, fmt.Sprintf("add_appr_user:%d", *u.ID)))
|
||
}
|
||
if totalPages > 1 {
|
||
kb.Rows = append(kb.Rows, buildPageRow(page, totalPages,
|
||
fmt.Sprintf("add_appr_user_page:%d:%d", approvalID, categoryID), "add_appr_page_noop"))
|
||
}
|
||
kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "Назад", fmt.Sprintf("add_appr_category:%d", categoryID)))
|
||
return kb.Build()
|
||
}
|
||
|
||
func BuildAddedApproversList(items []*typescore.ApprovalAdditionalApprover, page int, ctx context.Context, ipc *types.InternalProviderControl) interface{} {
|
||
const perPage = 6
|
||
total := len(items)
|
||
totalPages := (total + perPage - 1) / perPage
|
||
if page < 0 {
|
||
page = 0
|
||
}
|
||
if page >= totalPages && totalPages > 0 {
|
||
page = totalPages - 1
|
||
}
|
||
start, end := page*perPage, page*perPage+perPage
|
||
if end > total {
|
||
end = total
|
||
}
|
||
|
||
kb := tgkit.NewInlineKeyboard()
|
||
for _, aa := range items[start:end] {
|
||
if aa.ID == nil || aa.ApprovalID == nil {
|
||
continue
|
||
}
|
||
approverName := "—"
|
||
if aa.ApproverID != nil {
|
||
if u, _ := ipc.Database.User.GetUserByIDDB(ctx, *aa.ApproverID); u != nil && u.FullName != nil {
|
||
approverName = *u.FullName
|
||
}
|
||
}
|
||
kb.Row(tgkit.Btn(fmt.Sprintf("#%d — %s", *aa.ApprovalID, approverName), fmt.Sprintf("add_appr_detail:%d", *aa.ID)))
|
||
}
|
||
if totalPages > 1 {
|
||
kb.Rows = append(kb.Rows, buildPageRow(page, totalPages, "add_appr_list_page", "add_appr_page_noop"))
|
||
}
|
||
return kb.Build()
|
||
}
|
||
|
||
func BuildAddedApproverDetail() interface{} {
|
||
return tgkit.NewInlineKeyboard().
|
||
Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "К списку", "add_appr_list")).
|
||
Build()
|
||
}
|
||
|
||
// BuildAddApproverToApproval — добавить согласующего прямо из карточки
|
||
func BuildAddApproverToApproval(approvalID uint64) interface{} {
|
||
return tgkit.NewInlineKeyboard().
|
||
Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Добавить согласующего", fmt.Sprintf("add_appr_to_approval:%d", approvalID))).
|
||
Build()
|
||
}
|