card 1.96.1 → 1.96.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/locales/de.yml +18 -23
  4. data/config/locales/en.yml +16 -21
  5. data/config/locales/es.yml +16 -21
  6. data/lib/card.rb +1 -3
  7. data/lib/card/codename.rb +2 -1
  8. data/lib/card/error.rb +73 -57
  9. data/lib/card/format.rb +2 -2
  10. data/lib/card/format/error.rb +17 -18
  11. data/lib/card/format/nesting/mode.rb +1 -1
  12. data/lib/card/format/permission.rb +8 -10
  13. data/lib/card/format/render.rb +1 -2
  14. data/lib/card/model/save_helper.rb +20 -12
  15. data/lib/card/query.rb +1 -1
  16. data/lib/card/query/card_query.rb +2 -2
  17. data/lib/card/query/card_query/found_by.rb +43 -0
  18. data/lib/card/query/card_query/match_attributes.rb +72 -0
  19. data/lib/card/query/card_query/relational_attributes.rb +19 -0
  20. data/lib/card/view.rb +0 -1
  21. data/lib/card/view/cache_action.rb +1 -10
  22. data/mod/account/set/right/token.rb +1 -3
  23. data/mod/account/set/self/account_links.rb +9 -12
  24. data/mod/basic_formats/set/all/json.rb +19 -54
  25. data/mod/basic_formats/spec/set/all/json_spec.rb +13 -3
  26. data/mod/basic_formats/spec/shared_context/json_shared_context.rb +3 -8
  27. data/mod/basic_types/set/type/json.rb +13 -1
  28. data/mod/bootstrap/set/abstract/bootswatch_theme/html_views.rb +0 -1
  29. data/mod/bootstrap/set/all/bootstrap/helper.rb +7 -0
  30. data/mod/bootstrap/set/self/script_bootstrap.rb +1 -2
  31. data/mod/core/set/all/content.rb +4 -6
  32. data/mod/core/set/all/export.rb +39 -15
  33. data/mod/core/set/all/fetch.rb +9 -0
  34. data/mod/core/set/all/permissions.rb +0 -4
  35. data/mod/core/set/all/phases.rb +1 -1
  36. data/mod/core/set/all/subcards.rb +1 -0
  37. data/mod/core/set/all/trash.rb +6 -2
  38. data/mod/core/set/all/type.rb +1 -1
  39. data/mod/core/set/all/utils.rb +13 -1
  40. data/mod/core/spec/set/all/fetch_spec.rb +17 -4
  41. data/mod/history/set/all/history.rb +34 -57
  42. data/mod/history/set/all/{act_view.rb → history/act_listing.rb} +0 -13
  43. data/mod/history/set/all/history/actions.rb +119 -0
  44. data/mod/history/set/all/history/acts.rb +12 -0
  45. data/mod/history/set/all/history/events.rb +94 -0
  46. data/mod/history/set/all/history/last.rb +97 -0
  47. data/mod/history/set/all/history/revision.rb +54 -0
  48. data/mod/history/set/all/history/selected.rb +64 -0
  49. data/mod/history/set/all/history/views.rb +34 -0
  50. data/mod/history/spec/set/all/history/views_spec.rb +29 -0
  51. data/mod/item/spec/set/all/bar_spec.rb +2 -2
  52. data/mod/machines/file/all_script_machine_output/file.js +66 -30621
  53. data/mod/machines/file/all_style_machine_output/file.css +2 -2
  54. data/mod/machines/file/script_html5shiv_printshiv_machine_output/file.js +1 -1
  55. data/mod/machines/lib/javascript/decko.js.coffee +1 -1
  56. data/mod/pointer/lib/javascript/script_pointer_config.js.coffee +1 -1
  57. data/mod/pointer/set/abstract/01_paging.rb +1 -0
  58. data/mod/pointer/set/abstract/02_pointer/html_views.rb +2 -2
  59. data/mod/pointer/set/abstract/02_pointer/html_views/checkbox_input.haml +2 -2
  60. data/mod/pointer/set/abstract/02_pointer/html_views/filter/filter_items.haml +1 -1
  61. data/mod/pointer/set/abstract/02_pointer/html_views/radio_input.haml +4 -4
  62. data/mod/pointer/set/abstract/02_pointer/options_api.rb +25 -1
  63. data/mod/pointer/set/abstract/02_pointer/other_views.rb +4 -0
  64. data/mod/pointer/spec/set/abstract/pointer/options_api_spec.rb +35 -0
  65. data/mod/search/set/abstract/search.rb +4 -114
  66. data/mod/search/set/abstract/search/views.rb +156 -0
  67. data/mod/search/set/abstract/wql_search.rb +10 -0
  68. data/mod/search/set/self/search.rb +3 -10
  69. data/mod/search/set/type/search_type.rb +5 -1
  70. data/mod/search/template/abstract/03_filter/filter_form.haml +1 -1
  71. data/mod/standard/set/all/error.rb +24 -192
  72. data/mod/standard/set/all/rich_html/content.rb +1 -1
  73. data/mod/standard/set/all/rich_html/error.rb +177 -0
  74. data/mod/standard/{template/all → set/all/rich_html}/error/not_found.haml +0 -0
  75. data/mod/standard/{template/all → set/all/rich_html}/error/server_error.haml +0 -0
  76. data/mod/standard/set/all/rich_html/form.rb +9 -9
  77. data/mod/standard/set/all/rich_html/menu.rb +14 -5
  78. data/mod/standard/spec/content/chunk/include_spec.rb +1 -2
  79. data/mod/standard/spec/set/type/search_type_spec.rb +1 -1
  80. data/mod/utility/set/abstract/bs_badge/bs_badge.haml +1 -1
  81. data/mod/utility/set/abstract/media.rb +3 -1
  82. metadata +20 -16
  83. data/lib/card/query/card_query/attribute_helper.rb +0 -74
  84. data/lib/card/query/card_query/special_attributes.rb +0 -49
  85. data/mod/history/set/all/action_view.rb +0 -52
  86. data/mod/history/set/all/actions.rb +0 -185
  87. data/mod/history/set/all/acts.rb +0 -16
  88. data/mod/history/set/all/content_history.rb +0 -180
  89. data/mod/history/spec/set/all/act_view_spec.rb +0 -16
  90. data/mod/history/spec/set/all/action_view_spec.rb +0 -10
  91. data/mod/history/spec/set/all/history_spec.rb +0 -11
