class Object

Public Instance Methods

added_item_cards() click to toggle source
# File set/abstract/01_pointer/events.rb, line 67
def added_item_cards
  return item_cards unless db_content_before_act

  all_item_cards item_names: added_item_names
end
added_item_names() click to toggle source
# File set/abstract/01_pointer/events.rb, line 45
def added_item_names
  return [] if trash
  return item_names unless (old_content = db_content_before_act)

  old_items = item_names content: old_content
  item_names - old_items
end
autocomplete_input() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 63
def autocomplete_input
  haml :autocomplete_input, item: items_for_input.first, options_card: options_card_name
end
changed_item_cards() click to toggle source

TODO: refactor. many of the above could be written more elegantly with improved handling of :content in item_names. If content is nil here, we would expect an empty set of cards, but in fact we get items based on self.content.

# File set/abstract/01_pointer/events.rb, line 57
def changed_item_cards
  dropped_item_cards + added_item_cards
end
changed_item_names() click to toggle source
# File set/abstract/01_pointer/events.rb, line 33
def changed_item_names
  dropped_item_names + added_item_names
end
checkbox_input() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 67
def checkbox_input
  raw haml(:checkbox_input, submit_on_change: @submit_on_change)
end
chunk_list() click to toggle source
# File set/type/link_list.rb, line 14
def chunk_list
  :references
end
content() click to toggle source
# File set/abstract/code_pointer.rb, line 31
def content
  item_codenames.map do |codename|
    Card.fetch_name codename
  end.compact.to_pointer_content
end
count() click to toggle source
# File set/abstract/01_pointer.rb, line 8
def count
  item_strings.size
end
default_filter_card() click to toggle source
# File set/abstract/01_pointer/html_views/filter.rb, line 45
def default_filter_card
  fcard = card.options_rule_card || Card[:all]
  return fcard if fcard.respond_to? :cql_hash

  fcard.fetch :referred_to_by, new: {}
end
default_input_type() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 39
def default_input_type
  :list
end
default_item_view() click to toggle source

generalize to all collections?

# File set/abstract/01_pointer/other_views.rb, line 82
def default_item_view
  :content
end
default_limit() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 4
def default_limit
  20
end
diff_args() click to toggle source
# File set/abstract/01_pointer.rb, line 4
def diff_args
  { diff_format: :pointer }
end
dropped_item_cards() click to toggle source
# File set/abstract/01_pointer/events.rb, line 61
def dropped_item_cards
  return [] unless db_content_before_act

  all_item_cards item_names: dropped_item_names
end
dropped_item_names() click to toggle source
# File set/abstract/01_pointer/events.rb, line 37
def dropped_item_names
  return item_names if trash
  return [] unless (old_content = db_content_before_act)

  old_items = item_names content: old_content
  old_items - item_names
end
each_reference_out() { |name, CODE| ... } click to toggle source
# File set/type/list.rb, line 3
def each_reference_out
  item_names.each do |name|
    yield(name, Card::Content::Chunk::Link::CODE)
  end
end
essentials() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 65
def essentials
  return {} if depth > max_depth

  card.item_cards.map do |item|
    nest item, view: :essentials
  end
end
filter_card() click to toggle source

for override @return [Card] search card on which filtering is based

# File set/abstract/01_pointer/html_views/filter.rb, line 41
def filter_card
  filter_card_from_params || default_filter_card
end
filter_card_from_params() click to toggle source
# File set/abstract/01_pointer/html_views/filter.rb, line 52
def filter_card_from_params
  return unless params[:filter_card]

  Card.fetch params[:filter_card], new: {}
end
filtered_list_input() click to toggle source
# File set/abstract/01_pointer/html_views/filter.rb, line 12
def filtered_list_input
  with_nest_mode :normal do
    class_up "card-slot", filtered_list_slot_class
    with_class_up "card-slot", filtered_list_slot_class do
      wrap do
        haml :filtered_list_input
      end
    end
  end
end
filtered_list_item(item_card) click to toggle source
# File set/abstract/01_pointer/html_views/filter.rb, line 33
def filtered_list_item item_card
  nest_item item_card do |rendered, item_view|
    wrap_item rendered, item_view
  end
