card 1.99.1 → 1.99.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/01_core_extensions/array.rb +1 -0
  4. data/config/initializers/01_core_extensions/persistent_identifiers.rb +1 -1
  5. data/config/initializers/02_patches/zeitwerk.rb +13 -0
  6. data/config/initializers/patches.rb +7 -0
  7. data/config/initializers/recaptcha.rb +1 -2
  8. data/config/initializers/zeitwerk.rb +5 -0
  9. data/config/locales/de.yml +1 -1
  10. data/config/locales/en.yml +1 -1
  11. data/config/locales/es.yml +1 -1
  12. data/db/migrate/20110511221913_require_earlier_migrations.rb +0 -3
  13. data/db/migrate/20141001105348_move_revisions_to_actions.rb +1 -1
  14. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +5 -5
  15. data/db/migrate_core_cards/20141120120605_fix_notification_html_message.rb +1 -1
  16. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +1 -1
  17. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +2 -2
  18. data/db/migrate_core_cards/20150317162412_bootstrap_themes.rb +4 -4
  19. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  20. data/db/migrate_core_cards/20190204195039_add_rule_card.rb +1 -1
  21. data/db/migrate_core_cards/20191008201046_fixture_fix.rb +3 -1
  22. data/db/migrate_core_cards/20191028135243_add_link_editor_to_tiny_mce_config.rb +8 -0
  23. data/db/migrate_core_cards/20191115160748_history_cleanup.rb +27 -0
  24. data/db/migrate_core_cards/20191118145629_codename_fixes.rb +6 -0
  25. data/db/seed/new/card_actions.yml +874 -874
  26. data/db/seed/new/card_acts.yml +2 -2
  27. data/db/seed/new/card_references.yml +2 -2
  28. data/db/seed/new/cards.yml +1576 -1576
  29. data/db/seed/new/schema_migrations_core_cards.yml +8 -0
  30. data/db/seed/test/fixtures/card_actions.yml +1815 -1815
  31. data/db/seed/test/fixtures/card_acts.yml +499 -499
  32. data/db/seed/test/fixtures/card_changes.yml +66 -66
  33. data/db/seed/test/fixtures/card_references.yml +634 -634
  34. data/db/seed/test/fixtures/cards.yml +2730 -2730
  35. data/db/seed/test/fixtures/schema_migrations_core_cards.yml +8 -0
  36. data/db/test_seed.rb +10 -11
  37. data/lib/card.rb +9 -30
  38. data/lib/card/act_manager.rb +0 -2
  39. data/lib/card/auth.rb +0 -5
  40. data/lib/card/auth/current.rb +32 -59
  41. data/lib/card/auth/setup.rb +1 -1
  42. data/lib/card/codename.rb +5 -6
  43. data/lib/card/content.rb +5 -8
  44. data/lib/card/content/chunk.rb +0 -78
  45. data/lib/card/content/chunk/abstract.rb +88 -0
  46. data/lib/card/content/clean.rb +3 -3
  47. data/lib/card/content/diff/{lcs.rb → l_c_s.rb} +5 -7
  48. data/lib/card/content/diff/{processor.rb → l_c_s/processor.rb} +0 -0
  49. data/lib/card/content/parser.rb +1 -1
  50. data/lib/card/dirty.rb +25 -31
  51. data/lib/card/dirty/method_factory.rb +15 -0
  52. data/lib/card/env.rb +0 -3
  53. data/lib/card/error.rb +6 -2
  54. data/lib/card/format.rb +5 -5
  55. data/lib/card/format/nest/fetch.rb +2 -1
  56. data/lib/card/mark.rb +1 -0
  57. data/lib/card/migration.rb +4 -0
  58. data/lib/card/mod.rb +2 -5
  59. data/lib/card/mod/dirs.rb +1 -0
  60. data/lib/card/mod/load_strategy.rb +23 -12
  61. data/lib/card/mod/loader.rb +13 -13
  62. data/lib/card/mod/loader/set_loader.rb +7 -1
  63. data/lib/card/mod/loader/set_pattern_loader.rb +2 -2
  64. data/lib/card/mod/module_template.rb +1 -5
  65. data/lib/card/mod_inflector.rb +16 -0
  66. data/lib/card/model/save_helper.rb +2 -2
  67. data/lib/card/name.rb +2 -2
  68. data/lib/card/name/name_variants.rb +19 -0
  69. data/lib/card/query.rb +4 -2
  70. data/lib/card/query/card_query/reference_attributes.rb +2 -2
  71. data/lib/card/query/sql_statement.rb +4 -0
  72. data/lib/card/set.rb +18 -3
  73. data/lib/card/set/abstract.rb +6 -0
  74. data/lib/card/set/event.rb +13 -11
  75. data/lib/card/set/event/delayed_event.rb +2 -0
  76. data/lib/card/set/format.rb +3 -3
  77. data/lib/card/set/helpers.rb +20 -8
  78. data/lib/card/set/loader.rb +1 -1
  79. data/lib/card/set/pattern.rb +47 -0
  80. data/lib/card/{set_pattern.rb → set/pattern/base.rb} +11 -92
  81. data/lib/card/set/required_field.rb +64 -30
  82. data/lib/card/set/trait.rb +3 -2
  83. data/lib/card/set/type.rb +46 -0
  84. data/lib/card/subcards.rb +0 -4
  85. data/lib/card/tasks/card.rake +1 -0
  86. data/lib/card/tasks/card/migrate.rake +1 -1
  87. data/lib/card/view.rb +2 -7
  88. data/lib/card/view/cache.rb +3 -0
  89. data/lib/card/view/cache/stub.rb +5 -0
  90. data/lib/cardio.rb +73 -46
  91. data/mod/account/set/abstract/accountable.rb +49 -0
  92. data/mod/account/set/all/account.rb +3 -3
  93. data/mod/account/set/right/account.rb +1 -1
  94. data/mod/account/set/self/signin.rb +2 -2
  95. data/mod/account/set/type/role.rb +1 -1
  96. data/mod/account/set/type/signup.rb +2 -2
  97. data/mod/account/set/type/signup/views.rb +1 -1
  98. data/mod/account/set/type/user.rb +1 -1
  99. data/mod/account/spec/set/abstract/accountable_spec.rb +7 -0
  100. data/mod/account/spec/set/all/account_spec.rb +3 -3
  101. data/mod/account/spec/set/right/account_spec.rb +1 -1
  102. data/mod/account/spec/set/type/signup_spec.rb +4 -4
  103. data/mod/admin/set/self/admin.rb +1 -1
  104. data/mod/admin/set/self/admin_info.rb +2 -2
  105. data/mod/admin/set/self/version.rb +1 -1
  106. data/mod/basic_types/set/type/json.rb +4 -0
  107. data/mod/basic_types/spec/set/type/html_spec.rb +1 -1
  108. data/mod/bootstrap/db/migrate_core_cards/data/20181108181219_migrate_classic_skins_to_bootstrap.rb +2 -2
  109. data/mod/bootstrap/lib/bootstrap/component_loader.rb +1 -1
  110. data/mod/bootstrap/lib/stylesheets/style_bootstrap_cards.scss +1 -0
  111. data/mod/bootstrap/set/abstract/bootswatch_theme.rb +1 -1
  112. data/mod/bootstrap/set/all/bootstrap/tabs.rb +4 -4
  113. data/mod/bootstrap/set/type/customized_bootswatch_skin.rb +5 -4
  114. data/mod/carrierwave/config/core_initializers/carrierwave.rb +1 -3
  115. data/mod/carrierwave/lib/carrier_wave/{cardmount.rb → card_mount.rb} +2 -2
  116. data/mod/carrierwave/lib/carrier_wave/file_card_uploader.rb +27 -12
  117. data/mod/carrierwave/set/abstract/attachment.rb +0 -2
  118. data/mod/carrierwave/set/all/file_utils.rb +5 -1
  119. data/mod/carrierwave/set/self/admin.rb +1 -1
  120. data/mod/core/chunk/link.rb +99 -91
  121. data/mod/core/chunk/nest.rb +2 -2
  122. data/mod/core/chunk/query_reference.rb +79 -74
  123. data/mod/core/chunk/view_stub.rb +10 -1
  124. data/mod/core/format/html_format.rb +1 -1
  125. data/mod/core/set/abstract/code_file.rb +6 -6
  126. data/mod/core/set/all/content.rb +1 -1
  127. data/mod/core/set/all/event_conditions.rb +1 -2
  128. data/mod/core/set/all/fetch.rb +22 -19
  129. data/mod/core/set/all/fetch_helper.rb +7 -5
  130. data/mod/core/set/all/initialize.rb +35 -9
  131. data/mod/core/set/all/item.rb +16 -6
  132. data/mod/core/set/all/name.rb +19 -15
  133. data/mod/core/set/all/pattern.rb +4 -0
  134. data/mod/core/set/all/permissions.rb +13 -11
  135. data/mod/core/set/all/rename.rb +1 -0
  136. data/mod/core/set/all/rules.rb +4 -4
  137. data/mod/core/set/all/subcards.rb +36 -1
  138. data/mod/core/set/all/type.rb +1 -1
  139. data/mod/core/set_pattern/03_type.rb +2 -0
  140. data/mod/core/spec/chunk/nest_spec.rb +7 -2
  141. data/mod/core/spec/set/all/fetch_spec.rb +1 -1
  142. data/mod/core/spec/set/all/permissions_spec.rb +11 -12
  143. data/mod/core/spec/set/all/rules_spec.rb +3 -3
  144. data/mod/edit/set/all/bridge.rb +1 -3
  145. data/mod/edit/set/all/bridge/tab_views.rb +0 -7
  146. data/mod/edit/set/all/bridge/tab_visibility.rb +5 -7
  147. data/mod/edit/set/all/form_buttons.rb +1 -1
  148. data/mod/edit/set/all/form_elements.rb +1 -0
  149. data/mod/edit/set/all/new.rb +2 -2
  150. data/mod/edit/spec/set/all/bridge/tab_views_spec.rb +1 -1
  151. data/mod/edit/spec/set/all/{nest_editor → reference_editor/nest_editor}/nest_parser_spec.rb +1 -1
  152. data/mod/edit/spec/set/all/{nest_editor_spec.rb → reference_editor/nest_editor_spec.rb} +6 -3
  153. data/mod/edit/spec/set/all/{nest_image_spec.rb → reference_editor/nest_image_spec.rb} +1 -1
  154. data/mod/email/set/abstract/test_context.rb +1 -1
  155. data/mod/email/set/type/email_template/email_config.rb +1 -1
  156. data/mod/follow/set/all/notify.rb +1 -1
  157. data/mod/follow/set/all/notify/base_views.rb +1 -1
  158. data/mod/follow/set/right/account.rb +8 -6
  159. data/mod/follow/set/right/followers.rb +2 -5
  160. data/mod/follow/set/right/following.rb +1 -1
  161. data/mod/follow/spec/set/all/follow_spec.rb +3 -3
  162. data/mod/follow/spec/set/all/notify_spec.rb +1 -1
  163. data/mod/follow/spec/set/right/followers_spec.rb +2 -2
  164. data/mod/history/lib/card/act.rb +3 -1
  165. data/mod/history/lib/card/action.rb +3 -3
  166. data/mod/history/lib/card/action/admin.rb +0 -11
  167. data/mod/history/set/all/history_bridge.rb +1 -1
  168. data/mod/machines/file/all_script_machine_output/file.js +38415 -69
  169. data/mod/machines/file/all_style_machine_output/file.css +2 -2
  170. data/mod/machines/file/script_html5shiv_printshiv_machine_output/file.js +1 -1
  171. data/mod/machines/lib/javascript/decko/filter.js.coffee +7 -1
  172. data/mod/machines/lib/javascript/decko/filter_links.js.coffee +13 -2
  173. data/mod/machines/lib/javascript/decko/link_editor.js.coffee +64 -0
  174. data/mod/machines/lib/javascript/decko/mod.js.coffee +3 -0
  175. data/mod/machines/lib/javascript/decko/nest_editor.js.coffee +49 -29
  176. data/mod/machines/lib/javascript/decko/nest_editor_name.js.coffee +30 -7
  177. data/mod/machines/lib/javascript/decko/slot.js.coffee +4 -1
  178. data/mod/machines/lib/stylesheets/style_cards.scss +31 -19
  179. data/mod/machines/set/abstract/machine/output_cache.rb +1 -1
  180. data/mod/machines/set/abstract/machine/output_update.rb +1 -1
  181. data/mod/machines/set/all/reset_machines.rb +2 -2
  182. data/mod/machines/set/self/script_decko.rb +1 -0
  183. data/mod/media/set/abstract/media.rb +1 -1
  184. data/mod/media/set/type/image.rb +1 -1
  185. data/mod/navbar/set/abstract/account_dropdown.rb +5 -1
  186. data/mod/navbar/set/right/enabled_roles.rb +1 -1
  187. data/mod/navbar/set/self/account_links.rb +1 -1
  188. data/mod/pointer/set/abstract/02_pointer.rb +1 -1
  189. data/mod/pointer/set/abstract/02_pointer/events.rb +30 -10
  190. data/mod/pointer/set/abstract/02_pointer/html_views.rb +6 -2
  191. data/mod/pointer/set/abstract/02_pointer/html_views/autocomplete_input.haml +1 -1
  192. data/mod/pointer/set/abstract/02_pointer/html_views/filter.rb +1 -1
  193. data/mod/pointer/set/abstract/02_pointer/item_api.rb +51 -31
  194. data/mod/pointer/set/abstract/id_pointer.rb +21 -0
  195. data/mod/pointer/set/type/link_list.rb +1 -1
  196. data/mod/pointer/set/type/mirror_list.rb +1 -1
  197. data/mod/pointer/set/type/mirrored_list.rb +2 -2
  198. data/mod/pointer/spec/set/abstract/paging_params_spec.rb +1 -1
  199. data/mod/pointer/spec/set/abstract/pointer/item_api_spec.rb +1 -1
  200. data/mod/recaptcha/set/all/recaptcha.rb +4 -9
  201. data/mod/rules/set/rule/editor.rb +2 -2
  202. data/mod/rules/set/type/set/html_views/rule_lists.rb +1 -1
  203. data/mod/rules/spec/set/type/set_spec.rb +1 -1
  204. data/mod/search/set/abstract/03_filter/filter_form.haml +1 -1
  205. data/mod/search/set/abstract/03_filter/filter_form.rb +23 -2
  206. data/mod/search/set/abstract/03_filter/quick_filters.haml +7 -10
  207. data/mod/search/template/abstract/search/checkbox_item.haml +5 -6
  208. data/mod/settings/set/abstract/permission.rb +2 -2
  209. data/mod/settings/set/right/input_type.rb +3 -3
  210. data/mod/settings/set/right/structure.rb +1 -1
  211. data/mod/settings/set/right/style.rb +1 -1
  212. data/mod/settings/set/type/setting.rb +2 -2
  213. data/mod/standard/set/all/rich_html/html_views/guide.rb +1 -1
  214. data/mod/standard/set/all/rich_html/menu.rb +6 -5
  215. data/mod/standard/set/self/cardtype.rb +1 -1
  216. data/mod/standard/set/type/cardtype.rb +33 -17
  217. data/mod/standard/set/type/session.rb +12 -0
  218. data/mod/standard/spec/set/type/email_template/email_config_spec.rb +1 -2
  219. data/mod/standard/spec/set/type/email_template_spec.rb +1 -3
  220. data/mod/tinymce_editor/lib/javascript/script_tinymce_config.js.coffee +3 -2
  221. data/mod/tinymce_editor/public/assets/tinymce/plugins/nest/plugin.min.js +1 -1
  222. data/mod/tinymce_editor/set/all/reference_editor.rb +23 -0
  223. data/mod/tinymce_editor/set/all/reference_editor/_link_editor.haml +18 -0
  224. data/mod/tinymce_editor/set/all/reference_editor/_nest_editor.haml +17 -0
  225. data/mod/tinymce_editor/set/all/reference_editor/link_editor.rb +33 -0
  226. data/mod/tinymce_editor/set/all/reference_editor/link_editor/link_parser.rb +35 -0
  227. data/mod/tinymce_editor/set/all/reference_editor/nest_editor.rb +174 -0
  228. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_help.haml +0 -0
  229. data/mod/tinymce_editor/set/all/reference_editor/nest_editor/_options.haml +12 -0
  230. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select.haml +0 -0
  231. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/_options_select_row.haml +0 -0
  232. data/mod/{edit/set/all → tinymce_editor/set/all/reference_editor}/nest_editor/nest_parser.rb +7 -1
  233. data/mod/tinymce_editor/set/all/reference_editor/nest_image.rb +70 -0
  234. data/mod/tinymce_editor/set/all/reference_editor/reference_editor.haml +18 -0
  235. metadata +39 -21
  236. data/mod/account/set/abstract/accounted.rb +0 -15
  237. data/mod/edit/set/all/bridge/account_section.rb +0 -16
  238. data/mod/edit/set/all/nest_editor.rb +0 -122
  239. data/mod/edit/set/all/nest_editor/_options.haml +0 -12
  240. data/mod/edit/set/all/nest_editor/nest_editor.haml +0 -31
  241. data/mod/edit/set/all/nest_image.rb +0 -37
