card-mod-search 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/lib/card/filter_query.rb +74 -0
  3. data/set/abstract/00_filter_helper.rb +46 -0
  4. data/set/abstract/02_search_params.rb +52 -0
  5. data/set/abstract/03_filter.rb +29 -0
  6. data/set/abstract/03_filter/_filter_input.haml +8 -0
  7. data/set/abstract/03_filter/filter_form.haml +56 -0
  8. data/set/abstract/03_filter/filter_form.rb +101 -0
  9. data/set/abstract/03_filter/filtered_content.haml +5 -0
  10. data/set/abstract/03_filter/form_helper.rb +105 -0
  11. data/set/abstract/03_filter/query_construction.rb +38 -0
  12. data/set/abstract/03_filter/quick_filters.haml +11 -0
  13. data/set/abstract/03_filter/selectable_filtered_content.haml +2 -0
  14. data/set/abstract/04_right_filter_form.rb +26 -0
  15. data/set/abstract/05_search.rb +80 -0
  16. data/set/abstract/05_search/checkbox_item.haml +5 -0
  17. data/set/abstract/05_search/select_item.haml +15 -0
  18. data/set/abstract/05_search/views.rb +167 -0
  19. data/set/abstract/06_cql_search.rb +91 -0
  20. data/set/abstract/filterable.rb +13 -0
  21. data/set/abstract/filterable_bar.rb +11 -0
  22. data/set/right/children.rb +4 -0
  23. data/set/right/created.rb +3 -0
  24. data/set/right/edited.rb +3 -0
  25. data/set/right/editors.rb +3 -0
  26. data/set/right/follow.rb +3 -0
  27. data/set/right/linked_to_by.rb +3 -0
  28. data/set/right/links_to.rb +5 -0
  29. data/set/right/mates.rb +3 -0
  30. data/set/right/nested_by.rb +3 -0
  31. data/set/right/nests.rb +3 -0
  32. data/set/right/referred_to_by.rb +3 -0
  33. data/set/right/refers_to.rb +3 -0
  34. data/set/self/recent.rb +35 -0
  35. data/set/self/search.rb +93 -0
  36. data/set/type/cardtype.rb +5 -0
  37. data/set/type/search_type.rb +80 -0
  38. metadata +110 -0
