Skip to content

Commit

Permalink
Volumes: list annotations in manager
Browse files Browse the repository at this point in the history
Note that this also changes the response of the volumes listing endpoint
from an array of objects to an array of arrays, with a separate
`columns` field.
  • Loading branch information
aschampion authored and tomka committed Oct 17, 2018
1 parent e42e954 commit 0e577fd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
29 changes: 25 additions & 4 deletions django/applications/catmaid/control/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,31 @@ def volume_collection(request, project_id):
# FIXME: Parsing our PostGIS geometry with GeoDjango doesn't work
# anymore since Django 1.8. Therefore, the geometry fields isn't read.
# See: https://github.com/catmaid/CATMAID/issues/1250
fields = ('id', 'name', 'comment', 'user', 'editor', 'project',
'creation_time', 'edition_time')
volumes = Volume.objects.filter(project_id=project_id).values(*fields)
return Response(volumes)

cursor = connection.cursor()
cursor.execute("""
SELECT v.id, v.name, v.comment, v.user_id, v.editor_id, v.project_id,
v.creation_time, v.edition_time,
JSON_AGG(ann.name) FILTER (WHERE ann.name IS NOT NULL) AS annotations
FROM catmaid_volume v
LEFT JOIN volume_class_instance vci ON vci.volume_id = v.id
LEFT JOIN class_instance_class_instance cici
ON cici.class_instance_a = vci.class_instance_id
LEFT JOIN class_instance ann ON ann.id = cici.class_instance_b
WHERE v.project_id = %(pid)s
AND (
cici.relation_id IS NULL OR
cici.relation_id = (
SELECT id FROM relation
WHERE project_id = %(pid)s AND relation_name = 'annotated_with'
)
)
GROUP BY v.id
""", {'pid': project_id})
return JsonResponse({
'columns': [r[0] for r in cursor.description],
'data': cursor.fetchall()
})

def get_volume_details(project_id, volume_id):
cursor = connection.cursor()
Expand Down
10 changes: 10 additions & 0 deletions django/applications/catmaid/static/js/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,14 @@ CATMAID.tools = CATMAID.tools || {};
return path.substring(start, end);
};

/**
* Create an object from matched arrays of keys and values.
*/
tools.buildObject = function (keys, values) {
return keys.reduce(function (obj, k, i) {
obj[k] = values[i];
return obj;
}, {});
};

})(CATMAID.tools);
16 changes: 13 additions & 3 deletions django/applications/catmaid/static/js/widgets/volumewidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
table.style.width = "100%";
var header = table.createTHead();
var hrow = header.insertRow(0);
var columns = ['', 'Name', 'Id', 'Comment', 'User', 'Creation time',
var columns = ['', 'Name', 'Id', 'Comment', 'Annotations', 'User', 'Creation time',
'Editor', 'Edition time', 'Action'];
columns.forEach(function(c) {
hrow.insertCell().appendChild(document.createTextNode(c));
Expand All @@ -166,8 +166,8 @@

CATMAID.fetch(project.id + "/volumes/")
.then(function(volumeData) {
let volumes = volumeData.map(function(volume) {
return new CATMAID.Volume(volume);
let volumes = volumeData.data.map(function(volume) {
return new CATMAID.Volume(CATMAID.tools.buildObject(volumeData.columns, volume));
});
callback({
draw: data.draw,
Expand All @@ -186,6 +186,16 @@
{data: "title"},
{data: "id"},
{data: "comment"},
{
data: "annotations",
render: function (data, type, row, meta) {
if (type === 'display') {
return data.join(', ');
} else {
return data;
}
}
},
{
data: "user_id",
render: function(data, type, row, meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
*/
listAll: function(projectId) {
var url = projectId + '/volumes/';
return CATMAID.fetch(url, 'GET');
return CATMAID.fetch(url, 'GET').then(function (volumes) {
return volumes.data.map(function (vol) {
return CATMAID.tools.buildObject(volumes.columns, vol);
});
});
},

/**
Expand Down
7 changes: 4 additions & 3 deletions django/applications/catmaid/static/libs/catmaid/volumes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
CATMAID.Volume = function(options) {
options = options || {};
this.id = options.id || null;
this.project_id = options.project || null;
this.user_id = options.user || null;
this.editor_id = options.editor || null;
this.project_id = options.project_id || null;
this.user_id = options.user_id || null;
this.editor_id = options.editor_id || null;
this.title = options.name || '';
this.comment = options.comment || '';
this.edition_time = options.edition_time || null;
this.creation_time = options.creation_time || null;
this.selected = options.selected || false;
this.annotations = options.annotations || [];
};

CATMAID.Volume.prototype = {};
Expand Down

0 comments on commit 0e577fd

Please sign in to comment.