Skip to content

Commit 7cca176

Browse files
jpRabbITCybErSeC
authored andcommitted
wip on datatable integration to soarca backend
1 parent bddaf09 commit 7cca176

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

handlers/reporting.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"soarca-gui/backend"
88
"soarca-gui/utils"
99
"soarca-gui/views/components/cards"
10+
"soarca-gui/views/components/table"
1011
"soarca-gui/views/dashboard/reporting"
1112

1213
"github.com/gin-gonic/gin"
@@ -52,6 +53,29 @@ func (r *reportingHandler) ReportingIndexHandler(context *gin.Context) {
5253
context.Render(http.StatusOK, render)
5354
}
5455

56+
func (r *reportingHandler) ReportingTableCardHandler(context *gin.Context) {
57+
reports, _ := r.backend.GetReportings()
58+
59+
var rows []table.ReportingDataTableRow
60+
61+
for _, report := range reports {
62+
row := table.ReportingDataTableRow{
63+
ExecutionID: report.ExecutionId,
64+
StartTime: report.Started.String(),
65+
EndTime: report.Ended.String(),
66+
Link: "",
67+
}
68+
rows = append(rows, row)
69+
}
70+
formatedTable := table.ReportingTableMeta{
71+
Loaded: true,
72+
DataRows: rows,
73+
}
74+
75+
render := utils.NewTempl(context, http.StatusOK, table.LoadReportingTableBody(formatedTable))
76+
context.Render(http.StatusOK, render)
77+
}
78+
5579
// func (r *reportingHandler) GetReportsHandler() ([]reporting.PlaybookExecutionReport, error) {
5680
// return []reporting.PlaybookExecutionReport{}, nil
5781
// }

routes/routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func ReportingRoutes(backend backend.Backend, app *gin.RouterGroup) {
4747
reportingRoute := app.Group("/reporting")
4848
{
4949
reportingRoute.GET("/", reportingHandlers.ReportingIndexHandler)
50-
reportingRoute.GET("/reportingcard/:id", reportingHandlers.ReportingCardHandler)
50+
reportingRoute.GET("/card/:id", reportingHandlers.ReportingCardHandler)
51+
reportingRoute.GET("/table/", reportingHandlers.ReportingTableCardHandler)
5152
}
5253
}
5354

views/components/cards/reporting_card.templ

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package cards
22

33
import "fmt"
44

5+
const (
6+
reportingMetaCardEndpoint = "/reporting/card/"
7+
)
8+
59
type ReportingCardData struct {
610
Loaded bool
711
Name string
@@ -69,7 +73,7 @@ templ reportingCardUnkownComponent() {
6973
templ LoadReportingCard(data ReportingCardData) {
7074
if !data.Loaded {
7175
<div
72-
hx-get={ string(templ.URL(fmt.Sprintf("/reporting/reportingcard/%s", data.ID))) }
76+
hx-get={ string(templ.URL(fmt.Sprintf(reportingMetaCardEndpoint+"%s", data.ID))) }
7377
hx-trigger="load"
7478
hx-swap="outerHTML"
7579
class="relative"

views/components/table/reporting_table.templ

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
)
88

99
const (
10-
reportingDataEndpoint = "/status/indicator/card"
10+
reportingDataEndpoint = "/reporting/table"
1111
)
1212

1313
type ReportingTableMeta struct {
14-
Loaded bool
14+
Loaded bool
15+
DataRows []ReportingDataTableRow
1516
}
1617

1718
var headers = []string{"Execution ID", "Start Time", "End Time", "Status", "Link"}
@@ -24,14 +25,17 @@ type ReportingDataTableRow struct {
2425
Link string
2526
}
2627

27-
templ LoadReportingTableCard(data ReportingTableMeta) {
28+
templ LoadReportingTableBody(data ReportingTableMeta) {
2829
if !data.Loaded {
2930
<div
3031
hx-get={ string(templ.URL(fmt.Sprintf(reportingDataEndpoint))) }
3132
hx-trigger="load"
3233
hx-swap="outerHTML"
3334
class="relative"
3435
></div>
36+
@Body()
37+
} else {
38+
@tableBody(data.DataRows)
3539
}
3640
}
3741

@@ -43,11 +47,18 @@ templ ReportingTableCard() {
4347
<span class="text-base font-normal text-gray-500 dark:text-gray-400">Reports from API</span>
4448
</div>
4549
</div>
46-
@ReportList2()
50+
@FormatTable()
4751
}
4852
}
4953

50-
templ ReportingTableHeaders() {
54+
templ FormatTable() {
55+
@Table() {
56+
@reportingTableHeaders()
57+
@LoadReportingTableBody(ReportingTableMeta{Loaded: false})
58+
}
59+
}
60+
61+
templ reportingTableHeaders() {
5162
@Header() {
5263
for _, header := range headers {
5364
<th { Th()... }>
@@ -57,7 +68,7 @@ templ ReportingTableHeaders() {
5768
}
5869
}
5970

60-
templ ReportingTableDataRow(row ReportingDataTableRow) {
71+
templ reportingTableDataRow(row ReportingDataTableRow) {
6172
<td { Td()... }>
6273
{ row.ExecutionID }
6374
</td>
@@ -72,12 +83,8 @@ templ ReportingTableDataRow(row ReportingDataTableRow) {
7283
</td>
7384
}
7485

75-
// templ tableBody(rows []reporting_models.ReportingRow) {
76-
// }
77-
templ ReportList2() {
78-
@Table() {
79-
@ReportingTableHeaders()
80-
@Body() {
81-
}
86+
templ tableBody(rows []ReportingDataTableRow) {
87+
for _, row := range rows {
88+
@reportingTableDataRow(row)
8289
}
8390
}

views/dashboard/reporting/reporting.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ templ ReportingIndex() {
1515
@layouts.DashboardLayout() {
1616
@banner()
1717
@ReportingBase()
18-
@table.ReportList2()
18+
@table.ReportingTableCard()
1919
}
2020
}
2121

0 commit comments

Comments
 (0)