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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bbf86a0899439d11bb1da369c65a0d146d2c4b9fdc9613caf3f1fe2f9ce3c33e
4
+ data.tar.gz: bda881d106accf098eb980e20300c2b3d6e13fee05538444730f5b3e41ad8342
5
+ SHA512:
6
+ metadata.gz: 06f3b0771593a044d23e0be61a5772a1bdca68805ea1f238dcb22e037c27cde0bb08c7f5269e471c82b1d8bed4f3641dd3cb4f08d2e655c038abcce4f04f0268
7
+ data.tar.gz: 64fa89e1d49600d372133867a98710db3072e131be17d1b88fbe8e12cdb694729571f831d46007dc11bc541e8cb33c54cbaacc74004067a1c995248fc40ac8d1
@@ -0,0 +1,23 @@
1
+ $(window).ready ->
2
+ # permissions mod
3
+ $('body').on 'click', '.perm-vals input', ->
4
+ $(this).slot().find('#inherit').attr('checked',false)
5
+
6
+ $('body').on 'click', '.perm-editor #inherit', ->
7
+ slot = $(this).slot()
8
+ slot.find('.perm-group input:checked').attr('checked', false)
9
+ slot.find('.perm-indiv input').val('')
10
+
11
+ # rstar mod
12
+ $('body').on 'click', '._rule-submit-button', ->
13
+ f = $(this).closest('form')
14
+ checked = f.find('.set-editor input:checked')
15
+ if checked.val()
16
+ if checked.attr('warning')
17
+ confirm checked.attr('warning')
18
+ else
19
+ true
20
+ else
21
+ f.find('.set-editor').addClass('attention')
22
+ $(this).notify 'To what Set does this Rule apply?'
23
+ false
@@ -0,0 +1,3 @@
1
+ def prototype_default_card
2
+ left
3
+ end
@@ -0,0 +1,4 @@
1
+ def related_sets _with_self=false
2
+ [[name, Card::Set::TypePlusRight.label(name.left)],
3
+ ["#{name[1]}+*right", Card::Set::Right.label(name[1])]]
4
+ end
@@ -0,0 +1,8 @@
1
+
2
+ def rule_user_name
3
+ is_preference? ? name.trunk_name.tag : nil
4
+ end
5
+
6
+ def rule_user
7
+ is_preference? ? self[-2] : nil
8
+ end
@@ -0,0 +1,92 @@
1
+ format :html do
2
+ bar_cols 6, 6
3
+ info_bar_cols 5, 4, 3
4
+
5
+ def existing_rule_card
6
+ @existing_rule_card ||= find_existing_rule_card
7
+ end
8
+
9
+ view :bar, unknown: true do
10
+ voo.hide :bar_nav unless existing_rule_card
11
+ super()
12
+ end
13
+
14
+ view :expanded_bar, unknown: true do
15
+ super()
16
+ end
17
+
18
+ view :one_line_content,
19
+ wrap: { div: { class: "text-muted one-line" } }, unknown: true do
20
+ return render_mini_unknown unless existing_rule_card
21
+
22
+ with_nest_mode :compact do
23
+ one_line_content
24
+ end
25
+ end
26
+
27
+ view :raw_one_line_content,
28
+ wrap: { div: { class: "text-muted one-line" } }, unknown: true do
29
+ return render_mini_unknown unless existing_rule_card
30
+
31
+ raw_one_line_content
32
+ end
33
+
34
+ view :bar_bottom, unknown: true do
35
+ if nest_mode == :edit
36
+ current_rule_form
37
+ else
38
+ nest existing_rule_card, view: :core
39
+ end
40
+ end
41
+
42
+ view :bar_middle, unknown: true do
43
+ rule_info
44
+ end
45
+
46
+ view :bar_left, unknown: true do
47
+ super()
48
+ end
49
+
50
+ view :bar_right, unknown: true do
51
+ voo.show?(:bar_bottom) ? rule_info : rule_short_content
52
+ end
53
+
54
+ def rule_short_content
55
+ return "" unless existing_rule_card
56
+
57
+ nest existing_rule_card, { view: :one_line_content },
58
+ set_context: card.name.trunk_name
59
+ end
60
+
61
+ def bar_title
62
+ return super() if voo.show? :full_name
63
+
64
+ linking_to_existing_rule { card.rule_setting_title }
65
+ end
66
+
67
+ # LOCALIZE
68
+ def rule_info
69
+ return wrap_with(:em, "no existing #{setting_link} rule") unless existing_rule_card
70
+
71
+ wrap_with :span,
72
+ "#{rule_setting_link} rule that applies to "\
73
+ "#{rule_set_link existing_rule_card}"
74
+ end
75
+
76
+ def rule_setting_link
77
+ link_to_card card.rule_setting, card.rule_setting_name
78
+ end
79
+
80
+ def rule_set_link existing_rule
81
+ count = link_to_card [card.rule_set, :by_name], card.rule_set.count
82
+ "#{link_to_card card.rule_set, existing_rule.trunk&.label&.downcase} (#{count})"
83
+ end
84
+
85
+ private
86
+
87
+ def linking_to_existing_rule
88
+ return yield unless existing_rule_card && voo.show?(:toggle)
89
+
90
+ link_to_view bar_title_toggle_view, yield
91
+ end
92
+ end
@@ -0,0 +1,28 @@
1
+ format :html do
2
+ view :overlay_rule, cache: :never, unknown: true do
3
+ wrap_with_overlay slot: breadcrumb_data("Rule editing", "rules") do
4
+ current_rule_form
5
+ end
6
+ end
7
+
8
+ view :modal_rule, cache: :never, unknown: true,
9
+ wrap: { modal: { title: ->(format) { format.render_title } } } do
10
+ current_rule_form
11
+ end
12
+
13
+ view :overlay_title do
14
+ edit_rule_title
15
+ end
16
+
17
+ view :help_text, unknown: true, cache: :never do
18
+ wrap_help_text [rule_based_help, setting_link].join(" ")
19
+ end
20
+
21
+ def setting_link
22
+ wrap_with :div, class: "ml-auto" do
23
+ link_to_card card.rule_setting_name,
24
+ " (#{card.rule_setting.count} #{card.rule_setting_title} rules)",
25
+ class: "text-muted"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,110 @@
1
+ def left_type_for_nest_editor_set_selection
2
+ return super unless is_template?
3
+
4
+ case Card.fetch_id rule_set_pattern_name
5
+ when TypeID
6
+ rule_set.anchor_name
7
+ when SelfID
8
+ rule_set.anchor.type_name
9
+ else
10
+ super
11
+ end
12
+ end
13
+
14
+ format :html do
15
+ attr_accessor :rule_context
16
+
17
+ view :rule_edit, cache: :never, unknown: true,
18
+ wrap: { modal: { size: :large,
19
+ title: :edit_rule_title,
20
+ footer: "" } } do
21
+ current_rule_form form_type: :modal
22
+ end
23
+
24
+ view :rule_help, unknown: true, perms: :none, cache: :never do
25
+ wrap_with :div, class: "alert alert-info rule-instruction" do
26
+ rule_based_help
27
+ end
28
+ end
29
+
30
+ view :rule_bridge_link, unknown: true do
31
+ opts = bridge_link_opts(class: "edit-rule-link nav-link",
32
+ "data-toggle": "pill",
33
+ "data-cy": "#{setting_title.to_name.key}-pill")
34
+ opts[:path].delete(:layout)
35
+ link_to_view(:overlay_rule, (setting_title + short_help_text), opts)
36
+ end
37
+
38
+ def edit_link_view
39
+ :rule_edit
40
+ end
41
+
42
+ def edit_rule_title
43
+ output [
44
+ wrap_with(:h5, setting_title, class: "title font-weight-bold")
45
+ # render_overlay_rule_help
46
+ ]
47
+ end
48
+
49
+ def current_rule
50
+ if params[:assign]
51
+ card
52
+ elsif (existing = find_existing_rule_card)
53
+ existing
54
+ else
55
+ card
56
+ end
57
+ end
58
+
59
+ def quick_editor
60
+ rule_content_formgroup
61
+ end
62
+
63
+ def setting_title
64
+ card.name.tag.tr "*", ""
65
+ end
66
+
67
+ def short_help_text
68
+ "<div class=\"help-text\">#{card.short_help_text}</div>"
69
+ end
70
+
71
+ def rule_set_description
72
+ card.rule_set.follow_label
73
+ end
74
+
75
+ def rules_type_formgroup
76
+ return unless card.right.rule_type_editable
77
+
78
+ success = @edit_rule_success
79
+ wrap_type_formgroup do
80
+ type_field(
81
+ href: path(mark: success[:id], view: :rule_form, assign: true),
82
+ class: "type-field rule-type-field live-type-field",
83
+ "data-remote" => true
84
+ )
85
+ end
86
+ end
87
+
88
+ def rule_content_formgroup
89
+ _render_content_formgroup hide: :conflict_tracker
90
+ end
91
+
92
+ def current_set_key
93
+ card.new_card? ? Card.quick_fetch(:all).name.key : card.rule_set_key
94
+ end
95
+
96
+ private
97
+
98
+ def find_existing_rule_card
99
+ card.new_card? ? existing_rule_from_prototype : card
100
+ end
101
+
102
+ # self.card is a POTENTIAL rule; it quacks like a rule but may or may not exist.
103
+ # This generates a prototypical member of the POTENTIAL rule's set
104
+ # and returns that member's ACTUAL rule for the POTENTIAL rule's setting
105
+ def existing_rule_from_prototype
106
+ return unless (setting = card.right)
107
+
108
+ card.set_prototype.rule_card setting.codename, user: card.rule_user
109
+ end
110
+ end
@@ -0,0 +1,13 @@
1
+ format :html do
2
+ view :core do
3
+ # Rule cards that are searches are usual right structures and refer to the left
4
+ # in the search query. In that case the search doesn't work
5
+ # properly in the context of the rule card itself. Hence we show the query syntax
6
+ # and not the search result.
7
+ if card.type_id == SearchTypeID
8
+ render_raw
9
+ else
10
+ super()
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ format :html do
2
+ view :quick_edit, unknown: true, wrap: :slot do
3
+ quick_edit
4
+ end
5
+
6
+ view :quick_edit_success do
7
+ set_info true
8
+ end
9
+
10
+ def quick_edit
11
+ haml :quick_edit
12
+ end
13
+
14
+ def quick_form
15
+ card_form :update, quick_form_opts do
16
+ quick_editor
17
+ end
18
+ end
19
+
20
+ def quick_form_opts
21
+ { "data-slot-selector": ".set-info.card-slot",
22
+ success: { view: :quick_edit_success } }
23
+ end
24
+
25
+ def set_info notify_change=nil
26
+ wrap true, class: "set-info" do
27
+ haml :set_info, notify_change: notify_change
28
+ end
29
+ end
30
+
31
+ def undo_button
32
+ link_to "undo", method: :post, rel: "nofollow", remote: true,
33
+ class: "btn btn-secondary ml-2 btn-sm btn-reduced-padding slotter",
34
+ "data-slot-selector": ".card-slot.quick_edit-view",
35
+ path: { action: :update,
36
+ revert_actions: [card.last_action_id],
37
+ revert_to: :previous }
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ .rule-item
2
+ %h6.font-weight-bold
3
+ = setting_title
4
+ = short_help_text
5
+ = quick_form
6
+ = set_info
7
+
8
+
@@ -0,0 +1,10 @@
1
+ .form-group.form-control-feedback
2
+ %label
3
+ Set
4
+ %p.text-muted
5
+ = find_existing_rule_card&.left&.label || "--"
6
+ - if notify_change
7
+ %p.autosubmit-success-notification
8
+ %span.text-success
9
+ Applied!
10
+ = undo_button
@@ -0,0 +1,57 @@
1
+ format :html do
2
+ view :rule_form, cache: :never, unknown: true do
3
+ @success_view ||= :open
4
+ @rule_context ||= card
5
+ @form_type ||= :overlay
6
+
7
+ wrap do
8
+ edit_rule_form @success_view do
9
+ [
10
+ hidden_tags(success: @edit_rule_success),
11
+ haml(:rule_form)
12
+ ].join
13
+ end
14
+ end
15
+ end
16
+
17
+ def form_type
18
+ @form_type || :overlay
19
+ end
20
+
21
+ def current_rule_form success_view: :overlay_rule, form_type: :overlay
22
+ current_rule_format = subformat current_rule
23
+ current_rule_format.rule_form success_view, card, form_type
24
+ end
25
+
26
+ def rule_form success_view, rule_context, form_type=:overlay
27
+ validate_form_type form_type
28
+
29
+ @rule_context = rule_context
30
+ @form_type = form_type
31
+ @success_view = success_view
32
+
33
+ render_rule_form
34
+ end
35
+
36
+ def validate_form_type form_type
37
+ return if form_type.in? %i[overlay modal]
38
+
39
+ raise "invalid rule_form type: #{form_type}; has to be overlay or modal"
40
+ end
41
+
42
+ def edit_rule_form success_view, &block
43
+ @rule_context ||= card
44
+ @edit_rule_success = edit_rule_success(success_view)
45
+ action_args = { action: :update, no_mark: true }
46
+ card_form action_args, rule_form_args, &block
47
+ end
48
+
49
+ def rule_form_args
50
+ { class: "card-rule-form", "data-slotter-mode": "update-origin" }
51
+ end
52
+
53
+ def edit_rule_success view="overlay_rule"
54
+ { id: @rule_context.name.url_key,
55
+ view: view }
56
+ end
57
+ end
@@ -0,0 +1,46 @@
1
+ format :html do
2
+ def edit_rule_buttons
3
+ wrap_with(:div, class: "button-area") do
4
+ [
5
+ standard_save_button(class: "_rule-submit-button"),
6
+ standard_save_and_close_button(class: "_rule-submit-button", close: form_type),
7
+ edit_rule_cancel_button,
8
+ edit_rule_delete_button
9
+ ]
10
+ end
11
+ end
12
+
13
+ def edit_rule_cancel_button
14
+ send "#{form_type}_close_button", "Cancel", situation: "secondary", class: "btn-sm"
15
+ end
16
+
17
+ def edit_rule_delete_button args={}
18
+ return if card.new_card?
19
+
20
+ delete_opts = {
21
+ confirm: delete_confirm(args[:fallback_set]),
22
+ # success: @edit_rule_success,
23
+ no_success: true,
24
+ "data-slotter-mode": "silent-success",
25
+ class: "_close-#{form_type}-on-success"
26
+ }
27
+ delete_opts["data-slot-selector"] = slot_selector if args[:slot_selector]
28
+ wrap_with :span, class: "rule-delete-section" do
29
+ delete_button delete_opts
30
+ end
31
+ end
32
+
33
+ def delete_confirm fallback_set
34
+ setting = card.rule_setting_name
35
+
36
+ if fallback_set && (fallback_set_card = Card.fetch(fallback_set))
37
+ "Deleting will revert to #{setting} rule for #{fallback_set_card.label}"
38
+ else
39
+ "Are you sure you want to delete the #{setting} rule for #{rule_set_description}?"
40
+ end
41
+ end
42
+
43
+ def edit_rule_submit_button
44
+ submit_button class: "_rule-submit-button"
45
+ end
46
+ end