Ejemplo n.º 1
0
Archivo: globi.js Proyecto: ritec/globi
 showData: function(data, searchHash) {
     var me = this, stats = { sourceTaxa: [], targetTaxa: [], interactionCount: 0 };
     searchHash.resultType = 'csv';
     searchHash.includeObservations = true;
     searchHash.fields = ['source_taxon_id', 'source_taxon_name', 'source_taxon_path', 'source_taxon_path_ids',
         'source_specimen_life_stage','source_specimen_physiological_state','source_specimen_body_part'
         , 'interaction_type'
         , 'target_taxon_id', 'target_taxon_name', 'target_taxon_path', 'target_taxon_path_ids'
         , 'target_specimen_life_stage','target_specimen_physiological_state','target_specimen_body_part'
         , 'latitude', 'longitude'
         , 'study_citation', 'study_url', 'study_source_citation'];
     var downloadUrl = globiData.urlForTaxonInteractionQuery(searchHash);
     var odd = true;
     if (data.length > 0) {
         var table = $('<table class="interactions-result"/>');
         var tableHead = $('<thead/>');
         var tableBody = $('<tbody/>');
         data.forEach(function (item) {
             var rowId = (item.source_taxon_external_id + '---' + item.interaction_type + '---' + item.target_taxon_external_id).replace(/:/g, '_');
             if (stats.sourceTaxa.indexOf(item.source_taxon_external_id) === -1) {
                 stats.sourceTaxa.push(item.source_taxon_external_id);
             }
             if (stats.targetTaxa.indexOf(item.target_taxon_external_id) === -1) {
                 stats.targetTaxa.push(item.target_taxon_external_id);
             }
             stats.interactionCount++;
             tableBody.append(
                 '<tr id="' + rowId + '" class="interaction-result ' + (odd ? 'odd' : 'even') + '" ' +
                     'data-source-taxon="' + item.source_taxon_external_id + '" ' +
                     'data-source-taxon-name="' + item.source_taxon_name + '" ' +
                     'data-target-taxon="' + item.target_taxon_external_id + '" ' +
                     'data-target-taxon-name="' + item.target_taxon_name + '" ' +
                     'data-interaction-type="' + item.interaction_type + '">' +
                     '<td class="source-cell">' + item.source_taxon_name + '</td>' +
                     '<td class="type-cell">' + me._camelCaseToRealWords(item.interaction_type) + '</td>' +
                     '<td class="target-cell">' + item.target_taxon_name + '</td>' +
                 '</tr>');
             odd = !odd;
         });
         tableHead.append(
             '<tr>' +
             '<th></th>' +
             '<th class="download"><a href="' + downloadUrl + '">Download data</a></th>' +
             '<th></th>' +
             '</tr>' +
             '<tr>' +
             '<th>' + stats.sourceTaxa.length + ' source(s)' + '</th>' +
             '<th>' + stats.interactionCount + ' interaction(s)' + '</th>' +
             //'<th><a href="' + downloadUrl + '">Download ' + stats.interactionCount + ' interaction(s)' + '</a></th>' +
             '<th>' + stats.targetTaxa.length + ' target(s)' + '</th>' +
             '</tr>');
         table.append(tableHead);
         table.append(tableBody);
         this.resultView.append(table);
     } else {
         this.resultView.html('Empty resultset');
     }
 },
Ejemplo n.º 2
0
Archivo: globi.js Proyecto: ritec/globi
        retrieveData: function() {
            var me = this,
                searchHash = {
                    'resultType': 'json',
                    'bbox': me.settings.bboxString
                },
                url;
            var selectorCount = 0;

            if (this.selectedSourceTaxon !== null) {
                searchHash['sourceTaxa'] = [this.selectedSourceTaxon];
                selectorCount++;
            }
            if (this.selectedTargetTaxon !== null) {
                searchHash['targetTaxa'] = [this.selectedTargetTaxon];
                selectorCount++;
            }
            if (this.selectedInteractionType !== null) {
                searchHash['interactionType'] = this.selectedInteractionType;
                selectorCount++;
            }

            url = globiData.urlForTaxonInteractionQuery(searchHash);

            if (!this.dataFetcher) {
                this.dataFetcher = new globi.PaginatedDataFetcher({
                    url: url
                });
            } else {
                this.dataFetcher.settings.url = url;
            }
            clearTimeout(this.timeout);
            me.clearResultView();
            if (selectorCount > 1) {
                this.timeout = setTimeout(function() {
                    me.disableSelectors();
                    me.dataFetcher.fetch(function(data) {
                        me.enableSelectors();
                        me.showData(globi.ResponseMapper(data)(), searchHash);
                    });
                }, 500);

            } else {
                me.enableSelectors();
            }
        },