diff --git a/varify/samples/resources.py b/varify/samples/resources.py index d8896ccf..94c1f55c 100644 --- a/varify/samples/resources.py +++ b/varify/samples/resources.py @@ -17,6 +17,7 @@ from varify import api from varify.assessments.models import Assessment from .models import Sample, Result, ResultScore +from restlib2.http import codes log = logging.getLogger(__name__) @@ -246,6 +247,28 @@ def get(self, request, pk): return data + post = get + + +class ResultsResource(ThrottledResource): + template = api.templates.SampleResultVariant + + def post(self, request): + ids_not_found = 'ids' not in request.data + not_a_list = not isinstance(request.data['ids'], list) + + if ids_not_found or not_a_list: + return self.render( + {'message': 'An array of "ids" is required'}, + status=codes.unprocessable_entity) + + data = [] + resource = SampleResultResource() + for id in request.data['ids']: + data.append(resource.get(request, id)) + + return data + class PhenotypeResource(ThrottledResource): def get(self, request, sample_id): @@ -327,6 +350,7 @@ def get(self, request, year, month, day, name): named_sample_resource = never_cache(NamedSampleResource()) sample_results_resource = never_cache(SampleResultsResource()) sample_result_resource = never_cache(SampleResultResource()) +results_resource = never_cache(ResultsResource()) phenotype_resource = never_cache(PhenotypeResource()) pedigree_resource = never_cache(PedigreeResource()) @@ -338,6 +362,7 @@ def get(self, request, year, month, day, name): named_sample_resource, name='named_sample'), url(r'^(?P\d+)/variants/$', sample_results_resource, name='variants'), url(r'^variants/(?P\d+)/$', sample_result_resource, name='variant'), + url(r'^variants/$', results_resource, name='results_resource'), url(r'^(?P.+)/phenotypes/$', phenotype_resource, name='phenotype'), url(r'^pedigrees/(?P\d+)/(?P\d+)/(?P\d+)/(?P.+)$', diff --git a/varify/static/js/src/models/result.js b/varify/static/js/src/models/result.js index 0b04689f..d3b0781f 100644 --- a/varify/static/js/src/models/result.js +++ b/varify/static/js/src/models/result.js @@ -44,7 +44,16 @@ define([ } }); + var ResultCollection = Backbone.Collection.extend({ + model: Result, + + url: function() { + return '' + utils.getRootUrl() + 'api/samples/variants/'; + } + }); + return { - Result: Result + Result: Result, + ResultCollection: ResultCollection }; }); diff --git a/varify/static/js/src/ui/tables/body.js b/varify/static/js/src/ui/tables/body.js index 18ba24a5..9712ab64 100644 --- a/varify/static/js/src/ui/tables/body.js +++ b/varify/static/js/src/ui/tables/body.js @@ -3,8 +3,9 @@ define([ 'underscore', 'marionette', + '../../models', './row' -], function(_, Marionette, row) { +], function(_, Marionette, models, row) { // Represents a "frame" of rows. The model is referenced for keeping // track which frame this is relative to the whole series. @@ -13,11 +14,18 @@ define([ template: function() {}, - itemView: row.ResultRow, + initialize: function(options) { + this.collection = new models.ResultCollection(); + var data = {ids: options.collection.pluck('pk')}; + this.collection.fetch({ + data: JSON.stringify(data), + type: 'POST', + contentType: 'application/json', + parse: true + }); + }, - itemViewOptions: function (model, index) { - return _.defaults({resultPk: model.get('pk')}, this.options); - } + itemView: row.ResultRow }); return { diff --git a/varify/static/js/src/ui/tables/row.js b/varify/static/js/src/ui/tables/row.js index 29c05c45..bfa96385 100644 --- a/varify/static/js/src/ui/tables/row.js +++ b/varify/static/js/src/ui/tables/row.js @@ -19,27 +19,11 @@ define([ 'click': 'onClick' }, - onClick: function(events) { + onClick: function() { c.dialogs.resultDetails.open(this, this.model); }, - initialize: function() { - _.bindAll(this, 'onSync'); - - this.data = {}; - - if (!(this.data.resultPk = this.options.resultPk)) { - throw new Error('result pk required'); - } - - this.model = new models.Result({ - id: this.data.resultPk - }); - - this.model.on('sync', this.onSync); - }, - - onSync: function() { + onRender: function() { var $condensedFlags, $gene, $genomicPosition, $genotype, $hgvsC, $hgvsP, $phenotypeScore, $variantEffects, assessment, resultScore, variant; @@ -84,12 +68,7 @@ define([ this.$el.empty(); return this.$el.append($gene, $hgvsP, $variantEffects, $hgvsC, $genotype, $genomicPosition, $phenotypeScore, $condensedFlags); - }, - - onRender: function() { - this.model.fetch(); } - }); var EmptyResultRow = c.ui.LoadView.extend({