@@ -29,7 +29,7 @@ format :html do
29
29
  end
30
30
 
31
31
  def button_formgroup
32
- wrap_with :div, class: "form-group" do
32
+ wrap_with :div, class: classy("form-group") do
33
33
  wrap_with :div, yield
34
34
  end
35
35
  end
@@ -92,10 +92,14 @@ format :html do
92
92
 
93
93
  # test: are we opening a new multi-card form?
94
94
  def multi_card_editor?
95
- nests_editor? || # editor configured in voo
96
- voo.structure || voo.edit_structure || # structure configured in voo
97
- card.structure || # structure in card rule
98
- edit_fields.present? # list of fields in card rule
95
+ voo.structure || voo.edit_structure || # structure configured in voo
96
+ card.structure || # structure in card rule
97
+ edit_fields? # list of fields in card rule
98
+ end
99
+
100
+ # override and return true to optimize
101
+ def edit_fields?
102
+ edit_fields.present?
99
103
  end
100
104
 
101
105
  # test: are we already within a multi-card form?
@@ -103,10 +107,6 @@ format :html do
103
107
  @in_multi_card_editor.present?
104
108
  end
105
109
 
106
- def nests_editor?
107
- voo.editor == :nests
108
- end
109
-
110
110
  def single_card_edit_field
111
111
  if voo.show?(:type_formgroup) || voo.show?(:name_formgroup)
112
112
  # display content field in formgroup for consistency with other fields
@@ -14,22 +14,31 @@ format :html do
14
14
  end
15
15
 
16
16
  def wrap_menu
17
- wrap_with :div, class: classy(%w(menu-slot nodblclick)) do
17
+ wrap_with :div, class: classy(%w[menu-slot nodblclick]) do
18
18
  yield
