1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: flash messages framework (resolve #446)

This commit is contained in:
Ferdinand Mütsch
2023-01-02 18:05:28 +01:00
parent a1444bca8c
commit 746608c062
22 changed files with 214 additions and 113 deletions

19
models/view/common.go Normal file
View File

@@ -0,0 +1,19 @@
package view
type BasicViewModel interface {
SetError(string)
SetSuccess(string)
}
type Messages struct {
Success string
Error string
}
func (m *Messages) SetError(message string) {
m.Error = message
}
func (m *Messages) SetSuccess(message string) {
m.Success = message
}

View File

@@ -6,19 +6,18 @@ type Newsbox struct {
}
type HomeViewModel struct {
Success string
Error string
Messages
TotalHours int
TotalUsers int
Newsbox *Newsbox
}
func (s *HomeViewModel) WithSuccess(m string) *HomeViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *HomeViewModel) WithError(m string) *HomeViewModel {
s.Error = m
s.SetError(m)
return s
}

View File

@@ -1,18 +1,17 @@
package view
type ImprintViewModel struct {
Messages
HtmlText string
Success string
Error string
}
func (s *ImprintViewModel) WithSuccess(m string) *ImprintViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *ImprintViewModel) WithError(m string) *ImprintViewModel {
s.Error = m
s.SetError(m)
return s
}

View File

@@ -8,6 +8,7 @@ import (
)
type LeaderboardViewModel struct {
Messages
User *models.User
By string
Key string
@@ -16,17 +17,15 @@ type LeaderboardViewModel struct {
UserLanguages map[string][]string
ApiKey string
PageParams *utils.PageParams
Success string
Error string
}
func (s *LeaderboardViewModel) WithSuccess(m string) *LeaderboardViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *LeaderboardViewModel) WithError(m string) *LeaderboardViewModel {
s.Error = m
s.SetError(m)
return s
}

View File

@@ -1,8 +1,7 @@
package view
type LoginViewModel struct {
Success string
Error string
Messages
TotalUsers int
AllowSignup bool
}
@@ -13,11 +12,11 @@ type SetPasswordViewModel struct {
}
func (s *LoginViewModel) WithSuccess(m string) *LoginViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *LoginViewModel) WithError(m string) *LoginViewModel {
s.Error = m
s.SetError(m)
return s
}

View File

@@ -6,6 +6,7 @@ import (
)
type SettingsViewModel struct {
Messages
User *models.User
LanguageMappings []*models.LanguageMapping
Aliases []*SettingsVMCombinedAlias
@@ -16,8 +17,6 @@ type SettingsViewModel struct {
UserFirstData time.Time
SupportContact string
ApiKey string
Success string
Error string
}
type SettingsVMCombinedAlias struct {
@@ -36,11 +35,11 @@ func (s *SettingsViewModel) SubscriptionsEnabled() bool {
}
func (s *SettingsViewModel) WithSuccess(m string) *SettingsViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *SettingsViewModel) WithError(m string) *SettingsViewModel {
s.Error = m
s.SetError(m)
return s
}

View File

@@ -3,6 +3,7 @@ package view
import "github.com/muety/wakapi/models"
type SummaryViewModel struct {
Messages
*models.Summary
*models.SummaryParams
User *models.User
@@ -10,18 +11,16 @@ type SummaryViewModel struct {
EditorColors map[string]string
LanguageColors map[string]string
OSColors map[string]string
Error string
Success string
ApiKey string
RawQuery string
}
func (s *SummaryViewModel) WithSuccess(m string) *SummaryViewModel {
s.Success = m
s.SetSuccess(m)
return s
}
func (s *SummaryViewModel) WithError(m string) *SummaryViewModel {
s.Error = m
s.SetError(m)
return s
}