diff --git a/config.example.toml b/config.example.toml index d344f72..f8caeb2 100644 --- a/config.example.toml +++ b/config.example.toml @@ -15,18 +15,12 @@ nonpaid_project_tasks = "entry.714539999" nonpaid_project_hours = "entry.52836812_hour" nonpaid_project_minutes = "entry.52836812_minute" nonpaid_project_seconds = "entry.52836812_second" -next_tasks = "entry.1462603973" report_year = "entry.1783131858_year" report_month = "entry.1783131858_month" report_day = "entry.1783131858_day" -internal_tasks = "entry.20657743" -internal_hours = "entry.2061354997_hour" -internal_minutes = "entry.2061354997_minute" -internal_seconds = "entry.2061354997_second" [forms.google.params] url = "https://docs.google.com/forms/d/e/GOOGLE_FORM_KEY/viewform" -internal = "internal" [reporter] project_time_precision = 300 # in seconds diff --git a/forms/forms.go b/forms/forms.go index f7d02ad..df6723f 100644 --- a/forms/forms.go +++ b/forms/forms.go @@ -17,14 +17,9 @@ type GoogleFormFieldsMapping struct { NonpaidProjectHours string `toml:"nonpaid_project_hours"` NonpaidProjectMinutes string `toml:"nonpaid_project_minutes"` NonpaidProjectSeconds string `toml:"nonpaid_project_seconds"` - NextTasks string `toml:"next_tasks"` ReportYear string `toml:"report_year"` ReportMonth string `toml:"report_month"` ReportDay string `toml:"report_day"` - InternalTasks string `toml:"internal_tasks"` - InternalHours string `toml:"internal_hours"` - InternalMinutes string `toml:"internal_minutes"` - InternalSeconds string `toml:"internal_seconds"` } type GoogleFormData struct { @@ -37,14 +32,9 @@ type GoogleFormData struct { NonpaidProjectHours int NonpaidProjectMinutes int NonpaidProjectSeconds int - NextTasks string ReportYear int ReportMonth int ReportDay int - InternalTasks string - InternalHours int - InternalMinutes int - InternalSeconds int } type GoogleFormGenerator struct { @@ -56,52 +46,21 @@ type GoogleFormGenerator struct { func (gen *GoogleFormGenerator) ConvertReportToFormsData(report report.Report) map[string]GoogleFormData { formData := make(map[string]GoogleFormData) - var internalProjectData *GoogleFormData - - var projectWithInternal string for _, project := range report.Projects { - if project.Name == gen.InternalProjectName { - internalProjectData = &GoogleFormData{ - ProjectName: gen.InternalProjectName, - InternalTasks: gen.Formatter.Format(project.Paid.Tasks), - InternalHours: utils.Hours(project.Paid.Duration), - InternalMinutes: utils.Minutes(project.Paid.Duration), - InternalSeconds: utils.Seconds(project.Paid.Duration), - ReportYear: report.At.Year(), - ReportMonth: int(report.At.Month()), - ReportDay: report.At.Day(), - } - } else { - projectWithInternal = project.Name - formData[project.Name] = GoogleFormData{ - ProjectName: project.Name, - ProjectTasks: gen.Formatter.Format(project.Paid.Tasks), - ProjectHours: utils.Hours(project.Paid.Duration), - ProjectMinutes: utils.Minutes(project.Paid.Duration), - ProjectSeconds: utils.Seconds(project.Paid.Duration), - NonpaidProjectTasks: gen.Formatter.Format(project.NonPaid.Tasks), - NonpaidProjectHours: utils.Hours(project.NonPaid.Duration), - NonpaidProjectMinutes: utils.Minutes(project.NonPaid.Duration), - NonpaidProjectSeconds: utils.Seconds(project.NonPaid.Duration), - ReportYear: report.At.Year(), - ReportMonth: int(report.At.Month()), - ReportDay: report.At.Day(), - } - } - } - - if internalProjectData != nil { - data, ok := formData[projectWithInternal] - if projectWithInternal != "" && ok { - data.InternalTasks = internalProjectData.InternalTasks - data.InternalHours = internalProjectData.InternalHours - data.InternalMinutes = internalProjectData.InternalMinutes - data.InternalSeconds = internalProjectData.InternalSeconds - - formData[projectWithInternal] = data - } else { - formData[internalProjectData.ProjectName] = *internalProjectData + formData[project.Name] = GoogleFormData{ + ProjectName: project.Name, + ProjectTasks: gen.Formatter.Format(project.Paid.Tasks), + ProjectHours: utils.Hours(project.Paid.Duration), + ProjectMinutes: utils.Minutes(project.Paid.Duration), + ProjectSeconds: utils.Seconds(project.Paid.Duration), + NonpaidProjectTasks: gen.Formatter.Format(project.NonPaid.Tasks), + NonpaidProjectHours: utils.Hours(project.NonPaid.Duration), + NonpaidProjectMinutes: utils.Minutes(project.NonPaid.Duration), + NonpaidProjectSeconds: utils.Seconds(project.NonPaid.Duration), + ReportYear: report.At.Year(), + ReportMonth: int(report.At.Month()), + ReportDay: report.At.Day(), } } @@ -128,8 +87,8 @@ func (gen *GoogleFormGenerator) ConvertReportToForms(report report.Report) map[s func (gen *GoogleFormGenerator) encode(form GoogleFormData) string { query := url.Values{} query.Set(gen.Mapping.ProjectName, form.ProjectName) - - if (form.ProjectTasks != "") { + + if form.ProjectTasks != "" { query.Set(gen.Mapping.ProjectTasks, form.ProjectTasks) } else { query.Set(gen.Mapping.ProjectTasks, "-") @@ -143,17 +102,9 @@ func (gen *GoogleFormGenerator) encode(form GoogleFormData) string { query.Set(gen.Mapping.NonpaidProjectMinutes, strconv.Itoa(form.NonpaidProjectMinutes)) query.Set(gen.Mapping.NonpaidProjectSeconds, strconv.Itoa(form.NonpaidProjectSeconds)) - if form.NextTasks != "" { - query.Set(gen.Mapping.NextTasks, form.NextTasks) - } query.Set(gen.Mapping.ReportYear, strconv.Itoa(form.ReportYear)) query.Set(gen.Mapping.ReportMonth, strconv.Itoa(form.ReportMonth)) query.Set(gen.Mapping.ReportDay, strconv.Itoa(form.ReportDay)) - query.Set(gen.Mapping.InternalTasks, form.InternalTasks) - query.Set(gen.Mapping.InternalHours, strconv.Itoa(form.InternalHours)) - query.Set(gen.Mapping.InternalMinutes, strconv.Itoa(form.InternalMinutes)) - query.Set(gen.Mapping.InternalSeconds, strconv.Itoa(form.InternalSeconds)) - return query.Encode() } diff --git a/forms/forms_test.go b/forms/forms_test.go index 0183468..070db85 100644 --- a/forms/forms_test.go +++ b/forms/forms_test.go @@ -18,14 +18,9 @@ func GenTestMapping() GoogleFormFieldsMapping { NonpaidProjectHours: "entry.52836812_hour", NonpaidProjectMinutes: "entry.52836812_minute", NonpaidProjectSeconds: "entry.52836812_second", - NextTasks: "entry.1462603973", ReportYear: "entry.1783131858_year", ReportMonth: "entry.1783131858_month", ReportDay: "entry.1783131858_day", - InternalTasks: "entry.20657743", - InternalHours: "entry.2061354997_hour", - InternalMinutes: "entry.2061354997_minute", - InternalSeconds: "entry.2061354997_second", } }