Skip to content

Commit

Permalink
added facet sort and ref cit mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoAnderson committed May 1, 2024
1 parent 2823c47 commit e94f636
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/app/core/config/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export interface Config {
codeSystemMapping?: {
[code: string]: string;
};
citationMapping?: {
[code: string]: string;
};
structureEditor?: 'ketcher' | 'jsdraw';
nameFormPageSizeOptions?: Array<number>;
nameFormPageSizeDefault?: number;
Expand Down
17 changes: 17 additions & 0 deletions src/app/core/facets-manager/facets-manager.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@
<mat-progress-bar class="facet-search-loading" mode="indeterminate"
*ngIf="searchText[facet.name] && searchText[facet.name].isLoading"></mat-progress-bar>
</div>
<div class="facet-advanced-options-link" *ngIf="facet.$showAdvanced">
<mat-form-field class="sort">
<mat-label>Sort Results By</mat-label>
<mat-select (openedChange)="facetOrderChange(topIndex, $event)" [ngModel] = "facetSort[topIndex]" (selectionChange)="facetOrderChange(topIndex, facet, $event)">
<!--<mat-option *ngFor="let option of sortValues" [value]="option.value">
{{option.display}}
</mat-option>-->
<mat-option value="count" selected> count </mat-option>
<mat-option value="inverse">inverse count </mat-option>

<mat-option value="AZ"> Alphabetical AZ </mat-option>
<mat-option value="ZA"> Alphabetical ZA </mat-option>


</mat-select>
</mat-form-field>
</div>
<ng-container *ngFor="let value of facet.values; index as index">
<div class="facet-value">
<div class="facet-value-checkbox">
Expand Down
93 changes: 91 additions & 2 deletions src/app/core/facets-manager/facets-manager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { DisplayFacet } from './display-facet';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { UserQueryListDialogComponent } from '@gsrs-core/bulk-search/user-query-list-dialog/user-query-list-dialog.component';
import { MatDialogRef, MatDialog } from '@angular/material/dialog';
import { searchSortValues } from '../utils/search-sort-values';
import { FormControl, FormGroup, Validators, FormBuilder } from '@angular/forms';


@Component({
selector: 'app-facets-manager',
Expand Down Expand Up @@ -45,6 +48,10 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit
_facetNameText: string;
urlSearch: string;
stagingFacets: any;
facetSort: Array<any> = [];
public sortValues = searchSortValues;
order: string;
testing = new FormControl();
private privateFacetParams: FacetParam;
private privateRawFacets: Array<Facet>;
private facetSearchChanged = new Subject<{ index: number; query: any; facets?: any; }>();
Expand Down Expand Up @@ -165,6 +172,10 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit
});
}

facetViewChange() {

}