@@ -1,5 +1,5 @@
1
1
  def fetch_cache_card input_card, new=nil
2
- new &&= { type_id: PlainTextID }
2
+ new &&= { type_id: Card::PlainTextID }
3
3
  Card.fetch input_card.name, name, :machine_cache, new: new
4
4
  end
5
5
 
@@ -19,7 +19,7 @@ def update_machine_output
19
19
  end
20
20
 
21
21
  def ensure_machine_output
22
- output = fetch trait: :machine_output
22
+ output = fetch :machine_output
23
23
  return if output&.selected_content_action_id
24
24
  update_machine_output
25
25
  end
@@ -5,7 +5,7 @@ module ClassMethods
5
5
  if card
6
6
  card.update_columns trash: true
7
7
  card.expire
8
- Card::Virtual.where(right_id: MachineCacheID).delete_all
8
+ Card::Virtual.where(right_id: Card::MachineCacheID).delete_all
9
9
  end
10
10
  end
11
11
  end
@@ -16,7 +16,7 @@ module ClassMethods
16
16
  card.update_columns trash: true
17
17
  card.expire
18
18
  end
19
- Card::Virtual.where(right_id: MachineCacheID).delete_all
19
+ Card::Virtual.where(right_id: Card::MachineCacheID).delete_all
20
20
  end
