mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-15 10:35:45 +00:00
chore: code fmt
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
<template>
|
||||
<ActionButton v-if="component.type == 'link'" :actionData="component.action" :key="component.title" />
|
||||
|
||||
|
||||
<DashboardComponentDirectory v-else-if="component.type == 'directory'" :component="component" />
|
||||
<div v-else-if="component.type == 'directory'">
|
||||
</div>
|
||||
|
||||
|
||||
<DashboardComponentDisplay v-else-if="component.type == 'display'" :component="component" />
|
||||
|
||||
|
||||
@@ -1007,20 +1007,28 @@ func findDirectoriesInEntityFieldsets(entityType string, dashboards []*config.Da
|
||||
|
||||
func findDirectoriesInEntityFieldsetsRecursive(entityType string, component *config.DashboardComponent, directories *[]string) {
|
||||
if component.Entity == entityType {
|
||||
for _, subitem := range component.Contents {
|
||||
if subitem.Type == "directory" {
|
||||
*directories = append(*directories, subitem.Title)
|
||||
}
|
||||
}
|
||||
collectDirectoriesFromComponent(component, directories)
|
||||
}
|
||||
|
||||
if len(component.Contents) > 0 {
|
||||
for _, subitem := range component.Contents {
|
||||
findDirectoriesInEntityFieldsetsRecursive(entityType, subitem, directories)
|
||||
searchSubcomponentsForDirectories(entityType, component.Contents, directories)
|
||||
}
|
||||
}
|
||||
|
||||
func collectDirectoriesFromComponent(component *config.DashboardComponent, directories *[]string) {
|
||||
for _, subitem := range component.Contents {
|
||||
if subitem.Type == "directory" {
|
||||
*directories = append(*directories, subitem.Title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func searchSubcomponentsForDirectories(entityType string, contents []*config.DashboardComponent, directories *[]string) {
|
||||
for _, subitem := range contents {
|
||||
findDirectoriesInEntityFieldsetsRecursive(entityType, subitem, directories)
|
||||
}
|
||||
}
|
||||
|
||||
func (api *oliveTinAPI) GetEntity(ctx ctx.Context, req *connect.Request[apiv1.GetEntityRequest]) (*connect.Response[apiv1.Entity], error) {
|
||||
user := auth.UserFromApiCall(ctx, req, api.cfg)
|
||||
|
||||
|
||||
@@ -30,20 +30,22 @@ func (rr *DashboardRenderRequest) findActionForEntity(title string, entity *enti
|
||||
continue
|
||||
}
|
||||
|
||||
if entity == nil {
|
||||
if binding.Entity == nil {
|
||||
return buildAction(binding, rr)
|
||||
}
|
||||
} else {
|
||||
if binding.Entity != nil && binding.Entity.UniqueKey == entity.UniqueKey {
|
||||
return buildAction(binding, rr)
|
||||
}
|
||||
if matchesEntity(binding, entity) {
|
||||
return buildAction(binding, rr)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func matchesEntity(binding *executor.ActionBinding, entity *entities.Entity) bool {
|
||||
if entity == nil {
|
||||
return binding.Entity == nil
|
||||
}
|
||||
|
||||
return binding.Entity != nil && binding.Entity.UniqueKey == entity.UniqueKey
|
||||
}
|
||||
|
||||
func buildEffectivePolicy(policy *config.ConfigurationPolicy) *apiv1.EffectivePolicy {
|
||||
ret := &apiv1.EffectivePolicy{
|
||||
ShowDiagnostics: policy.ShowDiagnostics,
|
||||
|
||||
@@ -25,11 +25,11 @@ func buildEntityFieldsets(entityTitle string, tpl *config.DashboardComponent, rr
|
||||
|
||||
func buildEntityFieldset(tpl *config.DashboardComponent, ent *entities.Entity, rr *DashboardRenderRequest) *apiv1.DashboardComponent {
|
||||
return &apiv1.DashboardComponent{
|
||||
Title: entities.ParseTemplateWith(tpl.Title, ent),
|
||||
Type: "fieldset",
|
||||
Contents: removeFieldsetIfHasNoLinks(buildEntityFieldsetContents(tpl.Contents, ent, tpl.Entity, rr)),
|
||||
CssClass: entities.ParseTemplateWith(tpl.CssClass, ent),
|
||||
Action: rr.findAction(tpl.Title),
|
||||
Title: entities.ParseTemplateWith(tpl.Title, ent),
|
||||
Type: "fieldset",
|
||||
Contents: removeFieldsetIfHasNoLinks(buildEntityFieldsetContents(tpl.Contents, ent, tpl.Entity, rr)),
|
||||
CssClass: entities.ParseTemplateWith(tpl.CssClass, ent),
|
||||
Action: rr.findAction(tpl.Title),
|
||||
EntityType: tpl.Entity,
|
||||
EntityKey: ent.UniqueKey,
|
||||
}
|
||||
@@ -70,23 +70,40 @@ func cloneItem(subitem *config.DashboardComponent, ent *entities.Entity, entityT
|
||||
clone := &apiv1.DashboardComponent{}
|
||||
clone.CssClass = entities.ParseTemplateWith(subitem.CssClass, ent)
|
||||
|
||||
if subitem.Type == "" || subitem.Type == "link" {
|
||||
clone.Type = "link"
|
||||
clone.Title = entities.ParseTemplateWith(subitem.Title, ent)
|
||||
clone.Action = rr.findActionForEntity(subitem.Title, ent)
|
||||
} else {
|
||||
clone.Title = entities.ParseTemplateWith(subitem.Title, ent)
|
||||
clone.Type = subitem.Type
|
||||
|
||||
if clone.Type == "directory" && ent != nil && entityType != "" {
|
||||
clone.EntityType = entityType
|
||||
clone.EntityKey = ent.UniqueKey
|
||||
}
|
||||
|
||||
if len(subitem.Contents) > 0 {
|
||||
clone.Contents = buildEntityFieldsetContents(subitem.Contents, ent, entityType, rr)
|
||||
}
|
||||
if isLinkType(subitem.Type) {
|
||||
return cloneLinkItem(subitem, ent, clone, rr)
|
||||
}
|
||||
|
||||
return cloneNonLinkItem(subitem, ent, entityType, clone, rr)
|
||||
}
|
||||
|
||||
func isLinkType(itemType string) bool {
|
||||
return itemType == "" || itemType == "link"
|
||||
}
|
||||
|
||||
func cloneLinkItem(subitem *config.DashboardComponent, ent *entities.Entity, clone *apiv1.DashboardComponent, rr *DashboardRenderRequest) *apiv1.DashboardComponent {
|
||||
clone.Type = "link"
|
||||
clone.Title = entities.ParseTemplateWith(subitem.Title, ent)
|
||||
clone.Action = rr.findActionForEntity(subitem.Title, ent)
|
||||
return clone
|
||||
}
|
||||
|
||||
func cloneNonLinkItem(subitem *config.DashboardComponent, ent *entities.Entity, entityType string, clone *apiv1.DashboardComponent, rr *DashboardRenderRequest) *apiv1.DashboardComponent {
|
||||
clone.Title = entities.ParseTemplateWith(subitem.Title, ent)
|
||||
clone.Type = subitem.Type
|
||||
|
||||
if isDirectoryWithEntity(clone.Type, ent, entityType) {
|
||||
clone.EntityType = entityType
|
||||
clone.EntityKey = ent.UniqueKey
|
||||
}
|
||||
|
||||
if len(subitem.Contents) > 0 {
|
||||
clone.Contents = buildEntityFieldsetContents(subitem.Contents, ent, entityType, rr)
|
||||
}
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
func isDirectoryWithEntity(itemType string, ent *entities.Entity, entityType string) bool {
|
||||
return itemType == "directory" && ent != nil && entityType != ""
|
||||
}
|
||||
|
||||
@@ -32,28 +32,40 @@ func getEntityFromRequest(rr *DashboardRenderRequest) *entities.Entity {
|
||||
}
|
||||
|
||||
func findAndRenderDashboard(rr *DashboardRenderRequest, dashboardTitle string) *apiv1.Dashboard {
|
||||
if dashboard := findDashboardByTitle(rr, dashboardTitle); dashboard != nil {
|
||||
return renderDashboardIfValid(dashboard, rr)
|
||||
}
|
||||
|
||||
return renderDirectoryDashboard(rr, dashboardTitle)
|
||||
}
|
||||
|
||||
func findDashboardByTitle(rr *DashboardRenderRequest, dashboardTitle string) *config.DashboardComponent {
|
||||
for _, dashboard := range rr.cfg.Dashboards {
|
||||
if dashboard.Title != dashboardTitle {
|
||||
continue
|
||||
if dashboard.Title == dashboardTitle {
|
||||
return dashboard
|
||||
}
|
||||
|
||||
if len(dashboard.Contents) == 0 {
|
||||
logEmptyDashboard(dashboard.Title, rr.AuthenticatedUser.Username)
|
||||
return nil
|
||||
}
|
||||
|
||||
return buildDashboardFromConfig(dashboard, rr)
|
||||
}
|
||||
|
||||
directoryComponent := findDirectoryComponent(rr, dashboardTitle)
|
||||
if directoryComponent != nil {
|
||||
entity := getEntityFromRequest(rr)
|
||||
return buildDashboardFromConfigWithEntity(directoryComponent, rr, entity)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderDashboardIfValid(dashboard *config.DashboardComponent, rr *DashboardRenderRequest) *apiv1.Dashboard {
|
||||
if len(dashboard.Contents) == 0 {
|
||||
logEmptyDashboard(dashboard.Title, rr.AuthenticatedUser.Username)
|
||||
return nil
|
||||
}
|
||||
return buildDashboardFromConfig(dashboard, rr)
|
||||
}
|
||||
|
||||
func renderDirectoryDashboard(rr *DashboardRenderRequest, dashboardTitle string) *apiv1.Dashboard {
|
||||
directoryComponent := findDirectoryComponent(rr, dashboardTitle)
|
||||
if directoryComponent == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
entity := getEntityFromRequest(rr)
|
||||
return buildDashboardFromConfigWithEntity(directoryComponent, rr, entity)
|
||||
}
|
||||
|
||||
func findDirectoryComponent(rr *DashboardRenderRequest, title string) *config.DashboardComponent {
|
||||
for _, dashboard := range rr.cfg.Dashboards {
|
||||
if component := searchDirectoryInComponent(dashboard, title); component != nil {
|
||||
@@ -64,11 +76,19 @@ func findDirectoryComponent(rr *DashboardRenderRequest, title string) *config.Da
|
||||
}
|
||||
|
||||
func searchDirectoryInComponent(component *config.DashboardComponent, title string) *config.DashboardComponent {
|
||||
if component.Title == title && len(component.Contents) > 0 && component.Type != "fieldset" {
|
||||
if isMatchingDirectory(component, title) {
|
||||
return component
|
||||
}
|
||||
|
||||
for _, subitem := range component.Contents {
|
||||
return searchDirectoryInSubcomponents(component.Contents, title)
|
||||
}
|
||||
|
||||
func isMatchingDirectory(component *config.DashboardComponent, title string) bool {
|
||||
return component.Title == title && len(component.Contents) > 0 && component.Type != "fieldset"
|
||||
}
|
||||
|
||||
func searchDirectoryInSubcomponents(contents []*config.DashboardComponent, title string) *config.DashboardComponent {
|
||||
for _, subitem := range contents {
|
||||
if found := searchDirectoryInComponent(subitem, title); found != nil {
|
||||
return found
|
||||
}
|
||||
@@ -252,24 +272,39 @@ func getDashboardComponentIcon(item *config.DashboardComponent, cfg *config.Conf
|
||||
}
|
||||
|
||||
func getDashboardComponentType(item *config.DashboardComponent, action *apiv1.Action) string {
|
||||
if hasContents(item) {
|
||||
return getTypeForComponentWithContents(item)
|
||||
}
|
||||
|
||||
if isAllowedType(item.Type) {
|
||||
return item.Type
|
||||
}
|
||||
|
||||
return getDefaultType(action)
|
||||
}
|
||||
|
||||
func hasContents(item *config.DashboardComponent) bool {
|
||||
return len(item.Contents) > 0
|
||||
}
|
||||
|
||||
func getTypeForComponentWithContents(item *config.DashboardComponent) string {
|
||||
if item.Type != "fieldset" {
|
||||
return "directory"
|
||||
}
|
||||
return "fieldset"
|
||||
}
|
||||
|
||||
func isAllowedType(itemType string) bool {
|
||||
allowedTypes := []string{
|
||||
"stdout-most-recent-execution",
|
||||
"display",
|
||||
}
|
||||
return slices.Contains(allowedTypes, itemType)
|
||||
}
|
||||
|
||||
if len(item.Contents) > 0 {
|
||||
if item.Type != "fieldset" {
|
||||
return "directory"
|
||||
}
|
||||
|
||||
return "fieldset"
|
||||
} else if slices.Contains(allowedTypes, item.Type) {
|
||||
return item.Type
|
||||
}
|
||||
|
||||
func getDefaultType(action *apiv1.Action) string {
|
||||
if action == nil {
|
||||
return "display"
|
||||
}
|
||||
|
||||
return "link"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user