98 lines
3.7 KiB
Go
98 lines
3.7 KiB
Go
package keyboard
|
||
|
||
import (
|
||
"bitrix_balancer_api/core/lib/external/tgkit"
|
||
"bitrix_balancer_api/core/typescore"
|
||
"fmt"
|
||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||
)
|
||
|
||
// BuildObserverApprovalDetail — карточка заявки с кнопками наблюдателя.
|
||
func BuildObserverApprovalDetail(approvalID uint64, topicCode string, commentsCount int) tgbotapi.InlineKeyboardMarkup {
|
||
return tgbotapi.NewInlineKeyboardMarkup(
|
||
tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData("🔔 Напомнить согласующему", fmt.Sprintf("obs_remind:%d", approvalID)),
|
||
tgbotapi.NewInlineKeyboardButtonData("💬 Добавить комментарий", fmt.Sprintf("appr_comment:%d", approvalID)),
|
||
),
|
||
tgbotapi.NewInlineKeyboardRow(
|
||
buildCommentsButtonData(approvalID, commentsCount),
|
||
),
|
||
tgbotapi.NewInlineKeyboardRow(
|
||
tgbotapi.NewInlineKeyboardButtonData("← К фильтрам", fmt.Sprintf("obs_topic:%s", topicCode)),
|
||
),
|
||
)
|
||
}
|
||
|
||
func buildCommentsButtonData(approvalID uint64, commentsCount int) tgbotapi.InlineKeyboardButton {
|
||
label := "💬 Посмотреть все комментарии"
|
||
if commentsCount > 0 {
|
||
label = fmt.Sprintf("💬 Посмотреть все комментарии (%d)", commentsCount)
|
||
}
|
||
return tgbotapi.NewInlineKeyboardButtonData(label, fmt.Sprintf("appr_view_comments:%d", approvalID))
|
||
}
|
||
|
||
// BuildObserverStatusFilterMenu — выбор статуса заявок для просмотра в рамках темы/категории
|
||
func BuildObserverStatusFilterMenu(topicCode string) tgbotapi.InlineKeyboardMarkup {
|
||
return tgkit.NewInlineKeyboard().
|
||
Row(tgkit.Btn("⏳ На согласовании", fmt.Sprintf("obs_status:pending:%s:0", topicCode))).
|
||
Row(tgkit.Btn("✅ Согласованные", fmt.Sprintf("obs_status:approved:%s:0", topicCode))).
|
||
Row(tgkit.Btn("📋 Все", fmt.Sprintf("obs_status:all:%s:0", topicCode))).
|
||
Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "Назад к темам", "obs_back_topics")).
|
||
Build()
|
||
}
|
||
|
||
// BuildObserverApprovalList — список заявок с пагинацией и учётом текущего фильтра.
|
||
// Кнопка "К фильтрам" возвращает на экран выбора статуса, "К темам" — к списку тем.
|
||
func BuildObserverApprovalList(
|
||
approvals []*typescore.Approval,
|
||
initiators map[uint64]*typescore.User,
|
||
departments map[uint64]*typescore.Department,
|
||
status, topicCode string,
|
||
page int,
|
||
) tgbotapi.InlineKeyboardMarkup {
|
||
const perPage = 8
|
||
|
||
total := len(approvals)
|
||
totalPages := (total + perPage - 1) / perPage
|
||
if page < 0 {
|
||
page = 0
|
||
}
|
||
if page >= totalPages && totalPages > 0 {
|
||
page = totalPages - 1
|
||
}
|
||
start := page * perPage
|
||
end := start + perPage
|
||
if end > total {
|
||
end = total
|
||
}
|
||
|
||
kb := tgkit.NewInlineKeyboard()
|
||
for _, a := range approvals[start:end] {
|
||
if a.ID == nil {
|
||
continue
|
||
}
|
||
label := fmt.Sprintf("#%d", *a.ID)
|
||
if a.InitiatorID != nil {
|
||
if u, ok := initiators[*a.InitiatorID]; ok && u.FullName != nil {
|
||
label += " " + *u.FullName
|
||
}
|
||
}
|
||
if a.DepartmentID != nil {
|
||
if d, ok := departments[*a.DepartmentID]; ok && d.Name != nil {
|
||
label += " — " + *d.Name
|
||
}
|
||
}
|
||
kb.Row(tgkit.Btn(label, fmt.Sprintf("obs_approval:%d", *a.ID)))
|
||
}
|
||
|
||
if totalPages > 1 {
|
||
prevCB := fmt.Sprintf("obs_status:%s:%s:%d", status, topicCode, page-1)
|
||
nextCB := fmt.Sprintf("obs_status:%s:%s:%d", status, topicCode, page+1)
|
||
kb.Rows = append(kb.Rows, tgkit.PaginationRow(page, totalPages, prevCB, nextCB, "obs_status_noop"))
|
||
}
|
||
|
||
kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "К фильтрам", fmt.Sprintf("obs_topic:%s", topicCode)))
|
||
kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleBack, "К темам", "obs_back_topics"))
|
||
return kb.Build()
|
||
}
|