end
filtered_list_slot_class() click to toggle source

currently actually used as a class (because we don't have api to override slot's id)

# File set/abstract/01_pointer/html_views/filter.rb, line 60
def filtered_list_slot_class
  @filtered_list_slot_class ||= "filtered-list-#{unique_id}"
end
input_type() click to toggle source
# File set/type/link_list.rb, line 20
def input_type
  :link_list
end
item_cards() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 53
def item_cards
  card.item_cards
end
item_ids(args={}) click to toggle source
# File set/abstract/id_pointer.rb, line 12
def item_ids args={}
  item_strings(args).map do |item|
    item = standardize_item item unless item.match?(/^~/)
    item.to_s.tr("~", "").to_i
  end.compact
end
item_names(args={}) click to toggle source
# File set/abstract/id_pointer.rb, line 19
def item_names args={}
  item_ids(args).map(&:cardname).compact
end
item_options() click to toggle source
# File set/type/nest_list.rb, line 7
def item_options
  nest_chunks.map(&:raw_options)
end
item_titles(default_to_name=true) click to toggle source
# File set/type/link_list.rb, line 7
def item_titles default_to_name=true
  reference_chunks.map do |chunk|
    chunk.options[:title] || (default_to_name ? chunk.referee_name : nil)
  end
end
item_to_insert() click to toggle source
# File set/abstract/01_pointer/events.rb, line 13
def item_to_insert
  Env.params["insert_item"]
end
items_for_export() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 61
def items_for_export
  card.item_cards
end
items_for_input(items=nil) click to toggle source

currently only used by :list and :autocomplete. could be generalized?

# File set/abstract/01_pointer/html_views.rb, line 118
def items_for_input items=nil
  items ||= card.item_names context: :raw
  items.empty? ? [""] : items
end
items_to_content(array) click to toggle source
# File set/type/nest_list.rb, line 11
def items_to_content array
  items = array.map { |i| standardize_item i }.reject(&:blank?)
  self.content = items.join("\n")
end
json_options?() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 8
def json_options?
  options_card&.type_id == JsonID
end
list_input(args={}) click to toggle source

view :nav_item do

nav_dropdown

end

# File set/abstract/01_pointer/html_views.rb, line 51
def list_input args={}
  items = items_for_input args[:item_list]
  extra_class = "pointer-list-ul"
  ul_classes = classy "pointer-list-editor", extra_class
  haml :list_input, items: items, ul_classes: ul_classes,
                    options_card: options_card_name
end
max_depth() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 57
def max_depth
  params[:max_depth] || 1
end
multiselect_input() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 82
def multiselect_input
  select_tag "pointer_multiselect-#{unique_id}",
             options_for_select(card.options_hash, card.item_names),
             multiple: true, class: "pointer-multiselect form-control"
end
nest_item_array() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 14
def nest_item_array
  card.item_cards.map do |item|
    nest_item item
  end
end
nest_list_input(args={}) click to toggle source
# File set/type/nest_list.rb, line 40
def nest_list_input args={}
  items = items_for_input args[:item_list]
  extra_class = "_nest-list-ul"
  ul_classes = classy "pointer-list-editor", extra_class
  haml :nest_list_input, items: items, ul_classes: ul_classes
end
not_ids_value() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 101
def not_ids_value
  card.item_ids.map(&:to_s).join(",")
end
one_line_content() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 107
def one_line_content
  if count == 1
    card.first_name
  else
    short_content
  end
end
option_cards() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 26
def option_cards
  option_names.map do |name|
    Card.fetch name, new: {}
  end
end
option_hash_from_names() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 12
def option_hash_from_names
  option_names.each_with_object({}) do |name, hash|
    hash[name] = name
  end
