mirror of
https://github.com/sablierapp/sablier.git
synced 2025-12-25 23:03:38 +01:00
@@ -25,6 +25,7 @@ type RenderOptionsInstanceState struct {
|
||||
|
||||
type RenderOptions struct {
|
||||
DisplayName string
|
||||
ShowDetails bool
|
||||
InstanceStates []RenderOptionsInstanceState
|
||||
SessionDuration time.Duration
|
||||
RefreshFrequency time.Duration
|
||||
@@ -61,9 +62,15 @@ func Render(options RenderOptions, writer io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
instanceStates := []RenderOptionsInstanceState{}
|
||||
|
||||
if options.ShowDetails {
|
||||
instanceStates = options.InstanceStates
|
||||
}
|
||||
|
||||
return tpl.Execute(writer, TemplateValues{
|
||||
DisplayName: options.DisplayName,
|
||||
InstanceStates: options.InstanceStates,
|
||||
InstanceStates: instanceStates,
|
||||
SessionDuration: humanizeDuration(options.SessionDuration),
|
||||
RefreshFrequency: fmt.Sprintf("%d", int64(options.RefreshFrequency.Seconds())),
|
||||
Version: options.Version,
|
||||
|
||||
@@ -242,6 +242,38 @@ func TestRenderContent(t *testing.T) {
|
||||
},
|
||||
wantContent: "<meta http-equiv=\"refresh\" content=\"10\" />",
|
||||
},
|
||||
{
|
||||
name: "details is rendered",
|
||||
args: args{
|
||||
options: RenderOptions{
|
||||
DisplayName: "Test",
|
||||
ShowDetails: true,
|
||||
InstanceStates: instanceStates,
|
||||
Theme: "ghost",
|
||||
SessionDuration: 10 * time.Minute,
|
||||
RefreshFrequency: 10 * time.Second,
|
||||
CustomThemes: nil,
|
||||
Version: "v0.0.0",
|
||||
},
|
||||
},
|
||||
wantContent: "started (4/4)",
|
||||
},
|
||||
{
|
||||
name: "details is not rendered",
|
||||
args: args{
|
||||
options: RenderOptions{
|
||||
DisplayName: "Test",
|
||||
ShowDetails: false,
|
||||
InstanceStates: instanceStates,
|
||||
Theme: "ghost",
|
||||
SessionDuration: 10 * time.Minute,
|
||||
RefreshFrequency: 10 * time.Second,
|
||||
CustomThemes: nil,
|
||||
Version: "v0.0.0",
|
||||
},
|
||||
},
|
||||
wantContent: "<table></table>",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
type DynamicRequest struct {
|
||||
Names []string `form:"names" binding:"required"`
|
||||
ShowDetails bool `form:"show_details"`
|
||||
DisplayName string `form:"display_name"`
|
||||
Theme string `form:"theme"`
|
||||
SessionDuration time.Duration `form:"session_duration" binding:"required"`
|
||||
|
||||
@@ -49,6 +49,7 @@ func NewServeStrategy(sessionsManager sessions.Manager, conf config.Strategy) *S
|
||||
func (s *ServeStrategy) ServeDynamic(c *gin.Context) {
|
||||
request := models.DynamicRequest{
|
||||
Theme: s.StrategyConfig.Dynamic.DefaultTheme,
|
||||
ShowDetails: s.StrategyConfig.Dynamic.ShowDetailsByDefault,
|
||||
RefreshFrequency: s.StrategyConfig.Dynamic.DefaultRefreshFrequency,
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ func (s *ServeStrategy) ServeDynamic(c *gin.Context) {
|
||||
|
||||
renderOptions := pages.RenderOptions{
|
||||
DisplayName: request.DisplayName,
|
||||
ShowDetails: request.ShowDetails,
|
||||
SessionDuration: request.SessionDuration,
|
||||
Theme: request.Theme,
|
||||
CustomThemes: s.customThemesFS,
|
||||
|
||||
Reference in New Issue
Block a user