aro 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -2
  3. data/README.md +10 -54
  4. data/aro.gemspec +6 -3
  5. data/bin/oss_om +2 -0
  6. data/checksums/aro-0.2.7.gem.sha512 +1 -0
  7. data/checksums/aro-0.2.8.gem.sha512 +1 -0
  8. data/listen.rb +1 -1
  9. data/locale/en.cor.yml +28 -35
  10. data/locale/en.yml +23 -60
  11. data/sys/aro/action.rb +132 -0
  12. data/sys/aro/book.rb +150 -0
  13. data/sys/aro/d.rb +3 -1
  14. data/sys/aro/db/migrate/1793913747_create_data_bases.rb +2 -0
  15. data/sys/aro/db/migrate/1793913777_create_data_base_directories.rb +2 -0
  16. data/sys/aro/db/migrate/1793913796_create_data_base_files.rb +2 -0
  17. data/sys/aro/db/migrate/1793913841_create_menus.rb +2 -0
  18. data/sys/aro/db/migrate/1793913861_create_menu_items.rb +3 -2
  19. data/sys/aro/db.rb +19 -33
  20. data/sys/aro/designer.rb +291 -102
  21. data/sys/aro/imports.rb +78 -0
  22. data/sys/aro/library.rb +202 -0
  23. data/sys/aro/locale.rb +4 -2
  24. data/sys/aro/mancy.rb +6 -39
  25. data/sys/aro/models/concerns/tar_go_for_root_sec.rb +34 -0
  26. data/sys/aro/models/concerns/uuid.rb +2 -0
  27. data/sys/aro/models/data_base.rb +73 -11
  28. data/sys/aro/models/directory.rb +3 -5
  29. data/sys/aro/models/file.rb +3 -1
  30. data/sys/aro/models/menu.rb +65 -1
  31. data/sys/aro/models/menu_item.rb +68 -4
  32. data/sys/aro/oss_open_menu.rb +307 -0
  33. data/sys/aro/p.rb +15 -9
  34. data/sys/aro/plugins.rb +104 -0
  35. data/sys/aro/r.rb +2 -0
  36. data/sys/aro/{cor.rb → settings/cor.rb} +163 -220
  37. data/sys/aro/settings/git.rb +44 -0
  38. data/sys/aro/settings/ssh.rb +108 -0
  39. data/sys/aro/store.rb +111 -37
  40. data/sys/aro/v.rb +3 -1
  41. data/sys/aro.rb +2 -0
  42. data/sys/ma_ain.rb +271 -0
  43. data/sys/reiquire.rb +41 -54
  44. data/sys/shr/prompt.rb +6 -1
  45. data/sys/shr/version.rb +8 -8
  46. data/tasks/make.rake +2 -3
  47. metadata +39 -24
  48. data/locale/en.cards.yml +0 -519
  49. data/locale/en.cmd.yml +0 -34
  50. data/locale/en.usage.yml +0 -142
  51. data/sys/aro/cmd.rb +0 -96
  52. data/sys/aro/db/migrate/1763374647_create_tecks.rb +0 -20
  53. data/sys/aro/db/migrate/1763432541_create_tlogs.rb +0 -20
  54. data/sys/aro/ma_ain.rb +0 -54
  55. data/sys/aro/models/teck.rb +0 -251
  56. data/sys/aro/models/tlog.rb +0 -21
  57. data/sys/aro/views/base.rb +0 -25
  58. data/sys/aro/views/teck.rb +0 -30
  59. data/sys/cli/constants.rb +0 -45
  60. data/sys/cli/create.rb +0 -23
  61. data/sys/cli/nterface.rb +0 -37
  62. data/sys/cli/teck.rb +0 -107
  63. data/sys/cli/usage.rb +0 -25
  64. data/sys/cli.rb +0 -23
  65. data/sys/shr/t.rb +0 -74
@@ -1,14 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateMenuItems < ActiveRecord::Migration[8.1]
2
4
  def change
3
5
  create_table :menu_items do |t|
