Skip to content

Commit

Permalink
add support for default page (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnochoo authored Nov 29, 2024
1 parent 81f6057 commit a3bda7b
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 77 deletions.
57 changes: 30 additions & 27 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down
22 changes: 11 additions & 11 deletions internal/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 12 additions & 10 deletions internal/frontend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
}
}
Expand Down
14 changes: 9 additions & 5 deletions internal/frontend/server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,6 +90,9 @@ func defaultFunctions(cfg funcsConfig) template.FuncMap {
"tz": func() string {
return cfg.TZ
},
"maxDashboardPageLimit": func() int {
return cfg.MaxDashboardPageLimit
},
}
}

Expand Down
43 changes: 22 additions & 21 deletions internal/frontend/templates/base.gohtml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{{define "base"}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ navbarTitle }}</title>
<script>
function getConfig() {
return {
apiURL: "{{ apiURL }}",
basePath: "{{ basePath }}",
title: "{{ navbarTitle }}",
navbarColor: "{{ navbarColor }}",
version: "{{ version }}",
tz: "{{ tz }}",
};
}
</script>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ navbarTitle }}</title>
<script>
function getConfig() {
return {
apiURL: "{{ apiURL }}",
basePath: "{{ basePath }}",
title: "{{ navbarTitle }}",
navbarColor: "{{ navbarColor }}",
version: "{{ version }}",
tz: "{{ tz }}",
maxDashboardPageLimit: "{{ maxDashboardPageLimit }}",
};
}
</script>
<script defer="defer" src="{{ basePath }}/assets/bundle.js?v={{ version }}"></script>
</head>
<body>
{{template "content" .}}
</body>
</head>
<body>
{{template "content" .}}
</body>
</html>
{{ end }}
1 change: 1 addition & 0 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
navbarColor: '',
version: '',
tz: '',
maxDashboardPageLimit: '',
};
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/contexts/ConfigContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type Config = {
title: string;
navbarColor: string;
tz: string;
version: string;
version: string;
maxDashboardPageLimit: number;
};

export const ConfigContext = createContext<Config>(null!);
Expand Down
4 changes: 2 additions & 2 deletions ui/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ for (const value in SchedulerStatus) {
function Dashboard() {
const [metrics, setMetrics] = React.useState<metrics>(defaultMetrics);
const appBarContext = React.useContext(AppBarContext);
const { data } = useSWR<ListWorkflowsResponse>(`/dags`, null, {
const config = useConfig();
const { data } = useSWR<ListWorkflowsResponse>(`/dags?limit=${config.maxDashboardPageLimit}`, null, {
refreshInterval: 10000,
});
const config = useConfig();

React.useEffect(() => {
if (!data) {
Expand Down

0 comments on commit a3bda7b

Please sign in to comment.