Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/client/components/element-info/entity-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class EntityInfo extends DataComponent {
name: name,
limit: s.limit,
offset: offset,
organismCounts: doc.organismCountsJson()
organismCounts: doc.organismCountsJson(el) // exclude el from org count (avoids mid typing biases)
};

if( s.updatePromise ){
Expand Down Expand Up @@ -467,7 +467,6 @@ class EntityInfo extends DataComponent {

orgMatches = _.sortBy(orgMatches, m => m.organismName);

const selectedIndex = _.findIndex(orgMatches, match => match.id === m.id && match.namespace === m.namespace);
const selectedOrg = assoc ? assoc.organism : null;

const getSelectDisplay = (om, includeName = false) => {
Expand All @@ -490,20 +489,20 @@ class EntityInfo extends DataComponent {
organism = h('div.entity-info-section.entity-info-organism-refinement', [
h('span.entity-info-title', 'Organism'),
h('select.entity-info-organism-dropdown', {
defaultValue: selectedIndex,
value: `${m.namespace}:${m.id}`,
onChange: e => {
const val = e.target.value;
const index = parseInt(val);
const om = orgMatches[index];
const [ns, id] = val.split(':');
const om = s.matches.find(match => match.namespace === ns && match.id === id);

if( om ){
this.associate(om);
} else {
this.enableManualMatchMode();
}
}
}, orgMatches.map((om, index) => {
const value = index;
}, orgMatches.map((om) => {
const value = `${om.namespace}:${om.id}`;
const orgMatches = orgToMatches.get(om.organism);
const multOrgMatches = orgMatches.length > 1;
const isFirstOrgMatch = orgMatches[0].id === om.id && orgMatches[0].namespace === om.namespace;
Expand All @@ -514,7 +513,7 @@ class EntityInfo extends DataComponent {

return h('option', { value }, getSelectDisplay(om));
}).concat([
selectedIndex < 0 ? h('option', { value: -1 }, getSelectDisplay(m, true)) : null,
// selectedIndex < 0 ? h('option', { value: -1 }, getSelectDisplay(m, true)) : null,
h('option', { value: -2 }, 'Other')
]))
]);
Expand All @@ -524,30 +523,28 @@ class EntityInfo extends DataComponent {
const needDisam = ambigGrs && ambigGrs.length > 1;

if( needDisam ){
const selectedAmIndex = _.findIndex(ambigGrs, match => match.id === m.id && match.namespace === m.namespace);

disambiguation = h('div.entity-info-section.entity-info-organism-refinement', [
h('span.entity-info-title', 'Which' + (s.name ? ` ${s.name}` : '') + ''),
h('select.entity-info-organism-dropdown', {
defaultValue: selectedAmIndex,
value: `${m.namespace}:${m.id}`,
onChange: e => {
const val = e.target.value;
const index = parseInt(val);
const om = ambigGrs[index];
const [ns, id] = val.split(':');
const om = s.matches.find(om => om.namespace === ns && om.id === id);

if( om ){
this.associate(om);
} else {
this.enableManualMatchMode();
}
}
}, ambigGrs.map((om, index) => {
const value = index;
}, ambigGrs.map((om) => {
const value = `${om.namespace}:${om.id}`;

return h('option', { value }, getDisamtDisplay(om));
}).concat([
selectedIndex < 0 ? h('option', { value: -1 }, getSelectDisplay(m, true)) : null,
h('option', { value: -2 }, 'Other')
// selectedIndex < 0 ? h('option', { value: -1 }, getSelectDisplay(m, true)) : null,
h('option', { value: 'other:other' }, 'Other')
]))
]);
}
Expand Down
8 changes: 5 additions & 3 deletions src/model/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,19 @@ class Document {
}

// mention count for all organisms (toggle + ent mentions)
organismCounts(){
organismCounts(excludedEnt){
let cnt = new Map(); // org => mention count
let addToCount = org => cnt.set( org, !cnt.has(org) ? 1 : cnt.get(org) + 1 );
let entIsAssocd = ent => ent.associated();
let entIsNotExcluded = ent => excludedEnt == null || !ent.same(excludedEnt);
let getOrgIdForEnt = ent => _.get( ent.association(), ['organism'] );

this.toggledOrganisms().forEach( addToCount );

(
this.entities()
.filter( entIsAssocd )
.filter( entIsNotExcluded )
.map( getOrgIdForEnt )
.filter( isNonNil ) // may be an entity w/o org
.forEach( addToCount )
Expand All @@ -261,10 +263,10 @@ class Document {
return cnt;
}

organismCountsJson(){
organismCountsJson(excludedEnt){
let json = {};

for( let [org, count] of this.organismCounts() ){
for( let [org, count] of this.organismCounts(excludedEnt) ){
json[ org ] = count;
}

Expand Down
4 changes: 4 additions & 0 deletions src/model/element/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class Element {
return this.syncher.get('id');
}

same(otherEle){
return this.id() === otherEle.id();
}

secret(){
return this.syncher.get('secret');
}
Expand Down