Skip to content

Commit bddaf09

Browse files
jpRabbITCybErSeC
authored andcommitted
refactor to dedicated reporting components
1 parent 5334fa0 commit bddaf09

File tree

6 files changed

+133
-114
lines changed

6 files changed

+133
-114
lines changed

handlers/dashboard.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package handlers
22

33
import (
4-
"fmt"
54
"net/http"
65

76
"soarca-gui/utils"
8-
"soarca-gui/views/components/cards"
97
dashboard "soarca-gui/views/dashboard/home"
10-
"soarca-gui/views/dashboard/reporting"
118
"soarca-gui/views/layouts"
129

1310
"github.com/gin-gonic/gin"
@@ -22,24 +19,3 @@ func HomeDashboard(context *gin.Context) {
2219
render := utils.NewTempl(context, http.StatusOK, dashboard.Home(nil))
2320
context.Render(http.StatusOK, render)
2421
}
25-
26-
func ReportingDashboard(context *gin.Context) {
27-
render := utils.NewTempl(context, http.StatusOK,
28-
reporting.ReportingIndex())
29-
30-
context.Render(http.StatusOK, render)
31-
}
32-
33-
func ReportingCard(context *gin.Context) {
34-
id := context.Param("id")
35-
updatedCard := cards.ReportingCardData{
36-
Loaded: true,
37-
ID: fmt.Sprint(id),
38-
Value: 10,
39-
Name: "Executed Playbooks",
40-
}
41-
42-
render := utils.NewTempl(context, http.StatusOK, cards.LoadReportingCard(updatedCard))
43-
44-
context.Render(http.StatusOK, render)
45-
}

handlers/reporting.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
package reporting
1+
package handlers
22

33
import (
44
"fmt"
55
"net/http"
66

7-
"soarca-gui/models/reporting"
8-
utils "soarca-gui/utils"
7+
"soarca-gui/backend"
8+
"soarca-gui/utils"
9+
"soarca-gui/views/components/cards"
10+
"soarca-gui/views/dashboard/reporting"
11+
12+
"github.com/gin-gonic/gin"
913
)
1014

1115
const (
@@ -14,20 +18,40 @@ const (
1418
)
1519

1620
type reportingHandler struct {
17-
Host string
21+
backend backend.Backend
1822
}
1923

20-
func NewReportingHandler(host string) reportingHandler {
21-
return reportingHandler{Host: host}
24+
func NewReportingHandler(backend backend.Backend) reportingHandler {
25+
return reportingHandler{backend: backend}
2226
}
2327

24-
func (r *reportingHandler) getReports() ([]reporting.PlaybookExecutionReport, error) {
25-
var response []reporting.PlaybookExecutionReport
26-
url := fmt.Sprintf("%s%s", r.Host, reportingApiPath)
28+
func ReportingDashboardHandler(context *gin.Context) {
29+
render := utils.NewTempl(context, http.StatusOK, reporting.ReportingIndex())
30+
31+
context.Render(http.StatusOK, render)
32+
}
2733

28-
reports, err := utils.MakeJsonRequest(url, http.MethodGet, nil, response)
29-
if err != nil {
30-
return nil, err
34+
func (r *reportingHandler) ReportingCardHandler(context *gin.Context) {
35+
id := context.Param("id")
36+
updatedCard := cards.ReportingCardData{
37+
Loaded: true,
38+
ID: fmt.Sprint(id),
39+
Value: 10,
40+
Name: "Executed Playbooks",
3141
}
32-
return reports, nil
42+
43+
render := utils.NewTempl(context, http.StatusOK, cards.LoadReportingCard(updatedCard))
44+
45+
context.Render(http.StatusOK, render)
3346
}
47+
48+
func (r *reportingHandler) ReportingIndexHandler(context *gin.Context) {
49+
render := utils.NewTempl(context, http.StatusOK,
50+
reporting.ReportingIndex())
51+
52+
context.Render(http.StatusOK, render)
53+
}
54+
55+
// func (r *reportingHandler) GetReportsHandler() ([]reporting.PlaybookExecutionReport, error) {
56+
// return []reporting.PlaybookExecutionReport{}, nil
57+
// }

models/reporting/reporter.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ import (
66
"soarca-gui/models/cacao"
77
)
88

9-
type ReportingRow struct {
10-
ExecutionID string
11-
StartTime string
12-
EndTime string
13-
Status string
14-
Link string
15-
}
16-
179
type PlaybookExecutionReport struct {
1810
Type string `bson:"type" json:"type"`
1911
ExecutionId string `bson:"execution_id" json:"execution_id"`

routes/routes.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func Setup(app *gin.Engine) {
2222
publicRoutes := app.Group("/")
2323

2424
PublicRoutes(publicRoutes)
25-
Reporting(publicRoutes)
26-
StatusGroup(backend, publicRoutes)
27-
SettingsRouter(publicRoutes)
25+
ReportingRoutes(backend, publicRoutes)
26+
StatusRoutes(backend, publicRoutes)
27+
SettingsRoutes(publicRoutes)
2828
}
2929

3030
func PublicRoutes(app *gin.RouterGroup) {
@@ -41,24 +41,26 @@ func PublicRoutes(app *gin.RouterGroup) {
4141
publicRoute.StaticFS("/public", public.GetPublicAssetsFileSystem())
4242
}
4343

44-
func Reporting(app *gin.RouterGroup) {
44+
func ReportingRoutes(backend backend.Backend, app *gin.RouterGroup) {
45+
reportingHandlers := handlers.NewReportingHandler(backend)
46+
4547
reportingRoute := app.Group("/reporting")
4648
{
47-
reportingRoute.GET("/", handlers.ReportingDashboard)
48-
reportingRoute.GET("/reportingcard/:id", handlers.ReportingCard)
49+
reportingRoute.GET("/", reportingHandlers.ReportingIndexHandler)
50+
reportingRoute.GET("/reportingcard/:id", reportingHandlers.ReportingCardHandler)
4951
}
5052
}
5153

52-
func StatusGroup(backend backend.Backend, app *gin.RouterGroup) {
53-
statusHandler := handlers.NewStatusHandler(backend)
54+
func StatusRoutes(backend backend.Backend, app *gin.RouterGroup) {
55+
statusHandlers := handlers.NewStatusHandler(backend)
5456

5557
statusRoute := app.Group("/status")
5658
{
57-
statusRoute.GET("/indicator/card", statusHandler.HealthComponentHandler)
59+
statusRoute.GET("/indicator/card", statusHandlers.HealthComponentHandler)
5860
}
5961
}
6062

61-
func SettingsRouter(app *gin.RouterGroup) {
63+
func SettingsRoutes(app *gin.RouterGroup) {
6264
reportingRoute := app.Group("/settings")
6365
{
6466
reportingRoute.GET("/", handlers.SettingsDashboard)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package table
2+
3+
import (
4+
"fmt"
5+
"soarca-gui/utils"
6+
"soarca-gui/views/components/cards"
7+
)
8+
9+
const (
10+
reportingDataEndpoint = "/status/indicator/card"
11+
)
12+
13+
type ReportingTableMeta struct {
14+
Loaded bool
15+
}
16+
17+
var headers = []string{"Execution ID", "Start Time", "End Time", "Status", "Link"}
18+
19+
type ReportingDataTableRow struct {
20+
ExecutionID string
21+
StartTime string
22+
EndTime string
23+
Status string
24+
Link string
25+
}
26+
27+
templ LoadReportingTableCard(data ReportingTableMeta) {
28+
if !data.Loaded {
29+
<div
30+
hx-get={ string(templ.URL(fmt.Sprintf(reportingDataEndpoint))) }
31+
hx-trigger="load"
32+
hx-swap="outerHTML"
33+
class="relative"
34+
></div>
35+
}
36+
}
37+
38+
templ ReportingTableCard() {
39+
@cards.Card(utils.Class("p-4")) {
40+
<div class="items-center justify-between lg:flex">
41+
<div class="mb-4 lg:mb-0">
42+
<h3 class="mb-2 text-xl text-gray-900 dark:text-white">Current Reports</h3>
43+
<span class="text-base font-normal text-gray-500 dark:text-gray-400">Reports from API</span>
44+
</div>
45+
</div>
46+
@ReportList2()
47+
}
48+
}
49+
50+
templ ReportingTableHeaders() {
51+
@Header() {
52+
for _, header := range headers {
53+
<th { Th()... }>
54+
{ header }
55+
</th>
56+
}
57+
}
58+
}
59+
60+
templ ReportingTableDataRow(row ReportingDataTableRow) {
61+
<td { Td()... }>
62+
{ row.ExecutionID }
63+
</td>
64+
<td { Td()... }>
65+
{ row.StartTime }
66+
</td>
67+
<td { Td()... }>
68+
{ row.EndTime }
69+
</td>
70+
<td { Td()... }>
71+
{ row.Link }
72+
</td>
73+
}
74+
75+
// templ tableBody(rows []reporting_models.ReportingRow) {
76+
// }
77+
templ ReportList2() {
78+
@Table() {
79+
@ReportingTableHeaders()
80+
@Body() {
81+
}
82+
}
83+
}

views/dashboard/reporting/reporting.templ

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,21 @@
11
package reporting
22

33
import (
4-
reporting_models "soarca-gui/models/reporting"
5-
"soarca-gui/utils"
64
"soarca-gui/views/components/cards"
75
"soarca-gui/views/components/table"
86
"soarca-gui/views/layouts"
97
)
108

11-
type report struct {
12-
ExecutionID string
13-
PlaybookID string
14-
15-
Status int
16-
}
17-
189
var initialCards = []cards.ReportingCardData{
1910
{Loaded: false, ID: "1"},
2011
{Loaded: false, ID: "2"},
2112
{Loaded: false, ID: "3"}}
2213

23-
var headers = []string{"Execution ID", "Start Time", "End Time", "Status", "Link"}
24-
2514
templ ReportingIndex() {
2615
@layouts.DashboardLayout() {
2716
@banner()
2817
@ReportingBase()
29-
@ReportingListTile()
30-
}
31-
}
32-
33-
templ ReportingListTile() {
34-
@cards.Card(utils.Class("p-4")) {
35-
<div class="items-center justify-between lg:flex">
36-
<div class="mb-4 lg:mb-0">
37-
<h3 class="mb-2 text-xl text-gray-900 dark:text-white">Current Reports</h3>
38-
<span class="text-base font-normal text-gray-500 dark:text-gray-400">Reports from API</span>
39-
</div>
40-
</div>
41-
@ReportList2()
18+
@table.ReportList2()
4219
}
4320
}
4421

@@ -52,41 +29,6 @@ templ banner() {
5229
</div>
5330
}
5431

55-
templ tableHeaders() {
56-
@table.Header() {
57-
for _, header := range headers {
58-
<th { table.Th()... }>
59-
{ header }
60-
</th>
61-
}
62-
}
63-
}
64-
65-
templ tableRow(row reporting_models.ReportingRow) {
66-
<td { table.Td()... }>
67-
{ row.ExecutionID }
68-
</td>
69-
<td { table.Td()... }>
70-
{ row.StartTime }
71-
</td>
72-
<td { table.Td()... }>
73-
{ row.EndTime }
74-
</td>
75-
<td { table.Td()... }>
76-
{ row.Link }
77-
</td>
78-
}
79-
80-
// templ tableBody(rows []reporting_models.ReportingRow) {
81-
// }
82-
templ ReportList2() {
83-
@table.Table() {
84-
@tableHeaders()
85-
@table.Body() {
86-
}
87-
}
88-
}
89-
9032
templ ReportList() {
9133
<div class="flex flex-col">
9234
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">

0 commit comments

Comments
 (0)