display paused instances separately (#173)

Reviewed-on: https://git.ptzo.gdn/feditools/relay/pulls/173
Co-authored-by: Tyr Mactire <tyr@pettingzoo.co>
Co-committed-by: Tyr Mactire <tyr@pettingzoo.co>
This commit is contained in:
Tyr Mactire 2022-12-09 06:48:59 +00:00 committed by PettingZoo Gitea
parent 1e1d15b8db
commit c6240950fe
No known key found for this signature in database
GPG Key ID: 39788A4390A1372F
6 changed files with 161 additions and 21 deletions

View File

@ -12,4 +12,5 @@ type Home struct {
HomeBody string
FollowingInstances [][]*models.Instance
PausedInstances [][]*models.Instance
}

View File

@ -55,14 +55,17 @@ func (m *Module) HomeGetHandler(w http.ResponseWriter, r *http.Request) {
// add tooltips script
tmplVars.AddFooterExtraScript(JSTooltip())
followingInstance, err := m.db.ReadInstancesWhereFollowing(r.Context())
allFollowingInstance, err := m.db.ReadInstancesWhereFollowing(r.Context())
if err != nil {
l.Errorf("db read instances: %s", err.Error())
m.returnErrorPage(w, r, http.StatusInternalServerError, localizer.TextErrorDatabase().String())
return
}
tmplVars.FollowingInstances = columnizer(followingInstance)
following, paused := splitFollowingInstances(allFollowingInstance)
tmplVars.FollowingInstances = columnizer(following)
tmplVars.PausedInstances = columnizer(paused)
// get metrics
received, err := m.logic.MetricsGetReceivedTotalWeek(r.Context(), 7)
@ -131,3 +134,19 @@ func JSHome(receive logic.MetricsDataPointsTime) string {
strings.Join(receiveData, ","),
)
}
func splitFollowingInstances(instances []*models.Instance) ([]*models.Instance, []*models.Instance) {
followingInstances := make([]*models.Instance, 0)
pausedInstances := make([]*models.Instance, 0)
for i := 0; i < len(instances); i++ {
if instances[i].IsPaused {
pausedInstances = append(pausedInstances, instances[i])
continue
}
followingInstances = append(followingInstances, instances[i])
}
return followingInstances, pausedInstances
}

View File

@ -20,6 +20,42 @@ func (l *Localizer) TextPaused() *LocalizedString {
}
}
// TextPausedInstances returns a translated phrase.
func (l *Localizer) TextPausedInstances() *LocalizedString {
text, tag, err := l.localizer.LocalizeWithTag(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: "PausedInstances",
Other: "Paused Instances",
},
})
if err != nil {
logger.WithField("func", "TextPausedInstances").Warningf(missingTranslationWarning, err.Error())
}
return &LocalizedString{
language: tag,
string: text,
}
}
// TextPausedInstancesDesc returns a translated phrase.
func (l *Localizer) TextPausedInstancesDesc() *LocalizedString {
text, tag, err := l.localizer.LocalizeWithTag(&i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
ID: "PausedInstancesDesc",
Other: "Delivery to the following instances has been paused.",
},
})
if err != nil {
logger.WithField("func", "TextPausedInstancesDesc").Warningf(missingTranslationWarning, err.Error())
}
return &LocalizedString{
language: tag,
string: text,
}
}
// TextProblemRunningJob returns a translated phrase.
func (l *Localizer) TextProblemRunningJob(job, errStr string) *LocalizedString {
text, tag, err := l.localizer.LocalizeWithTag(&i18n.LocalizeConfig{

View File

@ -38,6 +38,70 @@ func TestLocalizer_TextPaused(t *testing.T) {
}
}
func TestLocalizer_TextPausedInstances(t *testing.T) {
t.Parallel()
tables := []testTextTable{
{
inputLang: language.English,
outputString: "Paused Instances",
outputLang: language.English,
},
}
langMod, _ := New()
for i, table := range tables {
i := i
table := table
name := fmt.Sprintf(testTranslatedTo, i, table.inputLang)
t.Run(name, func(t *testing.T) {
t.Parallel()
localizer, err := langMod.NewLocalizer(table.inputLang.String())
if err != nil {
t.Errorf(testCantGetLocalizer, i, table.inputLang, err.Error())
return
}
testText(t, i, localizer.TextPausedInstances, table)
})
}
}
func TestLocalizer_TextPausedInstancesDesc(t *testing.T) {
t.Parallel()
tables := []testTextTable{
{
inputLang: language.English,
outputString: "Delivery to the following instances has been paused.",
outputLang: language.English,
},
}
langMod, _ := New()
for i, table := range tables {
i := i
table := table
name := fmt.Sprintf(testTranslatedTo, i, table.inputLang)
t.Run(name, func(t *testing.T) {
t.Parallel()
localizer, err := langMod.NewLocalizer(table.inputLang.String())
if err != nil {
t.Errorf(testCantGetLocalizer, i, table.inputLang, err.Error())
return
}
testText(t, i, localizer.TextPausedInstancesDesc, table)
})
}
}
func TestLocalizer_TextProblemRunningJob(t *testing.T) {
t.Parallel()

View File

@ -63,6 +63,8 @@ en:
OAuthConfigured: OAuth Configured
ObfuscatedDomain: Obfuscated Domain
Paused: Paused
PausedInstances: Paused Instances
PausedInstancesDesc: Delivery to the following instances has been paused.
ProblemRunningJob: 'Problem running the job ''{{.Job}}'': {{.Error}}'
ReceivedActivities: Received Activities
Relay: Relay

View File

@ -4,6 +4,8 @@
{{- $textHowToJoinInbox := .Localizer.TextHowToJoinInbox -}}
{{- $textInstances := .Localizer.TextInstances -}}
{{- $textPaused := .Localizer.TextPaused -}}
{{- $textPausedInstances := .Localizer.TextPausedInstances }}
{{- $textPausedInstancesDesc := .Localizer.TextPausedInstancesDesc }}
{{- $textReceivedActivities := .Localizer.TextReceivedActivities -}}
{{- $textRelay := .Localizer.TextRelay -}}
{{- template "header" . }}
@ -31,25 +33,6 @@
</ul>
</div>
</div>
<div class="row">
<div class="col mt-4">
<h2 lang="{{ $textInstances.Language }}"><i class="fa-solid fa-users-line"></i> {{ $textInstances }}</h2>
</div>
</div>
<div class="row">
{{- range $column := .FollowingInstances }}
<div class="col">
<ul>
{{- range $instance := $column }}
<li>
{{- $instance }}
{{- if $instance.IsPaused }} <span class="badge rounded-pill text-bg-secondary" lang="{{ $textPaused.Language }}">{{ $textPaused.Lower }}</span>{{end}}
</li>
{{- end }}
</ul>
</div>
{{- end }}
</div>
<div class="row">
<div class="col mt-4">
<h2 lang="{{ $textReceivedActivities.Language }}"><i class="fa-solid fa-inbox"></i> {{ $textReceivedActivities }}</h2>
@ -60,6 +43,41 @@
<canvas id="receiveChartContainer" style="height: 350px; width: 100%;"></canvas>
</div>
</div>
<div class="row">
<div class="col mt-4">
<h2 lang="{{ $textInstances.Language }}"><i class="fa-solid fa-users-line"></i> {{ $textInstances }}</h2>
</div>
</div>
<div class="row">
{{- range $column := .FollowingInstances }}
<div class="col">
<ul>
{{- range $instance := $column }}
<li>{{ $instance }}</li>
{{- end }}
</ul>
</div>
{{- end }}
</div>
{{- if .PausedInstances }}
<div class="row">
<div class="col mt-4">
<h2 lang="{{ $textPausedInstances.Language }}"><i class="fa-solid fa-users-line"></i> {{ $textPausedInstances }}</h2>
<p lang="{{ $textPausedInstancesDesc.Language }}">{{ $textPausedInstancesDesc }}</p>
</div>
</div>
<div class="row">
{{- range $column := .PausedInstances }}
<div class="col">
<ul>
{{- range $instance := $column }}
<li>{{ $instance }}</li>
{{- end }}
</ul>
</div>
{{- end }}
</div>
{{- end }}
</div><!-- /.container -->
{{ template "footer" . }}
{{ end }}