21
21
  end
22
22
  end
@@ -4,6 +4,7 @@ def source_files
4
4
  %w[mod editor name_editor autosave doubleclick layout navbox upload
5
5
  slot modal overlay recaptcha slotter bridge
6
6
  nest_editor nest_editor_rules nest_editor_options nest_editor_name
7
+ link_editor
7
8
  components decko follow card_menu slot_ready
8
9
  filter filter_links filter_items].map do |n|
9
10
  "decko/#{n}.js.coffee"
@@ -1,6 +1,6 @@
1
1
  format :html do
2
2
  def image_card
3
- @image_card ||= card.fetch(trait: :image, new: {})
3
+ @image_card ||= card.fetch(:image, new: {})
4
4
  end
5
5
 
6
6
  def text_with_image opts={}
@@ -33,6 +33,6 @@ format :html do
33
33
  end
34
34
 
35
35
  def image_box_title
36
- image_box_card_name
36
+ voo.title || image_box_card_name
37
37
  end
38
38
  end
@@ -8,11 +8,15 @@ format :html do
8
8
  split_button link_to_mycard, nil do
9
9
  [
10
10
  link_to_card([Auth.current, :account_settings], "Account"),
11
- (["Roles", role_items(&render_role_item)] unless Auth.no_special_roles?)
11
+ (["Roles", role_items(&render_role_item)] if special_roles?)
12
12
  ]