19
19
  end
20
20
  end
21
21
 
22
22
  view :menu_link do
23
- css_class =
24
- show_view?(:horizontal_menu, :hide) ? "d-sm-none" : "_show-on-hover"
23
+ menu_link
24
+ end
25
25
 
26
- wrap_with :div, class: "vertical-card-menu card-menu #{css_class}" do
26
+ def menu_link
27
+ wrap_with :div, class: "vertical-card-menu card-menu #{menu_link_classes}" do
27
28
  wrap_with :div, class: "btn-group slotter card-slot float-right" do
28
29
  link_to_view :vertical_menu, menu_icon, path: menu_link_path_opts
29
30
  end
30
31
  end
31
32
  end
32
33
 
34
+ def menu_link_classes
35
+ if show_view? :hover_link
36
+ show_view?(:horizontal_menu, :hide) ? "d-sm-none" : "_show-on-hover"
37
+ else
38
+ ""
39
+ end
40
+ end
41
+
33
42
  # this should probably be added in javascript.
34
43
  # the menu link is not a "slotter", because it doesn't replace the whole
35
44
  # slot (it just adds a menu). But it should use the js code that adds slot
@@ -60,7 +69,7 @@ format :html do
60
69
  def vertical_menu_item_list
61
70
  wrap_with :ul, class: "dropdown-menu dropdown-menu-right", role: "menu" do
62
71
  menu_item_list.map do |item|
