Skip to content

Commit

Permalink
use node names as keys for string template, re #997
Browse files Browse the repository at this point in the history
  • Loading branch information
apeters committed Oct 27, 2016
1 parent 701e669 commit 6aef46a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
16 changes: 3 additions & 13 deletions arches/app/functions/resource_functions.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import uuid, re
import uuid, re, json
from arches.app.models import models
from arches.app.models.tile import Tile

def get_primary_name_from_nodes(resource, config):
# eventally use sort order
#uuid_regex = '(?P<nodeid>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})'
# x = {}
# for match in re.findall(uuid_regex, config['string_template']):
# x[match] = ''

for tile in models.Tile.objects.filter(nodegroup_id=uuid.UUID(config['nodegroup_id']), sortorder=0):
t = Tile(tile)
#t.get_node_display_values()
for nodeid, nodevalue in t.data.iteritems():
#x[nodeid] = nodevalue
#print nodevalue
config['string_template'] = config['string_template'].replace('{%s}' % nodeid, nodevalue)
for node in models.Node.objects.filter(nodegroup_id=uuid.UUID(config['nodegroup_id'])):
config['string_template'] = config['string_template'].replace('<%s>' % node.name, tile.data[str(node.nodeid)])

return config['string_template']
17 changes: 9 additions & 8 deletions arches/app/media/js/views/functions/primary-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@ function (ko, koMapping, FunctionViewModel, CardModel, data) {
}
}, this);

this.primaryNameTemplate = ko.observable();
this.selectedNodegroup = ko.observable();
this.selectedNodegroup.subscribe(function(nodegroup_id){
this.primaryNameTemplate(nodegroup_id);
this.string_template = params.primaryNameConfig.string_template || ko.observable();
this.nodegroup_id = params.primaryNameConfig.nodegroup_id || ko.observable();
this.nodegroup_id.subscribe(function(nodegroup_id){
this.string_template(nodegroup_id);
var nodes = _.filter(this.graph.nodes, function(node){
return node.nodegroup_id === nodegroup_id;
}, this);
var templateFragments = [];
_.each(nodes, function(node){
templateFragments.push('<' + node.name + '{' + node.nodeid + '}>');
templateFragments.push('<' + node.name + '>');
}, this);


var template = templateFragments.join(', ');
this.primaryNameTemplate(template);
this.string_template(template);

}, this);

koMapping.fromJS({
string_template: this.primaryNameTemplate,
nodegroup_id: this.selectedNodegroup
string_template: this.string_template,
nodegroup_id: this.nodegroup_id
},params.primaryNameConfig);
},
template: {
Expand Down
6 changes: 5 additions & 1 deletion arches/app/media/js/views/graph/graph-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ require([
var graph = koMapping.fromJS(data.graph);
var iconFilter = ko.observable('');
var ontologyClass = ko.observable(data.node.ontologyclass);
var primaryNameConfig = koMapping.fromJS({});
var primaryNameConfig = koMapping.fromJS({
string_template: '',
nodegroup_id: ''
});
var jsonData = ko.computed(function() {
var relatableResourceIds = _.filter(data.resources, function(resource){
return resource.isRelatable();
Expand All @@ -33,6 +36,7 @@ require([
if (graph.ontology_id() === undefined) {
graph.ontology_id(null);
}
var x = primaryNameConfig;
return JSON.stringify({
graph: koMapping.toJS(graph),
relatable_resource_ids: relatableResourceIds,
Expand Down
11 changes: 7 additions & 4 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ def primary_name(self):
# config['nodegroup_id'] = '7a7dfaf5-971e-11e6-aec3-14109fd34195'
# config['string_template'] = '{6eeeb00f-9a32-11e6-a0c9-14109fd34195} Type({6eeeb9ca-9a32-11e6-ad09-14109fd34195})'

try:
functionConfig = models.FunctionXGraph.objects.get(graph=self.graph, function__functiontype='primaryname')
return get_primary_name(self, functionConfig.config)
except:
#try:
functionConfig = models.FunctionXGraph.objects.filter(graph=self.graph, function__functiontype='primaryname')
if len(functionConfig) == 1:
return get_primary_name(self, functionConfig[0].config)
else:
return 'undefined'
# except:
# return 'undefined'
#{"6eeeb00f-9a32-11e6-a0c9-14109fd34195": "Alexei", "6eeeb9ca-9a32-11e6-ad09-14109fd34195": ""}
#{"nodegroup_id": "6eeeb00f-9a32-11e6-a0c9-14109fd34195", "string_template": "{6eeeb00f-9a32-11e6-a0c9-14109fd34195} Type({6eeeb9ca-9a32-11e6-ad09-14109fd34195})"}
4 changes: 2 additions & 2 deletions arches/app/templates/views/functions/primary-name.htm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>

<div class="col-xs-12">
<select placeholder="{% trans "Select a nodegroup" %}" data-bind="chosen: {width: '100%'}, value: selectedNodegroup, options: cards, optionsText: 'name', optionsValue: 'nodegroup_id'"></select>
<select placeholder="{% trans "Select a nodegroup" %}" data-bind="chosen: {width: '100%'}, value: nodegroup_id, options: cards, optionsText: 'name', optionsValue: 'nodegroup_id'"></select>
</div>
</div>
</div>
Expand All @@ -18,7 +18,7 @@
</div>

<div class="col-xs-12">
<input placeholder="{% trans "put something here..." %}" class="form-control input-lg widget-input" data-bind="textInput: primaryNameTemplate">
<input placeholder="{% trans "put something here..." %}" class="form-control input-lg widget-input" data-bind="textInput: string_template">
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion arches/app/views/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def post(self, request, graphid):
if data['primaryNameViewModel']:
functionXgraph, created = models.FunctionXGraph.objects.update_or_create(
function_id = '60000000-0000-0000-0000-000000000010',
graph_id = graphid,
defaults = {
'graph_id': graphid,
'config': data['primaryNameViewModel']
}
)
Expand Down

0 comments on commit 6aef46a

Please sign in to comment.