128 lines
3.1 KiB
Go
128 lines
3.1 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"inbox/internal/domain/humantask"
|
|
"inbox/internal/domain/lane"
|
|
"inbox/internal/domain/message"
|
|
"inbox/internal/domain/topic"
|
|
"inbox/internal/domain/workflow"
|
|
)
|
|
|
|
func filterMessagesByKnownTopics(items []message.Record, known map[string]topic.Record) map[string][]message.Record {
|
|
out := make(map[string][]message.Record)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.TopicID] = append(out[item.TopicID], item)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func filterRunsByKnownTopics(items []workflow.Run, known map[string]topic.Record) map[string][]workflow.Run {
|
|
out := make(map[string][]workflow.Run)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.TopicID] = append(out[item.TopicID], item)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupLanesByKnownTopics(items []lane.Record, known map[string]topic.Record) map[string][]lane.Record {
|
|
out := make(map[string][]lane.Record)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.TopicID] = append(out[item.TopicID], item)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupHumanTasksByKnownTopics(items []humantask.Record, known map[string]topic.Record) map[string][]humantask.Record {
|
|
out := make(map[string][]humantask.Record)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.TopicID] = append(out[item.TopicID], item)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupPendingDeliveriesByTopicRole(items []message.PendingDelivery, known map[string]topic.Record) map[string]map[string]int {
|
|
out := make(map[string]map[string]int)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
if out[item.TopicID] == nil {
|
|
out[item.TopicID] = make(map[string]int)
|
|
}
|
|
out[item.TopicID][item.RoleName] += item.Count
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupPendingDeliveriesByRole(items []message.PendingDelivery, known map[string]topic.Record) map[string]int {
|
|
out := make(map[string]int)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.RoleName] += item.Count
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupPendingHumanTasksByTopicRole(items []humantask.Record, known map[string]topic.Record) map[string]map[string]int {
|
|
out := make(map[string]map[string]int)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
if out[item.TopicID] == nil {
|
|
out[item.TopicID] = make(map[string]int)
|
|
}
|
|
out[item.TopicID][item.RoleName]++
|
|
}
|
|
return out
|
|
}
|
|
|
|
func groupPendingHumanTasksByRole(items []humantask.Record, known map[string]topic.Record) map[string]int {
|
|
out := make(map[string]int)
|
|
for _, item := range items {
|
|
if _, ok := known[item.TopicID]; !ok {
|
|
continue
|
|
}
|
|
out[item.RoleName]++
|
|
}
|
|
return out
|
|
}
|
|
|
|
func latestRunTime(item *workflow.Run) string {
|
|
if item == nil {
|
|
return ""
|
|
}
|
|
return latestString(item.CompletedAt, item.StartedAt)
|
|
}
|
|
|
|
func latestString(values ...string) string {
|
|
var best string
|
|
for _, value := range values {
|
|
if value > best {
|
|
best = value
|
|
}
|
|
}
|
|
return best
|
|
}
|
|
|
|
func coalesce(value, fallback string) string {
|
|
if value != "" {
|
|
return value
|
|
}
|
|
return fallback
|
|
}
|