lib/dsu/subcommands/list.rb in dsu-2.4.2 vs lib/dsu/subcommands/list.rb in dsu-2.4.3
- old
+ new
@@ -1,12 +1,14 @@
# frozen_string_literal: true
+require_relative '../presenters/entry_group/list/date_presenter'
+require_relative '../presenters/entry_group/list/dates_presenter'
require_relative '../services/entry_group/counter_service'
require_relative '../support/command_options/dsu_times'
require_relative '../support/command_options/time_mnemonic'
require_relative '../support/time_formatable'
-require_relative '../views/entry_group/shared/no_entries_to_display'
+require_relative '../views/entry_group/list'
require_relative '../views/shared/error'
require_relative 'base_subcommand'
module Dsu
module Subcommands
@@ -23,27 +25,30 @@
desc I18n.t('subcommands.list.today.desc'), I18n.t('subcommands.list.today.usage')
long_desc I18n.t('subcommands.list.today.long_desc')
def today
time = Time.now
times = sorted_dsu_times_for(times: [time.yesterday, time])
- view_list_for(times: times, options: options)
+ presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
+ Views::EntryGroup::List.new(presenter: presenter).render
end
desc I18n.t('subcommands.list.tomorrow.desc'), I18n.t('subcommands.list.tomorrow.usage')
long_desc I18n.t('subcommands.list.tomorrow.long_desc')
def tomorrow
time = Time.now
times = sorted_dsu_times_for(times: [time, time.tomorrow])
- view_list_for(times: times, options: options)
+ presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
+ Views::EntryGroup::List.new(presenter: presenter).render
end
desc I18n.t('subcommands.list.yesterday.desc'), I18n.t('subcommands.list.yesterday.usage')
long_desc I18n.t('subcommands.list.yesterday.long_desc')
def yesterday
time = Time.now
times = sorted_dsu_times_for(times: [time.yesterday, time.yesterday.yesterday])
- view_list_for(times: times, options: options)
+ presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
+ Views::EntryGroup::List.new(presenter: presenter).render
end
desc I18n.t('subcommands.list.date.desc'), I18n.t('subcommands.list.date.usage')
long_desc I18n.t('subcommands.list.date.long_desc',
date_option_description: date_option_description,
@@ -53,11 +58,12 @@
time_from_mnemonic(command_option: date_or_mnemonic)
else
Time.parse(date_or_mnemonic)
end
times = sorted_dsu_times_for(times: [time, time.yesterday])
- view_list_for(times: times, options: options)
+ presenter = Presenters::EntryGroup::List::DatePresenter.new(times: times, options: options)
+ Views::EntryGroup::List.new(presenter: presenter).render
rescue ArgumentError => e
Views::Shared::Error.new(messages: e.message).render
end
desc I18n.t('subcommands.list.dates.desc'), I18n.t('subcommands.list.dates.usage')
@@ -77,14 +83,11 @@
end
# NOTE: special sort here, unlike the other commands where rules for
# displaying DSU entries are applied; this is more of a list command.
times = times_sort(times: times, entries_display_order: options[:entries_display_order])
- view_entry_groups(times: times, options: options) do
- if Services::EntryGroup::CounterService.new(times: times).call.zero?
- Views::EntryGroup::Shared::NoEntriesToDisplay.new(times: times, options: options).render
- end
- end
+ presenter = Presenters::EntryGroup::List::DatesPresenter.new(times: times, options: options)
+ Views::EntryGroup::List.new(presenter: presenter).render
rescue ArgumentError => e
Views::Shared::Error.new(messages: e.message).render
end
end
end