generated from VLADIMIR/template
update editor
This commit is contained in:
@@ -204,11 +204,21 @@ func (s *Services) GetGraph(ctx context.Context, req *proto.GetGraphReq) (*proto
|
||||
graph := s.storyService.GetGraph(ctx)
|
||||
nodes := make([]*proto.GetGraphRsp_Node, 0, len(graph.Nodes))
|
||||
for _, node := range graph.Nodes {
|
||||
applications := make([]*proto.GetGraphRsp_Application, 0, len(node.Applications))
|
||||
for _, application := range node.Applications {
|
||||
applications = append(
|
||||
applications,
|
||||
&proto.GetGraphRsp_Application{
|
||||
Name: application.Name,
|
||||
},
|
||||
)
|
||||
}
|
||||
nodes = append(nodes, &proto.GetGraphRsp_Node{
|
||||
Id: node.ID,
|
||||
Label: node.Label,
|
||||
Name: node.Name,
|
||||
Text: node.Text,
|
||||
Id: node.ID,
|
||||
Label: node.Label,
|
||||
Name: node.Name,
|
||||
Text: node.Text,
|
||||
Applications: applications,
|
||||
})
|
||||
}
|
||||
edges := make([]*proto.GetGraphRsp_Edge, 0, len(graph.Edges))
|
||||
|
||||
@@ -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)],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user