-
Notifications
You must be signed in to change notification settings - Fork 4
/
assignments.go
66 lines (58 loc) · 1.99 KB
/
assignments.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
package main
import (
// "encoding/json"
// "io/ioutil"
// "net/http"
// "github.com/spf13/viper"
// "log"
// "strconv"
// "time"
// "reflect"
// "time"
// "bytes"
"fmt"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
// ui "github.com/GideonWolfe/termui/v3"
// "github.com/GideonWolfe/termui/v3/widgets"
)
func createAssignmentTable(assignments *[]Assignment) *widgets.Table {
var tableData [][]string
header := []string{"Name", "Due at" ,"Score"}
for _, assn := range *assignments {
var assignmentData []string
assignmentData = append(assignmentData, assn.Name)
// percentScored := float64(assn.Submission.Score/assn.PointsPossible)*100
scoreString := fmt.Sprint(assn.Submission.EnteredScore)+"/"+fmt.Sprint(assn.PointsPossible)
dueAt := assn.DueAt.Local().Format("1/2 4:05 PM")
assignmentData = append(assignmentData, dueAt, scoreString)
tableData = append(tableData, assignmentData)
}
tableData = append(tableData, header)
// reverse the list
for i, j := 0, len(tableData)-1; i < j; i, j = i+1, j-1 {
tableData[i], tableData[j] = tableData[j], tableData[i]
}
assignmentTable := widgets.NewTable()
assignmentTable.Title = "Assignments:"
assignmentTable.Rows = tableData
assignmentTable.TextStyle = ui.NewStyle(ui.ColorWhite)
assignmentTable.RowSeparator = true
assignmentTable.FillRow = true
assignmentTable.RowStyles[0] = ui.NewStyle(ui.ColorWhite, ui.ColorBlack, ui.ModifierBold)
return assignmentTable
}
// based on an input course object, this function generates
// a grid with widgets populated with data from the course
func createAssignmentGrid(course Course, assignments *[]Assignment) *ui.Grid {
assignmentGrid := ui.NewGrid()
termWidth, termHeight := ui.TerminalDimensions()
assignmentGrid.SetRect(0, 0, termWidth, termHeight)
assignmentGrid.Title = "Course Assignment Grid"
assignmentGrid.Set(
ui.NewRow(1.0,
ui.NewCol(1.0, createAssignmentTable(assignments)),
),
)
return assignmentGrid
}