Skip to content

Commit a3bda7b

Browse files
authored
add support for default page (#729)
1 parent 81f6057 commit a3bda7b

File tree

8 files changed

+89
-77
lines changed

8 files changed

+89
-77
lines changed

internal/config/config.go

+30-27
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,34 @@ import (
3232

3333
// Config represents the configuration for the server.
3434
type Config struct {
35-
Host string // Server host
36-
Port int // Server port
37-
DAGs string // Location of DAG files
38-
Executable string // Executable path
39-
WorkDir string // Default working directory
40-
IsBasicAuth bool // Enable basic auth
41-
BasicAuthUsername string // Basic auth username
42-
BasicAuthPassword string // Basic auth password
43-
LogEncodingCharset string // Log encoding charset
44-
LogDir string // Log directory
45-
DataDir string // Data directory
46-
SuspendFlagsDir string // Suspend flags directory
47-
AdminLogsDir string // Directory for admin logs
48-
BaseConfig string // Common config file for all DAGs.
49-
NavbarColor string // Navbar color for the web UI
50-
NavbarTitle string // Navbar title for the web UI
51-
Env sync.Map // Store environment variables
52-
TLS *TLS // TLS configuration
53-
IsAuthToken bool // Enable auth token for API
54-
AuthToken string // Auth token for API
55-
LatestStatusToday bool // Show latest status today or the latest status
56-
BasePath string // Base path for the server
57-
APIBaseURL string // Base URL for API
58-
Debug bool // Enable debug mode (verbose logging)
59-
LogFormat string // Log format
60-
TZ string // The server time zone
61-
Location *time.Location // The server location
35+
Host string // Server host
36+
Port int // Server port
37+
DAGs string // Location of DAG files
38+
Executable string // Executable path
39+
WorkDir string // Default working directory
40+
IsBasicAuth bool // Enable basic auth
41+
BasicAuthUsername string // Basic auth username
42+
BasicAuthPassword string // Basic auth password
43+
LogEncodingCharset string // Log encoding charset
44+
LogDir string // Log directory
45+
DataDir string // Data directory
46+
SuspendFlagsDir string // Suspend flags directory
47+
AdminLogsDir string // Directory for admin logs
48+
BaseConfig string // Common config file for all DAGs.
49+
NavbarColor string // Navbar color for the web UI
50+
NavbarTitle string // Navbar title for the web UI
51+
Env sync.Map // Store environment variables
52+
TLS *TLS // TLS configuration
53+
IsAuthToken bool // Enable auth token for API
54+
AuthToken string // Auth token for API
55+
LatestStatusToday bool // Show latest status today or the latest status
56+
BasePath string // Base path for the server
57+
APIBaseURL string // Base URL for API
58+
Debug bool // Enable debug mode (verbose logging)
59+
LogFormat string // Log format
60+
TZ string // The server time zone
61+
Location *time.Location // The server location
62+
MaxDashboardPageLimit int // The default page limit for the dashboard
6263
}
6364

6465
type TLS struct {
@@ -184,6 +185,7 @@ func setupViper() error {
184185
viper.SetDefault("navbarTitle", "Dagu")
185186
viper.SetDefault("basePath", "")
186187
viper.SetDefault("apiBaseURL", "/api/v1")
188+
viper.SetDefault("maxDashboardPageLimit", 100)
187189

188190
// Set executable path
189191
// This is used for invoking the workflow process on the server.
@@ -216,6 +218,7 @@ func bindEnvs() {
216218
_ = viper.BindEnv("basePath", "DAGU_BASE_PATH")
217219
_ = viper.BindEnv("apiBaseURL", "DAGU_API_BASE_URL")
218220
_ = viper.BindEnv("tz", "DAGU_TZ")
221+
_ = viper.BindEnv("maxDashboardPageLimit", "DAGU_MAX_DASHBOARD_PAGE_LIMIT")
219222

220223
// Basic authentication
221224
_ = viper.BindEnv("isBasicAuth", "DAGU_IS_BASICAUTH")

internal/frontend/frontend.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ func New(cfg *config.Config, lg logger.Logger, cli client.Client) *server.Server
3434
))
3535

3636
serverParams := server.NewServerArgs{
37-
Host: cfg.Host,
38-
Port: cfg.Port,
39-
TLS: cfg.TLS,
40-
Logger: lg,
41-
Handlers: hs,
42-
AssetsFS: assetsFS,
43-
NavbarColor: cfg.NavbarColor,
44-
NavbarTitle: cfg.NavbarTitle,
45-
BasePath: cfg.BasePath,
46-
APIBaseURL: cfg.APIBaseURL,
47-
TimeZone: cfg.TZ,
37+
Host: cfg.Host,
38+
Port: cfg.Port,
39+
TLS: cfg.TLS,
40+
Logger: lg,
41+
Handlers: hs,
42+
AssetsFS: assetsFS,
43+
NavbarColor: cfg.NavbarColor,
44+
NavbarTitle: cfg.NavbarTitle,
45+
APIBaseURL: cfg.APIBaseURL,
46+
MaxDashboardPageLimit: cfg.MaxDashboardPageLimit,
47+
TimeZone: cfg.TZ,
4848
}
4949

5050
if cfg.IsAuthToken {

internal/frontend/server/server.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ type NewServerArgs struct {
6060
AssetsFS fs.FS
6161

6262
// Configuration for the frontend
63-
NavbarColor string
64-
NavbarTitle string
65-
BasePath string
66-
APIBaseURL string
67-
TimeZone string
63+
NavbarColor string
64+
NavbarTitle string
65+
BasePath string
66+
APIBaseURL string
67+
TimeZone string
68+
MaxDashboardPageLimit int
6869
}
6970

7071
type BasicAuth struct {
@@ -91,11 +92,12 @@ func New(params NewServerArgs) *Server {
9192
handlers: params.Handlers,
9293
assets: params.AssetsFS,
9394
funcsConfig: funcsConfig{
94-
NavbarColor: params.NavbarColor,
95-
NavbarTitle: params.NavbarTitle,
96-
BasePath: params.BasePath,
97-
APIBaseURL: params.APIBaseURL,
98-
TZ: params.TimeZone,
95+
NavbarColor: params.NavbarColor,
96+
NavbarTitle: params.NavbarTitle,
97+
BasePath: params.BasePath,
98+
APIBaseURL: params.APIBaseURL,
99+
TZ: params.TimeZone,
100+
MaxDashboardPageLimit: params.MaxDashboardPageLimit,
99101
},
100102
}
101103
}

internal/frontend/server/templates.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ func (srv *Server) useTemplate(
5555
}
5656

5757
type funcsConfig struct {
58-
NavbarColor string
59-
NavbarTitle string
60-
BasePath string
61-
APIBaseURL string
62-
TZ string
58+
NavbarColor string
59+
NavbarTitle string
60+
BasePath string
61+
APIBaseURL string
62+
TZ string
63+
MaxDashboardPageLimit int
6364
}
6465

6566
func defaultFunctions(cfg funcsConfig) template.FuncMap {
@@ -89,6 +90,9 @@ func defaultFunctions(cfg funcsConfig) template.FuncMap {
8990
"tz": func() string {
9091
return cfg.TZ
9192
},
93+
"maxDashboardPageLimit": func() int {
94+
return cfg.MaxDashboardPageLimit
95+
},
9296
}
9397
}
9498

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
{{define "base"}}
22
<!DOCTYPE html>
33
<html lang="en">
4-
<head>
5-
<meta charset="UTF-8" />
6-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8-
<title>{{ navbarTitle }}</title>
9-
<script>
10-
function getConfig() {
11-
return {
12-
apiURL: "{{ apiURL }}",
13-
basePath: "{{ basePath }}",
14-
title: "{{ navbarTitle }}",
15-
navbarColor: "{{ navbarColor }}",
16-
version: "{{ version }}",
17-
tz: "{{ tz }}",
18-
};
19-
}
20-
</script>
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>{{ navbarTitle }}</title>
9+
<script>
10+
function getConfig() {
11+
return {
12+
apiURL: "{{ apiURL }}",
13+
basePath: "{{ basePath }}",
14+
title: "{{ navbarTitle }}",
15+
navbarColor: "{{ navbarColor }}",
16+
version: "{{ version }}",
17+
tz: "{{ tz }}",
18+
maxDashboardPageLimit: "{{ maxDashboardPageLimit }}",
19+
};
20+
}
21+
</script>
2122
<script defer="defer" src="{{ basePath }}/assets/bundle.js?v={{ version }}"></script>
22-
</head>
23-
<body>
24-
{{template "content" .}}
25-
</body>
23+
</head>
24+
<body>
25+
{{template "content" .}}
26+
</body>
2627
</html>
2728
{{ end }}

ui/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
navbarColor: '',
1414
version: '',
1515
tz: '',
16+
maxDashboardPageLimit: '',
1617
};
1718
}
1819
</script>

ui/src/contexts/ConfigContext.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export type Config = {
66
title: string;
77
navbarColor: string;
88
tz: string;
9-
version: string;
9+
version: string;
10+
maxDashboardPageLimit: number;
1011
};
1112

1213
export const ConfigContext = createContext<Config>(null!);

ui/src/pages/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ for (const value in SchedulerStatus) {
2323
function Dashboard() {
2424
const [metrics, setMetrics] = React.useState<metrics>(defaultMetrics);
2525
const appBarContext = React.useContext(AppBarContext);
26-
const { data } = useSWR<ListWorkflowsResponse>(`/dags`, null, {
26+
const config = useConfig();
27+
const { data } = useSWR<ListWorkflowsResponse>(`/dags?limit=${config.maxDashboardPageLimit}`, null, {
2728
refreshInterval: 10000,
2829
});
29-
const config = useConfig();
3030

3131
React.useEffect(() => {
3232
if (!data) {

0 commit comments

Comments
 (0)