4
6
  t.belongs_to :menu, null: false, foreign_key: true
5
7
  t.string :uuid, null: false
6
- t.string :tty_name
8
+ t.integer :type_flag, default: 1
7
9
 
8
10
  t.timestamps
9
11
  end
10
12
 
11
13
  add_index :menu_items, :uuid, unique: true
12
- add_index :menu_items, [:menu_id, :tty_name], unique: true
13
14
  end
14
15
  end
data/sys/aro/db.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  =begin
2
4
 
3
5
  db.rb
@@ -20,11 +22,8 @@ module Aro
20
22
 
21
23
  def self.ensure_connected!
22
24
  return if self.instance.connected?
23
-
24
25
  Aro::Db.configure_logger
25
- if Aro::Mancy.in_aro?
26
- self.instance.setup_local_aro
27
- end
26
+ self.instance.setup_local_aro if Aro::Mancy.in_aro?
28
27
  end
29
28
 
30
29
  def connected?
@@ -41,13 +40,7 @@ module Aro
41
40
  end
42
41
 
43
42
  def self.base_db_dir
44
- db_dir = File.join(Aro::Mancy.root_dir, :db.to_s)
45
- return "#{db_dir}_#{Aro::Cor::ENVS[:TEST]}" if Aro::Cor.is_test?
46
- db_dir
47
- end
48
-
49
- def self.migrate_dir
50
- File.join(Aro::Db.base_db_dir, :migrate.to_s)
43
+ File.join(Aro::Mancy.root_dir, :db.to_s)
51
44
  end
52
45
 
53
46
  def self.sql_filepath
@@ -70,7 +63,15 @@ module Aro
70
63
  end
71
64
 
72
65
  unless File.exist?(db_config_filepath)
73
- pw = Aro::P.p.ask(I18n.t("messages.base_db_password_prompt", aro_name: aro_name, sql_filepath: self.class.sql_filepath))
66
+ pw = Aro::P.p.ask(
67
+ I18n.t(
68
+ "open_menu.base_db_password_prompt",
69
+ sql_filepath: self.class.sql_filepath.gsub(
70
+ Aro::Mancy.root_dir, Aro::Mancy::ARO_DIRECTORY.to_s
71
+ ),
72
+ aro_name: aro_name
73
+ )
74
+ )
74
75
  pw = aro_name unless pw.present?
75
76
  # create database config yaml file
