Skip to content

Commit

Permalink
Merge cf808d9 into 8fb432e
Browse files Browse the repository at this point in the history
  • Loading branch information
ethn committed May 8, 2024
2 parents 8fb432e + cf808d9 commit aa520c5
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 547 deletions.
6 changes: 0 additions & 6 deletions mod/deckorate_core/data/real.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
- :name: designer badge
:codename: designer_badge



- :name: Details
:codename: details
- :name: Organizer
Expand Down Expand Up @@ -58,11 +56,7 @@
- :name: unpublished
:codename: unpublished


# (duplicate)
- :name: Wikipedia
:codename: wikipedia
# can't create company without wikipedia, so this can't be a company yet
- :name: hybrid
:codename: hybrid
- :name: Company Group
Expand Down
505 changes: 0 additions & 505 deletions mod/deckorate_core/data/test/metrics.yml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions mod/deckorate_graphql/lib/graph_q_l/types/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module Types
# Company type for GraphQL
class Company < DeckorateCard
field :headquarters, String, null: true
field :wikipedia, String, null: true
field :open_corporates, String, null: true
field :sec_cik, String, null: true
field :os_id, String, null: true
lookup_field :answer, Answer, :metric_answer, true
field :relationships, [Relationship],
"relationships of which company is either subject or object", null: true
field :datasets, [Dataset], null: false
field :logo_url, String, "url for company logo image", null: true

::Card::Set::Type::CorporateIdentifier.names.each do |identifier|
field identifier, String, null: true
end

def os_id
object.card.oar_id
end
Expand Down
2 changes: 1 addition & 1 deletion mod/deckorate_research/set/type/source/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def form_fields
end

def tab_list
%i[preview metric metric_answer details]
%i[details preview metric metric_answer]
end

def tab_options
Expand Down
2 changes: 1 addition & 1 deletion mod/topics/set/type/wikirate_topic/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

def tab_list
%i[metric dataset research_group details]
%i[details metric dataset research_group]
end

def tab_options
Expand Down
8 changes: 4 additions & 4 deletions mod/wikirate_companies/data/real.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
:codename: sec_cik
:type: corporate_identifier


- :name: Wikipedia
:codename: wikipedia
:type: corporate_identifier

- :name: OpenCorporates
:type: :research_group
:codename: open_corporates

- :name: Incorporation
:codename: incorporation
- :name: Wikipedia
:type: :wikirate_company
:codename: wikipedia
- :name: company search
:codename: company_search
- :name: Country
Expand Down
2 changes: 2 additions & 0 deletions mod/wikirate_companies/data/recode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
open_corporates: open_corporates_id
2 changes: 1 addition & 1 deletion mod/wikirate_companies/set/type/company_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

def tab_list
%i[wikirate_company details]
%i[details wikirate_company]
end

view :details_tab do
Expand Down
42 changes: 42 additions & 0 deletions mod/wikirate_companies/set/type/corporate_identifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

event :clear_corporate_identifier_caches, :integrate do
%w[NAMES EXCERPTS].each do |suffix|
Card.cache.delete "CORPORATE-IDENTIFIER-#{suffix}"
end
end

class << self
def cards
Card.search type: :corporate_identifier, sort: :name
end

def names
Card.cache.fetch "CORPORATE-IDENTIFIER-NAMES" do
cards.map do |ident|
Type::WikirateCompany::Structure.corporate_identifier_accessor ident.codename
ident.name
end
end
end

def excerpts
Card.cache.fetch "CORPORATE-IDENTIFIER-EXCERPTS" do
names.select do |name|
excerpt? name.card.codename
end
end
end

def non_excerpts
names - excerpts
end

private

def excerpt? codename
return unless codename

fldmod = TypePlusRight::WikirateCompany.const_get_if_defined codename.to_s.camelcase
fldmod&.include? Abstract::CompanyExcerpt
end
end
7 changes: 2 additions & 5 deletions mod/wikirate_companies/set/type/wikirate_company/export.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
format :json do
NESTED_FIELD_CODENAMES =
%i[wikipedia open_corporates alias headquarters oar_id sec_cik].freeze

view :links do
[]
end
Expand Down Expand Up @@ -41,8 +38,8 @@ def molecule
private