13
13
  end
14
14
  end
15
15
 
16
+ def special_roles?
17
+ Auth.current_roles.size > 1
18
+ end
19
+
16
20
  def role_items
17
21
  Auth.current_roles.map do |role_name|
18
22
  yield role_name
@@ -43,7 +43,7 @@ format :html do
43
43
  end
44
44
 
45
45
  def hidden_form_tags _action, opts
46
- "#{super} #{hidden_tags card: { type_id: SessionID }}"
46
+ "#{super} #{hidden_tags card: { type_id: Card::SessionID }}"
47
47
  end
48
48
 
49
49
  def checkbox_input
@@ -67,7 +67,7 @@ format :html do
67
67
  end
68
68
 
69
69
  def enabled_roles_card
70
- Auth.current.fetch trait: :enabled_roles, new: { type_id: SessionID }
70
+ Auth.current.fetch :enabled_roles, new: { type_id: Card::SessionID }
71
71
  end
72
72
 
73
73
  def role_list
@@ -5,5 +5,5 @@ def diff_args
5
5
  end
6
6
 
7
7
  def count
8
- all_raw_item_strings.size
8
+ item_strings.size
9
9
  end
@@ -22,29 +22,49 @@ end
22
22
  # it' still pointer content. The "when" clause helps with that (but is a hack)
