update editor

This commit is contained in:
2025-12-07 01:34:42 +07:00
parent d372104760
commit 09b04de9c3
8 changed files with 209 additions and 109 deletions
+33 -18
View File
@@ -39,25 +39,30 @@ type Place struct {
Applications []*Application `json:"applications"`
}
type Application struct {
Name string `json:"name"`
}
type Graph struct {
Nodes []*Node
Edges []*Edge
Nodes []*GraphNode
Edges []*GraphEdge
}
type Node struct {
ID int32
Label string
Name string
Text string
type GraphNode struct {
ID int32
Label string
Name string
Text string
Applications []*GraphApplication
}
type Edge struct {
type GraphEdge struct {
From int32
To int32
}
type Application struct {
Name string `json:"name"`
type GraphApplication struct {
Name string
}
type StoryService struct {
@@ -107,26 +112,36 @@ func (s *StoryService) GetPlace(code string) *Place {
func (s *StoryService) GetGraph(ctx context.Context) *Graph {
m := make(map[string]int32, len(s.story.Places))
nodes := make([]*Node, 0, len(s.story.Places))
nodes := make([]*GraphNode, 0, len(s.story.Places))
for i, place := range s.story.Places {
m[clearCode(place.Code)] = int32(i)
applications := make([]*GraphApplication, 0, len(place.Applications))
for _, application := range place.Applications {
applications = append(
applications,
&GraphApplication{
Name: application.Name,
},
)
}
nodes = append(
nodes, &Node{
ID: int32(i),
Label: place.Code,
Name: place.Name,
Text: place.Text,
nodes, &GraphNode{
ID: int32(i),
Label: place.Code,
Name: place.Name,
Text: place.Text,
Applications: applications,
},
)
}
edges := make([]*Edge, 0, len(s.story.Places)*3)
edges := make([]*GraphEdge, 0, len(s.story.Places)*3)
for _, place := range s.story.Places {
re := regexp.MustCompile(`\(\[[a-zA-Zа-яА-Я\d-]+\]\)`)
matches := re.FindAllString(place.Text, -1)
for _, match := range matches {
edges = append(edges, &Edge{
edges = append(edges, &GraphEdge{
From: m[clearCode(place.Code)],
To: m[clearMatch(match)],
})