-
Notifications
You must be signed in to change notification settings - Fork 0
/
preViewinter.go
864 lines (786 loc) · 25.5 KB
/
preViewinter.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
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/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
"image/color"
"log"
"math"
"sort"
"strconv"
"strings"
"time"
)
const (
AccountView = 0
TeamView = 1
)
var taskColors = []color.Color{
color.RGBA{R: 255, G: 90, B: 33, A: 255},
color.RGBA{R: 42, G: 43, B: 61, A: 255},
color.RGBA{R: 58, G: 178, B: 218, A: 255},
color.RGBA{R: 111, G: 219, B: 161, A: 255},
color.RGBA{R: 242, G: 15, B: 98, A: 255},
color.RGBA{R: 240, G: 53, B: 9, A: 255},
color.RGBA{R: 240, G: 53, B: 9, A: 255},
color.RGBA{R: 247, G: 153, B: 174, A: 255},
color.RGBA{R: 79, G: 179, B: 129, A: 255},
color.RGBA{R: 180, G: 222, B: 180, A: 255},
color.RGBA{G: 146, B: 199, A: 255},
color.RGBA{R: 120, G: 94, A: 255},
}
var allAccountNames = make([]string, 0)
func CreatePreviewInterface(appTab *container.AppTabs, client pb.ServiceClient, mw fyne.Window, msgChan <-chan string) *fyne.Container {
now := time.Now()
flushActivity := widget.NewActivity()
var previewInterface *fyne.Container
curView := AccountView //0:个人, 1:团队
// 创建一个网格布局,每行显示一天的任务
accountViewPage := 0
viewGrid := make([]*fyne.Container, 7)
var teamGrid fyne.CanvasObject
for i := range viewGrid {
viewGrid[i] = container.NewGridWithRows(1)
}
data, expired := loadAccountGrid(client, mw, config.Cfg.Login.UserName)
//var allData map[int][]*pb.Task
//var allExpired []*pb.Task
var allTidyData map[string]soredTV
var allTidyExpired []*pb.Task
var topBtn *fyne.Container
var bottom *fyne.Container
var teamBottom *fyne.Container
flushInterface := func() {
flushActivity.Start()
switch curView {
case AccountView:
appTab.Items[0].Content = container.NewBorder(topBtn, bottom, nil, nil, viewGrid[accountViewPage])
data, expired = loadAccountGrid(client, mw, config.Cfg.Login.UserName)
//previewInterface = container.NewBorder(topBtn, bottom, nil, nil, viewGrid[0])
previewInterface.Objects[2] = viewGrid[accountViewPage]
case TeamView:
allTidyData, allTidyExpired = loadTidyTeamGrid(client, mw)
if len(allAccountNames) == 0 {
rep, _ := client.GetAllUserName(context.Background(), &pb.GetAllUserNameRequest{})
allAccountNames = rep.Names
}
//BUG:
teamGrid = tidyTeamGrid(allTidyData, allTidyExpired, mw)
appTab.Items[0].Content = container.NewBorder(topBtn, teamBottom, nil, nil, teamGrid)
}
appTab.Refresh()
flushActivity.Stop()
}
list := make(map[int]*widget.List, 31)
expiredList := widget.NewList(
// 获取列表项的数量
func() int {
return len(expired)
},
// 创建列表项的模板
func() 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.ListItemID, item fyne.CanvasObject) {
colid, _ := strconv.Atoi(expired[id].TaskId)
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*canvas.Rectangle).FillColor = taskColors[colid%len(taskColors)]
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).SetText(fmt.Sprintf("%s : %s", expired[id].TaskId, expired[id].Principal))
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).OnTapped = func() {
if err := ModForm(expired[id].TaskId, client); err != nil {
dialog.ShowError(err, mw)
} else {
flushInterface()
}
}
},
)
expiredLabel := canvas.NewText("Expired", theme.Color(theme.ColorNameForeground))
// 设置Label的字体颜色
expiredLabel.TextStyle = fyne.TextStyle{Bold: true}
expiredLabel.Color = color.White
bgTheme1 := canvas.NewRectangle(config.ColorTheme1)
viewGrid[0].Add(container.NewBorder(container.NewStack(bgTheme1, expiredLabel), nil, nil, nil, expiredList))
for d := 0; d < 31; d++ {
list[d] = widget.NewList(
// 获取列表项的数量
func() int {
return len(data[d])
},
// 创建列表项的模板
func() 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.ListItemID, item fyne.CanvasObject) {
colid, _ := strconv.Atoi(data[d][id].TaskId)
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*canvas.Rectangle).FillColor = taskColors[colid%len(taskColors)]
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).SetText(fmt.Sprintf("%s : %s", data[d][id].TaskId, data[d][id].Principal))
item.(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button).OnTapped = func() {
if err := ModForm(data[d][id].TaskId, client); err != nil {
dialog.ShowError(err, mw)
} else {
flushInterface()
}
}
},
)
date := now.AddDate(0, 0, d)
//dateLabel := widget.NewLabel(date.Format("2006-01-02"))
dateLabel := canvas.NewText(date.Format("2006-01-02"), theme.Color(theme.ColorNameForeground))
// 设置Label的字体颜色
dateLabel.TextStyle = fyne.TextStyle{Bold: true}
dateLabel.Color = color.White
viewGrid[d/DAYSPERPAGE].Add(container.NewBorder(container.NewStack(bgTheme1, dateLabel), nil, nil, nil, list[d]))
}
//TODO:team
addBtn := widget.NewButtonWithIcon("", theme.ContentAddIcon(), func() {
newTask := addForm(client)
if newTask != nil {
addData(newTask, &expired, data)
previewInterface.Refresh()
}
})
importBtn := widget.NewButtonWithIcon("", theme.UploadIcon(), func() {
flushChan := make(chan struct{})
common.ImportController(myapp, client, common.ImportXLStoTaskListByPython, flushChan)
for {
_, ok := <-flushChan
if ok {
flushInterface()
} else {
break
}
}
})
accountEty := widget.NewEntry()
accountEty.PlaceHolder = "请输入姓名进行查询"
preSearch := ""
accountBtn := widget.NewButtonWithIcon("", theme.AccountIcon(), func() {
if accountEty.Text != "" {
preSearch = accountEty.Text
//TODO:没有考虑用户是否存在
data, expired = loadAccountGrid(client, mw, accountEty.Text)
} else if preSearch != "" { //防止重复刷新
preSearch = ""
data, expired = loadAccountGrid(client, mw, config.Cfg.Login.UserName)
}
curView = AccountView
appTab.Items[0].Content = container.NewBorder(topBtn, bottom, nil, nil, viewGrid[accountViewPage])
appTab.Refresh()
})
accountBtnWithBg := container.NewStack(canvas.NewRectangle(config.ColorTheme1), accountBtn)
//accountBg := canvas.NewRectangle(colorTheme1)
//accountBox := container.NewStack(accountBg, container.NewHBox(accountBtn, accountEty, nil))
teamBtn := widget.NewButtonWithIcon("", theme.HomeIcon(), func() {
curView = TeamView
if teamGrid == nil {
//allData, allExpired = loadTeamGrid(client, mw)
allTidyData, allTidyExpired = loadTidyTeamGrid(client, mw)
if len(allAccountNames) == 0 {
rep, err := client.GetAllUserName(context.Background(), &pb.GetAllUserNameRequest{})
if err != nil {
log.Fatal(err)
}
allAccountNames = rep.Names
}
//teamGrid = createTeamGrid(allData, allExpired, mw)
teamGrid = tidyTeamGrid(allTidyData, allTidyExpired, mw)
}
appTab.Items[0].Content = container.NewBorder(topBtn, teamBottom, nil, nil, teamGrid)
appTab.Refresh()
})
flushBtn := widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
flushInterface()
})
updateCurViewGrid := func() {
appTab.Items[0].Content = container.NewBorder(topBtn, bottom, nil, nil, viewGrid[accountViewPage])
appTab.Refresh()
}
prevPageBtn := widget.NewButtonWithIcon("", theme.MediaFastRewindIcon(), func() {
accountViewPage = max(accountViewPage-1, 0)
updateCurViewGrid()
})
nextPageBtn := widget.NewButtonWithIcon("", theme.MediaFastForwardIcon(), func() {
accountViewPage = min(accountViewPage+1, 6)
updateCurViewGrid()
})
btnBar := container.NewBorder(
nil,
nil,
container.NewHBox(addBtn, importBtn, flushBtn, flushActivity, teamBtn, accountBtnWithBg),
nil,
container.NewStack(canvas.NewRectangle(config.ColorTheme1), accountEty))
bg := canvas.NewRectangle(color.RGBA{241, 241, 240, 255})
topBtn = container.NewStack(bg, btnBar)
personalBtn := widget.NewButton(config.Cfg.Login.UserName, func() {
if err := personalView(client); err != nil {
dialog.ShowError(err, mw)
}
})
personalBtn.Importance = widget.HighImportance
hideWd := false
newMsgWdFunc := func() fyne.Window {
msgWd := myapp.NewWindow("msg")
msgWd.SetContent(widget.NewLabel("xx"))
msgWd.SetIcon(theme.MailComposeIcon())
msgWd.Resize(fyne.NewSize(550, 300))
msgWd.SetCloseIntercept(func() {
msgWd.Hide()
hideWd = false
return
})
return msgWd
}
msgActivity := widget.NewActivity()
msgCntLabel := widget.NewLabel(strconv.Itoa(msgCnt))
msgWd := newMsgWdFunc()
var msgData []string
msgList := widget.NewList(
func() int {
return len(msgData)
},
func() fyne.CanvasObject {
return widget.NewLabel("template")
},
func(id widget.ListItemID, item fyne.CanvasObject) {
item.(*widget.Label).SetText(msgData[id])
},
)
msgWd.SetContent(msgList)
msgBtn := widget.NewButtonWithIcon("", theme.MailComposeIcon(), func() {
if hideWd {
msgWd.Hide()
hideWd = false
return
}
msgCnt = 0
msgCntLabel.SetText(fmt.Sprintf("%d", msgCnt))
msgActivity.Stop()
msgWd.Show()
hideWd = !hideWd
//清除消息
})
//后台管理消息窗口
go func() {
for msg := range msgChan {
msgActivity.Start()
msgCnt++
if msgCnt >= 10 {
msgCntLabel.SetText("9+")
} else {
msgCntLabel.SetText(fmt.Sprintf("%d", msgCnt))
}
msgData = append([]string{msg}, msgData...)
}
}()
undoBtn := widget.NewButtonWithIcon("", theme.ContentUndoIcon(), func() {
if err := logChain.undo(); err != nil {
dialog.ShowError(err, mw)
}
flushInterface()
})
redoBtn := widget.NewButtonWithIcon("", theme.ContentRedoIcon(), func() {
if err := logChain.redo(); err != nil {
dialog.ShowError(err, mw)
}
flushInterface()
})
msgBox := container.NewHBox(undoBtn, msgActivity, msgBtn, msgCntLabel, redoBtn)
bottom = container.NewStack(bg, container.NewHBox(personalBtn, layout.NewSpacer(), msgBox, layout.NewSpacer(), prevPageBtn, nextPageBtn))
teamBottom = container.NewStack(bg, container.NewHBox(personalBtn, layout.NewSpacer(), msgBox, layout.NewSpacer()))
previewInterface = container.NewBorder(topBtn, bottom, nil, nil, viewGrid[0])
return previewInterface
}
func tidyTeamGrid(data map[string]soredTV, expired []*pb.Task, mw fyne.Window) fyne.CanvasObject {
// 0 expired d1 d2 d3 d4 d5 ...
// dusong1
// dusong2
infoMap := make(map[int64][]string)
nameMap := make(map[string]int)
grid := make([][]string, len(allAccountNames)+1)
for i := range grid {
grid[i] = make([]string, 33)
}
for i, name := range allAccountNames {
nameMap[name] = i
grid[i+1][0] = name
}
grid[0][0] = "姓名\\日期"
grid[0][1] = "expired"
for i := 0; i < 31; i++ {
grid[0][i+2] = time.Now().Add(time.Duration(i) * 24 * time.Hour).Format("2006-01-02")
}
for _, exp := range expired {
infoMap[(int64(nameMap[exp.Principal]+1)<<32)|1] = append(infoMap[int64(nameMap[exp.Principal]+1)<<32|1], exp.TaskId)
}
for i := 0; i < len(allAccountNames); i++ { //姓名 +1为grid表格行
val := data[allAccountNames[i]]
for j := 0; len(val) != 0 && j < 31; j++ { //日期 +2为grid表格
if val[0].deadPoint == j {
for val[0].deadPoint == j {
if val[0].time > 8 {
infoMap[(int64(i+1)<<32)|int64(j+2)] = append(infoMap[(int64(i+1)<<32)|int64(j+2)], fmt.Sprintf("%s (%d)", val[0].taskId, val[0].time))
} else {
infoMap[(int64(i+1)<<32)|int64(j+2)] = append(infoMap[(int64(i+1)<<32)|int64(j+2)], val[0].taskId)
}
val = val[1:]
if len(val) == 0 {
break
}
}
} else {
infoMap[(int64(i+1)<<32)|int64(j+2)] = append(infoMap[(int64(i+1)<<32)|int64(j+2)], val[0].taskId)
val[0].time -= 8
if val[0].time <= 0 {
val = val[1:]
}
}
}
}
table := widget.NewTable(
func() (int, int) {
return len(grid), len(grid[0])
},
func() fyne.CanvasObject {
//BUG:
return widget.NewButton("", func() {})
},
func(id widget.TableCellID, obj fyne.CanvasObject) {
btn := obj.(*widget.Button)
//TODO:dus重置按钮状态
btn.Hidden = false
btn.OnTapped = nil
btn.Importance = widget.LowImportance
//tmpGrid : (n + 1) * 6\
if id.Row == 0 || id.Col == 0 {
btn.SetText(grid[id.Row][id.Col])
} else if value, exists := infoMap[(int64(id.Row)<<32)|int64(id.Col)]; exists {
if len(value) > 1 {
btn.SetText(value[0] + "+")
} else {
btn.SetText(value[0])
}
if len(value) > 1 || strings.HasSuffix(value[0], ")") {
btn.Importance = widget.DangerImportance
}
btn.OnTapped = func() {
//dialog.ShowInformation("TaskInfo", strings.Join(value, "\r\n"), mw)
popupWindow := fyne.CurrentApp().NewWindow("tasklist window")
label := widget.NewLabel(strings.Join(value, "\r\n"))
copyBtn := widget.NewButton("Copy", func() {
clipboard := fyne.CurrentApp().Driver().AllWindows()[0].Clipboard()
clipboard.SetContent(label.Text)
})
popupContent := container.NewBorder(nil, copyBtn, nil, nil, label)
popupWindow.SetContent(popupContent)
popupWindow.Resize(fyne.NewSize(300, 150))
popupWindow.Show()
}
} else {
btn.Hidden = true
}
btn.Refresh() // 强制刷新按钮
})
for k := 0; k < len(grid[0]); k++ {
table.SetColumnWidth(k, 150)
}
return table
}
func createTeamGrid(data map[int][]*pb.Task, expired []*pb.Task, mw fyne.Window) fyne.CanvasObject {
// 0 expired d1 d2 d3 d4 d5 ...
// dusong1
// dusong2
infoMap := make(map[int64][]string)
nameMap := make(map[string]int)
grid := make([][]string, len(allAccountNames)+1)
for i := range grid {
grid[i] = make([]string, 33)
}
for i, name := range allAccountNames {
nameMap[name] = i
grid[i+1][0] = name
}
grid[0][0] = "姓名\\日期"
grid[0][1] = "expired"
for i := 0; i < 31; i++ {
grid[0][i+2] = time.Now().Add(time.Duration(i) * 24 * time.Hour).Format("2006-01-02")
}
for _, exp := range expired {
infoMap[(int64(nameMap[exp.Principal]+1)<<32)|0] = append(infoMap[int64(nameMap[exp.Principal]+1)<<32|0], exp.TaskId)
}
for day, tasks := range data {
for _, task := range tasks {
infoMap[(int64(nameMap[task.Principal]+1)<<32)|int64(day+1)] = append(infoMap[(int64(nameMap[task.Principal]+1)<<32)|int64(day+1)], task.TaskId)
}
}
table := widget.NewTable(
func() (int, int) {
return len(grid), len(grid[0])
},
func() fyne.CanvasObject {
//BUG:
return widget.NewButton("", func() {})
},
func(id widget.TableCellID, obj fyne.CanvasObject) {
btn := obj.(*widget.Button)
//TODO:dus重置按钮状态
btn.Hidden = false
btn.OnTapped = nil
btn.Importance = widget.LowImportance
//tmpGrid : (n + 1) * 6\
if id.Row == 0 || id.Col == 0 {
btn.SetText(grid[id.Row][id.Col])
} else if value, exists := infoMap[(int64(id.Row)<<32)|int64(id.Col-1)]; exists {
if len(value) > 1 {
btn.SetText(value[0] + "+")
} else {
btn.SetText(value[0])
}
if len(value) > 1 {
btn.Importance = widget.DangerImportance
}
btn.OnTapped = func() {
dialog.ShowInformation("TaskInfo", strings.Join(value, "\r\n"), mw)
}
} else {
btn.Hidden = true
}
btn.Refresh() // 强制刷新按钮
})
for k := 0; k < len(grid[0]); k++ {
table.SetColumnWidth(k, 150)
}
return table
}
func addData(t *pb.Task, expired *[]*pb.Task, data map[int][]*pb.Task) {
now := time.Now()
taskDate, err := time.Parse("2006-01-02", t.Deadline)
if err != nil {
logrus.Warningf("could not parse date: %v", err)
return
}
gap := int(taskDate.Sub(now.Truncate(24*time.Hour)).Hours() / 24) //任务时间距离现在有多少天
if gap < 0 {
*expired = append(*expired, t)
} else {
workDay := int(math.Ceil(float64(t.EstimatedWorkHours) / 8.0)) //预计完成天数(上取整)
//fmt.Println(gap, workDay, t.TaskId)
if gap-workDay+1 < 0 {
for d := 0; d < workDay; d++ { //gap:2, workday:3
data[min(gap, d)] = append(data[min(gap, d)], t)
}
} else {
for d := gap - workDay + 1; d <= gap; d++ {
data[d] = append(data[d], t)
}
}
}
}
func ModForm(taskId string, client pb.ServiceClient) error {
modTaskWindow := myapp.NewWindow("Update")
reply, err := client.GetTaskById(context.Background(), &pb.GetTaskByIdRequest{
TaskId: taskId,
})
if err != nil {
return err
}
task := reply.T
Deadline, Comment, EmergencyLevel, EstimatedWorkHours, State, Type, Principal := widget.NewEntry(), widget.NewMultiLineEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry()
Deadline.SetText((*task).Deadline)
Deadline.Validator = func(in string) error {
_, err := time.Parse("2006-01-02", Deadline.Text)
if err != nil {
return errors.New("deadline format error Usage: 2006-01-02")
}
return nil
}
Comment.SetText(task.Comment)
EmergencyLevel.SetText(fmt.Sprintf("%d", task.EmergencyLevel))
emergencyLevel32 := task.EmergencyLevel
EmergencyLevel.Validator = func(in string) error {
if in == "" {
return errors.New("can not be empty")
}
num, _ := strconv.Atoi(in)
emergencyLevel32 = int32(num)
return nil
}
EstimatedWorkHours.SetText(fmt.Sprintf("%d", task.EstimatedWorkHours))
estimatedWorkHours64 := task.EstimatedWorkHours
EstimatedWorkHours.Validator = func(in string) error {
if in == "" {
return errors.New("can not be empty")
}
tmp, _ := strconv.Atoi(in)
estimatedWorkHours64 = int32(tmp)
return nil
}
State.SetText(task.State)
State.Validator = func(in string) error {
if in == "" {
return errors.New("can not be empty")
}
return nil
}
Type.SetText(fmt.Sprintf("%d", task.TypeId))
typeid32 := task.TypeId
Type.Validator = func(in string) error {
if in == "" {
return errors.New("can not be empty")
}
tmp, _ := strconv.Atoi(in)
typeid32 = int32(tmp)
return nil
}
Principal.SetText(task.Principal)
Principal.Validator = func(in string) error {
if in == "" {
return errors.New("can not be empty")
}
return nil
}
// Id, Deadline, ReqNo, Comment, EmergencyLevel, EstimatedWorkHours, State, Type, Principal
isSucceed := make(chan error)
delBtn := widget.NewButtonWithIcon("Delete", theme.DeleteIcon(), func() {
go func() {
_, err := client.DelTask(context.Background(), &pb.DelTaskRequest{TaskNo: task.TaskId, User: config.Cfg.Login.UserName, Principal: task.Principal})
if err == nil {
logChain.append("del", task, nil)
}
isSucceed <- err
modTaskWindow.Close()
}()
})
delBtn.Importance = widget.HighImportance
//
//idLabel := widget.NewLabel(task.TaskId)
//idLabel.TextStyle = fyne.TextStyle{Bold: true}
//
//reqNoLabel := widget.NewLabel(task.ReqNo)
//reqNoLabel.TextStyle = fyne.TextStyle{Bold: true}
idEty, reqNoEty := widget.NewEntry(), widget.NewEntry()
idEty.SetText(task.TaskId)
idEty.Disable()
reqNoEty.SetText(task.ReqNo)
reqNoEty.Disable()
form := &widget.Form{
Items: []*widget.FormItem{
{Text: "任务单号", Widget: idEty},
{Text: "需求号", Widget: reqNoEty},
{Text: "截止日期", Widget: Deadline},
{Text: "负责人", Widget: Principal},
{Text: "预计工时(8h/d)", Widget: EstimatedWorkHours},
{Text: "紧急程度", Widget: EmergencyLevel},
{Text: "任务描述", Widget: Comment},
{Text: "任务类型", Widget: Type},
{Text: "任务状态", Widget: State},
{Widget: delBtn},
},
OnSubmit: func() {
newTask := &pb.Task{
TaskId: task.TaskId,
Comment: Comment.Text,
Deadline: Deadline.Text,
EmergencyLevel: emergencyLevel32,
EstimatedWorkHours: estimatedWorkHours64,
State: State.Text,
TypeId: typeid32,
ReqNo: task.ReqNo,
Principal: Principal.Text,
}
_, err := client.ModTask(context.Background(), &pb.ModTaskRequest{T: newTask, User: config.Cfg.Login.UserName})
if err == nil {
logChain.append("update", task, newTask)
}
isSucceed <- err
},
OnCancel: func() {
isSucceed <- nil
},
}
modTaskWindow.SetContent(form)
modTaskWindow.Resize(fyne.NewSize(300, 200))
modTaskWindow.Show()
modTaskWindow.SetOnClosed(func() {
isSucceed <- nil
})
ret := <-isSucceed
modTaskWindow.Close()
return ret
}
func addForm(client pb.ServiceClient) *pb.Task {
addTaskWindow := myapp.NewWindow("Update")
idEty, deadlineEty, reqNoEty, commentEty, emergencyLevelEty, estimatedWorkHoursEty, stateEty, typeEty, principalEty := widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewMultiLineEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry(), widget.NewEntry()
deadlineEty.SetText(time.Now().Format("2006-01-02"))
commentEty.SetText("null")
emergencyLevelEty.SetText("0")
estimatedWorkHoursEty.SetText("4")
stateEty.SetText("带启动")
typeEty.SetText("0")
principalEty.SetText(config.Cfg.Login.UserName) //TODO: 默认登录者自己的名字,最后考虑权限的问题
deadlineEty.Validator = func(in string) error {
_, err := time.Parse("2006-01-02", in)
if err != nil {
return errors.New("deadline format error Usage: 2006-01-02")
}
return nil
}
idEty.Validator = func(in string) error {
if idEty.Text == "" {
return errors.New("can not be empty")
}
return nil
}
reqNoEty.Validator = func(in string) error {
if reqNoEty.Text == "" {
return errors.New("can not be empty")
}
return nil
}
retChan := make(chan *pb.Task)
form := &widget.Form{
Items: []*widget.FormItem{
{Text: "任务单号", Widget: idEty},
{Text: "需求号", Widget: reqNoEty},
{Text: "截止日期", Widget: deadlineEty},
{Text: "负责人", Widget: principalEty},
{Text: "预计工时", Widget: estimatedWorkHoursEty},
{Text: "紧急程度", Widget: emergencyLevelEty},
{Text: "任务描述", Widget: commentEty},
{Text: "任务类型", Widget: typeEty},
{Text: "任务状态", Widget: stateEty},
},
OnSubmit: func() { // optional, handle form submission
numType, _ := strconv.Atoi(typeEty.Text)
taskType := int32(numType)
numHours, _ := strconv.Atoi(estimatedWorkHoursEty.Text)
estimatedWorkHours := int32(numHours)
numLevel, _ := strconv.Atoi(emergencyLevelEty.Text)
emergencyLevel := int32(numLevel)
newTask := &pb.Task{
TaskId: idEty.Text,
Comment: commentEty.Text,
Deadline: deadlineEty.Text,
EmergencyLevel: emergencyLevel,
EstimatedWorkHours: estimatedWorkHours,
State: stateEty.Text,
TypeId: taskType,
ReqNo: reqNoEty.Text,
Principal: principalEty.Text,
}
request := &pb.AddTaskRequest{T: newTask, User: config.Cfg.Login.UserName}
_, err := client.AddTask(context.Background(), request)
if err != nil {
dialog.NewInformation("error", err.Error(), addTaskWindow).Show()
} else {
logChain.append("add", nil, request)
retChan <- newTask
addTaskWindow.Close()
}
},
OnCancel: func() {
retChan <- nil
addTaskWindow.Close()
},
}
addTaskWindow.SetContent(form)
addTaskWindow.Resize(fyne.NewSize(300, 200))
addTaskWindow.Show()
addTaskWindow.SetOnClosed(func() {
retChan <- nil
})
return <-retChan
}
func loadTeamGrid(client pb.ServiceClient, mw fyne.Window) (data map[int][]*pb.Task, expired []*pb.Task) {
data = make(map[int][]*pb.Task)
expired = make([]*pb.Task, 0)
reply, err := client.GetTaskListAll(context.Background(), &pb.GetTaskListAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
return
}
for _, task := range reply.Tasks {
addData(task, &expired, data)
}
//log.Println("data dict size: " + strconv.Itoa(len(data)))
return data, expired
}
type tidyValue struct {
taskId string
time int8
deadPoint int
}
type soredTV []*tidyValue
func (stv soredTV) Len() int {
return len(stv)
}
func (stv soredTV) Less(i, j int) bool {
return stv[i].deadPoint < stv[j].deadPoint
}
func (stv soredTV) Swap(i, j int) {
stv[i], stv[j] = stv[j], stv[i]
}
func loadTidyTeamGrid(client pb.ServiceClient, mw fyne.Window) (data map[string]soredTV, expired []*pb.Task) {
data = make(map[string]soredTV)
expired = make([]*pb.Task, 0)
reply, err := client.GetTaskListAll(context.Background(), &pb.GetTaskListAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
return
}
for _, task := range reply.Tasks {
addTidyData(task, &expired, data)
}
//log.Println("data dict size: " + strconv.Itoa(len(data)))
for _, v := range data {
sort.Sort(v)
}
return data, expired
}
func addTidyData(task *pb.Task, exp *[]*pb.Task, data map[string]soredTV) {
now := time.Now()
taskDate, err := time.Parse("2006-01-02", task.Deadline)
if err != nil {
logrus.Warningf("could not parse date: %v", err)
return
}
gap := int(taskDate.Sub(now.Truncate(24*time.Hour)).Hours() / 24) //任务时间距离现在有多少天
if gap < 0 {
*exp = append(*exp, task)
} else {
data[task.Principal] = append(data[task.Principal], &tidyValue{task.TaskId, int8(task.EstimatedWorkHours), gap})
}
}
func loadAccountGrid(client pb.ServiceClient, mw fyne.Window, name string) (data map[int][]*pb.Task, expired []*pb.Task) {
data = make(map[int][]*pb.Task)
expired = make([]*pb.Task, 0)
reply, err := client.GetTaskListByName(context.Background(), &pb.GetTaskListOneRequest{Name: name})
if err != nil {
dialog.ShowError(err, mw)
return
}
for _, task := range reply.Tasks {
addData(task, &expired, data)
}
return data, expired
}