-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchsInter.go
371 lines (333 loc) · 11 KB
/
patchsInter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package main
import (
"OrderManager-cli/common"
"OrderManager-cli/config"
"OrderManager-cli/pb"
"context"
"errors"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"image/color"
"strings"
"time"
)
var (
COLOR_PATCHS = color.RGBA{52, 70, 94, 255}
COLOR_REQ = color.RGBA{84, 117, 161, 255}
COLOR_TASK = color.RGBA{125, 169, 227, 255}
)
func CreatePatchsInterface(client pb.ServiceClient, mw fyne.Window) fyne.CanvasObject {
orderMap := loadAllPatchs(client, mw)
var tree *widget.Tree
delAndFlushTree := func(id string) {
delete(orderMap, id)
var newroot []string
for _, root := range orderMap[""] {
if root != id {
newroot = append(newroot, root)
}
}
orderMap[""] = newroot
tree.Refresh()
}
tree = widget.NewTree(
func(id widget.TreeNodeID) []widget.TreeNodeID {
return orderMap[id]
},
func(id widget.TreeNodeID) bool {
return len(orderMap[id]) > 0
},
func(branch bool) fyne.CanvasObject {
bg := canvas.NewRectangle(color.Black)
btn := widget.NewButton("Do something", nil)
return container.NewPadded(
container.NewBorder(nil, nil, bg, nil, btn),
)
},
func(id widget.TreeNodeID, branch bool, o fyne.CanvasObject) {
if strings.HasPrefix(id, "P") { //补丁
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*canvas.Rectangle).FillColor = COLOR_PATCHS
} else if strings.HasPrefix(id, "T") {
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*canvas.Rectangle).FillColor = COLOR_TASK
} else {
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*canvas.Rectangle).FillColor = COLOR_REQ
}
//TODO
if patchsShow, ok := patchsInfoMap[id]; ok {
info := fmt.Sprintf("%s : <客户: %s -- 预计发布时间: %s -- 发布状态: %s>", id, patchsShow.clientName, patchsShow.deadline, patchsShow.state)
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).SetText(info)
} else if taskShow, ok := tasksInfoMap[id]; ok {
info := fmt.Sprintf("%s : <负责人: %s -- 截止日期: %s -- 任务状态: %s>", id, taskShow.principal, taskShow.deadline, taskShow.state)
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).SetText(info)
} else {
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).SetText(id)
}
o.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).OnTapped = func() {
if strings.HasPrefix(id, "P") { //补丁
retNo := ModPatchsForm(id, client)
if retNo == 1 { //删除
delAndFlushTree(id)
}
} else if strings.HasPrefix(id, "T") { //任务/修改单
if err := ModForm(id, client); err != nil {
dialog.ShowError(err, mw)
} else {
orderMap = loadAllPatchs(client, mw)
tree.Refresh()
}
}
}
})
importBtn := widget.NewButtonWithIcon("", theme.UploadIcon(), func() {
flushChan := make(chan struct{})
common.ImportController(myapp, client, common.ImportXLStoPatchTableByPython, flushChan)
for {
_, ok := <-flushChan
if ok {
orderMap = loadAllPatchs(client, mw)
tree.Refresh()
} else {
break
}
}
})
searchChoose := widget.NewSelect([]string{"补丁号", "发布状态", "客户名称"}, func(s string) {
})
searchEntry := widget.NewEntry()
activity := widget.NewActivity()
searchBtn := widget.NewButtonWithIcon("", theme.SearchIcon(), func() {
activity.Start()
if searchEntry.Text == "" {
orderMap = loadAllPatchs(client, mw)
tree.Refresh()
} else {
switch searchChoose.SelectedIndex() {
case 0:
orderMap = loadQueryPatchs(searchEntry.Text, client, mw)
case 1:
orderMap = QueryPatchsWithField("state", searchEntry.Text, client, mw)
case 2:
orderMap = QueryPatchsWithField("client_name", searchEntry.Text, client, mw)
}
tree.Refresh()
}
activity.Stop()
})
flushBtn := widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
orderMap = loadAllPatchs(client, mw)
tree.Refresh()
tree.CloseAllBranches()
})
activity.Show()
searchBar := container.NewStack(config.BarBg, container.NewBorder(nil, nil, container.NewHBox(importBtn, searchChoose), container.NewHBox(searchBtn, activity, flushBtn), searchEntry))
return container.NewBorder(searchBar, nil, nil, nil, tree)
}
type treePatchInfo struct {
clientName string
deadline string
state string
}
type treeTaskInfo struct {
principal string
deadline string
state string
}
var patchsInfoMap = make(map[string]treePatchInfo)
var tasksInfoMap = make(map[string]treeTaskInfo)
func loadAllPatchs(client pb.ServiceClient, mw fyne.Window) map[string][]string {
patchsReply, err := client.GetPatchsAll(context.Background(), &pb.GetPatchsAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
patchsData := patchsReply.Patchs
tasksReply, err := client.GetTaskListAll(context.Background(), &pb.GetTaskListAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
tasksData := tasksReply.Tasks
orderMap := make(map[string][]string)
keys := make([]string, 0)
for _, patch := range patchsData {
patchsInfoMap[patch.PatchNo] = treePatchInfo{
clientName: patch.ClientName,
deadline: patch.Deadline,
state: patch.State,
}
keys = append(keys, patch.PatchNo)
orderMap[patch.PatchNo] = append(orderMap[patch.PatchNo], strings.Split(patch.ReqNo, ",")...)
}
for _, task := range tasksData {
tasksInfoMap[task.TaskId] = treeTaskInfo{
principal: task.Principal,
deadline: task.Deadline,
state: task.State,
}
orderMap[task.ReqNo] = append(orderMap[task.ReqNo], task.TaskId)
}
orderMap[""] = keys
return orderMap
}
// TODO: 该功能暂时只支持单个补丁查询
// TODO:一个补丁和多个需求对应关系在一行中,不同需求由“ , ”隔开,不同补丁可能对应相同需求
func QueryPatchsWithField(fieldName string, fieldValue string, client pb.ServiceClient, mw fyne.Window) map[string][]string {
patchsReply, err := client.QueryPatchsWithField(context.Background(), &pb.QueryPatchsWithFieldRequest{FieldName: fieldName, FieldValue: fieldValue})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
orderMap := make(map[string][]string)
keys := make([]string, 0)
patchsDatas := patchsReply.Ps
for _, patchsData := range patchsDatas {
keys = append(keys, patchsData.PatchNo)
reqNos := strings.Split(patchsData.ReqNo, ",")
for _, reqNo := range reqNos {
tasksReply, err := client.QueryTaskByField(context.Background(), &pb.QueryTaskWithFieldRequest{Field: "req_no", FieldValue: reqNo})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
tasksData := tasksReply.Tasks
orderMap[patchsData.PatchNo] = append(orderMap[patchsData.PatchNo], reqNo)
for _, task := range tasksData {
orderMap[patchsData.ReqNo] = append(orderMap[task.ReqNo], task.TaskId)
}
}
}
orderMap[""] = keys
return orderMap
}
func loadQueryPatchs(patchNo string, client pb.ServiceClient, mw fyne.Window) map[string][]string {
patchsReply, err := client.GetOnePatchs(context.Background(), &pb.GetOnePatchsRequest{PatchNo: patchNo})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
orderMap := make(map[string][]string)
keys := make([]string, 0)
keys = append(keys, patchNo)
patchsData := patchsReply.P
reqNos := strings.Split(patchsData.ReqNo, ",")
for _, reqNo := range reqNos {
tasksReply, err := client.QueryTaskByField(context.Background(), &pb.QueryTaskWithFieldRequest{Field: "req_no", FieldValue: reqNo})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
tasksData := tasksReply.Tasks
orderMap[patchsData.PatchNo] = append(orderMap[patchsData.PatchNo], reqNo)
for _, task := range tasksData {
orderMap[patchsData.ReqNo] = append(orderMap[task.ReqNo], task.TaskId)
}
}
orderMap[""] = keys
return orderMap
}
// TODO:考虑查询到的第一个
func ModPatchsForm(patchNo string, client pb.ServiceClient) int {
modTaskWindow := myapp.NewWindow("Update")
reply, err := client.GetOnePatchs(context.Background(), &pb.GetOnePatchsRequest{PatchNo: patchNo})
if err != nil {
dialog.ShowError(err, modTaskWindow)
}
patchs := reply.P
patchNoEty, reqNoEty, describeEty, clientNameEty, deadlineEty, reasonEty, sponsorEty, stateEty := widget.NewEntry(), widget.NewEntry(), widget.NewMultiLineEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry()
patchNoEty.SetText(patchs.PatchNo)
patchNoEty.Disable()
reqNoEty.SetText(patchs.ReqNo)
reqNoEty.Disable()
describeEty.SetText(patchs.Describe)
clientNameEty.SetText(patchs.ClientName)
stateEty.SetText(patchs.State)
clientNameEty.Validator = func(in string) error {
if in == "" {
return errors.New("client name is empty")
}
return nil
}
deadlineEty.SetText(patchs.Deadline)
deadlineEty.Validator = func(in string) error {
_, err := time.Parse("2006-01-02", deadlineEty.Text)
if err != nil {
return errors.New("deadline format error Usage: 2006-01-02")
}
return nil
}
reasonEty.SetText(patchs.Reason)
sponsorEty.SetText(patchs.Sponsor)
sponsorEty.Validator = func(in string) error {
if in == "" {
return errors.New("sponsor is empty")
}
return nil
}
isSucceed := make(chan int) //-1 : 失败, 0:update 1 : delete
delBtn := widget.NewButtonWithIcon("Delete", theme.DeleteIcon(), func() {
go func() {
_, err := client.DelPatch(context.Background(), &pb.DelPatchRequest{PatchNo: patchNoEty.Text, User: config.Cfg.Login.UserName})
if err != nil {
dialog.ShowError(err, modTaskWindow)
isSucceed <- -1
} else {
isSucceed <- 1
modTaskWindow.Close()
return
}
}()
})
delBtn.Importance = widget.HighImportance
form := &widget.Form{
Items: []*widget.FormItem{
{Text: "补丁号", Widget: patchNoEty},
{Text: "需求号", Widget: reqNoEty},
{Text: "截止日期", Widget: deadlineEty},
{Text: "发起人", Widget: sponsorEty},
{Text: "客户名称", Widget: clientNameEty},
{Text: "问题描述", Widget: describeEty},
{Text: "补丁原因", Widget: reasonEty},
{Text: "发布状态", Widget: stateEty},
{Widget: delBtn},
},
OnSubmit: func() {
newPatch := &pb.Patch{
PatchNo: patchNoEty.Text,
ReqNo: reqNoEty.Text,
Describe: describeEty.Text,
Deadline: deadlineEty.Text,
ClientName: clientNameEty.Text,
Reason: reasonEty.Text,
Sponsor: sponsorEty.Text,
State: stateEty.Text,
}
_, err := client.ModPatch(context.Background(), &pb.ModPatchRequest{P: newPatch, User: config.Cfg.Login.UserName})
if err != nil {
isSucceed <- -1
logrus.Warning(err)
return
} else {
isSucceed <- 0
logrus.Infof("update patchs: %s succeed", newPatch.PatchNo)
}
modTaskWindow.Close()
},
OnCancel: func() {
isSucceed <- -1
modTaskWindow.Close()
},
}
modTaskWindow.SetContent(form)
modTaskWindow.Resize(fyne.NewSize(300, 200))
modTaskWindow.Show()
modTaskWindow.SetOnClosed(func() {
isSucceed <- -1
})
return <-isSucceed
}