Skip to content

Commit

Permalink
Merge pull request #9 from serge-gaia/data_visualization
Browse files Browse the repository at this point in the history
Data visualization
  • Loading branch information
serge-gaia authored Jun 10, 2016
2 parents 0accea9 + ec8707c commit 3060bf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions biosys/apps/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class AbstractRecord(models.Model):
def __str__(self):
return "{0}: {1}".format(self.dataset.name, Truncator(self.data).chars(100))

@property
def data_with_id(self):
return dict({'id': self.id}, **self.data)

class Meta:
abstract = True

Expand Down
24 changes: 18 additions & 6 deletions biosys/apps/publish/static/js/data_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,35 @@ biosys.view_data = function ($, _, moduleOptions) {
headers = _.map(ds.data_package.resources[0].schema.fields, function (field) {
return field.name;
});
// add the hidden id column

colDefs = _.map(headers, function (header) {
return {
'title': header,
'name': header,
'data': header
title: header,
name: header,
data: header
};
});
// add the hidden id column at the first place
colDefs.unshift(
{
title: 'id',
name: 'id',
data: 'id',
visible: false
}
);
url = '/publish/data/' + ds.id;
tableOptions = $.extend({}, defaultTableOptions, {
tableOptions = $.extend({
order: [[0, 'asc']] // sort by id
}, defaultTableOptions, {
ajax: {
url: url,
method: 'get',
error: function (xhr, textStatus, thrownError) {
console.log("Error while loading applications data:", thrownError, textStatus, xhr.responseText, xhr.status);
//Stop the data table 'Processing'.
//$(options.selectors.applicationsTable + '_processing').hide();
//$(options.selectors.table + '_processing').hide();
}
}
});
Expand All @@ -109,7 +122,6 @@ biosys.view_data = function ($, _, moduleOptions) {
return {
init: function () {
initProjectFilter();
//$('select').select2();
}
};
};
8 changes: 4 additions & 4 deletions biosys/apps/publish/views/data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def get_context_data(self, **kwargs):


class JSONDataTableView(LoginRequiredMixin, View):
def get(self, reuest, *args, **kwargs):
def get(self, request, *args, **kwargs):
ds = get_object_or_404(DataSet, pk=kwargs.get('pk'))
rows = []
records = GenericRecord.objects.filter(dataset=ds)
for record in records:
rows.append(record.data)
rows.append(record.data_with_id)
records = Observation.objects.filter(dataset=ds)
for record in records:
rows.append(record.data)
rows.append(record.data_with_id)
records = SpeciesObservation.objects.filter(dataset=ds)
for record in records:
rows.append(record.data)
rows.append(record.data_with_id)
return JsonResponse({
'data': rows
})

0 comments on commit 3060bf2

Please sign in to comment.