github.com/developest/gtm-core@v1.0.4-0.20220111132249-cc80a3372c3f/report/templates.go (about)

     1  // Copyright 2016 Michael Schenk. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package report
     6  
     7  const (
     8  	commitSummaryTpl string = `
     9  {{- $boldFormat := .BoldFormat }}
    10  {{- $greenFormat := .GreenFormat }}
    11  {{- range $line := .Lines }}
    12  	{{- if $line.StartGroup }}
    13  		{{- printf "\n" }}
    14  		{{- printf $boldFormat $line.Date }}
    15  	{{- end }}
    16  	{{- if $line.EndGroup }}
    17  		{{- FormatDuration $line.Total | printf "\n%14s" }}
    18  		{{- printf "\n" }}
    19  	{{- end }}
    20  	{{- if $line.CommitLine }}
    21  		{{- FormatDuration $line.Total | printf "\n%14s" }} {{ printf $greenFormat $line.Subject }} [{{ $line.Project }}]
    22  	{{- end }}
    23  {{- end -}}`
    24  	projectTotalsTpl string = `
    25  {{- $boldFormat := .BoldFormat }}
    26  {{- range $project, $total := .Projects }}
    27  	{{- FormatDuration $total | printf "\n%14s" }} {{ printf $boldFormat $project }}
    28  {{- end -}}`
    29  	commitsTpl string = `
    30  {{ $boldFormat := .BoldFormat }}
    31  {{ $greenFormat := .GreenFormat }}
    32  {{- $fullMessage := .FullMessage }}
    33  {{- range $note := .Notes }}
    34  	{{- $total := .Note.Total }}
    35  	{{- printf $boldFormat $note.Hash }} {{ printf $greenFormat $note.Subject }}{{- printf "\n" }}
    36  	{{- $note.Date }} {{ printf $boldFormat $note.Project }} {{ $note.Author }}{{- printf "\n" }}
    37  	{{- if $fullMessage}}{{- if $note.Message }}{{- printf "\n"}}{{- $note.Message }}{{- printf "\n"}}{{end}}{{end}}
    38  	{{- range $i, $f := .Note.Files }}
    39  		{{- if $f.IsApp }}
    40  			{{- FormatDuration $f.TimeSpent | printf "\n%14s" }} {{ Percent $f.TimeSpent $total | printf "%3.0f"}}% [{{ $f.Status }}] [app] {{$f.GetAppName }}
    41  		{{- else }}
    42  			{{- FormatDuration $f.TimeSpent | printf "\n%14s" }} {{ Percent $f.TimeSpent $total | printf "%3.0f"}}% [{{ $f.Status }}] {{$f.ShortenSourceFile 100}}
    43  		{{- end }}
    44  	{{- end }}
    45  	{{- if len .Note.Files }}
    46  	{{- FormatDuration $total | printf "\n%14s" }}          {{ printf $boldFormat $note.Project }} [{{$note.LineAdd}} {{$note.LineDel}} = {{$note.LineDiff}}] [{{$note.ChangeRate}}/hr]{{ printf "\n\n" }}
    47  	{{- else }}
    48  		{{- printf "\n" }}
    49  	{{- end }}
    50  {{- end -}}`
    51  
    52  	statusTpl string = `
    53  {{- $boldFormat := .BoldFormat }}
    54  {{- if .Note.Files }}{{ printf "\n"}}{{end}}
    55  {{- $total := .Note.Total }}
    56  {{- range $i, $f := .Note.Files }}
    57  	{{- if $f.IsApp }}
    58  		{{- FormatDuration $f.TimeSpent | printf "%14s" }} {{ Percent $f.TimeSpent $total | printf "%3.0f"}}% [{{ $f.Status }}] [{{$f.GetEventType}}] {{$f.GetAppName }}
    59  	{{- else }}
    60  		{{- FormatDuration $f.TimeSpent | printf "%14s" }} {{ Percent $f.TimeSpent $total | printf "%3.0f"}}% [{{ $f.Status }}] {{$f.ShortenSourceFile 100}}
    61  	{{- end }}
    62  {{ end }}
    63  {{- if len .Note.Files }}
    64  	{{- FormatDuration .Note.Total | printf "%14s" }}          {{ printf $boldFormat .ProjectName }} {{ if .Tags }}[{{ .Tags }}]{{ end }}
    65  {{ end }}`
    66  
    67  	// TODO: determine left padding based on size of total duration
    68  	timelineTpl string = `
    69  {{- $boldFormat := .BoldFormat }}
    70  {{- $greenFormat := .GreenFormat }}
    71  {{- $maxSecondsInHour := .Timeline.HourMaxSeconds }}
    72  {{printf $boldFormat "             00.01.02.03.04.05.06.07.08.09.10.11.12.01.02.03.04.05.06.07.08.09.10.11." }}
    73  {{printf $boldFormat "             ------------------------------------------------------------------------"}}
    74  {{ range $_, $entry := .Timeline }}
    75  {{- printf $boldFormat $entry.Day }} | {{ range $_, $h := .Hours }}{{ Blocks $h $maxSecondsInHour | printf $greenFormat }}{{ end }} | {{ LeftPad2Len $entry.Duration " " 13 | printf $boldFormat }}
    76  {{printf $boldFormat "             ------------------------------------------------------------------------"}}
    77  {{ end }}
    78  {{- if len .Timeline }}
    79  	{{- LeftPad2Len .Timeline.Duration " " 101 | printf $boldFormat }}
    80  {{ end }}`
    81  
    82  	timelineCommitTpl string = `
    83  {{- $boldFormat := .BoldFormat }}
    84  {{- $greenFormat := .GreenFormat }}
    85  {{- $maxCommitsInHour := .Timeline.HourMaxCommits}}
    86  {{printf $boldFormat "             00.01.02.03.04.05.06.07.08.09.10.11.12.01.02.03.04.05.06.07.08.09.10.11." }}
    87  {{printf $boldFormat "             ------------------------------------------------------------------------"}}
    88  {{ range $_, $entry := .Timeline }}
    89  {{- printf $boldFormat $entry.Day }} | {{ range $_, $c := .Commits }}{{ Blocks $c $maxCommitsInHour | printf $greenFormat }}{{ end }} | {{ printf "%4d" $entry.Total | printf $boldFormat }}
    90  {{printf $boldFormat "             ------------------------------------------------------------------------"}}
    91  {{ end }}
    92  {{- if len .Timeline }}
    93  	{{- printf "%92d" .Timeline.Total | printf $boldFormat }}
    94  {{ end }}`
    95  
    96  	// TODO: determine left padding based on total hours
    97  	filesTpl string = `
    98  {{- $total := .Files.Total }}
    99  {{ range $i, $f := .Files }}
   100  	{{- if $f.IsApp }}
   101  		{{- $f.Duration | printf "%14s" }} {{ Percent $f.Seconds $total | printf "%3.0f"}}%  [app] {{ $f.GetAppName }}
   102  	{{- else }}
   103  		{{- $f.Duration | printf "%14s" }} {{ Percent $f.Seconds $total | printf "%3.0f"}}%  {{ $f.Filename }}
   104  	{{- end }}
   105  {{ end }}
   106  {{- if len .Files }}
   107  	{{- .Files.Duration | printf "%14s" }}
   108  {{ end }}`
   109  )