Add real-time deployment updates and refactor JavaScript
- Add deploy stats (last deploy time, total count) to dashboard - Add recent-deployments API endpoint for real-time updates - Add live build logs to deployments history page - Fix git clone regression (preserve entrypoint for simple clones) - Refactor JavaScript into shared app.js with page init functions - Deploy button disables immediately on click - Auto-refresh deployment list and logs during builds - Format JavaScript with Prettier (4-space indent)
This commit is contained in:
@@ -537,6 +537,49 @@ func (h *Handlers) HandleAppStatusAPI() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleRecentDeploymentsAPI returns JSON with recent deployments.
|
||||
func (h *Handlers) HandleRecentDeploymentsAPI() http.HandlerFunc {
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
appID := chi.URLParam(request, "id")
|
||||
|
||||
application, findErr := models.FindApp(request.Context(), h.db, appID)
|
||||
if findErr != nil || application == nil {
|
||||
http.NotFound(writer, request)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
deployments, deployErr := application.GetDeployments(
|
||||
request.Context(),
|
||||
recentDeploymentsLimit,
|
||||
)
|
||||
if deployErr != nil {
|
||||
h.log.Error("failed to get deployments", "error", deployErr, "app", appID)
|
||||
|
||||
deployments = []*models.Deployment{}
|
||||
}
|
||||
|
||||
// Build response with formatted data
|
||||
deploymentsData := make([]map[string]any, 0, len(deployments))
|
||||
|
||||
for _, d := range deployments {
|
||||
deploymentsData = append(deploymentsData, map[string]any{
|
||||
"id": d.ID,
|
||||
"status": string(d.Status),
|
||||
"duration": d.Duration(),
|
||||
"shortCommit": d.ShortCommit(),
|
||||
"finishedAtISO": d.FinishedAtISO(),
|
||||
"finishedAtLabel": d.FinishedAtFormatted(),
|
||||
})
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(writer).Encode(map[string]any{
|
||||
"deployments": deploymentsData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// containerAction represents a container operation type.
|
||||
type containerAction string
|
||||
|
||||
|
||||
Reference in New Issue
Block a user