end
option_label(option_name, id) click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 65
def option_label option_name, id
  %(<label for="#{id}">#{option_label_text option_name}</label>)
end
option_label_text(option_name) click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 73
def option_label_text option_name
  return option_name unless (option_card = Card.fetch option_name)

  nest option_card, view: option_view
end
option_names() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 18
def option_names
  if (selected_options = item_names)
    (standard_option_names + selected_options).uniq
  else
    standard_option_names
  end
end
option_names_from_items() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 44
def option_names_from_items
  o_card = options_card
  limit = o_card.try(:default_limit).to_i
  o_card.item_names context: name, limit: limit
end
option_view() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 69
def option_view
  @option_view ||= card.rule(:content_option_view) || :smart_label
end
options_card() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 50
def options_card
  options_rule_card || Card[:all]
end
options_card_name() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 54
def options_card_name
  options_rule_card&.name&.url_key || ":all"
end
options_hash() click to toggle source

TODO: some of this should be moved to right/options!! or to type/JSON?

# File set/abstract/01_pointer/options_api.rb, line 4
def options_hash
  json_options? ? options_card.parse_content : option_hash_from_names
end
options_rule_card() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 32
def options_rule_card
  rule_card :content_options
end
pointer_items(args={}) click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 24
def pointer_items args={}
  page_args = args.extract! :limit, :offset
  listing card.item_cards(page_args), args
end
quick_edit() click to toggle source
Calls superclass method
# File set/right/content_option_view.rb, line 2
def quick_edit
  if card.left.prototype_default_card&.try(:show_content_options?) &&
     card.left.prototype.rule_card(:input_type)&.supports_content_option_view?
    super
  else
    ""
  end
end
quick_editor() click to toggle source
# File set/right/content_options.rb, line 11
def quick_editor
  wrap_type_formgroup do
    type_field class: "type-field rule-type-field _submit-on-select"
  end +
    wrap_content_formgroup do
      text_field :content, class: "d0-card-content _submit-after-typing"
    end
end
radio_input() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 71
def radio_input
  raw haml(:radio_input, submit_on_change: @submit_on_change)
end
raw_feed_items() click to toggle source
# File set/abstract/01_pointer/other_views.rb, line 100
def raw_feed_items
  @raw_feed_items ||= card.item_cards(limit: limit, offset: offset)
end
raw_item_strings(content) click to toggle source
# File set/type/link_list.rb, line 3
def raw_item_strings content
  reference_chunks(content).map(&:referee_name)
end
select_input() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 75
def select_input
  options = { "-- Select --" => "" }.merge card.options_hash
  select_tag("pointer_select-#{unique_id}",
             options_for_select(options, card.item_name),
             class: "pointer-select form-control")
end
standard_option_names() click to toggle source
# File set/abstract/01_pointer/options_api.rb, line 36
def standard_option_names
  if json_options?
    options_hash.values.map(&:to_name)
  else
    option_names_from_items
  end
end
standard_pointer_core() click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 12
def standard_pointer_core
  with_paging do |paging_args|
    wrap_with :div, standard_pointer_items(paging_args), class: "pointer-list"
  end
end
standard_pointer_items(paging_args) click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 18
def standard_pointer_items paging_args
  pointer_items(paging_args.extract!(:limit, :offset)).join(voo.separator || "\n")
end
standardize_item(cardish) click to toggle source

store items as ids, not names

# File set/abstract/id_pointer.rb, line 3
def standardize_item cardish
  if (id = Card.id cardish)
    "~#{id}"
  else
    Rails.logger.info "no id for '#{cardish}' added to id pointer"
    nil
  end
end
still_pointer?() click to toggle source
# File set/abstract/01_pointer/events.rb, line 28
def still_pointer?
  type_id == PointerID
  # Card.new(type_id: type_id).is_a? Abstract::Pointer
end
supports_content_option_view?() click to toggle source
# File set/all/supports_content_options.rb, line 5
def supports_content_option_view?
  false
end
supports_content_options?() click to toggle source
# File set/all/supports_content_options.rb, line 1
def supports_content_options?
  false
end
visible_cardtype_groups() click to toggle source
# File set/right/content_options.rb, line 20
def visible_cardtype_groups
  { "Organize" => %w[List Pointer] }
end
wrap_item(rendered, item_view) click to toggle source
# File set/abstract/01_pointer/html_views.rb, line 31
def wrap_item rendered, item_view
  %(<div class="pointer-item item-#{item_view}">#{rendered}</div>)
end