mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
* test * feat: #3365 add more dada to the dashboard page chart * feat: #3365 Add more data to the dashboard page chart
This commit is contained in:
parent
12b4d1c7cd
commit
2d1736f13a
@ -25,6 +25,12 @@ type Dashboard struct {
|
||||
ProviderCounts []int `json:"providerCounts"`
|
||||
ApplicationCounts []int `json:"applicationCounts"`
|
||||
SubscriptionCounts []int `json:"subscriptionCounts"`
|
||||
RoleCounts []int `json:"roleCounts"`
|
||||
GroupCounts []int `json:"groupCounts"`
|
||||
ResourceCounts []int `json:"resourceCounts"`
|
||||
CertCounts []int `json:"certCounts"`
|
||||
PermissionCounts []int `json:"permissionCounts"`
|
||||
TransactionCounts []int `json:"transactionCounts"`
|
||||
}
|
||||
|
||||
func GetDashboard(owner string) (*Dashboard, error) {
|
||||
@ -38,6 +44,12 @@ func GetDashboard(owner string) (*Dashboard, error) {
|
||||
ProviderCounts: make([]int, 31),
|
||||
ApplicationCounts: make([]int, 31),
|
||||
SubscriptionCounts: make([]int, 31),
|
||||
RoleCounts: make([]int, 31),
|
||||
GroupCounts: make([]int, 31),
|
||||
ResourceCounts: make([]int, 31),
|
||||
CertCounts: make([]int, 31),
|
||||
PermissionCounts: make([]int, 31),
|
||||
TransactionCounts: make([]int, 31),
|
||||
}
|
||||
|
||||
organizations := []Organization{}
|
||||
@ -45,9 +57,15 @@ func GetDashboard(owner string) (*Dashboard, error) {
|
||||
providers := []Provider{}
|
||||
applications := []Application{}
|
||||
subscriptions := []Subscription{}
|
||||
roles := []Role{}
|
||||
groups := []Group{}
|
||||
resources := []Resource{}
|
||||
certs := []Cert{}
|
||||
permissions := []Permission{}
|
||||
transactions := []Transaction{}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(5)
|
||||
wg.Add(11)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ormer.Engine.Find(&organizations, &Organization{Owner: owner}); err != nil {
|
||||
@ -86,6 +104,50 @@ func GetDashboard(owner string) (*Dashboard, error) {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
if err := ormer.Engine.Find(&roles, &Role{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
if err := ormer.Engine.Find(&groups, &Group{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ormer.Engine.Find(&resources, &Resource{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ormer.Engine.Find(&certs, &Cert{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ormer.Engine.Find(&permissions, &Permission{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := ormer.Engine.Find(&transactions, &Transaction{Owner: owner}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
nowTime := time.Now()
|
||||
@ -96,6 +158,12 @@ func GetDashboard(owner string) (*Dashboard, error) {
|
||||
dashboard.ProviderCounts[30-i] = countCreatedBefore(providers, cutTime)
|
||||
dashboard.ApplicationCounts[30-i] = countCreatedBefore(applications, cutTime)
|
||||
dashboard.SubscriptionCounts[30-i] = countCreatedBefore(subscriptions, cutTime)
|
||||
dashboard.RoleCounts[30-i] = countCreatedBefore(roles, cutTime)
|
||||
dashboard.GroupCounts[30-i] = countCreatedBefore(groups, cutTime)
|
||||
dashboard.ResourceCounts[30-i] = countCreatedBefore(resources, cutTime)
|
||||
dashboard.CertCounts[30-i] = countCreatedBefore(certs, cutTime)
|
||||
dashboard.PermissionCounts[30-i] = countCreatedBefore(permissions, cutTime)
|
||||
dashboard.TransactionCounts[30-i] = countCreatedBefore(transactions, cutTime)
|
||||
}
|
||||
return dashboard, nil
|
||||
}
|
||||
@ -138,6 +206,48 @@ func countCreatedBefore(objects interface{}, before time.Time) int {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Role:
|
||||
for _, r := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", r.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Group:
|
||||
for _, g := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", g.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Resource:
|
||||
for _, r := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", r.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Cert:
|
||||
for _, c := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", c.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Permission:
|
||||
for _, p := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", p.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
case []Transaction:
|
||||
for _, t := range obj {
|
||||
createdTime, _ := time.Parse("2006-01-02T15:04:05-07:00", t.CreatedTime)
|
||||
if createdTime.Before(before) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
@ -135,6 +135,12 @@ const Dashboard = (props) => {
|
||||
i18next.t("general:Applications"),
|
||||
i18next.t("general:Organizations"),
|
||||
i18next.t("general:Subscriptions"),
|
||||
i18next.t("general:Roles"),
|
||||
i18next.t("general:Groups"),
|
||||
i18next.t("general:Resources"),
|
||||
i18next.t("general:Certs"),
|
||||
i18next.t("general:Permissions"),
|
||||
i18next.t("general:Transactions"),
|
||||
], top: "10%"},
|
||||
grid: {left: "3%", right: "4%", bottom: "0", top: "25%", containLabel: true},
|
||||
xAxis: {type: "category", boundaryGap: false, data: dateArray},
|
||||
@ -145,6 +151,12 @@ const Dashboard = (props) => {
|
||||
{name: i18next.t("general:Providers"), type: "line", data: dashboardData.providerCounts},
|
||||
{name: i18next.t("general:Applications"), type: "line", data: dashboardData.applicationCounts},
|
||||
{name: i18next.t("general:Subscriptions"), type: "line", data: dashboardData.subscriptionCounts},
|
||||
{name: i18next.t("general:Roles"), type: "line", data: dashboardData.roleCounts},
|
||||
{name: i18next.t("general:Groups"), type: "line", data: dashboardData.groupCounts},
|
||||
{name: i18next.t("general:Resources"), type: "line", data: dashboardData.resourceCounts},
|
||||
{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},
|
||||
],
|
||||
};
|
||||
myChart.setOption(option);
|
||||
|
Loading…
x
Reference in New Issue
Block a user