Skip to content

Commit

Permalink
Merge 7c1d738 into 37e8ae3
Browse files Browse the repository at this point in the history
  • Loading branch information
simonreed committed Aug 29, 2019
2 parents 37e8ae3 + 7c1d738 commit 16247b9
Show file tree
Hide file tree
Showing 73 changed files with 581 additions and 1,305 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -91,6 +91,7 @@ group :development do
end

group :test do
gem "factory_bot_rails"
gem 'minitest', '5.10.3', '!= 5.10.2'
# Performance testing
#gem 'rails-perftest'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -97,6 +97,11 @@ GEM
docile (1.3.1)
erubis (2.7.0)
execjs (2.7.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
ffi (1.10.0)
figaro (1.1.1)
thor (~> 0.14)
Expand Down Expand Up @@ -301,6 +306,7 @@ DEPENDENCIES
db_fixtures_dump (= 0.1.1)
derailed_benchmarks (~> 1.3, >= 1.3.2)
devise (>= 4.6.0)
factory_bot_rails
figaro (= 1.1.1)
friendly_id (~> 5.2.4)
fuzzy_match (= 2.1.0)
Expand Down
32 changes: 17 additions & 15 deletions app/assets/javascripts/lib/data_manager.coffee
Expand Up @@ -78,7 +78,6 @@ data_manager.factory(
DataManager.Data.InstrumentStats = {}
DataManager.Data.Users = {}
DataManager.Data.Groups = {}
DataManager.Data.Clusters = {}

DataManager.Instruments.clearCache()
DataManager.Constructs.clearCache()
Expand Down Expand Up @@ -321,19 +320,6 @@ data_manager.factory(
else
cb?()

DataManager.getCluster = (type, id, force = false, cb)->
index = type + '/' + id
if (not DataManager.Data.Clusters[index]?) or force
DataManager.Data.Clusters[index] =
GetResource(
'/clusters/' + index + '.json',
true,
cb
)
else
cb?()
return DataManager.Data.Clusters[index]

DataManager.resolveConstructs = (options)->
DataManager.ConstructResolver ?= new ResolutionService.ConstructResolver DataManager.Data.Constructs
DataManager.ConstructResolver.broken_resolve()
Expand Down Expand Up @@ -371,10 +357,26 @@ data_manager.factory(
DataManager.updateTopic = (model, topic_id)->
console.log(model)
delete model.topic
delete model.strand
delete model.suggested_topic
model.$update_topic({topic_id: if Number.isInteger(topic_id) then topic_id else null })

DataManager.addSources = (model, new_sources, x, y)->
console.log(model)
model.$add_mapping {
sources:
id: new_sources
x: x
y: y
}

DataManager.addVariables = (model, variables)->
console.log(model)
model.$add_mapping {
variable_names: variables
x: null
y: null
}

DataManager.getInstrumentStats = (id, cb)->
DataManager.Data.InstrumentStats[id] = {$resolved: false}
DataManager.Data.InstrumentStats[id].$promise = InstrumentStats(id)
Expand Down
Expand Up @@ -39,4 +39,4 @@ questions.factory(
grid.clearCache() if grid?
}
]
)
)
2 changes: 1 addition & 1 deletion app/assets/javascripts/lib/resource.coffee
Expand Up @@ -82,4 +82,4 @@ resource.factory('GetResource', [
)
sub_promise.then(cb) if typeof cb is 'function'
rsrc
])
])
66 changes: 6 additions & 60 deletions app/assets/javascripts/sections/datasets/modules/show/index.coffee
Expand Up @@ -40,15 +40,6 @@ show.controller(
)
$scope.pageSize = 20

$scope.clusterMenuOptions = [
[
'Remove Topic',
($itemScope)->
console.log 'Removing topic'
console.log $itemScope
]
]

