add crud for node

This commit is contained in:
2025-12-13 21:31:45 +07:00
parent 3b182d7380
commit 6b18709e61
5 changed files with 153 additions and 136 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ВД Админка</title> <title>ВД Админка</title>
<script type="module" crossorigin src="/assets/index-DTvRzGpy.js"></script> <script type="module" crossorigin src="/assets/index-WLMuUXZt.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-BkyopZAN.css"> <link rel="stylesheet" crossorigin href="/assets/index-D8kPNaZP.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
+27 -10
View File
@@ -97,9 +97,16 @@ func (s *StoryService) GetPlace(code string) *Place {
} }
func (s *StoryService) UpdatePlace(code string, node *GraphNode) error { func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
update := false if code != "" && node.Code == "" {
for i := range s.story.Places { for i := range s.story.Places {
if s.story.Places[i].Code == code { if s.story.Places[i].Code == code {
s.story.Places = append(s.story.Places[:i], s.story.Places[i+1:]...)
break
}
}
s.Update()
return nil
}
nodeApplications := make([]*Application, 0, len(node.Applications)) nodeApplications := make([]*Application, 0, len(node.Applications))
for _, application := range node.Applications { for _, application := range node.Applications {
nodeApplications = append( nodeApplications = append(
@@ -109,6 +116,25 @@ func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
}, },
) )
} }
if code == "" && node.Code != "" {
s.story.Places = append(
s.story.Places,
&Place{
Code: node.Code,
Name: node.Name,
Text: formatText(node.Text),
Applications: nodeApplications,
},
)
s.Update()
return nil
}
if code == "" || node.Code == "" {
return nil
}
update := false
for i := range s.story.Places {
if s.story.Places[i].Code == code {
s.story.Places[i] = &Place{ s.story.Places[i] = &Place{
Code: node.Code, Code: node.Code,
Name: node.Name, Name: node.Name,
@@ -122,15 +148,6 @@ func (s *StoryService) UpdatePlace(code string, node *GraphNode) error {
if !update { if !update {
for i := range s.story.Places { for i := range s.story.Places {
if s.story.Places[i].Code == node.Code { 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{ s.story.Places[i] = &Place{
Code: code, Code: code,
Name: node.Name, Name: node.Name,