diff options
| author | Teddy Wing | 2017-03-12 18:47:21 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-03-12 18:47:21 +0100 | 
| commit | 4b1de1d7bfb0261d28a192171b73388cb639eae4 (patch) | |
| tree | 67355f25ee10580fd2b7e797d244a8506d1345e5 | |
| parent | 72ce73048e3c04982012c7900eef080ca5b1f726 (diff) | |
| download | timetasker-4b1de1d7bfb0261d28a192171b73388cb639eae4.tar.bz2 | |
Add GenerateWeeklyTimesheet()
A function to generate a weekly time sheet.
Add a new `defaults` key to the config.yml file. Looks like this:
    defaults:
      client:
      project:
      module:
      task:
      work_type:
      time:
      billable:
This will be used to fill in default values when a timesheet is
generated.
| -rw-r--r-- | main.go | 7 | ||||
| -rw-r--r-- | templates/timesheet.yml.tmpl | 11 | ||||
| -rw-r--r-- | templates/weekly_timesheet.yml.tmpl | 3 | ||||
| -rw-r--r-- | timetask/generator.go | 27 | 
4 files changed, 46 insertions, 2 deletions
| @@ -16,7 +16,8 @@ type Config struct {  		Username    string  		PasswordCmd string `yaml:"password_cmd"`  	} -	Fields timetask.Fields +	Fields   timetask.Fields +	Defaults timetask.TimeEntry  }  var config Config @@ -43,7 +44,9 @@ func main() {  	log.Printf("%+v", time_entries) -	timetask.SubmitTimeEntries(config.Fields, time_entries) +	// timetask.SubmitTimeEntries(config.Fields, time_entries) + +	timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults)  }  func loadConfig() { diff --git a/templates/timesheet.yml.tmpl b/templates/timesheet.yml.tmpl new file mode 100644 index 0000000..1930b09 --- /dev/null +++ b/templates/timesheet.yml.tmpl @@ -0,0 +1,11 @@ +{{- define "timesheet" -}} +- client: {{.Client}} +  project: {{.Project}} +  module: {{.Module}} +  task: {{.Task}} +  work_type: {{.WorkType}} +  date: {{.Date.Format "02/01/06"}} +  time: {{.Time}} +  billable: {{.Billable}} +  description: {{.Description}} +{{ end -}} diff --git a/templates/weekly_timesheet.yml.tmpl b/templates/weekly_timesheet.yml.tmpl new file mode 100644 index 0000000..0ea6582 --- /dev/null +++ b/templates/weekly_timesheet.yml.tmpl @@ -0,0 +1,3 @@ +{{- range . -}} +	{{- template "timesheet" . -}} +{{- end -}} diff --git a/timetask/generator.go b/timetask/generator.go new file mode 100644 index 0000000..25986ae --- /dev/null +++ b/timetask/generator.go @@ -0,0 +1,27 @@ +package timetask + +import ( +	"io" +	"log" +	"text/template" +) + +func GenerateWeeklyTimesheet(wr io.Writer, defaults TimeEntry) { +	time_entries := []TimeEntry{} +	for i := 1; i <= 5; i++ { +		time_entries = append(time_entries, defaults) +	} + +	t, err := template.ParseFiles( +		"templates/weekly_timesheet.yml.tmpl", +		"templates/timesheet.yml.tmpl", +	) +	if err != nil { +		log.Panic(err) +	} + +	err = t.Execute(wr, time_entries) +	if err != nil { +		log.Panic(err) +	} +} | 
