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

View File

@ -202,25 +202,25 @@ message GetGraphRsp {
int32 countEdges = 4; int32 countEdges = 4;
message Edge { message Edge {
int32 from = 1; string from = 1;
int32 to = 2; string to = 2;
string arrows = 3; string arrows = 3;
string type = 4; string type = 4;
} }
} }
message UpdateNodeReq { message UpdateNodeReq {
GraphNode node = 1; string code = 1;
GraphNode node = 2;
} }
message UpdateNodeRsp {} message UpdateNodeRsp {}
message GraphNode { message GraphNode {
int32 id = 1; string code = 1;
string label = 2; string name = 2;
string name = 3; string text = 3;
string text = 4; repeated GraphApplication applications = 4;
repeated GraphApplication applications = 5;
} }
message GraphApplication { message GraphApplication {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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-NoTmivv5.js"></script> <script type="module" crossorigin src="/assets/index-DTvRzGpy.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-b0_hiwBH.css"> <link rel="stylesheet" crossorigin href="/assets/index-BkyopZAN.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

File diff suppressed because one or more lines are too long

View File

@ -211,13 +211,12 @@ func (s *Services) UpdateNode(ctx context.Context, req *proto.UpdateNodeReq) (*p
) )
} }
node := &story_service.GraphNode{ node := &story_service.GraphNode{
ID: req.Node.Id, Code: req.Node.Code,
Label: req.Node.Label,
Name: req.Node.Name, Name: req.Node.Name,
Text: req.Node.Text, Text: req.Node.Text,
Applications: applications, Applications: applications,
} }
if err := s.storyService.UpdatePlace(node); err != nil { if err := s.storyService.UpdatePlace(req.Code, node); err != nil {
return nil, err return nil, err
} }
return &proto.UpdateNodeRsp{}, nil return &proto.UpdateNodeRsp{}, nil
@ -237,8 +236,7 @@ func (s *Services) GetGraph(ctx context.Context, req *proto.GetGraphReq) (*proto
) )
} }
nodes = append(nodes, &proto.GraphNode{ nodes = append(nodes, &proto.GraphNode{
Id: node.ID, Code: node.Code,
Label: node.Label,
Name: node.Name, Name: node.Name,
Text: node.Text, Text: node.Text,
Applications: applications, Applications: applications,

View File

@ -6,16 +6,15 @@ type Graph struct {
} }
type GraphNode struct { type GraphNode struct {
ID int32 Code string
Label string
Name string Name string
Text string Text string
Applications []*GraphApplication Applications []*GraphApplication
} }
type GraphEdge struct { type GraphEdge struct {
From int32 From string
To int32 To string
Type string Type string
} }

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 { for i := range s.story.Places {
if s.story.Places[i].Code == node.Label { if s.story.Places[i].Code == code {
applications := make([]*Application, 0, len(node.Applications)) nodeApplications := make([]*Application, 0, len(node.Applications))
for _, application := range node.Applications { for _, application := range node.Applications {
applications = append( nodeApplications = append(
applications, nodeApplications,
&Application{ &Application{
Name: application.Name, Name: application.Name,
}, },
) )
} }
s.story.Places[i] = &Place{ s.story.Places[i] = &Place{
Code: s.story.Places[i].Code, Code: node.Code,
Name: node.Name, Name: node.Name,
Text: formatText(node.Text), Text: formatText(node.Text),
Applications: applications, Applications: nodeApplications,
} }
update = true
break 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() s.Update()
return nil return nil
} }
func (s *StoryService) GetGraph(ctx context.Context) *Graph { 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)) nodes := make([]*GraphNode, 0, len(s.story.Places))
for i, place := range s.story.Places { for _, place := range s.story.Places {
m[clearCode(place.Code)] = int32(i) m[clearCode(place.Code)] = place.Code
applications := make([]*GraphApplication, 0, len(place.Applications)) applications := make([]*GraphApplication, 0, len(place.Applications))
for _, application := range place.Applications { for _, application := range place.Applications {
applications = append( applications = append(
@ -137,8 +162,7 @@ func (s *StoryService) GetGraph(ctx context.Context) *Graph {
} }
nodes = append( nodes = append(
nodes, &GraphNode{ nodes, &GraphNode{
ID: int32(i), Code: place.Code,
Label: place.Code,
Name: place.Name, Name: place.Name,
Text: place.Text, Text: place.Text,
Applications: applications, Applications: applications,

View File

@ -1356,7 +1356,8 @@ func (x *GetGraphRsp) GetCountEdges() int32 {
type UpdateNodeReq struct { type UpdateNodeReq struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Node *GraphNode `protobuf:"bytes,1,opt,name=node,proto3" json:"node,omitempty"` Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Node *GraphNode `protobuf:"bytes,2,opt,name=node,proto3" json:"node,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -1391,6 +1392,13 @@ func (*UpdateNodeReq) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{29} return file_main_proto_rawDescGZIP(), []int{29}
} }
func (x *UpdateNodeReq) GetCode() string {
if x != nil {
return x.Code
}
return ""
}
func (x *UpdateNodeReq) GetNode() *GraphNode { func (x *UpdateNodeReq) GetNode() *GraphNode {
if x != nil { if x != nil {
return x.Node return x.Node
@ -1436,11 +1444,10 @@ func (*UpdateNodeRsp) Descriptor() ([]byte, []int) {
type GraphNode struct { type GraphNode struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
Label string `protobuf:"bytes,2,opt,name=label,proto3" json:"label,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` Text string `protobuf:"bytes,3,opt,name=text,proto3" json:"text,omitempty"`
Text string `protobuf:"bytes,4,opt,name=text,proto3" json:"text,omitempty"` Applications []*GraphApplication `protobuf:"bytes,4,rep,name=applications,proto3" json:"applications,omitempty"`
Applications []*GraphApplication `protobuf:"bytes,5,rep,name=applications,proto3" json:"applications,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -1475,16 +1482,9 @@ func (*GraphNode) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{31} return file_main_proto_rawDescGZIP(), []int{31}
} }
func (x *GraphNode) GetId() int32 { func (x *GraphNode) GetCode() string {
if x != nil { if x != nil {
return x.Id return x.Code
}
return 0
}
func (x *GraphNode) GetLabel() string {
if x != nil {
return x.Label
} }
return "" return ""
} }
@ -1556,8 +1556,8 @@ func (x *GraphApplication) GetName() string {
type GetGraphRsp_Edge struct { type GetGraphRsp_Edge struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
From int32 `protobuf:"varint,1,opt,name=from,proto3" json:"from,omitempty"` From string `protobuf:"bytes,1,opt,name=from,proto3" json:"from,omitempty"`
To int32 `protobuf:"varint,2,opt,name=to,proto3" json:"to,omitempty"` To string `protobuf:"bytes,2,opt,name=to,proto3" json:"to,omitempty"`
Arrows string `protobuf:"bytes,3,opt,name=arrows,proto3" json:"arrows,omitempty"` Arrows string `protobuf:"bytes,3,opt,name=arrows,proto3" json:"arrows,omitempty"`
Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"` Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
@ -1594,18 +1594,18 @@ func (*GetGraphRsp_Edge) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{28, 0} return file_main_proto_rawDescGZIP(), []int{28, 0}
} }
func (x *GetGraphRsp_Edge) GetFrom() int32 { func (x *GetGraphRsp_Edge) GetFrom() string {
if x != nil { if x != nil {
return x.From return x.From
} }
return 0 return ""
} }
func (x *GetGraphRsp_Edge) GetTo() int32 { func (x *GetGraphRsp_Edge) GetTo() string {
if x != nil { if x != nil {
return x.To return x.To
} }
return 0 return ""
} }
func (x *GetGraphRsp_Edge) GetArrows() string { func (x *GetGraphRsp_Edge) GetArrows() string {
@ -1702,19 +1702,19 @@ const file_main_proto_rawDesc = "" +
"countEdges\x18\x04 \x01(\x05R\n" + "countEdges\x18\x04 \x01(\x05R\n" +
"countEdges\x1aV\n" + "countEdges\x1aV\n" +
"\x04Edge\x12\x12\n" + "\x04Edge\x12\x12\n" +
"\x04from\x18\x01 \x01(\x05R\x04from\x12\x0e\n" + "\x04from\x18\x01 \x01(\tR\x04from\x12\x0e\n" +
"\x02to\x18\x02 \x01(\x05R\x02to\x12\x16\n" + "\x02to\x18\x02 \x01(\tR\x02to\x12\x16\n" +
"\x06arrows\x18\x03 \x01(\tR\x06arrows\x12\x12\n" + "\x06arrows\x18\x03 \x01(\tR\x06arrows\x12\x12\n" +
"\x04type\x18\x04 \x01(\tR\x04type\"G\n" + "\x04type\x18\x04 \x01(\tR\x04type\"[\n" +
"\rUpdateNodeReq\x126\n" + "\rUpdateNodeReq\x12\x12\n" +
"\x04node\x18\x01 \x01(\v2\".crabs.evening_detective.GraphNodeR\x04node\"\x0f\n" + "\x04code\x18\x01 \x01(\tR\x04code\x126\n" +
"\rUpdateNodeRsp\"\xa8\x01\n" + "\x04node\x18\x02 \x01(\v2\".crabs.evening_detective.GraphNodeR\x04node\"\x0f\n" +
"\tGraphNode\x12\x0e\n" + "\rUpdateNodeRsp\"\x96\x01\n" +
"\x02id\x18\x01 \x01(\x05R\x02id\x12\x14\n" + "\tGraphNode\x12\x12\n" +
"\x05label\x18\x02 \x01(\tR\x05label\x12\x12\n" + "\x04code\x18\x01 \x01(\tR\x04code\x12\x12\n" +
"\x04name\x18\x03 \x01(\tR\x04name\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\x12\x12\n" +
"\x04text\x18\x04 \x01(\tR\x04text\x12M\n" + "\x04text\x18\x03 \x01(\tR\x04text\x12M\n" +
"\fapplications\x18\x05 \x03(\v2).crabs.evening_detective.GraphApplicationR\fapplications\"&\n" + "\fapplications\x18\x04 \x03(\v2).crabs.evening_detective.GraphApplicationR\fapplications\"&\n" +
"\x10GraphApplication\x12\x12\n" + "\x10GraphApplication\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name2\xe4\v\n" + "\x04name\x18\x01 \x01(\tR\x04name2\xe4\v\n" +
"\x10EveningDetective\x12Y\n" + "\x10EveningDetective\x12Y\n" +

View File

@ -368,12 +368,10 @@
"type": "object", "type": "object",
"properties": { "properties": {
"from": { "from": {
"type": "integer", "type": "string"
"format": "int32"
}, },
"to": { "to": {
"type": "integer", "type": "string"
"format": "int32"
}, },
"arrows": { "arrows": {
"type": "string" "type": "string"
@ -583,11 +581,7 @@
"evening_detectiveGraphNode": { "evening_detectiveGraphNode": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": { "code": {
"type": "integer",
"format": "int32"
},
"label": {
"type": "string" "type": "string"
}, },
"name": { "name": {
@ -661,6 +655,9 @@
"evening_detectiveUpdateNodeReq": { "evening_detectiveUpdateNodeReq": {
"type": "object", "type": "object",
"properties": { "properties": {
"code": {
"type": "string"
},
"node": { "node": {
"$ref": "#/definitions/evening_detectiveGraphNode" "$ref": "#/definitions/evening_detectiveGraphNode"
} }