Skip to content

Commit

Permalink
feat: add model, adapter and enforcer to the dashboard page chart (ca…
Browse files Browse the repository at this point in the history
…sdoor#3413)

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

* feat: add model, adapter, enforcer to dashboard
  • Loading branch information
XIAOZHUOWU authored Dec 9, 2024
1 parent b927c6d commit 7322f67
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
56 changes: 55 additions & 1 deletion object/get-dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Dashboard struct {
CertCounts []int `json:"certCounts"`
PermissionCounts []int `json:"permissionCounts"`
TransactionCounts []int `json:"transactionCounts"`
ModelCounts []int `json:"modelCounts"`
AdapterCounts []int `json:"adapterCounts"`
EnforcerCounts []int `json:"enforcerCounts"`
}

func GetDashboard(owner string) (*Dashboard, error) {
Expand All @@ -50,6 +53,9 @@ func GetDashboard(owner string) (*Dashboard, error) {
CertCounts: make([]int, 31),
PermissionCounts: make([]int, 31),
TransactionCounts: make([]int, 31),
ModelCounts: make([]int, 31),
AdapterCounts: make([]int, 31),
EnforcerCounts: make([]int, 31),
}

organizations := []Organization{}
Expand All @@ -63,9 +69,12 @@ func GetDashboard(owner string) (*Dashboard, error) {
certs := []Cert{}
permissions := []Permission{}
transactions := []Transaction{}
models := []Model{}
adapters := []Adapter{}
enforcers := []Enforcer{}

var wg sync.WaitGroup
wg.Add(11)
wg.Add(14)
go func() {
defer wg.Done()
if err := ormer.Engine.Find(&organizations, &Organization{Owner: owner}); err != nil {
Expand Down Expand Up @@ -148,6 +157,27 @@ func GetDashboard(owner string) (*Dashboard, error) {
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()

nowTime := time.Now()
Expand All @@ -164,6 +194,9 @@ func GetDashboard(owner string) (*Dashboard, error) {
dashboard.CertCounts[30-i] = countCreatedBefore(certs, cutTime)
dashboard.PermissionCounts[30-i] = countCreatedBefore(permissions, 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
}
Expand Down Expand Up @@ -248,6 +281,27 @@ func countCreatedBefore(objects interface{}, before time.Time) int {
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
}
6 changes: 6 additions & 0 deletions web/src/basic/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ const Dashboard = (props) => {
i18next.t("general:Certs"),
i18next.t("general:Permissions"),
i18next.t("general:Transactions"),
i18next.t("general:Models"),
i18next.t("general:Adapters"),
i18next.t("general:Enforcers"),
], top: "10%"},
grid: {left: "3%", right: "4%", bottom: "0", top: "25%", containLabel: true},
xAxis: {type: "category", boundaryGap: false, data: dateArray},
Expand All @@ -157,6 +160,9 @@ const Dashboard = (props) => {
{name: i18next.t("general:Certs"), type: "line", data: dashboardData.certCounts},
{name: i18next.t("general:Permissions"), type: "line", data: dashboardData.permissionCounts},
{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);
Expand Down

0 comments on commit 7322f67

Please sign in to comment.