Example #1
0
func NewBug(p chan string, btype έντομο.Type) gui.Widget {
	attrs := append([]string{"title"}, bug.ListAttributes()...)
	fields := []gui.Widget{}
	b := btype.Create()
	for _, attr := range attrs {
		fields = append(fields, gui.Row(gui.Text(attr+":"), AttributeChooser(b, attr, WriteLater)))
	}
	maintext := gui.TextArea("")
	fields = append(fields, gui.Text("Comment:"))
	fields = append(fields, maintext)
	submit := gui.Button("Submit bug")
	go func() {
		mainstr := ""
		for {
			select {
			case mainstr = <-maintext.Changes():
				// Nothing to do...
			case _ = <-submit.Clicks():
				b.ScheduleChange(mainstr)
				b.FlushPending()
				p <- "/"
				return
			}
		}
	}()
	fields = append(fields, submit)
	return gui.Column(fields...)
}
Example #2
0
func BugPage(p chan string, btype έντομο.Type, bnum int) gui.Widget {
	bl, err := btype.List()
	if err != nil {
		return gui.Text("Error: " + err.String())
	}
	if bnum >= len(bl) {
		return gui.Text(fmt.Sprint("Error: no such ", btype, " as number ", bnum))
	}
	b := bl[bnum]
	cs, err := b.Comments()
	if err != nil {
		return gui.Text("Error: " + err.String())
	}
	attrs := []gui.Widget{}
	for attr := range b.Attributes {
		attrs = append(attrs, gui.Row(gui.Text(attr+":"), AttributeChooser(b, attr, WriteNow)))
	}
	newcomment := gui.TextArea("")
	attrs = append(attrs, gui.Text("New comment:"))
	attrs = append(attrs, newcomment)
	submit := gui.Button("Add comment")
	attrs = append(attrs, submit)
	go func() {
		commentstr := ""
		for {
			select {
			case commentstr = <-newcomment.Changes():
				fmt.Println("Got nice comment:", commentstr)
				// Nothing to do...
			case _ = <-submit.Clicks():
				fmt.Println("Got add comment pushed.")
				b.AddComment(commentstr)
				p <- "/" + string(btype) + "-" + fmt.Sprint(bnum)
				return
			}
		}
	}()
	var bugs []gui.Widget
	for _, c := range cs {
		if len(c.Text) > 0 {
			bugs = append(bugs, gui.Row(gui.Text(c.Author), gui.Text(c.Date)),
				gui.Markdown(c.Text))
		}
	}
	return gui.Column(append(attrs, gui.Table(transpose(bugs)))...)
}
Example #3
0
func NewWidget() gui.Window {
	window := gui.Window{"Class survey", "", nil}

	teamname := ""
	team := gui.Menu(0,
		"", "archimedes", "boltzmann", "curie", "doppler", "euler", "feynman", "galileo",
		"hamilton", "ising", "joule", "kelvin", "lagrange", "maxwell", "newton", "onsager", "planck",
	)
	teamrow := gui.Table([][]gui.Widget{{gui.Text("Team:"), team}})

	name := ""
	namebox := gui.EditText(name)
	namerow := gui.Row(gui.Text("Name:"), namebox)
	// namebox.HandleChanged = func(old string) (modified gui.Widget, refresh bool) {
	// 	window.Title = `Survey of ` + namebox.Text.String
	// 	return
	// }
	partner := ""
	partnerbox := gui.EditText(partner)
	partnerrow := gui.Row(gui.Text("Partner:"), partnerbox)
	donetext := ""
	dotoday := gui.TextArea(donetext)
	learnedtoday := ""
	learntoday := gui.TextArea(learnedtoday)
	problems := ""
	workwell := gui.TextArea(problems)

	button := gui.Button("Submit")

	widget := gui.Table([][]gui.Widget{
		{teamrow},
		{namerow},
		{partnerrow},
		{gui.Text("What did you do today?")},
		{dotoday},
		{gui.Text("What is one thing you learned today?")},
		{learntoday},
		{gui.Text("What is one thing that didn't work well today?")},
		{workwell},
		{button},
	})
	window.Contents = widget
	go func() {
		for {
			select {
			case teamname = <-team.Changes():
				fmt.Println("Team name changed to", teamname)
			case name = <-namebox.Changes():
				//fmt.Println("Name changed to", name)
			case partner = <-partnerbox.Changes():
				//fmt.Println("Partner changed to", partner)
			case donetext = <-dotoday.Changes():
				fmt.Println("Done text is", donetext)
			case learnedtoday = <-learntoday.Changes():
				fmt.Println("Learned today is", learnedtoday)
			case problems = <-workwell.Changes():
				fmt.Println("Problems is", problems)
			case _ = <-button.Clicks():
				t := time.LocalTime()
				// First let's see if today has already been created
				if _, err := os.Stat(t.Format("2006-01-02")); err != nil {
					surveyfile.WriteString(t.Format("\\thisday{Monday}{2006-01-02}\n\n"))
				} else {
					fmt.Println("Day already exists.")
				}

				dir := t.Format("2006-01-02/15.04.05")
				err := os.MkdirAll(dir, 0777)
				if err != nil {
					fmt.Println("ERROR CREATING DIRECTORY", dir, "!")
					return
				}
				f, err := os.Create(filepath.Join(dir, name))
				if err != nil {
					fmt.Println("ERROR CREATING FILE", filepath.Join(dir, name), "!", err)
					return
				}
				defer f.Close()
				_, err = fmt.Fprintf(f, "\\daily{%s}{%s}{%s}{%s}{\n%s\n}{\n%s\n}{\n%s\n}\n",
					t.Format("3:04PM"),
					name, partner, teamname,
					IndentWrapText("  ", CleanLatex(donetext)),
					IndentWrapText("  ", CleanLatex(learnedtoday)),
					IndentWrapText("  ", CleanLatex(problems)))
				if err == nil {
					surveyfile.WriteString(t.Format("\\input{2006-01-02/15.04.05/" +
						name + "}\n"))
				} else {
					fmt.Println("I ran into a bug!", err)
					return
				}
				window.Contents.Updater() <- gui.Text("Thank you, " + name + "!")
			}
		}
	}()
	return window
}