update edit node

This commit is contained in:
2025-12-13 20:35:18 +07:00
parent 48e7adace0
commit 3b182d7380
11 changed files with 208 additions and 355 deletions
@@ -6,16 +6,15 @@ type Graph struct {
}
type GraphNode struct {
ID int32
Label string
Code string
Name string
Text string
Applications []*GraphApplication
}
type GraphEdge struct {
From int32
To int32
From string
To string
Type string
}
+36 -12
View File
@@ -96,36 +96,61 @@ func (s *StoryService) GetPlace(code string) *Place {
}
}
func (s *StoryService) UpdatePlace(node *GraphNode) error {
func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
update := false
for i := range s.story.Places {
if s.story.Places[i].Code == node.Label {
applications := make([]*Application, 0, len(node.Applications))
if s.story.Places[i].Code == code {
nodeApplications := make([]*Application, 0, len(node.Applications))
for _, application := range node.Applications {
applications = append(
applications,
nodeApplications = append(
nodeApplications,
&Application{
Name: application.Name,
},
)
}
s.story.Places[i] = &Place{
Code: s.story.Places[i].Code,
Code: node.Code,
Name: node.Name,
Text: formatText(node.Text),
Applications: applications,
Applications: nodeApplications,
}
update = true
break
}
}
if !update {
for i := range s.story.Places {
if s.story.Places[i].Code == node.Code {
nodeApplications := make([]*Application, 0, len(node.Applications))
for _, application := range node.Applications {
nodeApplications = append(
nodeApplications,
&Application{
Name: application.Name,
},
)
}
s.story.Places[i] = &Place{
Code: code,
Name: node.Name,
Text: formatText(node.Text),
Applications: nodeApplications,
}
update = true
break
}
}
}
s.Update()
return nil
}
func (s *StoryService) GetGraph(ctx context.Context) *Graph {
m := make(map[string]int32, len(s.story.Places))
m := make(map[string]string, 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)
for _, place := range s.story.Places {
m[clearCode(place.Code)] = place.Code
applications := make([]*GraphApplication, 0, len(place.Applications))
for _, application := range place.Applications {
applications = append(
@@ -137,8 +162,7 @@ func (s *StoryService) GetGraph(ctx context.Context) *Graph {
}
nodes = append(
nodes, &GraphNode{
ID: int32(i),
Label: place.Code,
Code: place.Code,
Name: place.Name,
Text: place.Text,
Applications: applications,