-
Notifications
You must be signed in to change notification settings - Fork 0
/
inboxInter.go
146 lines (138 loc) · 4.68 KB
/
inboxInter.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
package main
import (
"OrderManager-cli/config"
"OrderManager-cli/pb"
"context"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func buildData(tasks []*pb.Task) [][]interface{} {
tableData := make([][]interface{}, 0)
//tableData = append(tableData, []interface{}{"TaskId", "Principal", "ReqNo", "Deadline", "WorkHours", "Comment", "State", "Level", "TypeId"})
tableData = append(tableData, []interface{}{"任务号", "负责人", "需求号", "截止日期", "预计工时", "任务描述", "状态", "紧急程度", "任务类型"})
for _, task := range tasks {
tableData = append(tableData, []interface{}{task.TaskId, task.Principal, task.ReqNo, task.Deadline, task.EstimatedWorkHours, task.Comment, task.State, task.EmergencyLevel, task.TypeId})
}
return tableData
}
func flushData(client pb.ServiceClient, mw fyne.Window) [][]interface{} {
reply, err := client.GetTaskListAll(context.Background(), &pb.GetTaskListAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
return nil
}
tableData := make([][]interface{}, 0)
tableData = append(tableData, []interface{}{"任务号", "负责人", "需求号", "截止日期", "预计工时", "任务描述", "状态", "紧急程度", "任务类型"})
for _, task := range reply.Tasks {
tableData = append(tableData, []interface{}{task.TaskId, task.Principal, task.ReqNo, task.Deadline, task.EstimatedWorkHours, task.Comment, task.State, task.EmergencyLevel, task.TypeId})
}
return tableData
}
// TODO: 更新操作
func CreateInBoxInterface(client pb.ServiceClient, mw fyne.Window) fyne.CanvasObject {
reply, err := client.GetTaskListAll(context.Background(), &pb.GetTaskListAllRequest{})
if err != nil {
dialog.ShowError(err, mw)
errRet := widget.NewEntry()
errRet.SetPlaceHolder(err.Error())
return errRet
}
tableData := buildData(reply.Tasks)
table := widget.NewTable(
func() (int, int) {
return len(tableData), len(tableData[0])
},
func() fyne.CanvasObject {
return widget.NewButton("", nil)
},
func(i widget.TableCellID, o fyne.CanvasObject) {
if i.Row == 0 {
o.(*widget.Button).SetText(tableData[i.Row][i.Col].(string))
} else {
if v, ok := tableData[i.Row][i.Col].(string); ok {
o.(*widget.Button).SetText(v)
} else {
o.(*widget.Button).SetText(fmt.Sprintf("%d", tableData[i.Row][i.Col]))
}
o.(*widget.Button).OnTapped = func() {
if err := ModForm(tableData[i.Row][0].(string), client); err != nil {
dialog.ShowError(err, mw)
} else {
flushData(client, mw)
}
}
}
})
for i := 0; i < 9; i++ {
table.SetColumnWidth(i, 150)
}
searchEntry := widget.NewEntry()
searchChoose := widget.NewSelect([]string{"修改单号", "负责人", "需求号", "截止日期", "SQL"}, func(s string) {
switch s {
case "修改单号":
searchEntry.SetText("")
searchEntry.Refresh()
case "负责人":
searchEntry.SetText("")
searchEntry.Refresh()
case "需求号":
searchEntry.SetText("")
searchEntry.Refresh()
case "截止日期":
searchEntry.SetText("Usage: 2006-01-02")
searchEntry.Refresh()
case "SQL":
searchEntry.SetText("Usage: select * from tasklist_table where task_id = ? (or principal = ? or req_no = ? deadline = ?)")
searchEntry.Refresh()
}
})
//sql语句查询, 或者输入字段查询
flushTableByField := func(fieldName string) {
rep, err := client.QueryTaskByField(context.Background(), &pb.QueryTaskWithFieldRequest{Field: fieldName, FieldValue: searchEntry.Text})
if err != nil {
dialog.ShowError(err, mw)
return
}
tableData = buildData(rep.Tasks)
table.Refresh()
}
activity := widget.NewActivity()
searchBtn := widget.NewButtonWithIcon("", theme.SearchIcon(), func() {
activity.Start()
defer activity.Stop()
if searchEntry.Text == "" {
tableData = flushData(client, mw)
table.Refresh()
return
}
switch searchChoose.SelectedIndex() {
case 0:
flushTableByField("task_id")
case 1:
flushTableByField("principal")
case 2:
flushTableByField("req_no")
case 3:
flushTableByField("deadline")
case 4:
rep, err := client.QueryTaskBySQL(context.Background(), &pb.QueryTaskWithSQLRequest{Sql: searchEntry.Text})
if err != nil {
dialog.ShowError(err, mw)
return
}
tableData = buildData(rep.Tasks)
table.Refresh()
}
})
flushBtn := widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), func() {
searchBtn.SetText("")
tableData = flushData(client, mw)
table.Refresh()
})
searchBar := container.NewStack(config.BarBg, container.NewBorder(nil, nil, searchChoose, container.NewHBox(searchBtn, activity, flushBtn), searchEntry))
return container.NewBorder(searchBar, nil, nil, nil, table)
}