23
23
  event :standardize_items, :prepare_to_validate,
24
24
  on: :save, changed: :content, when: :still_pointer? do
25
- self.content = item_names(context: :raw).map do |name|
26
- "[[#{name}]]"
27
- end.join "\n"
25
+ items_to_content item_strings
28
26
  end
29
27
 
30
28
  def still_pointer?
31
29
  type_id == Card::PointerID
32
30
  end
33
31
 
34
- stage_method :changed_item_names do
32
+ def changed_item_names
35
33
  dropped_item_names + added_item_names
36
34
  end
37
35
 
38
- stage_method :dropped_item_names do
39
- old_items = item_names content: db_content_before_act
36
+ def dropped_item_names
37
+ return item_names if trash
38
+ return [] unless (old_content = db_content_before_act)
39
+
40
+ old_items = item_names content: old_content
40
41
  old_items - item_names
41
42
  end
42
43
 
43
- stage_method :added_item_names do
44
- old_items = item_names content: db_content_before_act
44
+ def added_item_names
45
+ return [] if trash
46
+ return item_names unless (old_content = db_content_before_act)
47
+
48
+ old_items = item_names content: old_content
45
49
  item_names - old_items
46
50
  end
47
51
 
48
- stage_method :changed_item_cards do
49
- item_cards content: changed_item_names
52
+ # TODO: refactor. many of the above could be written more elegantly with improved
53
+ # handling of :content in item_names. If content is nil here, we would expect an
54
+ # empty set of cards, but in fact we get items based on self.content.
55
+
56
+ def changed_item_cards
57
+ dropped_item_cards + added_item_cards
58
+ end
59
+
60
+ def dropped_item_cards
61
+ return [] unless db_content_before_act
62
+
63
+ all_item_cards item_names: dropped_item_names
64
+ end
65
+
66
+ def added_item_cards
67
+ return item_cards unless db_content_before_act
68
+
69
+ all_item_cards item_names: added_item_names
50
70
  end