@@ -0,0 +1,11 @@
1
+ include_set Abstract::Filterable
2
+
3
+ before :bar do
4
+ class_up "bar-body", "_filterable"
5
+ super()
6
+ end
7
+
8
+ before :expanded_bar do
9
+ class_up "bar", "_filterable"
10
+ super()
11
+ end
@@ -0,0 +1,4 @@
1
+ def raw_help_text
2
+ "Cards formed by \"mating\" {{_left|name}} with another card. "\
3
+ "eg: \"{{_left|name}}+mate\"."
4
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards created by {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards edited by {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Users who have edited {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Get notified about changes"
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards that link to {{_left|name}}."
3
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ def raw_help_text
4
+ "Cards that <em>{{_left|name}}</em> links to."
5
+ end
@@ -0,0 +1,3 @@
1
+ def raw_helo_text
2
+ "If there is a card named \"X+{{_left|name}}\", then X is a mate of {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards that include {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards that {{_left|name}} includes."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards that refer to {{_left|name}}."
3
+ end
@@ -0,0 +1,3 @@
1
+ def raw_help_text
2
+ "Cards that {{_left|name}} refers to."
3
+ end
@@ -0,0 +1,35 @@
1
+ ACTS_PER_PAGE = 25
2
+
3
+ view :title do
4
+ voo.title ||= "Recent Changes"
5
+ super()
6
+ end
7
+
8
+ def recent_acts
9
+ action_relation = qualifying_actions.where "card_acts.id = card_act_id"
10
+ Act.where("EXISTS (#{action_relation.to_sql})").order id: :desc
11
+ end
12
+
13
+ def qualifying_actions
14
+ Action.all_viewable.where "draft is not true"
15
+ end
16
+
17
+ format :html do
18
+ view :core do
19
+ voo.hide :history_legend unless voo.main
20
+ @acts_per_page = ACTS_PER_PAGE
21
+ acts_layout card.recent_acts, :absolute
22
+ end
23
+ end
24
+
25
+ format :rss do
26
+ view :feed_item_description do
27
+ render_blank
28
+ end
29
+ end
30
+
31
+ format :json do
32
+ def items_for_export
33
+ card.item_cards limit: 20
34
+ end
35
+ end
@@ -0,0 +1,93 @@
1
+
2
+ format do
3
+ view :search_error, cache: :never do
4
+ sr_class = search_with_params.class.to_s
5
+
6
+ # don't show card content; not very helpful in this case
7
+ %(#{sr_class} :: #{search_with_params.message})
8
+ end
9
+
10
+ def search_with_params
11
+ @search_with_params ||= cql_keyword? ? cql_search : super
12
+ end
13
+
14
+ def cql_search
15
+ query = card.parse_json_cql search_keyword
16
+ rescuing_bad_query query do
17
+ Card.search query
18
+ end
19
+ end
20
+
21
+ def search_keyword
22
+ @search_keyword ||= search_vars&.dig :keyword
23
+ end
24
+
25
+ def search_vars
26
+ root.respond_to?(:search_params) ? root.search_params[:vars] : search_params[:vars]
27
+ end
28
+
29
+ def cql_keyword?
30
+ search_keyword&.match?(/^\{.+\}$/)
31
+ end
32
+ end
33
+
34
+ format :html do
35
+ view :title, cache: :never do
36
+ return super() unless (title = keyword_search_title)
37
+ voo.title = title
38
+ end
39
+
40
+ def keyword_search_title
41
+ search_keyword &&
42
+ %(Search results for: <span class="search-keyword">#{h search_keyword}</span>)
43
+ end
44
+ end
45
+
46
+ format :json do
47
+ view :complete, cache: :never do
48
+ term = term_param
49
+ exact = Card.fetch term, new: {}
50
+
51
+ {
52
+ search: true,
53
+ term: term,
54
+ add: add_item(exact),
55
+ new: new_item_of_type(exact),
56
+ goto: goto_items(term, exact)
57
+ }
58
+ end
59
+
60
+ def add_item exact
61
+ return unless exact.new_card? &&
62
+ exact.name.valid? &&
63
+ !exact.virtual? &&
64
+ exact.ok?(:create)
65
+ [h(exact.name), URI.escape(exact.name)]
66
+ end
67
+
68
+ def new_item_of_type exact
69
+ return unless (exact.type_id == CardtypeID) &&
70
+ Card.new(type_id: exact.id).ok?(:create)
71
+ [exact.name, "new/#{exact.name.url_key}"]
72
+ end
73
+
74
+ def goto_items term, exact
75
+ goto_names = complete_or_match_search start_only: Card.config.navbox_match_start_only
76
+ goto_names.unshift exact.name if add_exact_to_goto_names? exact, goto_names
77
+ goto_names.map do |name|
78
+ [name, name.to_name.url_key, h(highlight(name, term, sanitize: false))]
79
+ end
80
+ end
81
+
82
+ def add_exact_to_goto_names? exact, goto_names
83
+ exact.known? && !goto_names.find { |n| n.to_name.key == exact.key }
84
+ end
85
+
86
+ def term_param
87
+ term = query_params[:keyword]
88
+ if (term =~ /^\+/) && (main = params["main"])
89
+ term = main + term
90
+ end
91
+ term
92
+ end
93
+ end
@@ -0,0 +1,5 @@
1
+ include_set Abstract::CqlSearch
2
+
3
+ def cql_content
4
+ { type_id: id, sort: :name }
5
+ end
@@ -0,0 +1,80 @@
1
+ include_set Type::Json
2
+ include_set Abstract::CqlSearch
3
+
4
+ format do
5
+ view :core, cache: :never do
6
+ _render search_result_view
7
+ end
8
+
9
+ def chunk_list
10
+ :query
11
+ end
12
+
13
+ def search_result_view
14
+ case search_with_params
15
+ when Exception then :search_error
16
+ when Integer then :search_count
17
+ when nest_mode == :template then :raw
18
+ else :card_list
19
+ end
20
+ end
21
+ end
22
+
23
+ format :json do
24
+ def items_for_export
25
+ return [] if card.content.empty? || unexportable_tag?(card.name.tag_name.key)
26
+ card.item_cards
27
+ end
28
+
29
+ # avoid running the search from +:content_options (huge results)
30
+ # and +:structure (errors)
31
+ # TODO: make this configurable in set mods
32
+ def unexportable_tag? tag_key
33
+ %i[content_options structure].map { |code| code.cardname.key }.include? tag_key
34
+ end
35
+ end
36
+
37
+ format :rss do
38
+ view :feed_body do
39
+ case raw_feed_items
40
+ when Exception then @xml.item(render!(:search_error))
41
+ when Integer then @xml.item(render!(:search_count))
42
+ else super()
43
+ end
44
+ end
45
+
46
+ def raw_feed_items
47
+ @raw_feed_items ||= search_with_params
48
+ end
49
+ end
50
+
51
+ format :html do
52
+ view :core do
53
+ _render search_result_view
54
+ end
55
+
56
+ view :bar do
57
+ voo.hide :one_line_content
58
+ super()
59
+ end
60
+
61
+ view :one_line_content, cache: :never do
62
+ if depth > max_depth
63
+ "..."
64
+ else
65
+ search_params[:limit] = closed_limit
66
+ _render_core hide: "paging", items: { view: :link }
67
+ # TODO: if item is queryified to be "name", then that should work.
68
+ # otherwise use link
69
+ end
70
+ end
71
+
72
+ def rss_link_tag
73
+ path_opts = { format: :rss }
74
+ Array(search_params[:vars]).compact.each { |k, v| opts["_#{k}"] = v }
75
+ tag "link", rel: "alternate",
76
+ type: "application/rss+xml",
77
+ title: "RSS",
78
+ href: path(path_opts)
79
+ end
80
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: card-mod-search
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-collection
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
+ description: ''
44
+ email:
45
+ - info@decko.org
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - lib/card/filter_query.rb
51
+ - set/abstract/00_filter_helper.rb
52
+ - set/abstract/02_search_params.rb
53
+ - set/abstract/03_filter.rb
54
+ - set/abstract/03_filter/_filter_input.haml
55
+ - set/abstract/03_filter/filter_form.haml
56
+ - set/abstract/03_filter/filter_form.rb
57
+ - set/abstract/03_filter/filtered_content.haml
58
+ - set/abstract/03_filter/form_helper.rb
59
+ - set/abstract/03_filter/query_construction.rb
60
+ - set/abstract/03_filter/quick_filters.haml
61
+ - set/abstract/03_filter/selectable_filtered_content.haml
62
+ - set/abstract/04_right_filter_form.rb
63
+ - set/abstract/05_search.rb
64
+ - set/abstract/05_search/checkbox_item.haml
65
+ - set/abstract/05_search/select_item.haml
66
+ - set/abstract/05_search/views.rb
67
+ - set/abstract/06_cql_search.rb
68
+ - set/abstract/filterable.rb
69
+ - set/abstract/filterable_bar.rb
70
+ - set/right/children.rb
71
+ - set/right/created.rb
72
+ - set/right/edited.rb
73
+ - set/right/editors.rb
74
+ - set/right/follow.rb
75
+ - set/right/linked_to_by.rb
76
+ - set/right/links_to.rb
77
+ - set/right/mates.rb
78
+ - set/right/nested_by.rb
79
+ - set/right/nests.rb
80
+ - set/right/referred_to_by.rb
81
+ - set/right/refers_to.rb
82
+ - set/self/recent.rb
83
+ - set/self/search.rb
84
+ - set/type/cardtype.rb
85
+ - set/type/search_type.rb
86
+ homepage: http://decko.org
87
+ licenses:
88
+ - GPL-3.0
89
+ metadata:
90
+ card-mod: search
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '2.5'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: search
110
+ test_files: []