| 
							
							
							
						 |  |  | @@ -1,6 +1,9 @@ | 
		
	
		
			
				|  |  |  |  | package ui | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import ( | 
		
	
		
			
				|  |  |  |  | 	"os" | 
		
	
		
			
				|  |  |  |  | 	"path/filepath" | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	"git.ourworld.tf/herocode/heroagent/pkg/servers/ui/routes" // Import the routes package | 
		
	
		
			
				|  |  |  |  | 	"github.com/gofiber/fiber/v2" | 
		
	
		
			
				|  |  |  |  | 	jetadapter "github.com/gofiber/template/jet/v2" // Aliased for clarity | 
		
	
	
		
			
				
					
					|  |  |  | @@ -16,17 +19,41 @@ func NewApp(config AppConfig) *fiber.App { | 
		
	
		
			
				|  |  |  |  | 	// Initialize Jet template engine | 
		
	
		
			
				|  |  |  |  | 	// Using OSFileSystemLoader to load templates from the filesystem. | 
		
	
		
			
				|  |  |  |  | 	// The path is relative to where the application is run. | 
		
	
		
			
				|  |  |  |  | 	// For development, InDevelopmentMode can be true to reload templates on each request. | 
		
	
		
			
				|  |  |  |  | 	engine := jetadapter.New("./pkg/servers/ui/views", ".jet") | 
		
	
		
			
				|  |  |  |  | 	// Get current working directory and construct absolute path to views | 
		
	
		
			
				|  |  |  |  | 	cwd, err := os.Getwd() | 
		
	
		
			
				|  |  |  |  | 	if err != nil { | 
		
	
		
			
				|  |  |  |  | 		panic("Failed to get current working directory: " + err.Error()) | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  | 	viewsPath := filepath.Join(cwd, "pkg", "servers", "ui", "views") | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Enable template reloading for development. | 
		
	
		
			
				|  |  |  |  | 	// Set to false or remove this line for production. | 
		
	
		
			
				|  |  |  |  | 	// Validate that the views directory and key template files exist | 
		
	
		
			
				|  |  |  |  | 	if _, err := os.Stat(viewsPath); os.IsNotExist(err) { | 
		
	
		
			
				|  |  |  |  | 		panic("Views directory does not exist: " + viewsPath) | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Check for key template files | 
		
	
		
			
				|  |  |  |  | 	baseLayoutPath := filepath.Join(viewsPath, "layouts", "base.jet") | 
		
	
		
			
				|  |  |  |  | 	dashboardPath := filepath.Join(viewsPath, "pages", "dashboard.jet") | 
		
	
		
			
				|  |  |  |  | 	navbarPath := filepath.Join(viewsPath, "components", "navbar.jet") | 
		
	
		
			
				|  |  |  |  | 	sidebarPath := filepath.Join(viewsPath, "components", "sidebar.jet") | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	requiredFiles := []string{baseLayoutPath, dashboardPath, navbarPath, sidebarPath} | 
		
	
		
			
				|  |  |  |  | 	for _, filePath := range requiredFiles { | 
		
	
		
			
				|  |  |  |  | 		if _, err := os.Stat(filePath); os.IsNotExist(err) { | 
		
	
		
			
				|  |  |  |  | 			panic("Required template file does not exist: " + filePath) | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Log the views path for debugging | 
		
	
		
			
				|  |  |  |  | 	println("Views directory found at:", viewsPath) | 
		
	
		
			
				|  |  |  |  | 	println("All required template files exist") | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Create Fiber Jet adapter | 
		
	
		
			
				|  |  |  |  | 	engine := jetadapter.New(viewsPath, ".jet") | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Enable template reloading for development | 
		
	
		
			
				|  |  |  |  | 	engine.Reload(true) | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// If you need to add custom functions or global variables to Jet: | 
		
	
		
			
				|  |  |  |  | 	// engine.AddFunc("myCustomFunc", func(arg jet.Arguments) reflect.Value { ... }) | 
		
	
		
			
				|  |  |  |  | 	// engine.AddGlobal("myGlobalVar", "someValue") | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	// Create a new Fiber app with the configured Jet engine | 
		
	
		
			
				|  |  |  |  | 	app := fiber.New(fiber.Config{ | 
		
	
		
			
				|  |  |  |  | 		Views: engine, | 
		
	
	
		
			
				
					
					|  |  |  |   |