@@ -98,14 +98,18 @@ format :html do
98
98
  slot_selector: filtered_list_slot_class,
99
99
  item_selector: "_filtered-list-item",
100
100
  slot: { hide: [:modal_footer] },
101
- filter: { not_ids: card.item_ids.map(&:to_s).join(",") } }
101
+ filter: { not_ids: not_ids_value } }
102
+ end
103
+
104
+ def not_ids_value
105
+ card.item_ids.map(&:to_s).join(",")
102
106
  end
103
107
 
104
108
  def add_item_overlay_link; end
105
109
 
106
110
  def one_line_content
107
111
  if count == 1
108
- card.item_names.first
112
+ card.first_name
109
113
  else
110
114
  short_content
111
115
  end
@@ -1,3 +1,3 @@
1
1
  .pointer-list-editor.pointer-list-ul
2
2
  = text_field_tag 'pointer_item', item, class: "pointer-item-text form-control",
3
- "data-options-card": @options_card
3
+ "data-options-card": options_card
@@ -48,7 +48,7 @@ format :html do
48
48
  fcard = card.options_rule_card || Card[:all]
49
49
  return fcard if fcard.respond_to? :wql_hash
50
50
 
51
- fcard.fetch trait: :referred_to_by, new: {}
51
+ fcard.fetch :referred_to_by, new: {}
52
52
  end
53
53
 
54
54
  def filter_card_from_params
@@ -13,11 +13,24 @@
13
13
  # @option args [String, Integer] :limit max number of cards to return
14
14
  # @option args [String, Integer] :offset begin after the offset-th item
15
15
  def item_names args={}
16
- raw_item_strings(args[:content], args[:limit], args[:offset]).map do |item|
17
- clean_item_name item, args[:context]
16
+ context = args[:context]
17
+ item_strings(args).map do |item|
18
+ clean_item_name item, context
18
19
  end.compact
19
20
  end
20
21
 
