| 1 | package tinyclient |
| 2 | |
| 3 | import "html/template" |
| 4 | |
| 5 | func jobsFragment(result any, queryErr error) string { |
| 6 | if queryErr != nil { |
| 7 | return `<tbody><tr><td role="status">` + template.HTMLEscapeString(queryErr.Error()) + `</td></tr></tbody>` |
| 8 | } |
| 9 | rows := make([][]string, 0) |
| 10 | for _, row := range browseRows(result) { |
| 11 | values, _ := row.(map[string]any) |
| 12 | rows = append(rows, []string{plainString(nestedValue(values, "spec" , "id" )), plainString(firstValue(values, "phase" , "status" )), plainString(firstValue(values, "finished" , "started" ))}) |
| 13 | } |
| 14 | return tableRows([]string{"Job" , "Status" , "Updated" }, rows) |
| 15 | } |
| 16 | |
| 17 | func nestedValue(values map[string]any, keys ...string) any { |
| 18 | var current any = values |
| 19 | for _, key := range keys { |
| 20 | m, ok := current.(map[string]any) |
| 21 | if !ok { |
| 22 | return "" |
| 23 | } |
| 24 | current = m[key] |
| 25 | } |
| 26 | return current |
| 27 | } |
| 28 | |
| 29 | func firstValue(values map[string]any, keys ...string) any { |
| 30 | for _, key := range keys { |
| 31 | if value, ok := values[key]; ok && value != nil { |
| 32 | return value |
| 33 | } |
| 34 | } |
| 35 | return "" |
| 36 | } |