Class: DailyView

Inherits:
ChartBase show all
Defined in:
lib/jirametrics/daily_view.rb

Instance Attribute Summary collapse

Attributes inherited from ChartBase

#aggregated_project, #all_boards, #board_id, #canvas_height, #canvas_width, #data_quality, #date_range, #file_system, #holiday_dates, #issues, #settings, #time_range, #timezone_offset, #users

Instance Method Summary collapse

Methods inherited from ChartBase

#aggregated_project?, #canvas, #canvas_responsive?, #chart_format, #collapsible_issues_panel, #color_block, #color_for, #completed_issues_in_range, #current_board, #daily_chart_dataset, #describe_non_working_days, #description_text, #format_integer, #format_status, #header_text, #holidays, #html_directory, #icon_span, #label_days, #label_issues, #link_to_issue, #next_id, #random_color, #render, #render_top_text, #status_category_color, #working_days_annotation, #wrap_and_render

Constructor Details

#initialize(_block) ⇒ DailyView

Returns a new instance of DailyView.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jirametrics/daily_view.rb', line 6

def initialize _block
  super()

  header_text 'Daily View'
  description_text <<-HTML
    <div class="p">
      This view shows all the items you'll want to discuss during your daily coordination meeting
      (aka daily scrum, standup), in the order that you should be discussing them. The most important
      items are at the top, and the least at the bottom.
    </div>
    <div class="p">
      By default, we sort by priority first and then by age within each of those priorities.
      Hover over the issue to make it stand out more.
    </div>
  HTML
end

Instance Attribute Details

#possible_statusesObject

Returns the value of attribute possible_statuses.



4
5
6
# File 'lib/jirametrics/daily_view.rb', line 4

def possible_statuses
  @possible_statuses
end

Instance Method Details

#assemble_issue_lines(issue) ⇒ Object



230
231
232
233
234
235
236
237
# File 'lib/jirametrics/daily_view.rb', line 230

def assemble_issue_lines issue
  lines = []
  lines += make_stats_lines(issue)
  lines += make_blocked_stalled_lines(issue)
  lines += make_child_lines(issue)
  lines += make_history_lines(issue)
  lines
end

#expand_account_id(account_id) ⇒ Object



171
172
173
174
175
176
# File 'lib/jirametrics/daily_view.rb', line 171

def  
  user = @users.find { |u| u. ==  }
  text = 
  text = "@#{user.display_name}" if user
  "<span class='account_id'>#{text}</span>"
end

#issue_sorterObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jirametrics/daily_view.rb', line 48

def issue_sorter
  priority_names = settings['priority_order']
  lambda do |a, b|
    a_issue, a_priority, a_age = *a
    b_issue, b_priority, b_age = *b

    a_priority_index = priority_names.index(a_priority)
    b_priority_index = priority_names.index(b_priority)

    if a_priority_index.nil? && b_priority_index.nil?
      result = a_priority <=> b_priority
    elsif a_priority_index.nil?
      result = 1
    elsif b_priority_index.nil?
      result = -1
    else
      result = b_priority_index <=> a_priority_index
    end

    result = b_age <=> a_age if result.zero?
    result = a_issue <=> b_issue if result.zero?
    result
  end
end

#jira_rich_text_to_html(text) ⇒ Object



165
166
167
168
169
# File 'lib/jirametrics/daily_view.rb', line 165

