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