63
- %{<li>#{item}</li>}
72
+ %(<li>#{item}</li>)
64
73
  end.join("\n").html_safe
65
74
  end
66
75
  end
@@ -154,8 +154,7 @@ describe Card::Content::Chunk::Nest, "Inclusion" do
154
154
  create! "Quentin", "{{Admin}}"
155
155
  adm = Card["Quentin"]
156
156
  adm.update_attributes content: "{{Oak}}"
157
- result = adm.format.render_core
158
- expect(result).to match("too deep")
157
+ expect(adm.format.render_core).to match(/too deep/)
159
158
  end
160
159
 
161
160
  it "handles missing cards" do
@@ -131,7 +131,7 @@ RSpec.describe Card::Set::Type::SearchType do
131
131
 
132
132
  context "with paging" do
133
133
  def paging_url offset
134
- json_url(card_subject.name.url_key, "limit=1&offset=#{offset}")
134
+ json_url card_subject.name.url_key, "item=name&limit=1&offset=#{offset}"
135
135
  end
136
136
 
137
137
  let(:paging_values) do
@@ -1,5 +1,5 @@
1
1
  %span.labeled-badge{ class: klass }
2
2
  %span.badge{ class: "badge-#{color}" }
3
3
  = count
4
- %label.mr-2.text-muted
4
+ %label.mr-2.text-muted.small
5
5
  = label
@@ -13,6 +13,7 @@ format :html do
13
13
  end
14
14
 
15
15
  def text_with_image opts={}
16
+ class_up "media-left", "m-2"
16
17
  @image_card = Card.cardish(opts[:image]) if opts[:image]
17
18
  haml :media_snippet, normalized_text_with_image_opts(opts)
18
19
  end
@@ -26,6 +27,7 @@ format :html do
26
27
  alt: image_alt,
27
28
  size: :original,
28
29
  media_opts: {},
29
- media_left_extras: ""
30
+ media_left_extras: "",
31
+ media_left: ""
30
32
  end
31
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.96.1
4
+ version: 1.96.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-08-20 00:00:00.000000000 Z
14
+ date: 2018-09-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: cardname
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.6.1
22
+ version: 0.6.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.6.1
29
+ version: 0.6.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: haml
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -561,15 +561,15 @@ files:
561
561
  - lib/card/query/act_query.rb
562
562
  - lib/card/query/action_query.rb
563
563
  - lib/card/query/card_query.rb
564
- - lib/card/query/card_query/attribute_helper.rb
565
564
  - lib/card/query/card_query/conjunctions.rb
565
+ - lib/card/query/card_query/found_by.rb
566
566
  - lib/card/query/card_query/interpretation.rb
567
+ - lib/card/query/card_query/match_attributes.rb
567
568
  - lib/card/query/card_query/normalization.rb
568
569
  - lib/card/query/card_query/reference_attributes.rb
569
570
  - lib/card/query/card_query/relational_attributes.rb
570
571
  - lib/card/query/card_query/run.rb
571
572
  - lib/card/query/card_query/sorting.rb
572
- - lib/card/query/card_query/special_attributes.rb
573
573
  - lib/card/query/clause.rb
574
574
  - lib/card/query/join.rb
575
575
  - lib/card/query/reference_query.rb
@@ -4707,15 +4707,16 @@ files:
4707
4707
  - mod/history/lib/card/action/admin.rb
4708
4708
  - mod/history/lib/card/action/differ.rb
4709
4709
  - mod/history/lib/card/change.rb
4710
- - mod/history/set/all/act_view.rb
4711
- - mod/history/set/all/action_view.rb
4712
- - mod/history/set/all/actions.rb
4713
- - mod/history/set/all/acts.rb
4714
- - mod/history/set/all/content_history.rb
4715
4710
  - mod/history/set/all/history.rb
4716
- - mod/history/spec/set/all/act_view_spec.rb
4717
- - mod/history/spec/set/all/action_view_spec.rb
4718
- - mod/history/spec/set/all/history_spec.rb
4711
+ - mod/history/set/all/history/act_listing.rb
4712
+ - mod/history/set/all/history/actions.rb
4713
+ - mod/history/set/all/history/acts.rb
4714
+ - mod/history/set/all/history/events.rb
4715
+ - mod/history/set/all/history/last.rb
4716
+ - mod/history/set/all/history/revision.rb
4717
+ - mod/history/set/all/history/selected.rb
4718
+ - mod/history/set/all/history/views.rb
4719
+ - mod/history/spec/set/all/history/views_spec.rb
4719
4720
  - mod/item/set/all/bar.haml
4720
4721
  - mod/item/set/all/bar.rb
4721
4722
  - mod/item/set/all/box.haml
@@ -4901,6 +4902,7 @@ files:
4901
4902
  - mod/pointer/spec/set/abstract/pointer/events_spec.rb
4902
4903
  - mod/pointer/spec/set/abstract/pointer/html_views_spec.rb
4903
4904
  - mod/pointer/spec/set/abstract/pointer/item_api_spec.rb
4905
+ - mod/pointer/spec/set/abstract/pointer/options_api_spec.rb
4904
4906
  - mod/pointer/spec/set/abstract/pointer/other_views_spec.rb
4905
4907
  - mod/pointer/spec/set/self/input_options_spec.rb
4906
4908
  - mod/prosemirror_editor/db/migrate_core_cards/20160804112548_add_prosemirror_cards.rb
@@ -4919,6 +4921,7 @@ files:
4919
4921
  - mod/search/set/abstract/03_filter.rb
4920
4922
  - mod/search/set/abstract/04_right_filter_form.rb
4921
4923
  - mod/search/set/abstract/search.rb
4924
+ - mod/search/set/abstract/search/views.rb
4922
4925
  - mod/search/set/abstract/wql_search.rb
4923
4926
  - mod/search/set/self/navbox.rb
4924
4927
  - mod/search/set/self/recent.rb
@@ -5017,6 +5020,9 @@ files:
5017
5020
  - mod/standard/set/all/rich_html/content.rb
5018
5021
  - mod/standard/set/all/rich_html/editing.rb
5019
5022
  - mod/standard/set/all/rich_html/editor.rb
5023
+ - mod/standard/set/all/rich_html/error.rb
5024
+ - mod/standard/set/all/rich_html/error/not_found.haml
5025
+ - mod/standard/set/all/rich_html/error/server_error.haml
5020
5026
  - mod/standard/set/all/rich_html/form.rb
5021
5027
  - mod/standard/set/all/rich_html/form_elements.rb
5022
5028
  - mod/standard/set/all/rich_html/formgroup.rb
@@ -5105,8 +5111,6 @@ files:
5105
5111
  - mod/standard/spec/set/type/set_spec.rb
5106
5112
  - mod/standard/spec/set/type/toggle_spec.rb
5107
5113
  - mod/standard/spec/set/type/uri_spec.rb
5108
- - mod/standard/template/all/error/not_found.haml
5109
- - mod/standard/template/all/error/server_error.haml
5110
5114
  - mod/tinymce_editor/db/migrate_core_cards/20160804112560_add_tinymce_cards.rb
5111
5115
  - mod/tinymce_editor/db/migrate_core_cards/20171113233151_update_tinymce_config.rb
5112
5116
  - mod/tinymce_editor/lib/javascript/script_tinymce.js
@@ -1,74 +0,0 @@
1
- class Card
2
- module Query
3
- class CardQuery
4
- # helper methods for relational and special attributes
5
- module AttributeHelper
6
- private
7
-
8
- def tie_action action, val
9
- tie :action, { action => val }, to: :card_id
10
- end
11
-
12
- def tie_act action, val
13
- tie :act, { action => val }, to: :actor_id
14
- end
15
-
16
- def junction val, side, field
17
- tie :card, junction_val(val, side), to: field
18
- end
19
-
20
- def junction_val val, side
21
- part_clause, junction_clause = val.is_a?(Array) ? val : [val, {}]
22
- clause_to_hash(junction_clause).merge side => part_clause
23
- end
24
-
25
- def name_or_content_match val
26
- cxn = connection
27
- or_join([field_match("replace(#{table_alias}.name,'+',' ')", val, cxn),
28
- field_match("#{table_alias}.db_content", val, cxn)])
29
- end
30
-
31
- def field_match field, val, cxn
32
- %(#{field} #{cxn.match quote("[[:<:]]#{val}[[:>:]]")})
33
- end
34
-
35
- def name_like patterns, extra_cond=""
36
- likes =
37
- Array(patterns).map do |pat|
38
- "lower(#{table_alias}.name) LIKE lower(#{quote pat})"
39
- end
40
- add_condition "#{or_join(likes)} #{extra_cond}"
41
- end
42
-
43
- def found_by_statement card
44
- card&.try(:wql_hash) || invalid_found_by_card!(card)
45
- end
46
-
47
- def invalid_found_by_card! card
48
- raise Card::Error::BadQuery, '"found_by" value must be valid Search, ' \
49
- "but #{card.name} is a #{card.type_name}"
50
- end
51
-
52
- def found_by_cards val
53
- if val.is_a? Hash
54
- Query.run val
55
- else
56
- Array.wrap(val).map do |v|
57
- Card.fetch v.to_name.absolute(context), new: {}
58
- end
59
- end
60
- end
61
-
62
- # TODO: use standard conjunction handling
63
-
64
- def or_join conditions
65
- "(#{Array(conditions).join ' OR '})"
66
- end
67
-
68
- def and_join conditions
69
- "(#{Array(conditions).join ' AND '})"
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,49 +0,0 @@
1
- class Card
2
- module Query
3
- class CardQuery
4
- # handle special CQL attributes
5
- module SpecialAttributes
6
- def found_by val
7
- found_by_cards(val).compact.each do |card|
8
- subquery found_by_statement(card).merge(fasten: :direct, context: card.name)
9
- end
10
- end
11
-
12
- # Implements the match attribute that matches always against content and name.
13
- # That's different from the match operator that can be restricted to names or
14
- # content.
15
- # Example: { match: "name or content" } vs. { name: ["match", "a name"] }
16
- def match val
17
- val.gsub!(/[^#{Card::Name::OK4KEY_RE}]+/, " ")
18
- return nil if val.strip.empty?
19
- val.gsub!("*", '\\\\\\\\*')
20
- val_list = val.split(/\s+/).map do |v|
21
- name_or_content_match v
22
- end
23
- add_condition and_join(val_list)
24
- end
25
-
26
- def name_match val
27
- name_like "%#{val}%"
28
- end
29
-
30
- def complete val
31
- no_plus_card = (val =~ /\+/ ? "" : "and #{table_alias}.right_id is null")
32
- # FIXME: -- this should really be more nuanced --
33
- # it breaks down after one plus
34
- name_like "#{val}%", no_plus_card
35
- end
36
-
37
- def junction_complete val
38
- name_like ["#{val}%", "%+#{val}%"]
39
- end
40
-
41
- def extension_type _val
42
- # DEPRECATED LONG AGO!!!
43
- Rails.logger.info "using DEPRECATED extension_type in WQL"
44
- interpret right_plus: AccountID
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,52 +0,0 @@
1
- format :html do
2
- view :action_summary do
3
- action_content action_from_context, :summary
4
- end
5
-
6
- view :action_expanded do
7
- action_content action_from_context, :expanded
8
- end
9
-
10
- def action_from_context
11
- if (action_id = voo.action_id || params[:action_id])
12
- Action.fetch action_id
13
- else
14
- card.last_action
15
- end
16
- end
17
-
18
- def action_content action, view_type
19
- return "" unless action.present?
20
- wrap do
21
- [action_content_toggle(action, view_type),
22
- content_diff(action, view_type)]
23
- end
24
- end
25
-
26
- def content_diff action, view_type
27
- diff = action.new_content? && content_changes(action, view_type)
28
- return "<i>empty</i>" unless diff.present?
29
- diff
30
- end
31
-
32
- def action_content_toggle action, view_type
33
- return unless show_action_content_toggle?(action, view_type)
34
- toggle_action_content_link action, view_type
35
- end
36
-
37
- def show_action_content_toggle? action, view_type
38
- view_type == :expanded || action.summary_diff_omits_content?
39
- end
40
-
41
- def toggle_action_content_link action, view_type
42
- other_view_type = view_type == :expanded ? :summary : :expanded
43
- link_to_view "action_#{other_view_type}",
44
- icon_tag(action_arrow_dir(view_type)),
45
- class: "slotter revision-#{action.card_act_id} float-right",
46
- path: { action_id: action.id, look_in_trash: true }
47
- end
48
-
49
- def action_arrow_dir view_type
50
- view_type == :expanded ? :triangle_left : :triangle_right
51
- end
52
- end
@@ -1,185 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # must be called on all actions and before :set_name, :process_subcards and
4
- # :validate_delete_children
5
- event :assign_action, :initialize, when: :actionable? do
6
- act = director.need_act
7
- @current_action = Card::Action.create(
8
- card_act_id: act.id,
9
- action_type: @action,
10
- draft: (Env.params["draft"] == "true")
11
- )
12
- if @supercard && @supercard != self
13
- @current_action.super_action = @supercard.current_action
14
- end
15
- end
16
-
17
- # can we store an action?
18
- def actionable?
19
- history?
20
- end
21
-
22
- # stores changes in the changes table and assigns them to the current action
23
- # removes the action if there are no changes
24
- event :finalize_action, :finalize, when: :finalize_action? do
25
- if changed_fields.present?
26
- @current_action.update_attributes! card_id: id
27
-
28
- # Note: #last_change_on uses the id to sort by date
29
- # so the changes for the create changes have to be created before the first change
30
- store_card_changes_for_create_action if first_change?
31
- store_card_changes if @current_action.action_type != :create
32
- elsif @current_action.card_changes.reload.empty?
33
- @current_action.delete
34
- @current_action = nil
35
- end
36
- end
37
-
38
- def finalize_action?
39
- actionable? && current_action
40
- end
41
-
42
- event :rollback_actions, :prepare_to_validate, on: :update, when: :rollback_request? do
43
- update_args = process_revert_actions
44
- Env.params["revert_actions"] = nil
45
- update_attributes! update_args
46
- clear_drafts
47
- abort :success
48
- end
49
-
50
- def rollback_request?
51
- history? && actions_to_revert.any?
52
- end
53
-
54
- def process_revert_actions
55
- update_args = { subcards: {} }
56
- reverting_to_previous = Env.params["revert_to"] == "previous"
57
- actions_to_revert.each do |action|
58
- merge_revert_action! action, update_args, reverting_to_previous
59
- end
60
- update_args
61
- end
62
-
63
- def actions_to_revert
64
- Array.wrap(Env.params["revert_actions"]).map do |a_id|
65
- Action.fetch(a_id) || nil
66
- end.compact
67
- end
68
-
69
- def merge_revert_action! action, update_args, reverting_to_previous
70
- rev = action.card.revision(action, reverting_to_previous)
71
- if action.card_id == id
72
- update_args.merge! rev
73
- else
74
- update_args[:subcards][action.card.name] = rev
75
- end
76
- end
77
-
78
- def select_action_by_params params
79
- return unless (action = find_action_by_params(params))
80
- run_callbacks :select_action do
81
- self.selected_action_id = action.id
82
- end
83
- end
84
-
85
- def find_action_by_params args
86
- if args[:rev]
87
- nth_action args[:rev]
88
- elsif args[:rev_id].is_a?(Integer) || args[:rev_id] =~ /^\d+$/
89
- if (action = Action.fetch(args[:rev_id])) && action.card_id == id
90
- action
91
- end
92
- # revision id is probably a mod (e.g. if you request
93
- # files/:logo/standard.png)
94
- elsif args[:rev_id]
95
- last_action
96
- end
97
- end
98
-
99
- def nth_action index
100
- index = index.to_i
101
- return unless id && index > 0
102
- Action.where("draft is not true AND card_id = #{id}")
103
- .order(:id).limit(1).offset(index - 1).first
104
- end
105
-
106
- def revision action, before_action=false
107
- # a "revision" refers to the state of all tracked fields
108
- # at the time of a given action
109
- action = Card::Action.fetch(action) if action.is_a? Integer
110
- return unless action
111
- return revision_before_action action if before_action
112
- Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, attr_changes|
113
- last_change = action.change(field) ||
114
- last_change_on(field, not_after: action)
115
- attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
116
- end
117
- end
118
-
119
- def revision_before_action action
120
- if (prev_action = action.previous_action)
121
- revision prev_action
122
- else
123
- { trash: true }
124
- end
125
- end
126
-
127
- # Delete all changes and old actions and make the last action the create action
128
- # (that way the changes for that action will be created with the first update)
129
- def make_last_action_the_initial_action
130
- delete_all_changes
131
- old_actions.delete_all
132
- last_action.update_attributes! action_type: :create
133
- end
134
-
135
- # # moves for every field the last change to the last action and deletes all other actions
136
- # def clear_history
137
- # Card::Change::TRACKED_FIELDS.each do |field|
138
- # # assign previous changes on each tracked field to the last action
139
- # next unless (la = last_action) && !la.change(field).present? &&
140
- # (last_change = last_change_on field)
141
- # # last_change comes as readonly record
142
- # last_change = Card::Change.find(last_change.id)
143
- # last_change.update_attributes!(card_action_id: last_action_id)
144
- # end
145
- # delete_old_action
146
- # end
147
-
148
- def clear_history
149
- delete_all_changes
150
- delete_old_actions
151
- end
152
-
153
- def delete_old_actions
154
- old_actions.delete_all
155
- end
156
-
157
- def delete_all_changes
158
- Card::Change.where(card_action_id: Card::Action.where(card_id: id).pluck(:id)).delete_all
159
- end
160
-
161
- def old_actions
162
- actions.where("id != ?", last_action_id)
163
- end
164
-
165
- def create_action
166
- @create_action ||= actions.first
167
- end
168
-
169
- # changes for the create action are stored after the first update
170
- def store_card_changes_for_create_action
171
- Card::Change::TRACKED_FIELDS.each do |f|
172
- Card::Change.create field: f,
173
- value: attribute_before_act(f),
174
- card_action_id: create_action.id
175
- end
176
- end
177
-
178
- def store_card_changes
179
- # FIXME: should be one bulk insert
180
- changed_fields.each do |f|
181
- Card::Change.create field: f,
182
- value: self[f],
183
- card_action_id: @current_action.id
184
- end
185
- end