ngOnDestroy() {
this.subscriptions.forEach(subscription => {
subscription.unsubscribe();
Expand All @@ -173,16 +184,20 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit

ngAfterViewInit() {
this.urlSearch = this.activatedRoute.snapshot.queryParams['search'] || null;
let index = 0;
if (this.includeFacetSearch) {
const facetSearchSubscription = this.facetSearchChanged.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap(event => {

index = event.index;
const facet = this.facets[event.index];
this.facetOrderChange(event.index, facet);
if (!facet._self) {
facet._self = this.facetManagerService.generateSelfUrl('stagingArea', facet.name);
}
return this.facetsService.getFacetsHandler(facet, event.query, null, this.privateFacetParams, this.urlSearch).pipe(take(1));
return this.facetsService.getFacetsHandler(facet, event.query, null, this.privateFacetParams, this.urlSearch).pipe(take(1));
})
).subscribe(response => {
this.activeSearchedFaced.values = this.activeSearchedFaced.values.filter(value => {
Expand All @@ -207,6 +222,7 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit
});
this.activeSearchedFaced.values = this.activeSearchedFaced.values.concat(response.content);
this.searchText[this.activeSearchedFaced.name].isLoading = false;
this.facetOrderChange(index, this.activeSearchedFaced);
}, error => {
this.searchText[this.activeSearchedFaced.name].isLoading = false;
});
Expand Down Expand Up @@ -688,6 +704,7 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit

moreFacets(index: number, facet: Facet) {
this.facets[index].$isLoading = true;
this.searchText[facet.name].isLoading = true;
// This check for _self should be temporary while it's incorporation in the staging area is complete.
// If no meta fields exist, generate what they are expected to look like
if (facet.$next == null) {
Expand All @@ -696,37 +713,109 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit
}
facet.$next = facet._self.replace('fskip=0', 'fskip=10');
}
this.facetManagerService.getFacetsHandler(this.facets[index], '', facet.$next, this.privateFacetParams, this.urlSearch).pipe(take(1)).subscribe(resp => {

let sort = 'count';
let direction = 'true';

if (this.facetSort[index]) {
if (this.facetSort[index] === 'inverse') {
direction = 'false';
} else if (this.facetSort[index] === 'AZ'){
sort = 'name';
direction = 'false';
}else if (this.facetSort[index] === 'ZA'){
sort = 'name';
}
}
this.facetManagerService.getFacetsHandler(this.facets[index], '', facet.$next, this.privateFacetParams, this.urlSearch, sort, direction).pipe(take(1)).subscribe(resp => {
this.facets[index].$next = resp.nextPageUri;
this.facets[index].$previous = resp.previousPageUri;
this.facets[index].values = this.facets[index].values.concat(resp.content);
this.facets[index].$fetched = this.facets[index].values;
this.facets[index].$total = resp.ftotal;
this.facets[index].$isLoading = false;
this.searchText[facet.name].isLoading = false;
}, error => {
this.facets[index].$isLoading = false;
this.searchText[facet.name].isLoading = false;
});
}

lessFacets(index: number) {
this.facets[index].$isLoading = true;
this.searchText[this.facets[index].name].isLoading = true;
const nextUrl = this.facets[index].$next;
this.facetManagerService.getFacetsHandler(this.facets[index], null, null, this.privateFacetParams, this.urlSearch).pipe(take(1)).subscribe(response => {
this.facets[index].values = response.content;
this.facets[index].$fetched = response.content;
this.facets[index].$next = response.nextPageUri;
this.facets[index].$previous = response.previousPageUri;
this.facets[index].$isLoading = false;
this.searchText[this.facets[index].name].isLoading = false;
}, error => {
this.facets[index].$isLoading = false;
this.searchText[this.facets[index].name].isLoading = false;
});
}

filterFacets(index: number, searchTerm: string, faceName: string): void {
this.searchText[faceName].isLoading = true;
this.activeSearchedFaced = this.facets[index];
this.facetOrderChange(index, this.activeSearchedFaced);
console.log(this.facetSort[index]);
this.facetSearchChanged.next({ index: index, query: searchTerm, facets: this.privateFacetParams });
setTimeout( ()=> this.facetOrderChange(index, this.activeSearchedFaced)
, 500 );
}
facetOrderChange( index, facet, event?) {
//re-fetch facets from server if clicking more... otherwise frontend sort if facet is displaying search results.
if (event) {
this.facetSort[index] = event.value;
if (this.searchText[facet]) {

if(this.facetSort[index]) {
if (this.facetSort[index] === 'count') {
this.facets[index].values = this.facets[index].values.sort((a, b) => a.count-b.count);
}
else if (this.facetSort[index] === 'inverse') {
this.facets[index].values = this.facets[index].values.sort((a, b) => a.count-b.count);
} else if (this.facetSort[index] === 'AZ') {
this.facets[index].values = this.facets[index].values.sort((a, b) => a.label.localeCompare(b.label));

} else if (this.facetSort[index] === 'ZA') {
this.facets[index].values = this.facets[index].values.sort((a, b) => b.label.localeCompare(a.label));
}
}
} else {
let sort = 'count';
let order = 'true';
if (this.facetSort[index] === 'inverse') {
order = 'false';
} else if (this.facetSort[index] === 'AZ') {
sort = 'name';
order = 'false';
} else if (this.facetSort[index] === 'ZA') {
sort = 'name';

}
this.facets[index]._self.replace('fskip=0', 'fskip=10');
this.facetManagerService.getFacetsHandler(this.facets[index], '', null, this.privateFacetParams, this.urlSearch, sort, order).pipe(take(1)).subscribe(resp => {
this.facets[index].$next = resp.nextPageUri;
this.facets[index].$previous = resp.previousPageUri;
this.facets[index].values = resp.content;
this.facets[index].$fetched = this.facets[index].values;
this.facets[index].$total = resp.ftotal;
// this.facets[index].$isLoading = false;
// this.searchText[facet.name].isLoading = false;
}, error => {
// this.facets[index].$isLoading = false;
// this.searchText[facet.name].isLoading = false;
});
}
}

}


clearFacetSearch(index: number, facetName: string): void {
this.searchText[facetName].value = '';
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/facets-manager/facets-manager.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { FormsModule } from '@angular/forms';
import { FacetDisplayPipe } from './facet-display.pipe';
import { FacetFilterPipe } from './facet-filter.pipe';
import { CodeDisplayModule } from '@gsrs-core/utils/code-display.module';
import { MatOptionModule } from '@angular/material/core';
import { MatSelectModule } from '@angular/material/select';

@NgModule({
declarations: [
Expand All @@ -24,6 +26,8 @@ import { CodeDisplayModule } from '@gsrs-core/utils/code-display.module';
MatExpansionModule,
MatFormFieldModule,
MatInputModule,
MatOptionModule,
MatSelectModule,
MatCheckboxModule,
FormsModule,
MatIconModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div class="form-row">
<app-cv-input required = 'true' class="source-type" domain = 'DOCUMENT_TYPE' title = "Source Type" [model] = "reference.docType"
(valueChange)= "reference.docType = $event" name = "docType">
(valueChange)= "setSourceType($event)" name = "docType">
</app-cv-input>
<mat-form-field class="citation">
<input matInput placeholder="Source Text/Citation" [(ngModel)]="reference.citation" required name="citation" />
Expand Down
15 changes: 15 additions & 0 deletions src/app/core/substance-form/references/reference-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy
showPrev = false;
loading = false;
error = false;
citationMapping: any;
private subscriptions: Array<Subscription> = [];
constructor(
private cvService: ControlledVocabularyService,
Expand All @@ -41,6 +42,10 @@ export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy
ngOnInit() {
this.overlayContainer = this.overlayContainerService.getContainerElement();
this.disableReferenceDocumentUpload = this.configService.configData.disableReferenceDocumentUpload;
if (this.configService.configData && this.configService.configData.citationMapping) {
//This config object is meant to map certain source type values with an automatically filled out citation value on selection.
this.citationMapping = this.configService.configData.citationMapping;
}
}

ngAfterViewInit() {
Expand Down Expand Up @@ -140,4 +145,14 @@ export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy
window.open(url);
}

setSourceType(event: any): void {
if (event) {
this.reference.docType = event;
}
if (this.citationMapping && this.citationMapping[this.reference.docType]) {
this.reference.citation = this.citationMapping[this.reference.docType];
}

}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form class="structure-form" *ngIf="structure && type === 'structure'">
<div class="form-row">
<mat-form-field class="mol-formula">
<input matInput placeholder="Molecular Formula" [(ngModel)]="structure.formula" name="formula" required />
<input matInput placeholder="Molecular Formula" [(ngModel)]="structure.formula" name="formula" />
</mat-form-field>

<mat-form-field class="stereochemistry">
Expand Down
24 changes: 22 additions & 2 deletions src/app/core/substance/substance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,12 @@ export class SubstanceService extends BaseHttpService {



getSubstanceFacets(facet: Facet, searchTerm?: string, nextUrl?: string, otherFacets?: string, pageQuery?: string): Observable<FacetQueryResponse> {
getSubstanceFacets(facet: Facet, searchTerm?: string, nextUrl?: string, otherFacets?: string, pageQuery?: string, sort?: string, order?: string): Observable<FacetQueryResponse> {
let url: string;
console.log('this one');
//console.log(nextUrl);
if (searchTerm) {
url = `${this.configService.configData.apiBaseUrl}api/v1/substances/search/@facets?wait=false&kind=ix.ginas.models.v1.Substance&skip=0&fdim=200&sideway=true&field=${facet.name.replace(' ', '+')}&top=14448&fskip=0&fetch=100&termfilter=SubstanceDeprecated%3Afalse&order=%24lastEdited&ffilter=${searchTerm}`;
url = `http://gsrs-test-public.ncats.io:8080/api/v1/substances/search/@facets?wait=false&kind=ix.ginas.models.v1.Substance&skip=0&fdim=200&sideway=true&field=${facet.name.replace(' ', '+')}&top=14448&fskip=0&fetch=100&termfilter=SubstanceDeprecated%3Afalse&ffilter=${searchTerm}`;
if(pageQuery) {
url += `&q=${pageQuery}`;
}
Expand All @@ -832,6 +834,24 @@ export class SubstanceService extends BaseHttpService {
}
});
}
if (sort) {
if(url.indexOf('sortBy') !== -1){

} else {
url += "&sortBy=" + sort;
}
}
if (order) {
if(url.indexOf('sortDesc') !== -1){

} else {
url += "&sortDesc=" + order;
}
}

url = url.replace('http://localhost:8081/','http://gsrs-test-public.ncats.io:8080/' );
console.log(url);

return this.http.get<FacetQueryResponse>(url);
}

Expand Down

0 comments on commit e94f636

Please sign in to comment.