diff --git a/arches/app/functions/resource_functions.py b/arches/app/functions/resource_functions.py index 8f59e18097f..478e281c429 100644 --- a/arches/app/functions/resource_functions.py +++ b/arches/app/functions/resource_functions.py @@ -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[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'] diff --git a/arches/app/media/js/views/functions/primary-name.js b/arches/app/media/js/views/functions/primary-name.js index e00d5003739..e40cc765d8d 100644 --- a/arches/app/media/js/views/functions/primary-name.js +++ b/arches/app/media/js/views/functions/primary-name.js @@ -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: { diff --git a/arches/app/media/js/views/graph/graph-settings.js b/arches/app/media/js/views/graph/graph-settings.js index dab28c7feb9..da95330a950 100644 --- a/arches/app/media/js/views/graph/graph-settings.js +++ b/arches/app/media/js/views/graph/graph-settings.js @@ -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(); @@ -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, diff --git a/arches/app/models/resource.py b/arches/app/models/resource.py index c661291d986..c50fd61df9f 100644 --- a/arches/app/models/resource.py +++ b/arches/app/models/resource.py @@ -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})"} \ No newline at end of file diff --git a/arches/app/templates/views/functions/primary-name.htm b/arches/app/templates/views/functions/primary-name.htm index 84d19e72939..e41d6c0e1ba 100644 --- a/arches/app/templates/views/functions/primary-name.htm +++ b/arches/app/templates/views/functions/primary-name.htm @@ -7,7 +7,7 @@
- +
@@ -18,7 +18,7 @@
- +
diff --git a/arches/app/views/graph.py b/arches/app/views/graph.py index cb057e4407c..57c164ccce1 100644 --- a/arches/app/views/graph.py +++ b/arches/app/views/graph.py @@ -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'] } )