From 54e488910661ab1a8bffeec47e3ff84eb5daf720 Mon Sep 17 00:00:00 2001 From: Brett Terpstra Date: Wed, 29 Jun 2022 05:52:47 -0500 Subject: [PATCH] Remove meanwhile from tag totals - FIXED: code duplication in timers.rb - IMPROVED: Remove @meanwhile from tag totals - IMPROVED: Less spacing between items in default HTML export CSS --- Gemfile.lock | 2 +- lib/doing/wwid/timers.rb | 157 +-------------------------------------- lib/templates/doing.css | 4 +- 3 files changed, 4 insertions(+), 159 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4ecf0243..b8878246 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/lib/doing/wwid/timers.rb b/lib/doing/wwid/timers.rb index 154e65e7..517891f0 100644 --- a/lib/doing/wwid/timers.rb +++ b/lib/doing/wwid/timers.rb @@ -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 = < - Tag Totals - - - - - - - project - time - - - -EOHEAD - sorted_tags_data.reverse.each do |k, v| - if v.positive? - output += "#{k}#{v.time_string(format: :clock)}\n" - end - end - tail = < - - - - - - Total - #{total.time_string(format: :clock)} - - - -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 diff --git a/lib/templates/doing.css b/lib/templates/doing.css index 7b202e4c..5283937c 100644 --- a/lib/templates/doing.css +++ b/lib/templates/doing.css @@ -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; @@ -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; }