76
77
  c = {
@@ -98,36 +99,21 @@ module Aro
98
99
  Aro::D.say("#{self}#{__method__}#{self.active_record_connection_instance.inspect}")
99
100
  end
100
101
 
101
- def self.migrations_filepaths
102
- File.join(Aro::Db.migrate_dir, "*.rb")
102
+ def self.gem_migrations_filepaths
103
+ File.join(gem_migration_dir, "*.rb")
103
104
  end
104
105
 
105
- def self.gem_migrations_filepaths
106
- File.join(Reiquire.gem_migrations_path, :migrate.to_s, "*.rb")
106
+ def self.gem_migration_dir
107
+ File.join(Reiquire.gem_migrations_path, :migrate.to_s)
107
108
  end
108
109
 
109
110
  def migrate
110
- puts __method__
111
- migration_file_names = Dir[self.class.migrations_filepaths].map{|fp| File.basename(fp)}
112
- puts "migration_file_names: #{migration_file_names}"
113
111
  gem_migration_file_names = Dir[self.class.gem_migrations_filepaths].map{|fp| File.basename(fp)}
114
- puts "gem_migration_file_names: #{gem_migration_file_names}"
115
- mfs_all = gem_migration_file_names.all?{|gmf|
116
- migration_file_names.include?(gmf)
117
- }
118
- puts "mfs_all: #{mfs_all}"
119
-
120
- unless Dir.exist?(Aro::Db.migrate_dir) && mfs_all
121
- puts "Reiquire.copy_db_migrations_from_gem!"
122
- puts "ls #{Aro::Db.migrate_dir}"
123
- puts migration_file_names
124
- Reiquire.copy_db_migrations_from_gem!
125
- end
126
112
 
127
- migration_version = migration_file_names.map{|n|
113
+ migration_version = gem_migration_file_names.map{|n|
128
114
  n.to_s.split("_")[0].to_i
129
115
  }.max
130
- ActiveRecord::MigrationContext.new(Aro::Db.migrate_dir).migrate(migration_version)
116
+ ActiveRecord::MigrationContext.new(Aro::Db.gem_migration_dir).migrate(migration_version)
131
117
  dump_schema!
132
118
  end
133
119
 
data/sys/aro/designer.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  =begin
2
4
 
3
5
  designer.rb
@@ -11,66 +13,69 @@
11
13
  module Aro
12
14
  module Dom
13
15
  class Designer
14
- ACTION_LJUST = 22
15
- CLASS_LJUST = 33
16
-
17
- def self.design_aro
18
- env_home_val = ENV[:HOME.to_s]
19
- Aro::P.say(:"checking for bash env var $HOME in ruby ENV".to_s)
20
- Aro::P.say(:"$HOME is set to #{env_home_val}".to_s)
21
- abs_home = Aro::P.p.ask(:"use alternative aro_root? (empty to use $HOME): ".to_s)
22
- raise "missing required value for aro_root!" if abs_home.nil? && env_home_val.nil?
23
- aro_home_dir = abs_home || env_home_val
24
- oss_om_base_dir = ::File.join(aro_home_dir, Aro::Mancy::ARO_DIRECTORY.to_s)
16
+ ITEM_TITLE_JUSTIFY = 28
17
+
18
+ def self.design_oss_om
19
+ oss_home_path = File.expand_path(Dir.pwd)
20
+ Aro::P.say("set up oss_om home directory in '#{oss_home_path}'?")
21
+ abs_home = Aro::Dom::Designer.get_new_value_from_user(
22
+ "leave empty to use '#{oss_home_path}' as home.",
23
+ "enter new path: "
24
+ )
25
+ raise "missing required value for oss_om home!" if abs_home.nil? && oss_home_path.nil?
26
+ oss_home_path = abs_home.nil? ? oss_home_path : File.expand_path(abs_home)
27
+ oss_om_base_dir = ::File.join(oss_home_path, Aro::Mancy::ARO_DIRECTORY.to_s)
25
28
  Aro::P.say("FileUtils.mkdir_p(#{oss_om_base_dir})")
26
29
  FileUtils.mkdir_p(oss_om_base_dir)
27
- Aro::P.say("FileUtils.chdir(#{aro_home_dir})")
28
- FileUtils.chdir(aro_home_dir) do
29
- Aro::P.say("Aro::Cor.instance.load_env")
30
- Aro::Cor.instance.load_env
31
- Aro::P.say("Aro::Cor.set_ivar(:OSS_OM_HOME, #{File.absolute_path(aro_home_dir)})")
32
- Aro::Cor.set_ivar(:OSS_OM_HOME, File.absolute_path(aro_home_dir))
33
- Aro::P.say("Aro::Db.ensure_connected!")
34
- Aro::Db.ensure_connected!
35
- Aro::P.say("Aro::Mancy.init(#{aro_home_dir})")
36
- Aro::Mancy.init(aro_home_dir)
37
- Aro::P.say("Reiquire.reload_i18n!")
38
- Reiquire.reload_i18n!
39
- # design_menu(Aro::Dom::Menu.first)
40
- end
41
30
 
42
- if File.absolute_path(Dir.pwd) != Aro::Cor.ivar(:OSS_OM_HOME)
43
- Aro::P.say("user needs to cd")
44
- Aro::P.say("enter $ cd #{Aro::Cor.ivar(:OSS_OM_HOME)}")
31
+ Aro::P.say("Aro::Cor.set_ivar(:OSS_OM_HOME, #{oss_home_path})")
32
+ Aro::Cor.set_ivar(:OSS_OM_HOME, oss_home_path)
33
+
34
+ if ::File.expand_path(Dir.pwd) != Aro::Cor.ivar(:OSS_OM_HOME)
35
+ Aro::P.say("run the following commands to continue:")
36
+ Aro::P.say("$ cd #{Aro::Cor.ivar(:OSS_OM_HOME)} && oss_om")
37
+ Aro::P.say("exiting...")
45
38
  exit
39
+ else
40
+ Aro::Dom::Ma_ain.instance.reign!
46
41
  end
47
42
  design
48
43
  end
49
44
 
50
-
51
45
  def self.design
52
46
  if Aro::Cor.ivar(:OSS_OM_HOME).nil?
53
- design_aro
47
+ design_oss_om
54
48
  return
55
49
  end
56
- Aro::Dom::Ma_ain.instance.current_menu = Aro::Dom::DataBase.open_menu(:ma_ain)
57
50
 
51
+ Aro::P.say("Aro::Dom::Ma_ain.open!")
52
+ Aro::Dom::Ma_ain.open!
58
53
  loop do
59
- selected_menu_item_uuid = Aro::P.p.select(
54
+ selected_menu_item_uuid = Aro::P.default_select(
60
55
  "#{Aro::Dom::Ma_ain.instance.current_menu.localized_name}",
61
- [{name: :open_menu, value: :open_menu}] + Aro::Dom::Ma_ain.instance.current_menu.menu_items.map{|mi| mi.as_tty},
62
- show_help: :always,
63
- cycle: true,
64
- per_page: 11
56
+ Aro::Dom::Ma_ain.get_current_options
65
57
  )
66
58
 
67
- if selected_menu_item_uuid == :open_menu
68
- Aro::Dom::Designer.design_menu(Aro::Dom::Ma_ain.instance.current_menu)
69
- else
70
- Aro::Dom::Designer.design_menu_item(
71
- selected_menu_item_uuid,
59
+ case selected_menu_item_uuid.to_sym
60
+ when :back
61
+ # todo: call_stack_bread_crumbs
62
+ Aro::Dom::Ma_ain.open!
63
+ when :open_menu
64
+ design_menu(
72
65
  Aro::Dom::Ma_ain.instance.current_menu
73
66
  )
67
+ else
68
+ if Aro::Dom::Ma_ain.running?
69
+ selected_menu_item = Aro::Dom::Ma_ain.instance.current_menu.menu_items.find_by(
70
+ uuid: selected_menu_item_uuid
71
+ )
72
+ selected_menu_item.run!
73
+ else
74
+ design_menu_item(
75
+ selected_menu_item_uuid,
76
+ Aro::Dom::Ma_ain.instance.current_menu
77
+ )
78
+ end
74
79
  end
75
80
  end
76
81
  end
@@ -100,54 +105,69 @@ module Aro
100
105
  new_name = get_new_value_from_user(
101
106
  "#{__method__} #{Aro::Dom::MenuItem.name} for menu: '#{I18n.t(menu.full_i18n_path)}'"
102
107
  )
108
+
103
109
  unless new_name.nil? ||
104
110
  new_name.empty? ||
105
111
  new_name.kind_of?(FalseClass)
106
112
 
107
- menu_item = menu.menu_items.create(tty_name: Aro::Dom::Locale.i18n_keyify_text(new_name))
108
- Aro::Dom::Locale.add_i18n_key(
109
- new_name,
110
- library_name: :menu_items,
111
- new_i18n_display_key: menu_item.uuid,
112
- )
113
+ new_item = menu.generate_new_item(new_name)
114
+ raise "error generating new item!" if new_item.nil?
115
+
116
+ design_menu_item(new_item.uuid, menu)
113
117
  else
114
118
  Aro::P.say("#{new_name.inspect} is invalid")
119
+ design_menu(menu)
115
120
  end
116
-
117
- design_menu(menu)
118
121
  end
119
122
 
120
123
  def self.design_menu(menu = nil)
121
124
  return create_menu if menu.nil?
122
125
 
123
- # action,class,value
126
+ item_mapper = Proc.new{|mi|
127
+ {
128
+ name: "(edit_item)".ljust(ITEM_TITLE_JUSTIFY) +
129
+ "#{mi.localized_name}".ljust(ITEM_TITLE_JUSTIFY) +
130
+ "#{mi.class.name}(#{mi.id})".ljust(ITEM_TITLE_JUSTIFY),
131
+ value: mi.uuid
132
+ }
133
+ }
134
+
135
+ # action,value,class
124
136
  options = [
125
137
  {
126
138
  name: :back,
127
139
  value: :back
128
140
  },
129
141
  {
130
- name: "(edit_title)".ljust(ACTION_LJUST) +
131
- "#{menu.class.name}(#{menu.id})".ljust(CLASS_LJUST) +
132
- "#{menu.localized_name}",
133
- value: :edit_title
134
- }
135
- ] + menu.menu_items.map{|mi|
142
+ name: "(#{Aro::Dom::Ma_ain::UNICODE_KEYS[:yinyang]}) toggle_run_mode".ljust(ITEM_TITLE_JUSTIFY) +
143
+ ":#{Aro::Dom::Ma_ain::RUN_MODES[Aro::Dom::Ma_ain.instance.run_mode || Aro::Mancy::O]}".ljust(ITEM_TITLE_JUSTIFY) +
144
+ "available_modes: #{Aro::Dom::Ma_ain::RUN_MODES.to_s}".ljust(ITEM_TITLE_JUSTIFY),
145
+ value: :toggle_run_mode
146
+ },
136
147
  {
137
- name: "(edit_item)".ljust(ACTION_LJUST) +
138
- "#{mi.class.name}(#{mi.id})".ljust(CLASS_LJUST) +
139
- "#{mi.localized_name}",
140
- value: mi.uuid
148
+ name: "(#{Aro::Dom::Ma_ain::UNICODE_KEYS[:yinyang]}) open_shell".ljust(ITEM_TITLE_JUSTIFY) +
149
+ "open a bash session".ljust(ITEM_TITLE_JUSTIFY),
150
+ value: :open_shell
151
+ },
152
+ {
153
+ name: "(edit_title)".ljust(ITEM_TITLE_JUSTIFY) +
154
+ "#{menu.localized_name}".ljust(ITEM_TITLE_JUSTIFY) +
155
+ "#{menu.class.name}(#{menu.id})".ljust(ITEM_TITLE_JUSTIFY),
156
+ value: :edit_title
141
157
  }
142
- } + [
158
+ ] +
159
+ menu.menu_items.select{|mi| mi.user?}.map{|mi| item_mapper.call(mi)} +
160
+ menu.menu_items.select{|mi| mi.system?}.map{|mi| item_mapper.call(mi)} +
161
+ [
143
162
  {
144
- name: "(create_item)".ljust(ACTION_LJUST) +
145
- "#{Aro::Dom::MenuItem.name}(+)".ljust(CLASS_LJUST),
163
+ name: "(create_item)".ljust(ITEM_TITLE_JUSTIFY) +
164
+ "add new item to #{menu.localized_name}".ljust(ITEM_TITLE_JUSTIFY) +
165
+ "#{Aro::Dom::MenuItem.name}(+)".ljust(ITEM_TITLE_JUSTIFY),
146
166
  value: :create_item
147
167
  }
148
168
  ]
149
169
 
150
- v = Aro::P.p.select(
170
+ v = Aro::P.default_select(
151
171
  I18n.t("open_menu.edit_menu_localized_name", localized_name: menu.localized_name),
152
172
  options
153
173
  )
@@ -172,6 +192,12 @@ module Aro
172
192
  create_menu_item(menu)
173
193
  when :back
174
194
  return
195
+ when :toggle_run_mode
196
+ Aro::Dom::Ma_ain.toggle_run_mode
197
+ return
198
+ when :open_shell
199
+ Aro::P.say("starting bash session for #{`whoami`.strip}")
200
+ system(:bash.to_s)
175
201
  else
176
202
  design_menu_item(v, menu)
177
203
  end
@@ -182,22 +208,6 @@ module Aro
182
208
 
183
209
  menu_item = menu.menu_items.find_by(uuid: menu_item_uuid)
184
210
 
185
- # new_name = get_new_value_from_user(
186
- # "rename #{menu_item.class} '#{I18n.t(menu_item.full_i18n_path)}'"
187
- # )
188
- # unless new_name.nil? ||
189
- # new_name.empty? ||
190
- # new_name.kind_of?(FalseClass)
191
-
192
- # Aro::Dom::Locale.update_i18n_key(
193
- # new_name,
194
- # menu_item.uuid,
195
- # library_name: :menu_items
196
- # )
197
- # else
198
- # Aro::P.say("#{new_name.inspect} is invalid")
199
- # end
200
-
201
211
  # action,class,value
202
212
  options = [
203
213
  {
@@ -205,19 +215,20 @@ module Aro
205
215
  value: :back
206
216
  },
207
217
  {
208
- name: "(edit_title)".ljust(ACTION_LJUST) +
209
- "#{menu_item.class.name}(#{menu_item.id})".ljust(CLASS_LJUST) +
210
- "#{menu_item.localized_name}",
218
+ name: "(edit_title)".ljust(ITEM_TITLE_JUSTIFY) +
219
+ "#{menu_item.localized_name}".ljust(ITEM_TITLE_JUSTIFY) +
220
+ "#{menu_item.class.name}(#{menu_item.id})".ljust(ITEM_TITLE_JUSTIFY),
211
221
  value: :edit_title
212
222
  },
213
223
  {
214
- name: "(edit_action)".ljust(ACTION_LJUST) +
215
- "Aro::Dom::MenuItem::Action(+)".ljust(CLASS_LJUST),
224
+ name: "(edit_action)".ljust(ITEM_TITLE_JUSTIFY) +
225
+ "#{menu_item.action_display_text}".ljust(ITEM_TITLE_JUSTIFY) +
226
+ "Aro::Dom::MenuItem::Action(+)".ljust(ITEM_TITLE_JUSTIFY),
216
227
  value: :edit_action
217
228
  }
218
229
  ]
219
230
 
220
- v = Aro::P.p.select(
231
+ v = Aro::P.default_select(
221
232
  I18n.t("open_menu.edit_menu_item_localized_name", localized_name: menu_item.localized_name),
222
233
  options
223
234
  )
@@ -240,42 +251,220 @@ module Aro
240
251
  Aro::P.say("#{new_name.inspect} is invalid")
241
252
  end
242
253
  when :edit_action
243
- puts "this is where i am working"
254
+ design_action_for(menu_item)
255
+ when :back
244
256
  return
257
+ end
258
+ end
259
+
260
+ def self.edit_action_for(menu_item)
261
+ action_name = menu_item.store.safe_get_key("action_name")&.to_sym
262
+
263
+ raise "missing action!" if action_name.nil?
264
+
265
+ options = [
266
+ {
267
+ name: :back,
268
+ value: :back
269
+ },
270
+ {
271
+ name: "(edit_type)".ljust(ITEM_TITLE_JUSTIFY) +
272
+ "#{menu_item.action_storage_key}".ljust(ITEM_TITLE_JUSTIFY) +
273
+ "#{Aro::Dom::Action.name}(#{action_name})".ljust(ITEM_TITLE_JUSTIFY),
274
+ value: :edit_type
275
+ },
276
+ {
277
+ name: "(edit_method)".ljust(ITEM_TITLE_JUSTIFY) +
278
+ "#{menu_item.action_display_text}".ljust(ITEM_TITLE_JUSTIFY) +
279
+ "Aro::Dom::MenuItem::Action(#{action_name})".ljust(ITEM_TITLE_JUSTIFY),
280
+ value: :edit_method
281
+ }
282
+ ]
283
+ v = Aro::P.default_select(
284
+ I18n.t("open_menu.edit_action_for_menu_item", localized_name: menu_item.localized_name, action_name: action_name),
285
+ options
286
+ )
287
+
288
+ case v.to_sym
289
+ when :edit_type
290
+ design_action_for(menu_item, overwrite: true)
291
+ when :edit_method
292
+ # todo: case when for oss_om_entry types here
293
+ Aro::Dom::Oss_OpenMenu.create_exec_oss_om_entry_for(menu_item)
294
+ end
295
+ end
296
+
297
+ def self.design_action_for(menu_item, overwrite: false)
298
+ return if menu_item.nil?
299
+ return edit_action_for(menu_item) if menu_item.actionable? && !overwrite
300
+
301
+ # action,class,value
302
+ options = [
303
+ {
304
+ name: :back,
305
+ value: :back
306
+ }
307
+ ] + Aro::Dom::Action::TYPES.keys.map{|k|
308
+ {
309
+ name: "(#{k})".ljust(ITEM_TITLE_JUSTIFY) +
310
+ "#{menu_item.localized_name}".ljust(ITEM_TITLE_JUSTIFY) +
311
+ "#{menu_item.class.name}(#{menu_item.id})".ljust(ITEM_TITLE_JUSTIFY),
312
+ value: k
313
+ }
314
+ }
315
+
316
+ v = Aro::P.default_select(
317
+ I18n.t("open_menu.design_action_for_menu_item", localized_name: menu_item.localized_name),
318
+ options
319
+ )
320
+
321
+ case v.to_sym
245
322
  when :back
246
323
  return
324
+ else
325
+ Aro::Dom::Action.create(v, menu_item)
247
326
  end
327
+ end
328
+
329
+ def self.design_plugin_for(chapter_menu_item)
330
+ action_data = chapter_menu_item.store.safe_get_key("action_data") || {}
331
+ raise "missing action data for #{chapter_menu_item.inspect}!" if action_data.nil? ||
332
+ !action_data.kind_of?(Hash)
333
+
334
+ action_data = ensure_action_data_oss_om_type_exists!(action_data)
335
+
336
+ return design_schema_for(chapter_menu_item) if action_data["oss_om_type"].to_s == :key_value_store.to_s
337
+
338
+ plugin_file_path = Aro::Dom::Plugins.choose_plugin
339
+
340
+ return if plugin_file_path == false
341
+
342
+ raise "missing plugin! #{plugin_file_path}" unless ::File.exist?(plugin_file_path)
248
343
 
249
- # this is for updating data stores
250
- # todo:
251
- # Aro::P.say([
252
- # to_s,
253
- # "=> writing property :tty_name => '#{new_name}'",
254
- # "=> to #{menu_item.aro_file.class}(#{menu_item.aro_file.uuid})",
255
- # "=> in #{Aro::Dom::DataBase.name} #{menu_item.aro_file.aro_file_path}",
256
- # "=> for #{menu_item.class}(#{menu_item.uuid})"
257
- # ].join("\n"))
258
-
259
- # menu_item.aro_file.write!({tty_name: new_name})
344
+ new_action_data = {
345
+ plugin_file_path: plugin_file_path,
346
+ oss_om_type: action_data["oss_om_type"].to_s
347
+ }
348
+ Aro::P.say("enabled #{plugin_file_path} plugin.")
349
+ puts JSON.pretty_generate(new_action_data)
350
+ chapter_menu_item.aro_file.write!({
351
+ action_data: new_action_data
352
+ })
260
353
  end
261
354
 
262
- private
355
+ def self.design_schema_for(chapter_menu_item)
356
+ action_data = chapter_menu_item.store.safe_get_key("action_data") || {}
357
+ raise "missing action data for #{chapter_menu_item.inspect}!" if action_data.nil? ||
358
+ !action_data.kind_of?(Hash)
359
+
360
+ action_data = ensure_action_data_oss_om_type_exists!(action_data)
361
+
362
+ return design_plugin_for(chapter_menu_item) if action_data["oss_om_type"].to_s == :plugin.to_s
363
+
364
+ action_data_copy = action_data.except(:oss_om_type.to_s).dup
365
+ loop do
366
+ options = [
367
+ {name: :back, value: :back},
368
+ {name: "new_key(+)", value: :new_key}
369
+ ] + action_data_copy.map{|k, v|
370
+ {name: "#{k}(#{v})", value: k}
371
+ } + [
372
+ {name: :save, value: :save},
373
+ ]
374
+
375
+ selected_option = Aro::P.default_select(
376
+ I18n.t("open_menu.design_schema_for", localized_name: chapter_menu_item.localized_name),
377
+ options
378
+ )
379
+
380
+ case selected_option.to_sym
381
+ when :back
382
+ confirmed = true
383
+ if action_data_copy.any?{|k, v| action_data[k] != v} ||
384
+ (action_data_copy.keys & action_data.keys).count != action_data.keys.count
385
+ confirmed = get_new_value_from_user(
386
+ "unsaved changes exist. leave schema designer?",
387
+ "press enter to confirm ('n' to cancel):"
388
+ ).nil?
389
+ end
390
+ break if confirmed
391
+ when :save
392
+ action_data_copy[:oss_om_type.to_s] = action_data["oss_om_type"].to_s
393
+ chapter_menu_item.aro_file.write!({
394
+ action_data: action_data_copy
395
+ })
396
+ break
397
+ when :new_key
398
+ # create new key
399
+ new_key = get_new_value_from_user("enter new key: ")
400
+ next if new_key.nil?
401
+ if action_data_copy.keys.include?(new_key)
402
+ # confirm overwrite?
403
+ confirm_overwrite = get_new_value_from_user(
404
+ "key #{new_key} already exists.",
405
+ "press enter to confirm ('n' to cancel):"
406
+ )
407
+ unless confirm_overwrite.nil?
408
+ Aro::P.say("user cancelled")
409
+ next
410
+ end
411
+ end
412
+ action_data_copy[new_key] = get_new_value_from_user(
413
+ "enter new value for #{new_key}:",
414
+ )
415
+ Aro::P.say("set #{new_key} to #{action_data_copy[new_key]}")
416
+ else
417
+ # edit selected key
418
+ action_data_copy[selected_option] = get_new_value_from_user(
419
+ "enter new value for #{selected_option}:",
420
+ )
421
+ Aro::P.say("set #{selected_option} to #{action_data_copy[selected_option]}")
422
+ end
423
+ end
263
424
 
264
- def self.get_new_value_from_user(ask_text)
425
+ Aro::Dom::Ma_ain.navigate_to!(chapter_menu_item.menu)
426
+ end
427
+
428
+ def self.get_new_value_from_user(ask_text, prompt_text_override = nil)
265
429
  Aro::P.say(__method__)
266
430
  new_val = nil
267
431
  user_cancelled = false
268
432
  while new_val.nil? && !user_cancelled
269
433
  Aro::P.say(ask_text)
270
- new_val = Aro::P.p.ask(I18n.t("open_menu.get_new_value_from_user"))
434
+ puts "\n"
435
+ new_val = Aro::P.p.ask(prompt_text_override || I18n.t("open_menu.get_new_value_from_user"))
271
436
  user_cancelled = new_val.nil? || new_val.empty?
272
437
  new_val = nil if user_cancelled
273
438
  end
274
439
 
275
- return user_cancelled if user_cancelled
440
+ return nil if user_cancelled
276
441
  return new_val
277
442
  end
278
443
 
444
+ private
445
+
446
+ def self.ensure_action_data_oss_om_type_exists!(data)
447
+ unless data.keys.include?(:oss_om_type.to_s)
448
+ # ensure oss_om_type is set
449
+ options = [
450
+ {name: :key_value_store, value: :key_value_store},
451
+ {name: :plugin, value: :plugin}
452
+ ]
453
+
454
+ selected_option = Aro::P.default_select(
455
+ "select chapter schema oss_om_type: ",
456
+ options
457
+ )
458
+
459
+ case selected_option.to_sym
460
+ when :key_value_store, :plugin
461
+ data["oss_om_type"] = selected_option.to_s
462
+ end
463
+ end
464
+
465
+ data
466
+ end
467
+
279
468
  end
280
469
  end
281
470
  end