class Object
Constants
- MAX_ANONYMOUS_SEARCH_PARAM
- PAGE_LI_CLASS
Public Instance Methods
append item to list (does not save) @param cardish [Cardish]
# File set/abstract/items.rb, line 81 def << cardish add_item cardish end
I think the following should work as add_item…
# File set/all/item.rb, line 66 def add_id id add_item "~#{id}" end
append item to list (does not save) @param cardish [String, Card::Name] item name @param allow_duplicates [True/False] permit duplicate items (default is False)
# File set/abstract/items.rb, line 88 def add_item cardish, allow_duplicates=false return if !allow_duplicates && include_item?(cardish) items = item_strings << cardish items_to_content items end
append item to list and save card @param name [String, Card::Name] item name
# File set/abstract/items.rb, line 97 def add_item! name add_item(name) && save! end
# File set/abstract/paging/paging_views.rb, line 107 def add_paging_url hash, page, status return unless page && status.in?(%i[next previous]) hash[status] = path page_link_path_args(page) end
# File set/abstract/items.rb, line 147 def all_item_cards args={} names = args[:item_names] || item_names(args) names.map { |name| fetch_item_card name, args } end
# File set/all/extended.rb, line 31 def already_extended? item, book return true if book.include? item book << item false end
# File set/abstract/items.rb, line 192 def clean_item_name item, context item = item.to_name return item if context == :raw context ||= context_card.name item.absolute_name context rescue Card::Error::NotFound # eg for invalid ids or codenames # "Invalid Item: #{item}".to_name nil end
# File set/abstract/paging.rb, line 37 def contextual_param param env_search_param(param) || voo_search_param(param) end
# File set/abstract/paging.rb, line 16 def count_with_params @count_with_params ||= card.item_names.count end
# File set/abstract/paging.rb, line 26 def current_page (offset / limit).to_i end
# File set/all/item.rb, line 100 def default_item_view :name end
# File set/all/item.rb, line 112 def determine_item_view_options_type options return if options[:type] type_from_rule = card.item_type options[:type] = type_from_rule if type_from_rule end
# File set/all/item.rb, line 70 def drop_id id drop_item "~#{id}" end
remove item from list @param cardish [String, Card::Name] item to drop
# File set/abstract/items.rb, line 103 def drop_item cardish drop_item_name = Card::Name[cardish] items_to_content(item_names.reject { |item_name| item_name == drop_item_name }) end
remove item from list and save card @param cardish [String, Card::Name] item to drop
# File set/abstract/items.rb, line 110 def drop_item! cardish drop_item cardish save! end
# File set/abstract/paging.rb, line 54 def enforce_legal_limit! val return if Card::Auth.signed_in? || !val || val <= MAX_ANONYMOUS_SEARCH_PARAM raise Card::Error::PermissionDenied, "limit parameter exceeds maximum for anonymous users " \ "(#{MAX_ANONYMOUS_SEARCH_PARAM})" end
# File set/abstract/paging.rb, line 48 def enforcing_legal_limit param yield.tap do |val| enforce_legal_limit! val if param == :limit end
# File set/abstract/paging.rb, line 41 def env_search_param param enforcing_legal_limit param do val = Env.params[param] val.to_i if focal? && val.present? end end
# File set/all/extended.rb, line 19 def extend_item_list items, list, book item = items.shift return if already_extended? item, book if item.collection? # keep items in order items.unshift(*item.item_cards) else # no further level of items list << item end end
# File set/all/extended.rb, line 1 def extended_item_cards context=nil items = item_cards limit: "", context: (context || self).name list = [] book = ::Set.new # avoid loops extend_item_list items, list, book until items.empty? list end
# File set/all/extended.rb, line 9 def extended_item_contents context=nil extended_item_cards(context).map(&:item_names).flatten end
for override
# File set/abstract/paging.rb, line 31 def extra_paging_path_args {} end
# File set/abstract/items.rb, line 183 def fetch_item_card name, args={} Card.fetch name, new: new_unknown_item_args(args) end
clear we don't need paging even before running count query
# File set/abstract/paging/paging_views.rb, line 76 def fewer_results_than_limit? return false unless offset.zero? limit > offset + search_with_params.length end
# File set/abstract/items.rb, line 175 def filtered_items items, limit: 0, offset: 0 limit = limit.to_i offset = offset.to_i return items unless limit.positive? || offset.positive? items[offset, (limit.zero? ? items.size : limit)] || [] end
# File set/abstract/items.rb, line 26 def first_card args={} return unless (name = first_name) fetch_item_card name, args end
# File set/abstract/items.rb, line 32 def first_code first_card&.codename end
# File set/abstract/items.rb, line 36 def first_id first_card&.id end
# File set/abstract/items.rb, line 22 def first_name args={} item_names(args).first end
# File set/all/item.rb, line 89 def implicit_item_view view = voo_items_view || default_item_view Card::View.normalize view end
# File set/all/item.rb, line 33 def include_item? item item_names.include? Card::Name[item] end
# File set/all/item.rb, line 74 def insert_id index, id insert_item index, "~#{id}" end
insert item into list at specified location @param index [Integer] Array index in which to insert item (0 is first) @param name [String, Card::Name] item name
# File set/abstract/items.rb, line 118 def insert_item index, name new_names = item_names new_names.delete name new_names.insert index, name items_to_content new_names end
insert item into list at specified location and save @param index [Integer] Array index in which to insert item (0 is first) @param name [String, Card::Name] item name
# File set/abstract/items.rb, line 128 def insert_item! index, name insert_item index, name save! end
@return [Array] list of Card objects @param args [Hash] see item_names
for additional options @option args [String] :complete keyword to use in searching among items @option args [True/False] :known_only if true, return only known cards @option args [String] :type name of type to be used for unknown cards
# File set/abstract/items.rb, line 51 def item_cards args={} return item_cards_search(args) if args[:complete] return known_item_cards(args) if args[:known_only] all_item_cards args end
item_cards
helpers
# File set/abstract/items.rb, line 139 def item_cards_search query Card::Query.run query.reverse_merge(referred_to_by: name, limit: 0) end
# File set/all/item.rb, line 20 def item_count args={} item_names(args).size end
@return [Array] list of integers (card ids of items) @param args [Hash] see item_names
# File set/abstract/items.rb, line 42 def item_ids args={} item_names(args).map(&:card_id).compact end
# File set/all/item.rb, line 14 def item_keys args={} item_names(args).map do |item| item.to_name.key end end
# File set/all/item.rb, line 79 def item_links _args={} raw(render_core).split(/[,\n]/) end
@return [Array] list of Card::Name objects @param args [Hash] @option args [String] :content override card content @option args [String, Card::Name, Symbol] :context name in whose context relative items
will be interpreted. For example. +A in context of B is interpreted as B+A context defaults to pointer card's name. If value is `:raw`, then name is not contextualized
@option args [String, Integer] :limit max number of cards to return @option args [String, Integer] :offset begin after the offset-th item
# File set/abstract/items.rb, line 15 def item_names args={} context = args[:context] item_strings(args).map do |item| clean_item_name item, context end.compact end
# File set/abstract/items.rb, line 162 def item_strings args={} items = raw_item_strings(args[:content] || content) return items unless args.present? filtered_items items, limit: args[:limit], offset: args[:offset] end
TODO: support type_code and type_id. (currently type) uses name, because its most common use is from CQL
# File set/abstract/items.rb, line 154 def item_type opt = options_rule_card # FIXME: need better recursion prevention return if !opt || opt == self opt.item_type end
for override, eg by json
# File set/abstract/items.rb, line 66 def item_value item_name item_name end
# File set/all/item.rb, line 104 def item_view_options new_options={} options = (voo.items || {}).clone options = options.merge new_options options[:view] ||= implicit_item_view determine_item_view_options_type options options end
set card content based on array and save card @param array [Array] list of strings/names (Cardish)
# File set/abstract/items.rb, line 74 def items= array items_to_content array save! end
# File set/all/item.rb, line 24 def items_to_content array items = array.map { |i| standardize_item i }.reject(&:blank?) self.content = items.to_pointer_content end
# File set/abstract/items.rb, line 143 def known_item_cards args={} item_names(args).map { |name| Card.fetch name }.compact end
# File set/abstract/paging.rb, line 4 def limit @limit ||= contextual_param(:limit) || default_limit end
# File set/all/item.rb, line 119 def listing listing_cards, item_args={} listing_cards.map do |item_card| nest_item item_card, item_args do |rendered, item_view| wrap_item rendered, item_view end end end
# File set/all/item.rb, line 83 def nest_item cardish, options={}, &block options = item_view_options options options[:nest_name] = Card::Name[cardish].s nest cardish, options, &block end
# File set/abstract/items.rb, line 187 def new_unknown_item_args args itype = args[:type] || item_type itype ? { type: itype } : {} end
# File set/abstract/paging.rb, line 8 def offset @offset ||= contextual_param(:offset) || 0 end
# File set/abstract/paging/paging_views.rb, line 39 def page_link text, page, options return content_tag(:div, text.html_safe, class: "page-link") unless page options.merge! class: "card-paging-link slotter page-link", remote: true, path: page_link_path_args(page) link_to raw(text), options end
First page is 0 (not 1)
# File set/abstract/paging/paging_views.rb, line 29 def page_link_li text, page, status, options={} wrap_with :li, class: page_link_li_class(status) do page_link text, page, options end end
# File set/abstract/paging/paging_views.rb, line 35 def page_link_li_class status ["page-item", PAGE_LI_CLASS[status]].compact.join " " end
# File set/abstract/paging/paging_views.rb, line 63 def page_link_path_args page paging_path_args.merge offset: page * limit end
# File set/abstract/paging/paging_views.rb, line 22 def paging_links PagingLinks.new(total_pages, current_page).build do |text, page, status, options| page_link_li text, page, status, options end end
# File set/abstract/paging/paging_views.rb, line 67 def paging_needed? return false if limit < 1 return false if fewer_results_than_limit? # avoid extra count search # count search result instead limit < count_with_params end
# File set/abstract/paging/paging_views.rb, line 56 def paging_path_args local_args={} @paging_path_args ||= {} @paging_path_args.reverse_merge!(limit: limit, offset: offset) @paging_path_args.merge! extra_paging_path_args @paging_path_args.merge local_args end
# File set/abstract/paging/paging_views.rb, line 99 def paging_urls_hash hash = {} PagingLinks.new(total_pages, current_page).build do |_text, page, status, _options| add_paging_url hash, page, status end hash end
# File set/abstract/items.rb, line 169 def raw_item_strings content content.to_s.split(/\n+/).map { |i| strip_item i } end
# File set/all/item.rb, line 57 def replace_item old, new return unless include_item? old drop_item old add_item new end
# File set/abstract/paging.rb, line 12 def search_with_params @search_with_params ||= card.item_names end
# File set/all/item.rb, line 29 def standardize_item item Card::Name[item] end
# File set/abstract/items.rb, line 204 def strip_item item item.gsub(/\[\[|\]\]/, "").strip end
# File set/abstract/paging.rb, line 20 def total_pages return 1 if limit.zero? ((count_with_params - 1) / limit).to_i end
# File set/all/item.rb, line 94 def voo_items_view return unless voo && (items = voo.items) items[:view] end
# File set/abstract/paging.rb, line 62 def voo_search_param param voo&.cql&.dig(param)&.to_i end
# File set/abstract/paging/paging_views.rb, line 4 def with_paging path_args={} with_paging_path_args path_args do output [yield(@paging_path_args), _render_paging] end end
# File set/abstract/paging/paging_views.rb, line 48 def with_paging_path_args args tmp = @paging_path_args @paging_path_args = paging_path_args args yield ensure @paging_path_args = tmp end
# File set/all/item.rb, line 127 def wrap_item item, _args={} item # no wrap in base end