def add_fields_to_hash hash, view=:atom
NESTED_FIELD_CODENAMES.each do |fieldcode|
hash[fieldcode] = field_nest fieldcode, view: view
card.key_field_names.each do |fld|
hash[fld] = field_nest fld, view: view
end
end

Expand Down
2 changes: 1 addition & 1 deletion mod/wikirate_companies/set/type/wikirate_company/merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def move_source_listings_to target_company
end

def move_field_cards_to target_company
field_cards.each do |field_card|
key_field_cards.each do |field_card|
new_name = field_card.name.swap name, target_company
next if Card.exists? new_name
field_card.update! name: new_name
Expand Down
38 changes: 27 additions & 11 deletions mod/wikirate_companies/set/type/wikirate_company/structure.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
IDENTIFIERS = %i[sec_cik].freeze
INTEGRATIONS = %i[wikipedia oar_id open_corporates].freeze

card_accessor :headquarters, type: :pointer
(IDENTIFIERS + INTEGRATIONS).each { |field| card_accessor field, type: :phrase }

def field_cards
([:headquarters] + IDENTIFIERS + INTEGRATIONS).map { |field| fetch field }.compact
def self.corporate_identifier_accessor codename
card_accessor codename, type: :phrase if codename.present? && !method_defined?(codename)
end

def corporate_identifiers
@corporate_identifiers ||= CorporateIdentifier.names
end

def corporate_identifiers_with_excerpts
@corporate_identifiers_with_excerpts ||= CorporateIdentifier.excerpts
end

def corporate_identifiers_without_excerpts
@corporate_identifiers_without_excerpts ||= CorporateIdentifier.non_excerpts
end

def key_field_names
%i[alias headquarters] + corporate_identifiers
end

def key_field_cards
key_field_names.map { |field| fetch field }.compact
end

format :html do
# EDITING

before :content_formgroups do
voo.edit_structure = %i[image headquarters] + IDENTIFIERS + INTEGRATIONS
voo.edit_structure = %i[image headquarters] + card.corporate_identifiers
end

def header_list_items
Expand All @@ -25,9 +41,9 @@ def header_text

def tab_list
if contrib_page?
%i[metrics_designed research_group projects_organized details]
%i[details metrics_designed research_group projects_organized]
else
%i[metric_answer source company_group dataset details]
%i[details metric_answer source company_group dataset]
end
end

Expand Down Expand Up @@ -59,13 +75,13 @@ def tab_options
end

def identifiers
IDENTIFIERS.map do |code|
card.corporate_identifiers_without_excerpts.map do |code|
labeled_field code, :name if card.fetch(code)
end
end

def integrations
INTEGRATIONS.map do |fieldcode|
card.corporate_identifiers_with_excerpts.map do |fieldcode|
next unless card.fetch fieldcode

field_nest fieldcode, view: :titled, title: fieldcode.cardname
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
id: company.id,
url: "http://wikirate.org/Samsung.json",
type: "Company",
wikipedia: "Samsung",
open_corporates: nil,
sec_cik: nil,
oar_id: nil,
alias: [],
headquarters: nil)
headquarters: nil,
# "OpenCorporates" => nil,
"SEC CIK" => nil,
"OAR id" => nil,
"Wikipedia" => "Samsung")
end
end

Expand All @@ -28,8 +28,8 @@
id: company.id,
url: "http://wikirate.org/Samsung.json",
type: a_hash_including(name: "Company"),
wikipedia: a_hash_including(name: "Samsung+Wikipedia"),
open_corporates: a_hash_including(id: nil),
"Wikipedia" => a_hash_including(name: "Samsung+Wikipedia"),
# "OpenCorporates" => a_hash_including(id: nil),
alias: a_hash_including(id: nil),
headquarters: a_hash_including(id: nil),
answers_url: "http://wikirate.org/Samsung+Answer.json"
Expand Down
2 changes: 1 addition & 1 deletion script/swagger_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def fetch_wikirate_cardtypes

def fetch_optional_subcards
{
wikirate_company: Card::Set::Type::WikirateCompany::Export::NESTED_FIELD_CODENAMES,
wikirate_company: Card.new(type: :wikirate_company).key_field_cards,
metric: %w[question about methodology unit topics value_options research_policy
report_type],
metric_answer: %w[comment unpublished],
Expand Down

0 comments on commit aa520c5

Please sign in to comment.