card-mod-rules 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ format :html do
2
+ before :open do
3
+ voo.hide :template_closer
4
+ end
5
+
6
+ view :core, cache: :never do
7
+ filtered_rule_list :bar_rule_list
8
+ end
9
+
10
+ view :nest_rules, cache: :never, unknown: true, wrap: :slot do
11
+ filtered_rule_list :quick_edit_rule_list, :field_related_rules, :related, mark: ""
12
+ end
13
+
14
+ view :modal_nest_rules, cache: :never, unknown: true,
15
+ wrap: { modal: { title: "Rules for nest" } } do
16
+ filtered_rule_list :quick_edit_rule_list, :field_related_rules, :self
17
+ end
18
+
19
+ view :bridge_rules_tab, cache: :never do
20
+ filtered_rule_list :pill_rule_list, :common, :related, mark: ""
21
+ end
22
+
23
+ def filtered_rule_list view, *filter_args
24
+ [rules_filter(view, *filter_args),
25
+ render(view)]
26
+ end
27
+
28
+ view :set_label do
29
+ wrap_with :strong, card.label, class: "set-label"
30
+ end
31
+
32
+ Card::Setting.groups.each_key do |group_key|
33
+ view group_key.to_sym do
34
+ next unless card.visible_settings(group_key).present?
35
+
36
+ haml :group_panel, group_key: group_key
37
+ end
38
+ end
39
+
40
+ def setting_group default=:common
41
+ voo&.filter&.to_sym || params[:group]&.to_sym || default
42
+ end
43
+
44
+ view :input do
45
+ "Cannot currently edit Sets" # LOCALIZE
46
+ end
47
+
48
+ view :one_line_content, wrap: {} do
49
+ ""
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ - heading_id = "heading-#{group_key}"
2
+ - collapse_id = "collapse-#{card.name.safe_key}-#{group_key}"
3
+ .card
4
+ .card-header{ role: "tab", id: heading_id }
5
+ %h5.mb-0
6
+ = link_to (Card::Setting.group_names[group_key] || group_key.to_s),
7
+ href: "##{collapse_id}",
8
+ "data-toggle": "collapse", "aria-expanded": "false",
9
+ "data-parent": "#accordion", "aria-controls": collapse_id
10
+ .panel-collapse.collapse{ id: collapse_id,
11
+ role: "tabpanel",
12
+ "aria-labelledby": heading_id }
13
+ .card-body
14
+ = bar_rule_list card.visible_settings(group_key).map(&:codename)
@@ -0,0 +1,42 @@
1
+ format :html do
2
+ view :quick_edit_rule_list, cache: :never, wrap: { slot: { class: "rule-list" } } do
3
+ quick_edit_rule_list setting_list_from_params(:field_related)
4
+ end
5
+
6
+ view :bar_rule_list, cache: :never, wrap: { slot: { class: "rule-list" } } do
7
+ bar_rule_list setting_list_from_params
8
+ end
9
+
10
+ view :pill_rule_list, cache: :never, wrap: { slot: { class: "rule-list" } } do
11
+ pill_rule_list setting_list_from_params
12
+ end
13
+
14
+ def quick_edit_rule_list settings
15
+ list_tag class: "nav nav-pills flex-column bridge-pills" do
16
+ settings.map { |setting| rule_list_item setting, :quick_edit }
17
+ end
18
+ end
19
+
20
+ def pill_rule_list settings
21
+ list_items =
22
+ settings.map { |setting| rule_list_item setting, :rule_bridge_link }
23
+ bridge_pills list_items
24
+ end
25
+
26
+ def bar_rule_list settings
27
+ list_items =
28
+ settings.map { |setting| rule_list_item setting, :bar, hide: :full_name }
29
+ list_items.join("\n").html_safe
30
+ end
31
+
32
+ def rule_list_item setting, view, opts={}
33
+ return "" unless show_view? setting
34
+
35
+ rule_card = card.fetch setting, new: {}
36
+ nest(rule_card, opts.merge(view: view)).html_safe
37
+ end
38
+
39
+ def setting_list_from_params default=:common
40
+ setting_list setting_group(default)
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ format :html do
2
+ view :template_link, cache: :never do
3
+ wrap do
4
+ voo.title = parent.voo.nest_syntax if parent
5
+ "{{#{link_to_template_editor}}}"
6
+ end
7
+ end
8
+
9
+ def link_to_template_editor
10
+ link_to_view :modal_nest_rules, voo.title
11
+ end
12
+ end
@@ -0,0 +1,60 @@
1
+ format :html do
2
+ def rules_filter view, selected_setting=nil, set_options=nil, path_opts={}
3
+ form_tag path(path_opts.merge(view: view)),
4
+ remote: true, method: "get", role: "filter",
5
+ "data-slot-selector": ".card-slot.rule-list",
6
+ class: classy("nodblclick slotter form-inline slim-select2 m-2") do
7
+ output [
8
+ label_tag(:view, icon_tag("filter_list"), class: "mr-2"),
9
+ setting_select(selected_setting),
10
+ set_select(set_options)
11
+ ].flatten
12
+ end
13
+ end
14
+
15
+ def set_select set_options
16
+ return filter_text.html_safe unless set_options
17
+
18
+ [content_tag(:span, "rules that apply to set ...", class: "mx-2 small"),
19
+ set_select_tag(set_options)]
20
+ end
21
+
22
+ def setting_select selected=nil
23
+ select_tag(:group, grouped_options_for_select(setting_options, selected),
24
+ class: "_submit-on-select form-control",
25
+ "data-select2-id": "#{unique_id}-#{Time.now.to_i}")
26
+ end
27
+
28
+ def filter_text
29
+ wrap_with :span, class: "mx-2 small" do
30
+ "rules that apply to #{_render_set_label.downcase}" # LOCALIZE
31
+ end
32
+ end
33
+
34
+ def set_select_tag set_options=:related
35
+ select_tag(:mark, set_select_options(set_options),
36
+ class: "_submit-on-select form-control _close-rule-overlay-on-select",
37
+ "data-minimum-results-for-search": "Infinity",
38
+ "data-select2-id": "#{unique_id}-#{Time.now.to_i}")
39
+ end
40
+
41
+ def selected_set
42
+ params[:set]
43
+ end
44
+
45
+ def set_select_options set_options
46
+ options =
47
+ if set_options == :related
48
+ related_set_options
49
+ else
50
+ [[card.label, card.name.url_key]]
51
+ end
52
+ options_for_select(options, selected_set)
53
+ end
54
+
55
+ def related_set_options
56
+ card.related_sets(true).map do |name, label|
57
+ [label, name.to_name.url_key]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,76 @@
1
+ format :html do
2
+ SETTING_OPTIONS = [["Common", :common_rules],
3
+ ["All", :all_rules],
4
+ ["Field", :field_related_rules],
5
+ ["Recent", :recent_rules]].freeze
6
+
7
+ COMMON_SETTINGS = %i[create read update delete structure default guide].freeze
8
+ FIELD_SETTINGS = %i[default help].freeze
9
+
10
+ def setting_options
11
+ [["Categories", SETTING_OPTIONS],
12
+ ["Groups", Card::Setting.group_names.keys],
13
+ ["Single rules", card.visible_setting_codenames]]
14
+ end
15
+
16
+ def field_settings
17
+ %i[default help input_type content_options content_option_view]
18
+ end
19
+
20
+ # @param val setting category, setting group or single setting
21
+ def setting_list val
22
+ category_setting_list(val) || group_setting_list(val) || [val]
23
+ end
24
+
25
+ def group_setting_list group
26
+ card.visible_settings(group).map(&:codename) if Card::Setting.groups[group]
27
+ end
28
+
29
+ def category_setting_list cat
30
+ case cat
31
+ when :all, :all_rules
32
+ card.visible_setting_codenames.sort
33
+ when :recent, :recent_rules
34
+ recent_settings
35
+ when :common, :common_rules
36
+ card.visible_setting_codenames & COMMON_SETTINGS
37
+ when :field_related, :field_related_rules
38
+ field_related_settings
39
+ when :nest_editor_field_related
40
+ nest_editor_field_related_settings
41
+ end
42
+ end
43
+
44
+ def nest_editor_field_related_settings
45
+ field_settings
46
+ # & card.visible_settings(nil, card.prototype_default_type_id).map(&:codename)
47
+ end
48
+
49
+ def field_related_settings
50
+ field_settings # card.visible_setting_codenames &
51
+ end
52
+
53
+ def recent_settings
54
+ recent_settings = Card[:recent_settings].item_cards.map(&:codename)
55
+ recent_settings.map(&:to_sym) & card.visible_setting_codenames
56
+ end
57
+
58
+ view :all_rules_list do
59
+ pill_rule_list card.visible_setting_codenames.sort
60
+ end
61
+
62
+ view :recent_rules_list do
63
+ recent_settings = Card[:recent_settings].item_cards.map(&:codename)
64
+ settings = recent_settings.map(&:to_sym) & card.visible_setting_codenames
65
+ pill_rule_list settings
66
+ end
67
+
68
+ view :common_rules_list do
69
+ settings = card.visible_setting_codenames & COMMON_SETTINGS # "&" = set intersection
70
+ pill_rule_list settings
71
+ end
72
+
73
+ view :field_related_rules_list do
74
+ pill_rule_list field_related_settings
75
+ end
76
+ end
@@ -0,0 +1,79 @@
1
+ # require "json"
2
+
3
+ def self.member_names
4
+ @@member_names ||= begin
5
+ Card.search(
6
+ { type_id: SettingID, return: "key" },
7
+ "all setting cards"
8
+ ).each_with_object({}) do |card_key, hash|
9
+ hash[card_key] = true
10
+ end
11
+ end
12
+ end
13
+
14
+ format :data do
15
+ view :core do
16
+ cql = { left: { type: SetID },
17
+ right: card.id,
18
+ limit: 0 }
19
+ Card.search(cql).compact.map { |c| nest c }
20
+ end
21
+ end
22
+
23
+ def count
24
+ Card.search left: { type: SetID }, right: id, limit: 0, return: :count
25
+ end
26
+
27
+ def set_classes_with_rules
28
+ Card.set_patterns.reverse.map do |set_class|
29
+ rules = rules_for_set_class set_class
30
+ [set_class, rules] unless rules.empty?
31
+ end.compact
32
+ end
33
+
34
+ def rules_for_set_class set_class
35
+ cql = { left: { type: SetID }, right: id, sort: %w[content name], limit: 0 }
36
+ cql[:left][(set_class.anchorless? ? :id : :right_id)] = set_class.pattern_id
37
+ Card.search cql
38
+ end
39
+
40
+ format :html do
41
+ def rule_link rule, text
42
+ link_to_card rule, text, path: { view: :modal_rule },
43
+ slotter: true, "data-modal-class": "modal-lg"
44
+ end
45
+
46
+ view :core do
47
+ haml do
48
+ <<-'HAML'.strip_heredoc
49
+ = _render_rule_help
50
+ %h3 All #{card.name.tr "*", ""} rules that apply to
51
+ - card.set_classes_with_rules.each do |klass, rules|
52
+ %p
53
+ %h5
54
+ = klass.generic_label.downcase
55
+ - if klass.anchorless?
56
+ = nest rules.first, view: :bar, show: :full_name
57
+ - else
58
+ - rules.each do |rule|
59
+ = nest rule, view: :bar
60
+ HAML
61
+ end
62
+ end
63
+
64
+ # Because +*help content renders in "template" mode when you render its content
65
+ # directly, we render the help text in the context of the *all+<setting> card
66
+ view :rule_help do
67
+ nest [:all, card.name], view: :rule_help
68
+ end
69
+
70
+ view :one_line_content do
71
+ render_rule_help
72
+ end
73
+ end
74
+
75
+ format :json do
76
+ def items_for_export
77
+ Card.search left: { type: SetID }, right: card.id, limit: 0
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: card-mod-rules
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
+ platform: ruby
6
+ authors:
7
+ - Ethan McCutchen
8
+ - Philipp Kühl
9
+ - Gerry Gleason
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2020-12-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: card
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.101.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '='
27
+ - !ruby/object:Gem::Version
28
+ version: 1.101.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: card-mod-format
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '='
34
+ - !ruby/object:Gem::Version
35
+ version: 0.11.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.11.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: card-mod-search
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.11.0
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.11.0
57
+ description: ''
58
+ email:
59
+ - info@decko.org
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/javascript/script_rules.js.coffee
65
+ - set/right/self.rb
66
+ - set/right/type_plus_right.rb
67
+ - set/rstar/rule_user.rb
68
+ - set/rule/bar_view.rb
69
+ - set/rule/bridge_rules_editor.rb
70
+ - set/rule/editor.rb
71
+ - set/rule/html_views.rb
72
+ - set/rule/quick_editor.rb
73
+ - set/rule/quick_editor/quick_edit.haml
74
+ - set/rule/quick_editor/set_info.haml
75
+ - set/rule/rule_form.rb
76
+ - set/rule/rule_form/buttons.rb
77
+ - set/rule/rule_form/form_elements.rb
78
+ - set/rule/rule_form/rule_form.haml
79
+ - set/rule/rule_form/rule_set_radio.rb
80
+ - set/rule/rule_form/set_selection.rb
81
+ - set/rule/rules.rb
82
+ - set/self/cardtype.rb
83
+ - set/self/recent_settings.rb
84
+ - set/self/script_rules.rb
85
+ - set/type/set.rb
86
+ - set/type/set/html_views.rb
87
+ - set/type/set/html_views/group_panel.haml
88
+ - set/type/set/html_views/rule_lists.rb
89
+ - set/type/set/html_views/template.rb
90
+ - set/type/set/rules_filter.rb
91
+ - set/type/set/setting_lists.rb
92
+ - set/type/setting.rb
93
+ homepage: http://decko.org
94
+ licenses:
95
+ - GPL-3.0
96
+ metadata:
97
+ card-mod: rules
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '2.5'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: rules
117
+ test_files: []