Skip to content

Commit

Permalink
Merge branch 'develop' into f_equivilancies
Browse files Browse the repository at this point in the history
  • Loading branch information
wpoynter committed May 26, 2017
2 parents b59d19f + 272cd25 commit b715464
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 12 deletions.
9 changes: 9 additions & 0 deletions app/controllers/cc_questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ def variables
render 'variables/index'
end

def tq
@collection = collection.order(:id)
@collection.each { |v| v.strand }
respond_to do |format|
format.text { render 'tq.txt.erb', layout: false, content_type: 'text/plain' }
format.json {}
end
end

def set_topic
topic = Topic.find params[:topic_id]

Expand Down
10 changes: 8 additions & 2 deletions app/controllers/datasets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class DatasetsController < BasicController
include Importers::Controller

only_set_object { %i{ questions latest_document } }
only_set_object { %i{ questions latest_document dv } }

has_importers({
dv: ImportJob::DV,
topicv: ImportJob::TopicV
})
# only_set_object { %i{member_imports} }

@model_class = Dataset
@params_list = [:name]
Expand All @@ -27,6 +26,13 @@ def show
end
end

def dv
respond_to do |format|
format.text { render 'dv.txt.erb', layout: false, content_type: 'text/plain' }
format.json {}
end
end

def import
files = params[:files].nil? ? [] : params[:files]
options = {}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/instruments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class InstrumentsController < BasicController
qvmapping: ImportJob::Mapping,
topicq: ImportJob::TopicQ
})
only_set_object { %i{copy response_domains response_domain_codes reorder_ccs stats export mapper member_imports variables} }
only_set_object { %i{copy response_domains response_domain_codes reorder_ccs stats export mapper mapping member_imports variables} }

@model_class = Instrument
@params_list = %i{agency version prefix label study files import_question_grids}
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/variables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ class VariablesController < BasicController
@model_class = Variable
@params_list = [:name, :label, :var_type, :dataset_id]

def tv
@collection = collection.order(:id)
@collection.each { |v| v.strand }
respond_to do |format|
format.text { render 'tv.txt.erb', layout: false, content_type: 'text/plain' }
format.json {}
end
end

def set_topic
topic = Topic.find_by_id params[:topic_id]

Expand Down
4 changes: 4 additions & 0 deletions app/models/qv_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ class QvMapping < ActiveRecord::Base

belongs_to :dataset
belongs_to :instrument

def question_with_cell
self.question + ((self.x.nil? || self.y.nil?) ? '' : "$#{self.x};#{self.y}")
end
end
1 change: 0 additions & 1 deletion app/models/strand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def save (do_eval = false)
@id = Strand.redis.incr SCOPE + ':count'
self.class.active[@id.to_i] = self
end
puts @members.map(&:typed_id).inspect
Strand.redis.sadd SCOPE + ':' + @id.to_s, @members.map(&:typed_id)
@members.each do |member|
Strand.redis.hset LOOKUP, member.typed_id, @id.to_s
Expand Down
3 changes: 3 additions & 0 deletions app/views/cc_questions/tq.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @collection.each do |qc| %>
<%= qc.label %><%= "\t" %><%= qc.fully_resolved_topic_code %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/datasets/dv.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @object.dv_mappings.order(id: 'ASC').each do |map| %>
<%= map.variable %><%= "\t" %><%= map.source %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/instruments/mapping.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @object.qv_mappings.order(id: 'ASC').each do |map| %>
<%= map.question_with_cell %><%= "\t" %><%= map.variable %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/variables/tv.txt.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @collection.each do |v| %>
<%= v.name %><%= "\t" %><%= v.fully_resolved_topic_code %>
<% end %>
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Archivist
class Application
VERSION = '8.1.8'
VERSION = '8.2.1'
BETA = false
end
end
17 changes: 10 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
get 'external'
end
end
resources :datasets, constraints: -> (r) { (r.format == :json || r.format == :xml) } do

request_processor = lambda do |request|
[:json, :xml, :text].include?(request.format.symbol)
end

resources :datasets, constraints: request_processor do
resources :variables do
member do
post 'set_topic', to: 'variables#set_topic'
Expand All @@ -49,14 +54,10 @@
member do
match 'imports', to: 'datasets#member_imports', via: [:post, :put]
get 'questions', to: 'datasets#questions'
get 'dv', to: 'datasets#dv'
end
end

request_processor = lambda do |request|
# binding.pry if request.path =~ %r{/instruments/13/imports}
# 1
[:json, :xml, :text].include?(request.format.symbol)
end
get 'datasets/:dataset_id/tv', to: 'variables#tv', constraints: request_processor

resources :instruments, constraints: request_processor do
resources :cc_sequences
Expand Down Expand Up @@ -88,10 +89,12 @@
get 'stats', to: 'instruments#stats'
get 'export', to: 'instruments#export'
get 'mapper', to: 'instruments#mapper'
get 'mapping', to: 'instruments#mapping'
match 'imports', to: 'instruments#member_imports', via: [:post, :put]
get 'variables', to: 'instruments#variables'
end
end
get 'instruments/:instrument_id/tq', to: 'cc_questions#tq', constraints: request_processor

get 'instruments/:id/export', to: 'instruments#latest_document'
get 'datasets/:id/export', to: 'datasets#latest_document'
Expand Down
4 changes: 4 additions & 0 deletions lib/linkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ def get_suggested_topic
cluster = Cluster.find_by_member self
cluster&.suggested_topic
end

def fully_resolved_topic_code
(get_topic || get_suggested_topic)&.code&.to_s || '0'
end
end
end

0 comments on commit b715464

Please sign in to comment.