2022-10-03 11:53:27 +03:00
|
|
|
package view
|
|
|
|
|
2022-10-06 00:36:57 +03:00
|
|
|
import (
|
|
|
|
"github.com/muety/wakapi/models"
|
|
|
|
"strings"
|
|
|
|
)
|
2022-10-03 11:53:27 +03:00
|
|
|
|
|
|
|
type LeaderboardViewModel struct {
|
2022-10-05 22:52:10 +03:00
|
|
|
User *models.User
|
|
|
|
By string
|
|
|
|
Key string
|
|
|
|
Items []*models.LeaderboardItem
|
|
|
|
TopKeys []string
|
|
|
|
UserLanguages map[string][]string
|
|
|
|
ApiKey string
|
|
|
|
Success string
|
|
|
|
Error string
|
2022-10-03 11:53:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LeaderboardViewModel) WithSuccess(m string) *LeaderboardViewModel {
|
|
|
|
s.Success = m
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *LeaderboardViewModel) WithError(m string) *LeaderboardViewModel {
|
|
|
|
s.Error = m
|
|
|
|
return s
|
|
|
|
}
|
2022-10-04 00:52:22 +03:00
|
|
|
|
|
|
|
func (s *LeaderboardViewModel) ColorModifier(item *models.LeaderboardItem, principal *models.User) string {
|
|
|
|
if principal != nil && item.UserID == principal.ID {
|
|
|
|
return "self"
|
|
|
|
}
|
|
|
|
if item.Rank == 1 {
|
|
|
|
return "gold"
|
|
|
|
}
|
|
|
|
if item.Rank == 2 {
|
|
|
|
return "silver"
|
|
|
|
}
|
|
|
|
if item.Rank == 3 {
|
|
|
|
return "bronze"
|
|
|
|
}
|
|
|
|
return "default"
|
|
|
|
}
|
2022-10-06 00:36:57 +03:00
|
|
|
|
|
|
|
func (s *LeaderboardViewModel) LangIcon(lang string) string {
|
|
|
|
// https://icon-sets.iconify.design/mdi/
|
|
|
|
langs := map[string]string{
|
|
|
|
"c": "c",
|
|
|
|
"c++": "cpp",
|
|
|
|
"cpp": "cpp",
|
|
|
|
"go": "go",
|
|
|
|
"haskell": "haskell",
|
|
|
|
"html": "html5",
|
|
|
|
"java": "java",
|
|
|
|
"javascript": "javascript",
|
|
|
|
"kotlin": "kotlin",
|
|
|
|
"lua": "lua",
|
|
|
|
"php": "php",
|
|
|
|
"python": "python",
|
|
|
|
"r": "r",
|
|
|
|
"ruby": "ruby",
|
|
|
|
"rust": "rust",
|
|
|
|
"swift": "swift",
|
|
|
|
"typescript": "typescript",
|
|
|
|
}
|
|
|
|
if match, ok := langs[strings.ToLower(lang)]; ok {
|
|
|
|
return "mdi:language-" + match
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|