$scope.graphData = {}
$scope.graphOptions =
interaction:
Expand All @@ -68,52 +59,8 @@ show.controller(
type = 'Variable'
id = data.nodes[0] - 20000000

$scope.current_cluster_selection = $scope.graphData.nodes.get data.nodes[0]
console.log $scope

$scope.loadNetworkData = (object)->
$scope.current_cluster_selection =
topic:
name: ''
nodes = new VisDataSet()
edges = new VisDataSet()

$scope.cluster = DataManager.getCluster(
'Variable',
object.id,
true,
(response)->
groupings = {}
for strand in $scope.cluster.strands
for member in strand.members
member.id += if member.type == 'Variable' then 20000000 else 10000000
member.group = 'strand:' + strand.id.toString()
member.borderWidth = if member.topic? then 3 else 1
member.color =
border: if strand.good then 'black' else 'red'

tooltip = '<span'
tooltip += ' style="color: red;"' if not strand.good
tooltip += '>' + member.text
tooltip += '<br/>' + member.topic.name if member.topic?
tooltip += '</span>'

member.title = tooltip
nodes.add member
if member.sources?
for source in member.sources
edges.add {
from: member.id,
to: source.id + if source.type == 'Variable' then 20000000 else 10000000,
dashes: not source.interstrand
}
console.log nodes
)

$scope.graphData =
nodes: nodes,
edges: edges

$scope.split_mapping = (model, other, x = null, y = null)->
model.$split_mapping {
other:
Expand All @@ -126,14 +73,13 @@ show.controller(
$scope.detectKey = (event, variable, x = null, y = null)->
if event.keyCode == 13
new_sources = event.target.value.split ','
variable.$add_mapping {
sources:
id: new_sources
x: x
y: y
}
DataManager.addSources(variable, new_sources, x, y).then(->
$scope.model.orig_topic = $scope.model.topic
, (reason)->
variable.errors = reason.data.message
)
console.log variable

console.log $scope
]
)
)
14 changes: 6 additions & 8 deletions app/assets/javascripts/sections/mapping/index.coffee
Expand Up @@ -52,13 +52,11 @@ mapping.controller(
$scope.detectKey = (event, question, x = null, y = null)->
if event.keyCode == 13
variables = event.target.value.split ','
question.$add_mapping {
variable_names: variables
x: null
y: null
}
, ->
DataManager.resolveQuestions()
DataManager.addVariables(question, variables).then(->
$scope.model.orig_topic = $scope.model.topic
, (reason)->
question.errors = reason.data.message
)
console.log question

# $scope.detectKey = (event,question_id)->
Expand Down Expand Up @@ -137,7 +135,7 @@ mapping.directive(
$scope.model.orig_topic = $scope.model.topic
, (reason)->
$scope.model.topic = $scope.model.orig_topic
Flash.add('danger', reason.data.message)
$scope.model.errors = reason.data.message
).finally(->
bsLoadingOverlayService.stop()
)
Expand Down
Expand Up @@ -15,7 +15,6 @@ <h4 class="modal-title" id="copy-instrument-title">Topic Cluster</h4>
options="graphOptions"
events="graphEvents"
style="height: calc(100vh - 300px); width: 100%; display: block;"
context-menu="clusterMenuOptions"
></vis-network>
</div>
<div class="modal-footer">
Expand Down
16 changes: 8 additions & 8 deletions app/assets/javascripts/templates/partials/datasets/show.html
Expand Up @@ -32,16 +32,15 @@ <h3 class="panel-title">{{dataset.study}} - {{dataset.name}}</h3>
<td>{{variable.label}}</td>
<td>{{variable.var_type}}</td>
<td class="admin-min">
<a
href="#"
data-toggle="modal"
data-target="#topic-conflict"
data-ng-click="loadNetworkData(variable)"
>Cluster</a>
</td>
</tr>
<tr data-ng-repeat-end data-ng-class-odd="'odd'" data-ng-class="{danger: variable.strand && !variable.strand.good}">
<tr data-ng-repeat-end data-ng-class-odd="'odd'" data-ng-class="{danger: variable.errors}">
<td style="border-top:0" data-ng-attr-colspan="{{ is_admin() && 5 || 4 }}">
<div data-ng-if="variable.errors">
<div class="alert alert-danger" role="alert">
{{variable.errors}}
</div>
</div>
<form class="form-inline row">
<div class="form-group col-xs-3">
<label class="control-label">Used by</label>
Expand Down Expand Up @@ -91,6 +90,7 @@ <h3 class="panel-title">{{dataset.study}} - {{dataset.name}}</h3>
</div>
<div class="form-group col-xs-5">
<label class="col-xs-2">Topic</label>
<span>Resolved Topic - {{ variable.resolved_topic.name }}</span>
<div class="col-xs-10">
<a-topics
data-ng-model="variable"
Expand All @@ -112,4 +112,4 @@ <h3 class="panel-title">{{dataset.study}} - {{dataset.name}}</h3>
</div>
</div>

<div data-ng-include="'partials/datasets/modals/conflict.html'"></div>
<div data-ng-include="'partials/datasets/modals/conflict.html'"></div>
@@ -1,5 +1,10 @@
<script type="text/ng-template" id="child_render.html">
<div class="tree-container row" data-ng-if="obj.type!='statement'">
<div data-ng-if="obj.errors">
<div class="alert alert-danger" role="alert">
{{obj.errors}}
</div>
</div>
<span class="a-label col-md-2">
{{obj.label}}
<div class="col-md-6 tq-mapping" data-ng-if="obj.type=='sequence'" style="float: right;">
Expand Down
25 changes: 16 additions & 9 deletions app/controllers/cc_questions_controller.rb
Expand Up @@ -24,17 +24,24 @@ def add_variables
variables = @object.instrument.variables.where(name: variable_names)
variables.to_a.compact!

variables.each do |variable|
unless @object.variables.find_by_id(variable.id)
if params.has_key?(:x) && params.has_key?(:y)
@object.map.create(variable: variable, x: params[:x].to_i, y: params[:y].to_i)
else
@object.variables << variable
begin
ActiveRecord::Base.transaction do
variables.each do |variable|
unless @object.variables.find_by_id(variable.id)
if params.has_key?(:x) && params.has_key?(:y)
@object.map.create!(variable: variable, x: params[:x].to_i, y: params[:y].to_i)
else
@object.variables << variable
end
end
end
@object.save
end
end
respond_to do |format|
format.json { render 'show' }
respond_to do |format|
format.json { render 'show' }
end
rescue => e
render json: {message: e.message}, status: :conflict
end
end

Expand Down
21 changes: 0 additions & 21 deletions app/controllers/clusters_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/instruments_controller.rb
Expand Up @@ -78,7 +78,7 @@ def export
end

def variables
@collection = @object.variables
@collection = @object.variables.includes(:topic, :questions, :question_topics)
render 'variables/index'
end

Expand Down
14 changes: 10 additions & 4 deletions app/controllers/variables_controller.rb
Expand Up @@ -19,9 +19,15 @@ def add_sources

params[:sources] = JSON.parse(params[:sources])

@object.add_sources(params[:sources][:id], params[:sources][:x], params[:sources][:y])

render 'variables/show'
begin
ActiveRecord::Base.transaction do
@object.add_sources(params[:sources][:id], params[:sources][:x], params[:sources][:y])
@object.reload
end
render 'variables/show'
rescue => e
render json: {message: e.message}, status: :conflict
end
end

def remove_source
Expand All @@ -46,4 +52,4 @@ def collection
def set_dataset
@dataset = policy_scope(Dataset).includes(variables: [:questions, :src_variables, :der_variables, :topic] ).find(params[:dataset_id])
end
end
end

0 comments on commit 16247b9

Please sign in to comment.