Method: Doing::WWID#list_section

Defined in:
lib/doing/wwid/display.rb

#list_section(opt, items: Items.new) ⇒ Object

Display contents of a section based on options

Parameters:

  • opt (Hash)

    Additional Options



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/doing/wwid/display.rb', line 10

def list_section(opt, items: Items.new)
  logger.benchmark(:list_section, :start)
  opt[:config_template] ||= 'default'

  tpl_cfg = Doing.setting(['templates', opt[:config_template]])

  cfg = if opt[:view_template]
          Doing.setting(['views', opt[:view_template]]).deep_merge(tpl_cfg, { extend_existing_arrays: true, sort_merged_arrays: true })
        else
          tpl_cfg
        end

  cfg.deep_merge({
                   'wrap_width' => Doing.setting('wrap_width') || 0,
                   'date_format' => Doing.setting('default_date_format'),
                   'order' => Doing.setting('order') || :asc,
                   'tags_color' => Doing.setting('tags_color'),
                   'duration' => Doing.setting('duration'),
                   'interval_format' => Doing.setting('interval_format')
                 }, { extend_existing_arrays: true, sort_merged_arrays: true })

  opt[:duration] ||= cfg['duration'] || false
  opt[:interval_format] ||= cfg['interval_format'] || 'text'
  opt[:count] ||= 0
  opt[:age] ||= :newest
  opt[:age] = opt[:age].normalize_age
  opt[:format] ||= cfg['date_format']
  opt[:order] ||= cfg['order'] || :asc
  opt[:tag_order] ||= :asc
  opt[:tags_color] = cfg['tags_color'] || false if opt[:tags_color].nil?
  opt[:template] ||= cfg['template']
  opt[:sort_tags] ||= opt[:tag_sort]

  # opt[:highlight] ||= true
  title = ''
  is_single = true
  if opt[:section].nil?
    opt[:section] = choose_section
    title = opt[:section]
  elsif opt[:section].instance_of?(String)
    title = if opt[:section] =~ /^all$/i
              if opt[:page_title]
                opt[:page_title]
              elsif opt[:tag_filter] && opt[:tag_filter]['bool'].normalize_bool != :not
                opt[:tag_filter]['tags'].map { |tag| "@#{tag}" }.join(' + ')
              else
                'doing'
              end
            else
              guess_section(opt[:section])
            end
  end

  items = filter_items(items, opt: opt)

  items.reverse! unless opt[:order].normalize_order == :desc

  if opt[:delete]
    delete_items(items, force: opt[:force])

    write(@doing_file)
    return
  elsif opt[:editor]
    edit_items(items)

    write(@doing_file)
    return
  elsif opt[:interactive]
    opt[:menu] = !opt[:force]
    opt[:query] = '' # opt[:search]
    opt[:multiple] = true
    selected = Prompt.choose_from_items(items.reverse, include_section: opt[:section] =~ /^all$/i, **opt)

    raise NoResults, 'no items selected' if selected.nil? || selected.empty?

    act_on(selected, opt)
    return
  end

  opt[:output] ||= 'template'
  opt[:wrap_width] ||= Doing.setting('templates.default.wrap_width', 0)

  logger.benchmark(:list_section, :finish)
  output(items, title, is_single, opt)
end