Files
oc-lib/models/workflow/graph/item.go
T
2026-05-27 15:50:23 +02:00

47 lines
1.9 KiB
Go

package graph
import (
"cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/tools"
)
// GraphItem is a struct that represents an item in a graph
type GraphItem struct {
ID string `bson:"id" json:"id" validate:"required"` // ID is the unique identifier of the item
Width float64 `bson:"width" json:"width" validate:"required"` // Width is the graphical width of the item
Height float64 `bson:"height" json:"height" validate:"required"` // Height is the graphical height of the item
Position Position `bson:"position" json:"position" validate:"required"` // Position is the graphical position of the item
*resources.ItemResource // ItemResource is the resource of the item affected to the item
}
func (g *GraphItem) GetResource() (tools.DataType, resources.ResourceInterface) {
if g.ItemResource.Data != nil {
return tools.DATA_RESOURCE, g.ItemResource.Data
} else if g.ItemResource.Compute != nil {
return tools.COMPUTE_RESOURCE, g.ItemResource.Compute
} else if g.ItemResource.Workflow != nil {
return tools.WORKFLOW_RESOURCE, g.ItemResource.Workflow
} else if g.ItemResource.Processing != nil {
return tools.PROCESSING_RESOURCE, g.ItemResource.Processing
} else if g.ItemResource.Storage != nil {
return tools.STORAGE_RESOURCE, g.ItemResource.Storage
} else if g.ItemResource.NativeTool != nil {
return tools.NATIVE_TOOL, g.ItemResource.NativeTool
} else if g.ItemResource.Service != nil {
return tools.SERVICE_RESOURCE, g.ItemResource.Service
} else if g.ItemResource.Dynamic != nil {
return tools.DYNAMIC_RESOURCE, g.ItemResource.Dynamic
}
return tools.INVALID, nil
}
func (g *GraphItem) Clear() {
g.ItemResource.Data = nil
g.ItemResource.Compute = nil
g.ItemResource.Workflow = nil
g.ItemResource.Processing = nil
g.ItemResource.Storage = nil
g.ItemResource.Service = nil
g.ItemResource.Dynamic = nil
}