22
+ def first_name args={}
23
+ item_names(args).first
24
+ end
25
+
26
+ def first_card args={}
27
+ fetch_item_card first_name, args
28
+ end
29
+
30
+ def first_code
31
+ first_card&.codename
32
+ end
33
+
21
34
  # @return [Array] list of integers (card ids of items)
22
35
  # @param args [Hash] see #item_names
23
36
  def item_ids args={}
@@ -47,23 +60,24 @@ end
47
60
  # set card content based on array and save card
48
61
  # @param array [Array] list of strings/names (Cardish)
49
62
  def items= array
50
- self.content = ""
51
- array.each { |i| self << i }
63
+ items_to_content array
52
64
  save!
53
65
  end
54
66
 
55
67
  # append item to list (does not save)
56
68
  # @param item [Cardish]
57
- def << item
58
- add_item Card::Name[item]
69
+ def << cardish
70
+ add_item cardish
59
71
  end
60
72
 
61
73
  # append item to list (does not save)
62
- # @param name [String, Card::Name] item name
74
+ # @param cardish [String, Card::Name] item name
63
75
  # @param allow_duplicates [True/False] permit duplicate items (default is False)
64
- def add_item name, allow_duplicates=false
65
- return if !allow_duplicates && include_item?(name)
66
- self.content = "[[#{(item_names << name).reject(&:blank?) * "]]\n[["}]]"
76
+ def add_item cardish, allow_duplicates=false
77
+ return if !allow_duplicates && include_item?(cardish)
78
+
79
+ items = item_strings << cardish
80
+ items_to_content items
67
81
  end
68
82
 
69
83
  # append item to list and save card
@@ -74,11 +88,9 @@ end
74
88
 
75
89
  # remove item from list
76
90
  # @param name [String, Card::Name] item name
77
- def drop_item name
78
- return unless include_item? name
79
- key = name.to_name.key
80
- new_names = item_names.reject { |n| n.to_name.key == key }
81
- self.content = new_names.empty? ? "" : "[[#{new_names * "]]\n[["}]]"
91
+ def drop_item cardish
92
+ drop_item_name = Card::Name[cardish]
93
+ items_to_content(item_names.reject { |item_name| item_name == drop_item_name })
82
94
  end
83
95
 
84
96
  # remove item from list and save card
@@ -95,7 +107,7 @@ def insert_item index, name
95
107
  new_names = item_names
96
108
  new_names.delete name
97
109
  new_names.insert index, name
98
- self.content = new_names.map { |new_name| "[[#{new_name}]]" }.join "\n"
110
+ items_to_content new_names
99
111
  end
100
112
 
101
113
  # insert item into list at specified location and save
@@ -121,14 +133,8 @@ def known_item_cards args={}
121
133
  end
122
134
 
123
135
  def all_item_cards args={}
124
- item_names(args).map do |name|
125
- Card.fetch name, new: new_unknown_item_args(args)
126
- end
127
- end
128
-
129
- def new_unknown_item_args args
130
- itype = args[:type] || item_type
131
- itype ? { type: itype } : {}
136
+ names = args[:item_names] || item_names(args)
137
+ names.map { |name| fetch_item_card name, args }
132
138
  end
133
139
 
134
140
  # TODO: support type_code and type_id. (currently type)
@@ -140,24 +146,38 @@ def item_type
140
146
  opt.item_type
141
147
  end
142
148
 
143
- # #item_names helpers
149
+ def item_strings args={}
150
+ items = raw_item_strings(args[:content] || content)
151
+ return items unless args.present?
152
+
153
+ filtered_items items, args.slice(:limit, :offset)
154
+ end
155
+
156
+ def raw_item_strings content
157
+ content.to_s.split(/\n+/).map { |i| strip_item i }
158
+ end
159
+
160
+ private
144
161
 
145
- def raw_item_strings content, limit, offset
146
- items = all_raw_item_strings content
162
+ def filtered_items items, limit: 0, offset: 0
147
163
  limit = limit.to_i
148
164
  offset = offset.to_i
149
165
  return items unless limit.positive? || offset.positive?
166
+
150
167
  items[offset, (limit.zero? ? items.size : limit)] || []
151
168
  end
152
169
 
153
- def all_raw_item_strings content=nil
154
- (content || self.content).to_s.split(/\n+/)
170
+ def fetch_item_card name, args={}
171
+ Card.fetch name, new: new_unknown_item_args(args)
155
172
  end
156
173
 
157
- private
174
+ def new_unknown_item_args args
175
+ itype = args[:type] || item_type
176
+ itype ? { type: itype } : {}
177
+ end
158
178
 
159
179
  def clean_item_name item, context
160
- item = strip_item(item).to_name
180
+ item = item.to_name
161
181
  return item if context == :raw
162
182
  context ||= context_card.name
163
183
  item.absolute_name context
@@ -0,0 +1,21 @@
1
+ # store items as ids, not names
2
+
3
+ def standardize_item cardish
4
+ if (id = Card.fetch_id cardish)
5
+ "~#{id}"
6
+ else
7
+ Rails.logger.info "no id for '#{cardish}' added to id pointer"
8
+ nil
9
+ end
10
+ end
11
+
12
+ def item_ids args={}
13
+ item_strings(args).map do |item|
14
+ item = standardize_item item unless item.match?(/^~/)
15
+ item.to_s.tr("~", "").to_i
16
+ end.compact
17
+ end
18
+
19
+ def item_names args={}
20
+ item_ids(args).map(&:cardname).compact
21
+ end
@@ -1,6 +1,6 @@
1
1
  include_set Abstract::Pointer
2
2
 
3
- def all_raw_item_strings content=nil
3
+ def raw_item_strings content
4
4
  reference_chunks(content).map(&:referee_name)
5
5
  end
6
6
 
@@ -1,7 +1,7 @@
1
1
  include_set Abstract::Pointer
2
2
 
3
3
  event :validate_listed_by_name, :validate, on: :save, changing: :name do
4
- if !junction? || !right || right.type_id != CardtypeID
4
+ if !junction? || !right || right.type_id != Card::CardtypeID
5
5
  errors.add :name, tr(:cardtype_right)
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  include_set Abstract::Pointer
2
2
 
3
3
  event :validate_list_name, :validate, on: :save, changed: :name do
4
- errors.add :name, tr(:cardtype_right) unless right&.type_id == CardtypeID
4
+ errors.add :name, tr(:cardtype_right) unless right&.type_id == Card::CardtypeID
5
5
  end
6
6
 
7
7
  event :validate_list_item_type_change, :validate,
@@ -30,7 +30,7 @@ event :create_listed_by_cards, :prepare_to_validate,
30
30
  listed_by_name = "#{item_name}+#{left.type_name}"
31
31
  next if director.main_director.card.key == listed_by_name.to_name.key
32
32
  if !Card[listed_by_name]
33
- add_subcard listed_by_name, type_id: MirrorListID
33
+ add_subcard listed_by_name, type_id: Card::MirrorListID
34
34
  else
35
35
  Card[listed_by_name].update_references_out
36
36
  end
@@ -1,7 +1,7 @@
1
1
  RSpec.describe Card::Set::Abstract::PagingParams do
2
2
  describe "offset_param" do
3
3
  it "doesn't allow anonymous users to use extremely high values" do
4
- Card::Auth.current_id = Card::AnonymousID
4
+ Card::Auth.signin Card::AnonymousID
5
5
  with_params offset: 10_000 do
6
6
  expect { Card[:all].format(:json).offset_param }
7
7
  .to raise_error(Card::Error::PermissionDenied,
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
- describe Card::Set::Abstract::Pointer do
3
+ RSpec.describe Card::Set::Abstract::Pointer do
4
4
  let(:pointer) { Card.new type: "Pointer", content: "[[Busy]]\n[[Body]]" }
5
5
 
6
6
  context "with two items" do
@@ -13,17 +13,12 @@ def human?
13
13
  add_recaptcha_errors result["error-codes"]
14
14
  end
15
15
 
16
- def consider_recaptcha?
17
- true
18
- end
19
-
20
16
  def recaptcha_on?
21
- consider_recaptcha? &&
22
- recaptcha_keys? &&
23
- Env[:controller] &&
24
- !Auth.signed_in? &&
17
+ recaptcha_keys? &&
18
+ Env[:controller] &&
19
+ !Auth.signed_in? &&
20
+ !Auth.always_ok? &&
25
21
  !Auth.needs_setup? &&
26
- !Auth.always_ok? &&
27
22
  Card.toggle(rule(:captcha))
28
23
  end
29
24