Skip to content

Commit

Permalink
Remove meanwhile from tag totals
Browse files Browse the repository at this point in the history
- FIXED: code duplication in timers.rb
- IMPROVED: Remove @Meanwhile from tag totals
- IMPROVED: Less spacing between items in default HTML export CSS
  • Loading branch information
ttscoff committed Jun 29, 2022
1 parent 974a91c commit 54e4889
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
doing (2.1.60)
doing (2.1.61)
chronic (~> 0.10, >= 0.10.2)
deep_merge (~> 1.2, >= 1.2.1)
gli (~> 2.20, >= 2.20.1)
Expand Down
157 changes: 1 addition & 156 deletions lib/doing/wwid/timers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,162 +14,7 @@ class WWID
def tag_times(format: :text, sort_by: :time, sort_order: :asc)
return '' if @timers.empty?

max = @timers.keys.sort_by(&:length).reverse[0].length + 1

total = @timers.delete('All')

tags_data = @timers.delete_if { |_k, v| v.zero? }
sorted_tags_data = if sort_by.normalize_tag_sort == :name
tags_data.sort_by { |k, _v| k }
else
tags_data.sort_by { |_k, v| v }
end

sorted_tags_data.reverse! if sort_order.normalize_order == :asc
case format
when :html

output = <<EOHEAD
<table>
<caption id="tagtotals">Tag Totals</caption>
<colgroup>
<col style="text-align:left;"/>
<col style="text-align:left;"/>
</colgroup>
<thead>
<tr>
<th style="text-align:left;">project</th>
<th style="text-align:left;">time</th>
</tr>
</thead>
<tbody>
EOHEAD
sorted_tags_data.reverse.each do |k, v|
if v.positive?
output += "<tr><td style='text-align:left;'>#{k}</td><td style='text-align:left;'>#{v.time_string(format: :clock)}</td></tr>\n"
end
end
tail = <<EOTAIL
<tr>
<td style="text-align:left;" colspan="2"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td style="text-align:left;"><strong>Total</strong></td>
<td style="text-align:left;">#{total.time_string(format: :clock)}</td>
</tr>
</tfoot>
</table>
EOTAIL
output + tail
when :markdown
pad = sorted_tags_data.map { |k, _| k }.group_by(&:size).max.last[0].length
pad = 7 if pad < 7
output = <<~EOHEADER
| #{' ' * (pad - 7)}project | time |
| #{'-' * (pad - 1)}: | :------- |
EOHEADER
sorted_tags_data.reverse.each do |k, v|
if v.positive?
output += "| #{' ' * (pad - k.length)}#{k} | #{v.time_string(format: :clock)} |\n"
end
end
tail = '[Tag Totals]'
output + tail
when :json
output = []
sorted_tags_data.reverse.each do |k, v|
output << {
'tag' => k,
'seconds' => v,
'formatted' => v.time_string(format: :clock)
}
end
output
when :human
output = []
sorted_tags_data.reverse.each do |k, v|
spacer = ''
(max - k.length).times do
spacer += ' '
end
output.push("┃ #{spacer}#{k}:#{v.time_string(format: :hm)} ┃")
end

header = '┏━━ Tag Totals '
(max - 2).times { header += '━' }
header += '┓'
footer = '┗'
(max + 12).times { footer += '━' }
footer += '┛'
divider = '┣'
(max + 12).times { divider += '━' }
divider += '┫'
output = output.empty? ? '' : "\n#{header}\n#{output.join("\n")}"
output += "\n#{divider}"
spacer = ''
(max - 6).times do
spacer += ' '
end
total_time = total.time_string(format: :hm)
total = "┃ #{spacer}total: "
total += total_time
total += ' ┃'
output += "\n#{total}"
output += "\n#{footer}"
output
else
output = []
sorted_tags_data.reverse.each do |k, v|
spacer = ''
(max - k.length).times do
spacer += ' '
end
output.push("#{k}:#{spacer}#{v.time_string(format: :clock)}")
end

output = output.empty? ? '' : "\n--- Tag Totals ---\n#{output.join("\n")}"
output += "\n\nTotal tracked: #{total.time_string(format: :clock)}\n"
output
end
end

##
## Gets the interval between entry's start
## date and @done date
##
## @param item [Item] The entry
## @param formatted [Boolean] Return human readable
## time (default seconds)
## @param record [Boolean] Add the interval to the
## total for each tag
##
## @return Interval in seconds, or [d, h, m] array if
## formatted is true. False if no end date or
## interval is 0
##
def get_interval(item, formatted: true, record: true)
if item.interval
seconds = item.interval
record_tag_times(item, seconds) if record
return seconds.positive? ? seconds : false unless formatted

return seconds.positive? ? seconds.time_string(format: :clock) : false
end

false
end##
## Get total elapsed time for all tags in
## selection
##
## @param format [String] return format (html,
## json, or text)
## @param sort_by [Symbol] Sort by :name or :time
## @param sort_order [Symbol] The sort order (:asc or :desc)
##
def tag_times(format: :text, sort_by: :time, sort_order: :asc)
return '' if @timers.empty?
@timers.delete('meanwhile')

max = @timers.keys.sort_by(&:length).reverse[0].length + 1

Expand Down
4 changes: 2 additions & 2 deletions lib/templates/doing.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ article > ul > li:hover {
.date {
color: #7d9ca2;
font-size: 17px;
padding: 15px 1ch 0 0;
padding: 3px 1ch 0 0;
text-align: right;
white-space: nowrap;
transition: color .2s ease-in-out;
Expand All @@ -59,7 +59,7 @@ article > ul > li:hover {
.entry {
border-left: solid 1px #ccc;
line-height: 1.2;
padding: 10px 10px 10px 3ch;
padding: 2px 10px 2px 3ch;
text-indent: -2ch;
}

Expand Down

0 comments on commit 54e4889

Please sign in to comment.