def jira_rich_text_to_html text
  text
    .gsub(/{color:(#\w{6})}([^{]+){color}/, '<span style="color: \1">\2</span>')
    .gsub(/\[~accountid:([^\]]+)\]/) {  $1 }
end

#make_blocked_stalled_lines(issue) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jirametrics/daily_view.rb', line 73

def make_blocked_stalled_lines issue
  today = date_range.end
  started_date = issue.board.cycletime.started_stopped_times(issue).first&.to_date
  return [] unless started_date

  blocked_stalled = issue.blocked_stalled_by_date(
    date_range: today..today, chart_end_time: time_range.end, settings: settings
  )[today]
  return [] unless blocked_stalled

  lines = []
  if blocked_stalled.blocked?
    marker = color_block '--blocked-color'
    lines << ["#{marker} Blocked by flag"] if blocked_stalled.flag
    lines << ["#{marker} Blocked by status: #{blocked_stalled.status}"] if blocked_stalled.blocked_by_status?
    blocked_stalled.blocking_issue_keys&.each do |key|
      lines << ["#{marker} Blocked by issue: #{key}"]
      blocking_issue = issues.find { |i| i.key == key }
      lines << blocking_issue if blocking_issue
    end
  elsif blocked_stalled.stalled_by_status?
    lines << ["#{color_block '--stalled-color'} Stalled by status: #{blocked_stalled.status}"]
  else
    lines << ["#{color_block '--stalled-color'} Stalled by inactivity: #{blocked_stalled.stalled_days} days"]
  end
  lines
end

#make_child_lines(issue) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/jirametrics/daily_view.rb', line 153

def make_child_lines issue
  lines = []
  subtasks = issue.subtasks.reject { |i| i.done? }

  unless subtasks.empty?
    icon_urls = subtasks.collect(&:type_icon_url).uniq.collect { |url| "<img src='#{url}' class='icon' />" }
    lines << (icon_urls << 'Incomplete child issues')
    lines += subtasks
  end
  lines
end

#make_history_lines(issue) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/jirametrics/daily_view.rb', line 178

def make_history_lines issue
  history = issue.changes.reverse
  lines = []

  return lines if history.empty?

  id = next_id
  lines << [
    "<a href=\"javascript:toggle_visibility('open#{id}', 'close#{id}', 'table#{id}');\">" \
    "<span id='open#{id}'>▶ Issue History</span>" \
    "<span id='close#{id}' style='display: none'>▼ Issue History</span></a>"
  ]
  table = +''
  table << "<table id='table#{id}' style='display: none'>"
  history.each do |c|
    time = c.time.strftime '%b %d, %I:%M%P'

    table << '<tr>'
    table << "<td><span class='time' title='Timestamp: #{c.time}'>#{time}</span></td>"
    table << "<td><img src='#{c.author_icon_url}' class='icon' title='#{c.author}' /></td>"
    text = case # rubocop:disable Style/EmptyCaseCondition
    when c.comment?
      jira_rich_text_to_html(c.value)
    when c.status?
      board = issue.board
      to = format_status(board.possible_statuses.find_by_id(c.value_id), board: board)
      if c.old_value
        from = format_status(board.possible_statuses.find_by_id(c.old_value_id), board: board) if c.old_value
        "Status changed from #{from} to #{to}"
      else
        "Status set to #{to}"
      end
    when c.priority?, c.assignee?, c.due_date?, c.field == 'issuetype'
      if c.old_value && c.value
        "Changed from #{c.old_value} to #{c.value}"
      elsif c.value
        "Set to #{c.value}"
      else
        "Cleared from #{c.old_value}"
      end
    when c.flagged?
      c.value == '' ? 'Off' : 'On'
    else c.value
    end
    table << "<td><span class='field'>#{c.field_as_human_readable}</span> #{text}</td>"
    table << '</tr>'
  end
  table << '</table>'
  lines << [table]
  lines
end

#make_issue_label(issue) ⇒ Object



101
102
103
104
# File 'lib/jirametrics/daily_view.rb', line 101

def make_issue_label issue
  "<img src='#{issue.type_icon_url}' title='#{issue.type}' class='icon' /> " \
    "<b><a href='#{issue.url}'>#{issue.key}</a></b> &nbsp;<i>#{issue.summary}</i>"
end

#make_stats_lines(issue) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jirametrics/daily_view.rb', line 106

def make_stats_lines issue
  lines = []

  title_line = +''
  title_line << color_block('--expedited-color', title: 'Expedited') if issue.expedited?
  title_line << make_issue_label(issue)
  lines << [title_line]

  parent_key = issue.parent_key
  if parent_key
    parent = issues.find_by_key key: parent_key, include_hidden: true
    text = parent ? make_issue_label(parent) : parent_key
    lines << ["Parent: #{text}"]
  end

  chunks = []

  chunks << "<img src='#{issue.priority_url}' class='icon' /> <b>#{issue.priority_name}</b>"

  age = issue.board.cycletime.age(issue, today: date_range.end)
  chunks << "Age: <b>#{label_days age}</b>" if age

  chunks << "Status: <b>#{issue.status.name}</b>"

  column = issue.board.visible_columns.find { |c| c.status_ids.include?(issue.status.id) }
  chunks << "Column: <b>#{column&.name || '(not visible on board)'}</b>"

  if issue.assigned_to
    chunks << "Assignee: <img src='#{issue.assigned_to_icon_url}' class='icon' /> <b>#{issue.assigned_to}</b>"
  end

  chunks << "Due: <b>#{issue.due_date}</b>" if issue.due_date

  unless issue.labels.empty?
    labels = issue.labels.collect { |l| "<span class='label'>#{l}</span>" }.join(' ')
    chunks << "Labels: #{labels}"
  end

  unless issue.component_names.empty?
    labels = issue.component_names.collect { |l| "<span class='label'>#{l}</span>" }.join(' ')
    chunks << "Components: #{labels}"
  end

  lines << chunks
  lines
end

#render_issue(issue, css_class: 'daily_issue') ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/jirametrics/daily_view.rb', line 239

def render_issue issue, css_class: 'daily_issue'
  result = +''
  result << "<div class='#{css_class}'>"
  assemble_issue_lines(issue).each do |row|
    if row.is_a? Issue
      result << render_issue(row, css_class: 'child_issue')
    else
      result << '<div class="heading">'
      row.each do |chunk|
        result << "<div>#{chunk}</div>"
      end
      result << '</div>'
    end
  end
  result << '</div>'
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jirametrics/daily_view.rb', line 23

def run
  aging_issues = select_aging_issues

  return "<h1>#{@header_text}</h1>There are no items currently in progress" if aging_issues.empty?

  result = +''
  result << render_top_text(binding)
  aging_issues.each do |issue|
    result << render_issue(issue)
  end
  result
end

#select_aging_issuesObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jirametrics/daily_view.rb', line 36

def select_aging_issues
  aging_issues = issues.select do |issue|
    started_at, stopped_at = issue.board.cycletime.started_stopped_times(issue)
    started_at && !stopped_at
  end

  today = date_range.end
  aging_issues.collect do |issue|
    [issue, issue.priority_name, issue.board.cycletime.age(issue, today: today)]
  end.sort(&issue_sorter).collect(&:first)
end