Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions api/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,20 @@ type Rate struct {

// TimeEntry DTO
type TimeEntry struct {
ID string `json:"id"`
Billable bool `json:"billable"`
Description string `json:"description"`
HourlyRate Rate `json:"hourlyRate"`
IsLocked bool `json:"isLocked"`
Project *Project `json:"project"`
ProjectID string `json:"projectId"`
Tags []Tag `json:"tags"`
Task *Task `json:"task"`
TimeInterval TimeInterval `json:"timeInterval"`
TotalBillable int64 `json:"totalBillable"`
User *User `json:"user"`
WorkspaceID string `json:"workspaceId"`
ID string `json:"id"`
Billable bool `json:"billable"`
Description string `json:"description"`
HourlyRate Rate `json:"hourlyRate"`
IsLocked bool `json:"isLocked"`
Project *Project `json:"project"`
CustomFields []CustomField `json:"customFieldValues"`
ProjectID string `json:"projectId"`
Tags []Tag `json:"tags"`
Task *Task `json:"task"`
TimeInterval TimeInterval `json:"timeInterval"`
TotalBillable int64 `json:"totalBillable"`
User *User `json:"user"`
WorkspaceID string `json:"workspaceId"`
}

// NewTimeInterval will create a TimeInterval from start and end times
Expand Down Expand Up @@ -200,7 +201,7 @@ func (e Client) GetName() string { return e.Name }
// CustomField DTO
type CustomField struct {
CustomFieldID string `json:"customFieldId"`
Status string `json:"status"`
TimeEntryId string `json:"timeEntryId"`
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
Expand Down
8 changes: 6 additions & 2 deletions pkg/output/time-entry/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package timeentry
import (
"encoding/csv"
"io"
"strings"
"time"

"github.com/lucassabreu/clockify-cli/api/dto"
Expand All @@ -26,6 +27,7 @@ func TimeEntriesCSVPrint(timeEntries []dto.TimeEntry, out io.Writer) error {
"user.email",
"user.name",
"tags...",
"customFields...",
}); err != nil {
return err
}
Expand Down Expand Up @@ -74,8 +76,10 @@ func TimeEntriesCSVPrint(timeEntries []dto.TimeEntry, out io.Writer) error {
te.User.Name,
}

if err := w.Write(append(
arr, tagsToStringSlice(te.Tags)...)); err != nil {
arr = append(arr, strings.Join(tagsToStringSlice(te.Tags), ";"))
arr = append(arr, strings.Join(customFieldsToStringSlice(te.CustomFields), ";"))

if err := w.Write(arr); err != nil {
return err
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/output/time-entry/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,13 @@ func tagsToStringSlice(tags []dto.Tag) []string {
func durationToString(d time.Duration) string {
return dto.Duration{Duration: d}.HumanString()
}

func customFieldsToStringSlice(customFields []dto.CustomField) []string {
s := make([]string, len(customFields))

for i, cf := range customFields {
s[i] = fmt.Sprintf("%s(%s)=%s", cf.Name, cf.CustomFieldID, cf.Value)
}

return s
}
26 changes: 19 additions & 7 deletions pkg/output/time-entry/markdown.gotmpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@
{{- $tags = "No Tags" -}}
{{- end -}}

{{- $pad := maxLength .Description $project $tags $bil -}}
{{- $customFields := "" -}}
{{- with .CustomFields -}}
{{- range $index, $element := . -}}
{{- if ne $index 0 }}{{ $customFields = concat $customFields ", " }}{{ end -}}
{{- $customFields = concat $customFields $element.Name ": " $element.Value -}}
{{- end -}}
{{- else -}}
{{- $customFields = "No Custom Fields" -}}
{{- end -}}


{{- $pad := maxLength .Description $project $tags $customFields $bil -}}

## _Time Entry_: {{ .ID }}

Expand All @@ -35,9 +46,10 @@ Start Time: _{{ formatTimeWS .TimeInterval.Start }}_ 🗓 Today
{{- .TimeInterval.Start.Format " 01/02/2006" }}
{{- end }}

| | {{ pad "" $pad }} |
|---------------|-{{ repeatString "-" $pad }}-|
| _Description_ | {{ pad .Description $pad }} |
| _Project_ | {{ pad $project $pad }} |
| _Tags_ | {{ pad $tags $pad }} |
| _Billable_ | {{ pad $bil $pad }} |
| | {{ pad "" $pad }} |
|-----------------|-{{ repeatString "-" $pad }}-|
| _Description_ | {{ pad .Description $pad }} |
| _Project_ | {{ pad $project $pad }} |
| _Tags_ | {{ pad $tags $pad }} |
| _Billable_ | {{ pad $bil $pad }} |
| _Custom Fields_ | {{ pad $customFields $pad }} |
Loading