feat: add organisations to network view

See #78
This commit is contained in:
James Graham
2021-03-01 14:43:16 +00:00
parent 550d7cede0
commit b73e2dcb2d
3 changed files with 31 additions and 1 deletions

View File

@@ -15,7 +15,16 @@ class PersonSerializer(serializers.ModelSerializer):
'name',
]
class OrganisationSerializer(serializers.ModelSerializer):
class Meta:
model = models.Organisation
fields = [
'pk',
'name',
]
class RelationshipSerializer(serializers.ModelSerializer):
source = PersonSerializer()
target = PersonSerializer()

View File

@@ -53,6 +53,8 @@
-->
{{ person_set|json_script:'person-set-data' }}
{{ organisation_set|json_script:'organisation-set-data' }}
{{ relationship_set|json_script:'relationship-set-data' }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.14.0/cytoscape.min.js"
@@ -102,6 +104,22 @@
})
}
// Load organisations and add to graph
var organisation_set = JSON.parse(document.getElementById('organisation-set-data').textContent);
for (var item of organisation_set) {
cy.add({
group: 'nodes',
data: {
id: 'organisation-' + item.pk.toString(),
name: item.name
},
style: {
shape: 'rectangle'
}
})
}
// Load relationships and add to graph
var relationship_set = JSON.parse(document.getElementById('relationship-set-data').textContent);

View File

@@ -75,6 +75,9 @@ class NetworkView(LoginRequiredMixin, FormView):
context['person_set'] = serializers.PersonSerializer(
models.Person.objects.all(), many=True).data
context['organisation_set'] = serializers.OrganisationSerializer(
models.Organisation.objects.all(), many=True).data
context['relationship_set'] = serializers.RelationshipSerializer(
models.Relationship.objects.filter(
pk__in=relationship_answerset_set.values_list('relationship',