feat: add model, adapter and enforcer to the dashboard page chart (#3413)

* [feature] Add more data (Model, Adapter, Enforcer) to the dashboard page chart #3379

* feat: add model, adapter, enforcer to dashboard
This commit is contained in:
XIAOZHUOWU
2024-12-09 16:07:39 +08:00
committed by GitHub
parent b927c6d7b4
commit 7322f67ae0
2 changed files with 61 additions and 1 deletions

View File

@ -31,6 +31,9 @@ type Dashboard struct {
CertCounts []int `json:"certCounts"` CertCounts []int `json:"certCounts"`
PermissionCounts []int `json:"permissionCounts"` PermissionCounts []int `json:"permissionCounts"`
TransactionCounts []int `json:"transactionCounts"` TransactionCounts []int `json:"transactionCounts"`
ModelCounts []int `json:"modelCounts"`
AdapterCounts []int `json:"adapterCounts"`
EnforcerCounts []int `json:"enforcerCounts"`
} }
func GetDashboard(owner string) (*Dashboard, error) { func GetDashboard(owner string) (*Dashboard, error) {
@ -50,6 +53,9 @@ func GetDashboard(owner string) (*Dashboard, error) {
CertCounts: make([]int, 31), CertCounts: make([]int, 31),
PermissionCounts: make([]int, 31), PermissionCounts: make([]int, 31),
TransactionCounts: make([]int, 31), TransactionCounts: make([]int, 31),
ModelCounts: make([]int, 31),
AdapterCounts: make([]int, 31),
EnforcerCounts: make([]int, 31),
} }
organizations := []Organization{} organizations := []Organization{}
@ -63,9 +69,12 @@ func GetDashboard(owner string) (*Dashboard, error) {
certs := []Cert{} certs := []Cert{}
permissions := []Permission{} permissions := []Permission{}
transactions := []Transaction{} transactions := []Transaction{}
models := []Model{}
adapters := []Adapter{}
enforcers := []Enforcer{}
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(11) wg.Add(14)
go func() { go func() {
defer wg.Done() defer wg.Done()
if err := ormer.Engine.Find(&organizations, &Organization{Owner: owner}); err != nil { if err := ormer.Engine.Find(&organizations, &Organization{Owner: owner}); err != nil {
@ -148,6 +157,27 @@ func GetDashboard(owner string) (*Dashboard, error) {
panic(err) panic(err)
} }
}() }()
go func() {
defer wg.Done()
if err := ormer.Engine.Find(&models, &Model{Owner: owner}); err != nil {
panic(err)
}
}()
go func() {
defer wg.Done()
if err := ormer.Engine.Find(&adapters, &Adapter{Owner: owner}); err != nil {
panic(err)
}
}()
go func() {
defer wg.Done()
if err := ormer.Engine.Find(&enforcers, &Enforcer{Owner: owner}); err != nil {
panic(err)
}
}()
wg.Wait() wg.Wait()
nowTime := time.Now() nowTime := time.Now()
@ -164,6 +194,9 @@ func GetDashboard(owner string) (*Dashboard, error) {
dashboard.CertCounts[30-i] = countCreatedBefore(certs, cutTime) dashboard.CertCounts[30-i] = countCreatedBefore(certs, cutTime)
dashboard.PermissionCounts[30-i] = countCreatedBefore(permissions, cutTime) dashboard.PermissionCounts[30-i] = countCreatedBefore(permissions, cutTime)
dashboard.TransactionCounts[30-i] = countCreatedBefore(transactions, cutTime) dashboard.TransactionCounts[30-i] = countCreatedBefore(transactions, cutTime)
dashboard.ModelCounts[30-i] = countCreatedBefore(models, cutTime)
dashboard.AdapterCounts[30-i] = countCreatedBefore(adapters, cutTime)
dashboard.EnforcerCounts[30-i] = countCreatedBefore(enforcers, cutTime)
} }
return dashboard, nil return dashboard, nil
} }
@ -248,6 +281,27 @@ func countCreatedBefore(objects interface{}, before time.Time) int {
count++ count++
} }
} }
case []Model:
for _, m := range obj {
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", m.CreatedTime)
if createdTime.Before(before) {
count++
}
}
case []Adapter:
for _, a := range obj {
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", a.CreatedTime)
if createdTime.Before(before) {
count++
}
}
case []Enforcer:
for _, e := range obj {
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", e.CreatedTime)
if createdTime.Before(before) {
count++
}
}
} }
return count return count
} }

View File

@ -141,6 +141,9 @@ const Dashboard = (props) => {
i18next.t("general:Certs"), i18next.t("general:Certs"),
i18next.t("general:Permissions"), i18next.t("general:Permissions"),
i18next.t("general:Transactions"), i18next.t("general:Transactions"),
i18next.t("general:Models"),
i18next.t("general:Adapters"),
i18next.t("general:Enforcers"),
], top: "10%"}, ], top: "10%"},
grid: {left: "3%", right: "4%", bottom: "0", top: "25%", containLabel: true}, grid: {left: "3%", right: "4%", bottom: "0", top: "25%", containLabel: true},
xAxis: {type: "category", boundaryGap: false, data: dateArray}, xAxis: {type: "category", boundaryGap: false, data: dateArray},
@ -157,6 +160,9 @@ const Dashboard = (props) => {
{name: i18next.t("general:Certs"), type: "line", data: dashboardData.certCounts}, {name: i18next.t("general:Certs"), type: "line", data: dashboardData.certCounts},
{name: i18next.t("general:Permissions"), type: "line", data: dashboardData.permissionCounts}, {name: i18next.t("general:Permissions"), type: "line", data: dashboardData.permissionCounts},
{name: i18next.t("general:Transactions"), type: "line", data: dashboardData.transactionCounts}, {name: i18next.t("general:Transactions"), type: "line", data: dashboardData.transactionCounts},
{name: i18next.t("general:Models"), type: "line", data: dashboardData.modelCounts},
{name: i18next.t("general:Adapters"), type: "line", data: dashboardData.adapterCounts},
{name: i18next.t("general:Enforcers"), type: "line", data: dashboardData.enforcerCounts},
], ],
}; };
myChart.setOption(option); myChart.setOption(option);