generated from VLADIMIR/template
update edit node
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user