From a3bda7bec9e069313375f617e14fd7166658cecc Mon Sep 17 00:00:00 2001 From: Jonathon Choo Date: Sat, 30 Nov 2024 01:24:44 +1100 Subject: [PATCH] add support for default page (#729) --- internal/config/config.go | 57 +++++++++++++------------ internal/frontend/frontend.go | 22 +++++----- internal/frontend/server/server.go | 22 +++++----- internal/frontend/server/templates.go | 14 +++--- internal/frontend/templates/base.gohtml | 43 ++++++++++--------- ui/index.html | 1 + ui/src/contexts/ConfigContext.tsx | 3 +- ui/src/pages/index.tsx | 4 +- 8 files changed, 89 insertions(+), 77 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 398963691..a08a825e8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -32,33 +32,34 @@ import ( // Config represents the configuration for the server. type Config struct { - Host string // Server host - Port int // Server port - DAGs string // Location of DAG files - Executable string // Executable path - WorkDir string // Default working directory - IsBasicAuth bool // Enable basic auth - BasicAuthUsername string // Basic auth username - BasicAuthPassword string // Basic auth password - LogEncodingCharset string // Log encoding charset - LogDir string // Log directory - DataDir string // Data directory - SuspendFlagsDir string // Suspend flags directory - AdminLogsDir string // Directory for admin logs - BaseConfig string // Common config file for all DAGs. - NavbarColor string // Navbar color for the web UI - NavbarTitle string // Navbar title for the web UI - Env sync.Map // Store environment variables - TLS *TLS // TLS configuration - IsAuthToken bool // Enable auth token for API - AuthToken string // Auth token for API - LatestStatusToday bool // Show latest status today or the latest status - BasePath string // Base path for the server - APIBaseURL string // Base URL for API - Debug bool // Enable debug mode (verbose logging) - LogFormat string // Log format - TZ string // The server time zone - Location *time.Location // The server location + Host string // Server host + Port int // Server port + DAGs string // Location of DAG files + Executable string // Executable path + WorkDir string // Default working directory + IsBasicAuth bool // Enable basic auth + BasicAuthUsername string // Basic auth username + BasicAuthPassword string // Basic auth password + LogEncodingCharset string // Log encoding charset + LogDir string // Log directory + DataDir string // Data directory + SuspendFlagsDir string // Suspend flags directory + AdminLogsDir string // Directory for admin logs + BaseConfig string // Common config file for all DAGs. + NavbarColor string // Navbar color for the web UI + NavbarTitle string // Navbar title for the web UI + Env sync.Map // Store environment variables + TLS *TLS // TLS configuration + IsAuthToken bool // Enable auth token for API + AuthToken string // Auth token for API + LatestStatusToday bool // Show latest status today or the latest status + BasePath string // Base path for the server + APIBaseURL string // Base URL for API + Debug bool // Enable debug mode (verbose logging) + LogFormat string // Log format + TZ string // The server time zone + Location *time.Location // The server location + MaxDashboardPageLimit int // The default page limit for the dashboard } type TLS struct { @@ -184,6 +185,7 @@ func setupViper() error { viper.SetDefault("navbarTitle", "Dagu") viper.SetDefault("basePath", "") viper.SetDefault("apiBaseURL", "/api/v1") + viper.SetDefault("maxDashboardPageLimit", 100) // Set executable path // This is used for invoking the workflow process on the server. @@ -216,6 +218,7 @@ func bindEnvs() { _ = viper.BindEnv("basePath", "DAGU_BASE_PATH") _ = viper.BindEnv("apiBaseURL", "DAGU_API_BASE_URL") _ = viper.BindEnv("tz", "DAGU_TZ") + _ = viper.BindEnv("maxDashboardPageLimit", "DAGU_MAX_DASHBOARD_PAGE_LIMIT") // Basic authentication _ = viper.BindEnv("isBasicAuth", "DAGU_IS_BASICAUTH") diff --git a/internal/frontend/frontend.go b/internal/frontend/frontend.go index 4b078eff8..881d61224 100644 --- a/internal/frontend/frontend.go +++ b/internal/frontend/frontend.go @@ -34,17 +34,17 @@ func New(cfg *config.Config, lg logger.Logger, cli client.Client) *server.Server )) serverParams := server.NewServerArgs{ - Host: cfg.Host, - Port: cfg.Port, - TLS: cfg.TLS, - Logger: lg, - Handlers: hs, - AssetsFS: assetsFS, - NavbarColor: cfg.NavbarColor, - NavbarTitle: cfg.NavbarTitle, - BasePath: cfg.BasePath, - APIBaseURL: cfg.APIBaseURL, - TimeZone: cfg.TZ, + Host: cfg.Host, + Port: cfg.Port, + TLS: cfg.TLS, + Logger: lg, + Handlers: hs, + AssetsFS: assetsFS, + NavbarColor: cfg.NavbarColor, + NavbarTitle: cfg.NavbarTitle, + APIBaseURL: cfg.APIBaseURL, + MaxDashboardPageLimit: cfg.MaxDashboardPageLimit, + TimeZone: cfg.TZ, } if cfg.IsAuthToken { diff --git a/internal/frontend/server/server.go b/internal/frontend/server/server.go index fb5e17683..650448c83 100644 --- a/internal/frontend/server/server.go +++ b/internal/frontend/server/server.go @@ -60,11 +60,12 @@ type NewServerArgs struct { AssetsFS fs.FS // Configuration for the frontend - NavbarColor string - NavbarTitle string - BasePath string - APIBaseURL string - TimeZone string + NavbarColor string + NavbarTitle string + BasePath string + APIBaseURL string + TimeZone string + MaxDashboardPageLimit int } type BasicAuth struct { @@ -91,11 +92,12 @@ func New(params NewServerArgs) *Server { handlers: params.Handlers, assets: params.AssetsFS, funcsConfig: funcsConfig{ - NavbarColor: params.NavbarColor, - NavbarTitle: params.NavbarTitle, - BasePath: params.BasePath, - APIBaseURL: params.APIBaseURL, - TZ: params.TimeZone, + NavbarColor: params.NavbarColor, + NavbarTitle: params.NavbarTitle, + BasePath: params.BasePath, + APIBaseURL: params.APIBaseURL, + TZ: params.TimeZone, + MaxDashboardPageLimit: params.MaxDashboardPageLimit, }, } } diff --git a/internal/frontend/server/templates.go b/internal/frontend/server/templates.go index cf00d1ce2..50063e363 100644 --- a/internal/frontend/server/templates.go +++ b/internal/frontend/server/templates.go @@ -55,11 +55,12 @@ func (srv *Server) useTemplate( } type funcsConfig struct { - NavbarColor string - NavbarTitle string - BasePath string - APIBaseURL string - TZ string + NavbarColor string + NavbarTitle string + BasePath string + APIBaseURL string + TZ string + MaxDashboardPageLimit int } func defaultFunctions(cfg funcsConfig) template.FuncMap { @@ -89,6 +90,9 @@ func defaultFunctions(cfg funcsConfig) template.FuncMap { "tz": func() string { return cfg.TZ }, + "maxDashboardPageLimit": func() int { + return cfg.MaxDashboardPageLimit + }, } } diff --git a/internal/frontend/templates/base.gohtml b/internal/frontend/templates/base.gohtml index c8eb9ab2d..694a04789 100644 --- a/internal/frontend/templates/base.gohtml +++ b/internal/frontend/templates/base.gohtml @@ -1,27 +1,28 @@ {{define "base"}} - - - - - {{ navbarTitle }} - + + + + + {{ navbarTitle }} + - - - {{template "content" .}} - + + + {{template "content" .}} + {{ end }} diff --git a/ui/index.html b/ui/index.html index 08fa8184c..cce3a38e7 100644 --- a/ui/index.html +++ b/ui/index.html @@ -13,6 +13,7 @@ navbarColor: '', version: '', tz: '', + maxDashboardPageLimit: '', }; } diff --git a/ui/src/contexts/ConfigContext.tsx b/ui/src/contexts/ConfigContext.tsx index c59c8c68f..c734ef743 100644 --- a/ui/src/contexts/ConfigContext.tsx +++ b/ui/src/contexts/ConfigContext.tsx @@ -6,7 +6,8 @@ export type Config = { title: string; navbarColor: string; tz: string; - version: string; + version: string; + maxDashboardPageLimit: number; }; export const ConfigContext = createContext(null!); diff --git a/ui/src/pages/index.tsx b/ui/src/pages/index.tsx index 7de34d500..d365c19a0 100644 --- a/ui/src/pages/index.tsx +++ b/ui/src/pages/index.tsx @@ -23,10 +23,10 @@ for (const value in SchedulerStatus) { function Dashboard() { const [metrics, setMetrics] = React.useState(defaultMetrics); const appBarContext = React.useContext(AppBarContext); - const { data } = useSWR(`/dags`, null, { + const config = useConfig(); + const { data } = useSWR(`/dags?limit=${config.maxDashboardPageLimit}`, null, { refreshInterval: 10000, }); - const config = useConfig(); React.useEffect(() => { if (!data) {