Fix MachineResponse: expose last_seen_at/created_at, clean status string
The status field was being decorated with "(last seen ...)" suffix
which broke frontend statusVariant() matching and prevented the
LastSeen column from showing the separate timestamp.
Changes:
- machineToResp() now returns clean status ("online"/"offline")
- MachineResponse includes last_seen_at and created_at as separate fields
- Fix whitespace typo in WakeCheckIntervalSeconds field
This commit is contained in:
@@ -28,6 +28,8 @@ type MachineResponse struct {
|
||||
FingerprintConfirmed bool `json:"fingerprint_confirmed"`
|
||||
HostKeyFingerprint *string `json:"host_key_fingerprint"`
|
||||
Status string `json:"status"`
|
||||
LastSeenAt *string `json:"last_seen_at"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
type TestConnectionResponse struct {
|
||||
|
||||
@@ -444,11 +444,10 @@ func (h *MachineHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func machineToResp(m models.Machine) MachineResponse {
|
||||
var status string
|
||||
var lastSeen *string
|
||||
if m.LastSeenAt != nil {
|
||||
status = m.Status + " (last seen " + m.LastSeenAt.Format(time.RFC3339) + ")"
|
||||
} else {
|
||||
status = m.Status
|
||||
s := m.LastSeenAt.Format(time.RFC3339)
|
||||
lastSeen = &s
|
||||
}
|
||||
return MachineResponse{
|
||||
ID: m.ID,
|
||||
@@ -461,10 +460,12 @@ func machineToResp(m models.Machine) MachineResponse {
|
||||
WoLEnabled: m.WoLEnabled,
|
||||
BroadcastAddr: m.BroadcastAddr,
|
||||
WakeTimeoutSeconds: m.WakeTimeoutSeconds,
|
||||
WakeCheckIntervalSeconds: m.WakeCheckIntervalSeconds,
|
||||
WakeCheckIntervalSeconds: m.WakeCheckIntervalSeconds,
|
||||
FingerprintConfirmed: m.FingerprintConfirmed,
|
||||
HostKeyFingerprint: m.HostKeyFingerprint,
|
||||
Status: status,
|
||||
HostKeyFingerprint: m.HostKeyFingerprint,
|
||||
Status: m.Status,
|
||||
LastSeenAt: lastSeen,
|
||||
CreatedAt: m.CreatedAt.Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user