doto 0.0.1.pre.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.env.test +1 -0
  3. data/.reek.yml +20 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +206 -0
  6. data/.ruby-version +1 -0
  7. data/CHANGELOG.md +7 -0
  8. data/CODE_OF_CONDUCT.md +84 -0
  9. data/Gemfile +30 -0
  10. data/Gemfile.lock +179 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +38 -0
  13. data/Rakefile +16 -0
  14. data/bin/console +36 -0
  15. data/bin/doto +3 -0
  16. data/bin/setup +18 -0
  17. data/exe/doto +33 -0
  18. data/lib/core/ruby/color_theme_colors.rb +16 -0
  19. data/lib/core/ruby/color_theme_mode.rb +42 -0
  20. data/lib/core/ruby/wrap_and_join.rb +31 -0
  21. data/lib/doto/base_cli.rb +56 -0
  22. data/lib/doto/cli.rb +131 -0
  23. data/lib/doto/command_services/add_entry_service.rb +50 -0
  24. data/lib/doto/crud/json_file.rb +161 -0
  25. data/lib/doto/env.rb +44 -0
  26. data/lib/doto/migration/base_service.rb +118 -0
  27. data/lib/doto/migration/migrator.rb +24 -0
  28. data/lib/doto/migration/raw_helpers/color_theme_hash.rb +13 -0
  29. data/lib/doto/migration/raw_helpers/configuration_hash.rb +15 -0
  30. data/lib/doto/migration/raw_helpers/entry_group_hash.rb +13 -0
  31. data/lib/doto/migration/raw_json_file.rb +15 -0
  32. data/lib/doto/migration/raw_json_files.rb +56 -0
  33. data/lib/doto/migration/v20230613121411/service.rb +94 -0
  34. data/lib/doto/migration/v20240210161248/service.rb +148 -0
  35. data/lib/doto/migration/version.rb +7 -0
  36. data/lib/doto/models/color_theme.rb +224 -0
  37. data/lib/doto/models/configuration.rb +185 -0
  38. data/lib/doto/models/entry.rb +63 -0
  39. data/lib/doto/models/entry_group.rb +223 -0
  40. data/lib/doto/models/migration_version.rb +49 -0
  41. data/lib/doto/models/project.rb +295 -0
  42. data/lib/doto/presenters/base_presenter.rb +32 -0
  43. data/lib/doto/presenters/base_presenter_ex.rb +15 -0
  44. data/lib/doto/presenters/color_theme_presenter.rb +52 -0
  45. data/lib/doto/presenters/color_theme_show_presenter.rb +55 -0
  46. data/lib/doto/presenters/configuration_presenter.rb +50 -0
  47. data/lib/doto/presenters/entry_group/list/date_presenter.rb +77 -0
  48. data/lib/doto/presenters/entry_group/list/dates_presenter.rb +60 -0
  49. data/lib/doto/presenters/entry_group/list/messages.rb +15 -0
  50. data/lib/doto/presenters/entry_group/list/nothing_to_list.rb +15 -0
  51. data/lib/doto/presenters/entry_group_presenter.rb +35 -0
  52. data/lib/doto/presenters/entry_presenter.rb +25 -0
  53. data/lib/doto/presenters/export/all_presenter.rb +44 -0
  54. data/lib/doto/presenters/export/dates_presenter.rb +55 -0
  55. data/lib/doto/presenters/import/all_presenter.rb +57 -0
  56. data/lib/doto/presenters/import/dates_presenter.rb +70 -0
  57. data/lib/doto/presenters/import/import_entry.rb +22 -0
  58. data/lib/doto/presenters/import/import_file.rb +33 -0
  59. data/lib/doto/presenters/project/create_presenter.rb +44 -0
  60. data/lib/doto/presenters/project/defaultable.rb +15 -0
  61. data/lib/doto/presenters/project/delete_by_number_presenter.rb +54 -0
  62. data/lib/doto/presenters/project/delete_presenter.rb +53 -0
  63. data/lib/doto/presenters/project/list_presenter.rb +24 -0
  64. data/lib/doto/presenters/project/rename_by_number_presenter.rb +63 -0
  65. data/lib/doto/presenters/project/rename_presenter.rb +57 -0
  66. data/lib/doto/presenters/project/use_by_number_presenter.rb +57 -0
  67. data/lib/doto/presenters/project/use_presenter.rb +56 -0
  68. data/lib/doto/services/color_theme/hydrator_service.rb +42 -0
  69. data/lib/doto/services/configuration/hydrator_service.rb +42 -0
  70. data/lib/doto/services/entry/hydrator_service.rb +33 -0
  71. data/lib/doto/services/entry_group/browse_service.rb +100 -0
  72. data/lib/doto/services/entry_group/counter_service.rb +32 -0
  73. data/lib/doto/services/entry_group/deleter_service.rb +35 -0
  74. data/lib/doto/services/entry_group/editor_service.rb +103 -0
  75. data/lib/doto/services/entry_group/exporter_service.rb +98 -0
  76. data/lib/doto/services/entry_group/hydrator_service.rb +37 -0
  77. data/lib/doto/services/entry_group/importer_service.rb +117 -0
  78. data/lib/doto/services/migration_version/hydrator_service.rb +36 -0
  79. data/lib/doto/services/project/hydrator_service.rb +40 -0
  80. data/lib/doto/services/project/rename_service.rb +70 -0
  81. data/lib/doto/services/stderr_redirector_service.rb +27 -0
  82. data/lib/doto/services/stdout_redirector_service.rb +27 -0
  83. data/lib/doto/services/temp_file/reader_service.rb +33 -0
  84. data/lib/doto/services/temp_file/writer_service.rb +35 -0
  85. data/lib/doto/subcommands/base_subcommand.rb +12 -0
  86. data/lib/doto/subcommands/browse.rb +49 -0
  87. data/lib/doto/subcommands/config.rb +81 -0
  88. data/lib/doto/subcommands/delete.rb +108 -0
  89. data/lib/doto/subcommands/edit.rb +48 -0
  90. data/lib/doto/subcommands/export.rb +62 -0
  91. data/lib/doto/subcommands/import.rb +72 -0
  92. data/lib/doto/subcommands/list.rb +95 -0
  93. data/lib/doto/subcommands/project.rb +146 -0
  94. data/lib/doto/subcommands/theme.rb +131 -0
  95. data/lib/doto/support/ask.rb +44 -0
  96. data/lib/doto/support/color_themable.rb +36 -0
  97. data/lib/doto/support/command_help_colorizeable.rb +34 -0
  98. data/lib/doto/support/command_hookable.rb +71 -0
  99. data/lib/doto/support/command_options/doto_times.rb +48 -0
  100. data/lib/doto/support/command_options/time.rb +84 -0
  101. data/lib/doto/support/command_options/time_mnemonic.rb +108 -0
  102. data/lib/doto/support/command_options/time_mnemonics.rb +16 -0
  103. data/lib/doto/support/descriptable.rb +29 -0
  104. data/lib/doto/support/entry_group_browsable.rb +104 -0
  105. data/lib/doto/support/field_errors.rb +11 -0
  106. data/lib/doto/support/fileable.rb +136 -0
  107. data/lib/doto/support/presentable.rb +11 -0
  108. data/lib/doto/support/project_file_system.rb +118 -0
  109. data/lib/doto/support/short_string.rb +24 -0
  110. data/lib/doto/support/time_comparable.rb +21 -0
  111. data/lib/doto/support/time_formatable.rb +65 -0
  112. data/lib/doto/support/times_sortable.rb +71 -0
  113. data/lib/doto/support/transform_project_name.rb +24 -0
  114. data/lib/doto/support/utils.rb +11 -0
  115. data/lib/doto/validators/color_theme_validator.rb +74 -0
  116. data/lib/doto/validators/description_validator.rb +51 -0
  117. data/lib/doto/validators/entries_validator.rb +77 -0
  118. data/lib/doto/validators/project_name_validator.rb +58 -0
  119. data/lib/doto/validators/time_validator.rb +25 -0
  120. data/lib/doto/validators/version_validator.rb +29 -0
  121. data/lib/doto/version.rb +6 -0
  122. data/lib/doto/views/base_list_view.rb +41 -0
  123. data/lib/doto/views/color_theme/index.rb +62 -0
  124. data/lib/doto/views/color_theme/show.rb +107 -0
  125. data/lib/doto/views/configuration/show.rb +41 -0
  126. data/lib/doto/views/entry_group/edit.rb +121 -0
  127. data/lib/doto/views/entry_group/list.rb +23 -0
  128. data/lib/doto/views/entry_group/shared/no_entries_to_display.rb +53 -0
  129. data/lib/doto/views/entry_group/shared/no_entries_to_display_for_month_of.rb +32 -0
  130. data/lib/doto/views/entry_group/shared/no_entries_to_display_for_week_of.rb +33 -0
  131. data/lib/doto/views/entry_group/shared/no_entries_to_display_for_year_of.rb +33 -0
  132. data/lib/doto/views/entry_group/show.rb +63 -0
  133. data/lib/doto/views/export.rb +82 -0
  134. data/lib/doto/views/import.rb +105 -0
  135. data/lib/doto/views/import_dates.rb +17 -0
  136. data/lib/doto/views/project/create.rb +87 -0
  137. data/lib/doto/views/project/delete.rb +96 -0
  138. data/lib/doto/views/project/delete_by_number.rb +19 -0
  139. data/lib/doto/views/project/list.rb +115 -0
  140. data/lib/doto/views/project/rename.rb +98 -0
  141. data/lib/doto/views/project/rename_by_number.rb +21 -0
  142. data/lib/doto/views/project/use.rb +97 -0
  143. data/lib/doto/views/project/use_by_number.rb +19 -0
  144. data/lib/doto/views/shared/error.rb +17 -0
  145. data/lib/doto/views/shared/info.rb +17 -0
  146. data/lib/doto/views/shared/message.rb +85 -0
  147. data/lib/doto/views/shared/model_errors.rb +32 -0
  148. data/lib/doto/views/shared/success.rb +17 -0
  149. data/lib/doto/views/shared/warning.rb +17 -0
  150. data/lib/doto.rb +33 -0
  151. data/lib/locales/en/active_record.yml +17 -0
  152. data/lib/locales/en/commands.yml +165 -0
  153. data/lib/locales/en/miscellaneous.yml +29 -0
  154. data/lib/locales/en/presenters.yml +19 -0
  155. data/lib/locales/en/services.yml +14 -0
  156. data/lib/locales/en/subcommands.yml +786 -0
  157. data/lib/seed_data/0/.todo +5 -0
  158. data/lib/seed_data/20230613121411/.doto +8 -0
  159. data/lib/seed_data/20230613121411/doto/migration_version.json +3 -0
  160. data/lib/seed_data/20230613121411/doto/themes/cherry.json +79 -0
  161. data/lib/seed_data/20230613121411/doto/themes/christmas.json +79 -0
  162. data/lib/seed_data/20230613121411/doto/themes/default.json +79 -0
  163. data/lib/seed_data/20230613121411/doto/themes/lemon.json +79 -0
  164. data/lib/seed_data/20230613121411/doto/themes/light.json +79 -0
  165. data/lib/seed_data/20230613121411/doto/themes/matrix.json +79 -0
  166. data/lib/seed_data/20230613121411/doto/themes/whiteout.json +79 -0
  167. data/lib/seed_data/20240210161248/.doto +9 -0
  168. data/lib/seed_data/20240210161248/doto/current_project.json +4 -0
  169. data/lib/seed_data/20240210161248/doto/migration_version.json +3 -0
  170. data/lib/seed_data/20240210161248/doto/projects/default/project.json +5 -0
  171. data/lib/seed_data/20240210161248/doto/themes/cherry.json +79 -0
  172. data/lib/seed_data/20240210161248/doto/themes/christmas.json +79 -0
  173. data/lib/seed_data/20240210161248/doto/themes/default.json +79 -0
  174. data/lib/seed_data/20240210161248/doto/themes/lemon.json +79 -0
  175. data/lib/seed_data/20240210161248/doto/themes/light.json +79 -0
  176. data/lib/seed_data/20240210161248/doto/themes/matrix.json +79 -0
  177. data/lib/seed_data/20240210161248/doto/themes/whiteout.json +79 -0
  178. data/sig/dsu.rbs +4 -0
  179. metadata +406 -0
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../models/color_theme'
4
+ require_relative '../support/ask'
5
+ require_relative '../support/color_themable'
6
+
7
+ module Doto
8
+ module Views
9
+ class Import
10
+ include Support::Ask
11
+ include Support::ColorThemable
12
+
13
+ def initialize(presenter:, options:)
14
+ @presenter = presenter
15
+ @options = options&.dup || {}
16
+ @color_theme = Models::ColorTheme.find(theme_name: theme_name)
17
+ end
18
+
19
+ def render
20
+ return display_import_file_not_exist_message unless presenter.import_file_path_exist?
21
+ return display_nothing_to_import_message if presenter.nothing_to_import?
22
+
23
+ response = display_import_prompt
24
+ return display_cancelled_message unless response
25
+
26
+ response = display_project_override_prompt if presenter.overriding_project?
27
+ return display_cancelled_message unless response
28
+
29
+ display_import_messages presenter.respond
30
+ rescue StandardError => e
31
+ puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Doto.env.local?
32
+ message = I18n.t('subcommands.import.messages.import_error_raised', error: e.message)
33
+ puts apply_theme(message, theme_color: color_theme.error)
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :presenter, :color_theme, :options
39
+
40
+ def display_import_prompt
41
+ response = ask_while(prompt_with_options(prompt: import_prompt,
42
+ options: import_prompt_options), options: options) do |input|
43
+ message = I18n.t('information.input.try_again', options: import_prompt_options.join(','))
44
+ puts apply_theme(message, theme_color: color_theme.info) unless import_prompt_options.include?(input)
45
+ import_prompt_options.include?(input)
46
+ end
47
+ response == import_prompt_options.first
48
+ end
49
+
50
+ def display_project_override_prompt
51
+ response = ask_while(prompt_with_options(prompt: project_override_prompt,
52
+ options: import_prompt_options), options: options) do |input|
53
+ message = I18n.t('information.input.try_again', options: import_prompt_options.join(','))
54
+ puts apply_theme(message, theme_color: color_theme.info) unless import_prompt_options.include?(input)
55
+ import_prompt_options.include?(input)
56
+ end
57
+ response == import_prompt_options.first
58
+ end
59
+
60
+ def display_cancelled_message
61
+ puts apply_theme(I18n.t('subcommands.import.messages.cancelled'), theme_color: color_theme.info)
62
+ end
63
+
64
+ def display_nothing_to_import_message
65
+ puts apply_theme(I18n.t('subcommands.import.messages.nothing_to_import'), theme_color: color_theme.info)
66
+ end
67
+
68
+ def import_prompt
69
+ I18n.t('subcommands.import.prompts.import_all_confirm',
70
+ count: presenter.import_entry_groups_count, project: presenter.project_name)
71
+ end
72
+
73
+ def project_override_prompt
74
+ I18n.t('subcommands.import.prompts.project_override_confirm')
75
+ end
76
+
77
+ def import_prompt_options
78
+ I18n.t('subcommands.import.prompts.options')
79
+ end
80
+
81
+ def display_import_file_not_exist_message
82
+ puts apply_theme(I18n.t('subcommands.import.messages.file_not_exist',
83
+ file_path: presenter.import_file_path), theme_color: color_theme.info)
84
+ end
85
+
86
+ def display_import_messages(import_results)
87
+ import_results.each_pair do |entry_group_date, errors|
88
+ if errors.empty?
89
+ puts apply_theme(I18n.t('subcommands.import.messages.import_success',
90
+ date: entry_group_date), theme_color: color_theme.success)
91
+ else
92
+ errors.each do |error|
93
+ puts apply_theme(I18n.t('subcommands.import.messages.import_error',
94
+ date: entry_group_date, error: error), theme_color: color_theme.error)
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ def theme_name
101
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'import'
4
+
5
+ module Doto
6
+ module Views
7
+ class ImportDates < Import
8
+ private
9
+
10
+ def import_prompt
11
+ I18n.t('subcommands.import.prompts.import_dates_confirm',
12
+ from: presenter.from.to_date, to: presenter.to.to_date,
13
+ count: presenter.import_entry_groups_count, project: presenter.project_name)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../support/ask'
4
+ require_relative '../../support/color_themable'
5
+ require_relative '../../models/color_theme'
6
+
7
+ module Doto
8
+ module Views
9
+ module Project
10
+ class Create
11
+ include Support::Ask
12
+ include Support::ColorThemable
13
+
14
+ def initialize(presenter:, options: {})
15
+ @presenter = presenter
16
+ @options = options&.dup || {}
17
+ @color_theme = Models::ColorTheme.find(theme_name: theme_name)
18
+ end
19
+
20
+ def render
21
+ return display_project_errors if presenter.project_errors?
22
+ return display_project_already_exists if presenter.project_already_exists?
23
+
24
+ response = display_project_create_prompt
25
+ if presenter.respond response: response
26
+ display_project_created_message
27
+ else
28
+ display_project_cancelled_message
29
+ end
30
+ rescue StandardError => e
31
+ puts apply_theme(e.message, theme_color: color_theme.error)
32
+ puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Doto.env.local?
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :presenter, :color_theme, :options
38
+
39
+ def project_name
40
+ presenter.project_name
41
+ end
42
+
43
+ def display_project_cancelled_message
44
+ message = I18n.t('subcommands.project.messages.cancelled', project_name: project_name)
45
+ puts apply_theme(message, theme_color: color_theme.info)
46
+ end
47
+
48
+ def display_project_create_prompt
49
+ response = ask_while(prompt_with_options(prompt: create_prompt,
50
+ options: create_prompt_options), options: options) do |input|
51
+ message = I18n.t('information.input.try_again', options: create_prompt_options.join(','))
52
+ puts apply_theme(message, theme_color: color_theme.info) unless create_prompt_options.include?(input)
53
+ create_prompt_options.include?(input)
54
+ end
55
+ response == create_prompt_options.first
56
+ end
57
+
58
+ def display_project_created_message
59
+ message = I18n.t('subcommands.project.create.messages.created', project_name: project_name)
60
+ puts apply_theme(message, theme_color: color_theme.success)
61
+ end
62
+
63
+ def display_project_errors
64
+ errors = presenter.project_errors.join("\n")
65
+ puts apply_theme(errors, theme_color: color_theme.error)
66
+ end
67
+
68
+ def display_project_already_exists
69
+ message = I18n.t('subcommands.project.messages.already_exists', project_name: project_name)
70
+ puts apply_theme(message, theme_color: color_theme.error)
71
+ end
72
+
73
+ def create_prompt
74
+ I18n.t('subcommands.project.create.prompts.create_confirm', project_name: project_name)
75
+ end
76
+
77
+ def create_prompt_options
78
+ I18n.t('subcommands.project.create.prompts.create_options')
79
+ end
80
+
81
+ def theme_name
82
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../env'
4
+ require_relative '../../models/color_theme'
5
+ require_relative '../../support/ask'
6
+ require_relative '../../support/color_themable'
7
+
8
+ module Doto
9
+ module Views
10
+ module Project
11
+ class Delete
12
+ include Support::Ask
13
+ include Support::ColorThemable
14
+
15
+ attr_reader :presenter
16
+
17
+ def initialize(presenter:, options: {})
18
+ @presenter = presenter
19
+ @options = options&.dup || {}
20
+ @color_theme = Models::ColorTheme.find(theme_name: theme_name)
21
+ end
22
+
23
+ def render
24
+ return display_project_does_not_exists if presenter.project_does_not_exist?
25
+ return display_project_errors if presenter.project_errors.any?
26
+ return display_project_is_default if presenter.project_default?
27
+
28
+ response = display_project_delete_prompt
29
+ if presenter.respond response: response
30
+ display_deleted_project_message
31
+ else
32
+ display_delete_project_cancelled_message
33
+ end
34
+ rescue StandardError => e
35
+ puts apply_theme(e.message, theme_color: color_theme.error)
36
+ puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Doto.env.local?
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :color_theme, :options
42
+
43
+ def display_project_delete_prompt
44
+ response = ask_while(prompt_with_options(prompt: delete_prompt,
45
+ options: delete_prompt_options), options: options) do |input|
46
+ message = I18n.t('information.input.try_again', options: delete_prompt_options.join(','))
47
+ puts apply_theme(message, theme_color: color_theme.info) unless delete_prompt_options.include?(input)
48
+ delete_prompt_options.include?(input)
49
+ end
50
+ response == delete_prompt_options.first
51
+ end
52
+
53
+ def display_delete_project_cancelled_message
54
+ message = I18n.t('subcommands.project.messages.cancelled', project_name: presenter.project_name)
55
+ puts apply_theme(message, theme_color: color_theme.info)
56
+ end
57
+
58
+ def display_project_errors
59
+ errors = presenter.project_errors.join("\n")
60
+ puts apply_theme(errors, theme_color: color_theme.error)
61
+ end
62
+
63
+ def display_project_does_not_exists
64
+ message = I18n.t('subcommands.project.messages.does_not_exist',
65
+ project_name: presenter.project_name)
66
+ puts apply_theme(message, theme_color: color_theme.error)
67
+ end
68
+
69
+ def display_project_is_default
70
+ message = I18n.t('models.project.errors.delete_default_project',
71
+ project_name: presenter.project_name)
72
+ puts apply_theme(message, theme_color: color_theme.error)
73
+ end
74
+
75
+ def display_deleted_project_message
76
+ message = I18n.t('subcommands.project.delete.messages.deleted',
77
+ project_name: presenter.project_name)
78
+ puts apply_theme(message, theme_color: color_theme.success)
79
+ end
80
+
81
+ def delete_prompt
82
+ I18n.t('subcommands.project.delete.prompts.delete_confirm',
83
+ project_name: presenter.project_name, description: presenter.project_description)
84
+ end
85
+
86
+ def delete_prompt_options
87
+ I18n.t('subcommands.project.delete.prompts.delete_options')
88
+ end
89
+
90
+ def theme_name
91
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'delete'
4
+
5
+ module Doto
6
+ module Views
7
+ module Project
8
+ class DeleteByNumber < Delete
9
+ private
10
+
11
+ def display_project_does_not_exists
12
+ message = I18n.t('subcommands.project.messages.number_does_not_exist',
13
+ project_number: presenter.project_number)
14
+ puts apply_theme(message, theme_color: color_theme.error)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base_list_view'
4
+
5
+ module Doto
6
+ module Views
7
+ module Project
8
+ # TODO: I18n.
9
+ class List < Views::BaseListView
10
+ NO_JUSTIFICATION = 4
11
+ PROJECT_JUSTIFICATION = 15 + 10
12
+ DEFAULT_JUSTIFICATION = 10 + 10
13
+ CURRENT_JUSTIFICATION = 10 + 10
14
+ DESCRIPTION_JUSTIFICATION = 10 + 10
15
+
16
+ DETAIL_HEADER_STRING = "#{'No.'.ljust(NO_JUSTIFICATION)} " \
17
+ "#{'Project'.ljust(PROJECT_JUSTIFICATION)} " \
18
+ "#{'Default'.center(DEFAULT_JUSTIFICATION)} " \
19
+ "#{'Current'.center(CURRENT_JUSTIFICATION)} " \
20
+ "#{'Description'.ljust(DESCRIPTION_JUSTIFICATION)}".freeze
21
+
22
+ def render
23
+ super do
24
+ return display_no_projects if presenter.projects.none?
25
+
26
+ display_project_list
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def display_project_list
33
+ display_header
34
+ display_detail_header
35
+ display_detail
36
+ display_footer
37
+ end
38
+
39
+ def display_no_projects
40
+ # Should never happen
41
+ message = I18n.t('subcommands.project.messages.no_projects')
42
+ puts apply_theme(message, theme_color: color_theme.info)
43
+ end
44
+
45
+ def display_detail
46
+ presenter.projects.each_with_index do |project, index|
47
+ display_detail_data(
48
+ formatted_index(index: index),
49
+ project.project_name,
50
+ project.default_project?,
51
+ project.current_project?,
52
+ project.description
53
+ )
54
+ end
55
+ end
56
+
57
+ def display_detail_header
58
+ puts apply_theme(DETAIL_HEADER_STRING, theme_color: color_theme.index)
59
+ end
60
+
61
+ def display_detail_data(index, project_name, default_project, current_project, project_desc)
62
+ puts "#{index_detail_data(index)} " \
63
+ "#{project_name_detail_data(project_name)} " \
64
+ "#{project_default_detail_data(default_project)} " \
65
+ "#{project_current_detail_data(current_project)} " \
66
+ "#{project_desc_detail_data(project_desc)}"
67
+ end
68
+
69
+ # def display_detail_data(index, project_name, default_project, current_project, project_desc)
70
+ # puts "#{index_detail_data(index)}|" \
71
+ # "#{project_name_detail_data(project_name)}|" \
72
+ # "#{project_default_detail_data(default_project)}|" \
73
+ # "#{project_current_detail_data(current_project)}|" \
74
+ # "#{project_desc_detail_data(project_desc)}"
75
+ # end
76
+
77
+ def display_footer
78
+ footer = "\nTotal projects: #{presenter.projects.count}"
79
+ puts apply_theme(footer, theme_color: color_theme.footer)
80
+ end
81
+
82
+ def display_header
83
+ header = "Project list\n"
84
+ puts apply_theme(header, theme_color: color_theme.subheader)
85
+ end
86
+
87
+ def index_detail_data(value)
88
+ apply_theme(value.to_s.ljust(NO_JUSTIFICATION), theme_color: color_theme.index)
89
+ end
90
+
91
+ def project_name_detail_data(value)
92
+ apply_theme(value.to_s.ljust(PROJECT_JUSTIFICATION), theme_color: color_theme.body.bold!)
93
+ end
94
+
95
+ def project_default_detail_data(value)
96
+ value = value ? '*' : ' '
97
+ apply_theme(value.to_s.center(DEFAULT_JUSTIFICATION), theme_color: color_theme.body.bold!)
98
+ end
99
+
100
+ def project_current_detail_data(value)
101
+ value = value ? '*' : ' '
102
+ apply_theme(value.to_s.center(CURRENT_JUSTIFICATION), theme_color: color_theme.body.bold!)
103
+ end
104
+
105
+ def project_desc_detail_data(value)
106
+ apply_theme(value.to_s.ljust(DESCRIPTION_JUSTIFICATION), theme_color: color_theme.body)
107
+ end
108
+
109
+ def theme_name
110
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../env'
4
+ require_relative '../../models/color_theme'
5
+ require_relative '../../support/ask'
6
+ require_relative '../../support/color_themable'
7
+
8
+ module Doto
9
+ module Views
10
+ module Project
11
+ class Rename
12
+ include Support::Ask
13
+ include Support::ColorThemable
14
+
15
+ attr_reader :presenter
16
+
17
+ def initialize(presenter:, options: {})
18
+ @presenter = presenter
19
+ @options = options&.dup || {}
20
+ @color_theme = Models::ColorTheme.find(theme_name: theme_name)
21
+ end
22
+
23
+ def render
24
+ return display_project_does_not_exist if presenter.project_does_not_exist?
25
+ return display_new_project_already_exists if presenter.new_project_already_exists?
26
+ return display_new_project_errors if presenter.new_project_errors.any?
27
+
28
+ response = display_project_rename_prompt
29
+ if presenter.respond response: response
30
+ display_renamed_project_message
31
+ else
32
+ display_rename_project_cancelled_message
33
+ end
34
+ rescue StandardError => e
35
+ puts apply_theme(e.message, theme_color: color_theme.error)
36
+ puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Doto.env.local?
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :color_theme, :options
42
+
43
+ def display_project_rename_prompt
44
+ response = ask_while(prompt_with_options(prompt: rename_prompt,
45
+ options: rename_prompt_options), options: options) do |input|
46
+ message = I18n.t('information.input.try_again', options: rename_prompt_options.join(','))
47
+ puts apply_theme(message, theme_color: color_theme.info) unless rename_prompt_options.include?(input)
48
+ rename_prompt_options.include?(input)
49
+ end
50
+ response == rename_prompt_options.first
51
+ end
52
+
53
+ def display_rename_project_cancelled_message
54
+ message = I18n.t('subcommands.project.messages.cancelled')
55
+ puts apply_theme(message, theme_color: color_theme.info)
56
+ end
57
+
58
+ def display_new_project_errors
59
+ errors = presenter.new_project_errors.join("\n")
60
+ puts apply_theme(errors, theme_color: color_theme.error)
61
+ end
62
+
63
+ def display_project_does_not_exist
64
+ message = I18n.t('subcommands.project.messages.does_not_exist',
65
+ project_name: presenter.project_name)
66
+ puts apply_theme(message, theme_color: color_theme.error)
67
+ end
68
+
69
+ def display_new_project_already_exists
70
+ message = I18n.t('subcommands.project.rename.messages.new_project_already_exists',
71
+ new_project_name: presenter.new_project_name)
72
+ puts apply_theme(message, theme_color: color_theme.error)
73
+ end
74
+
75
+ def display_renamed_project_message
76
+ message = I18n.t('subcommands.project.rename.messages.renamed_project',
77
+ project_name: presenter.project_name, new_project_name: presenter.new_project_name)
78
+ puts apply_theme(message, theme_color: color_theme.success)
79
+ end
80
+
81
+ def rename_prompt
82
+ I18n.t('subcommands.project.rename.prompts.rename_confirm',
83
+ project_name: presenter.project_name,
84
+ new_project_name: presenter.new_project_name,
85
+ new_project_description: presenter.new_project_description)
86
+ end
87
+
88
+ def rename_prompt_options
89
+ I18n.t('subcommands.project.rename.prompts.rename_options')
90
+ end
91
+
92
+ def theme_name
93
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../env'
4
+ require_relative '../../models/color_theme'
5
+ require_relative '../../support/ask'
6
+ require_relative '../../support/color_themable'
7
+ require_relative 'rename'
8
+
9
+ module Doto
10
+ module Views
11
+ module Project
12
+ class RenameByNumber < Rename
13
+ def display_project_does_not_exist
14
+ message = I18n.t('subcommands.project.messages.number_does_not_exist',
15
+ project_number: presenter.project_number)
16
+ puts apply_theme(message, theme_color: color_theme.error)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../env'
4
+ require_relative '../../models/color_theme'
5
+ require_relative '../../support/ask'
6
+ require_relative '../../support/color_themable'
7
+
8
+ module Doto
9
+ module Views
10
+ module Project
11
+ class Use
12
+ include Support::Ask
13
+ include Support::ColorThemable
14
+
15
+ attr_reader :presenter
16
+
17
+ def initialize(presenter:, options: {})
18
+ @presenter = presenter
19
+ @options = options&.dup || {}
20
+ @color_theme = Models::ColorTheme.find(theme_name: theme_name)
21
+ end
22
+
23
+ def render
24
+ return display_project_does_not_exist if presenter.project_does_not_exist?
25
+ return display_project_already_current_project if presenter.already_current_project?
26
+ return display_project_errors if presenter.project_errors.any?
27
+
28
+ response = display_project_use_prompt
29
+ if presenter.respond response: response
30
+ display_using_project_message
31
+ else
32
+ display_use_project_cancelled_message
33
+ end
34
+ rescue StandardError => e
35
+ puts apply_theme(e.message, theme_color: color_theme.error)
36
+ puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Doto.env.local?
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :color_theme, :options
42
+
43
+ def display_project_use_prompt
44
+ response = ask_while(prompt_with_options(prompt: use_prompt,
45
+ options: use_prompt_options), options: options) do |input|
46
+ message = I18n.t('information.input.try_again', options: use_prompt_options.join(','))
47
+ puts apply_theme(message, theme_color: color_theme.info) unless use_prompt_options.include?(input)
48
+ use_prompt_options.include?(input)
49
+ end
50
+ response == use_prompt_options.first
51
+ end
52
+
53
+ def display_use_project_cancelled_message
54
+ message = I18n.t('subcommands.project.messages.cancelled')
55
+ puts apply_theme(message, theme_color: color_theme.info)
56
+ end
57
+
58
+ def display_project_errors
59
+ errors = presenter.project_errors.join("\n")
60
+ puts apply_theme(errors, theme_color: color_theme.error)
61
+ end
62
+
63
+ def display_project_does_not_exist
64
+ message = I18n.t('subcommands.project.messages.does_not_exist',
65
+ project_name: presenter.project_name)
66
+ puts apply_theme(message, theme_color: color_theme.error)
67
+ end
68
+
69
+ def display_using_project_message
70
+ message = I18n.t('subcommands.project.use.messages.using_project',
71
+ project_name: presenter.project_name)
72
+ puts apply_theme(message, theme_color: color_theme.success)
73
+ end
74
+
75
+ def display_project_already_current_project
76
+ message = I18n.t('subcommands.project.messages.already_current_project',
77
+ project_name: presenter.project_name)
78
+ puts apply_theme(message, theme_color: color_theme.success)
79
+ end
80
+
81
+ def use_prompt
82
+ I18n.t('subcommands.project.use.prompts.use_confirm',
83
+ project_name: presenter.project_name,
84
+ description: presenter.project_description)
85
+ end
86
+
87
+ def use_prompt_options
88
+ I18n.t('subcommands.project.use.prompts.use_options')
89
+ end
90
+
91
+ def theme_name
92
+ @theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'use'
4
+
5
+ module Doto
6
+ module Views
7
+ module Project
8
+ class UseByNumber < Use
9
+ private
10
+
11
+ def display_project_does_not_exist
12
+ message = I18n.t('subcommands.project.messages.number_does_not_exist',
13
+ project_number: presenter.project_number)
14
+ puts apply_theme(message, theme_color: color_theme.error)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end