From e94f6366cf9df71e7a2bc533eed1218166f3036d Mon Sep 17 00:00:00 2001 From: NikoAnderson Date: Wed, 1 May 2024 15:52:38 -0400 Subject: [PATCH] added facet sort and ref cit mapping --- src/app/core/config/config.model.ts | 3 + .../facets-manager.component.html | 17 ++++ .../facets-manager.component.ts | 93 ++++++++++++++++++- .../facets-manager/facets-manager.module.ts | 4 + .../references/reference-form.component.html | 2 +- .../references/reference-form.component.ts | 15 +++ .../structure/structure-form.component.html | 2 +- src/app/core/substance/substance.service.ts | 24 ++++- 8 files changed, 154 insertions(+), 6 deletions(-) diff --git a/src/app/core/config/config.model.ts b/src/app/core/config/config.model.ts index 09a35c839..997abcdc7 100644 --- a/src/app/core/config/config.model.ts +++ b/src/app/core/config/config.model.ts @@ -68,6 +68,9 @@ export interface Config { codeSystemMapping?: { [code: string]: string; }; + citationMapping?: { + [code: string]: string; + }; structureEditor?: 'ketcher' | 'jsdraw'; nameFormPageSizeOptions?: Array; nameFormPageSizeDefault?: number; diff --git a/src/app/core/facets-manager/facets-manager.component.html b/src/app/core/facets-manager/facets-manager.component.html index ee7a4f2fb..900966649 100644 --- a/src/app/core/facets-manager/facets-manager.component.html +++ b/src/app/core/facets-manager/facets-manager.component.html @@ -43,6 +43,23 @@ +
diff --git a/src/app/core/facets-manager/facets-manager.component.ts b/src/app/core/facets-manager/facets-manager.component.ts index e45706f68..3c76f12f7 100644 --- a/src/app/core/facets-manager/facets-manager.component.ts +++ b/src/app/core/facets-manager/facets-manager.component.ts @@ -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', @@ -45,6 +48,10 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit _facetNameText: string; urlSearch: string; stagingFacets: any; + facetSort: Array = []; + public sortValues = searchSortValues; + order: string; + testing = new FormControl(); private privateFacetParams: FacetParam; private privateRawFacets: Array; private facetSearchChanged = new Subject<{ index: number; query: any; facets?: any; }>(); @@ -165,6 +172,10 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit }); } + facetViewChange() { + + } + ngOnDestroy() { this.subscriptions.forEach(subscription => { subscription.unsubscribe(); @@ -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 => { @@ -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; }); @@ -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) { @@ -696,20 +713,37 @@ 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; @@ -717,16 +751,71 @@ export class FacetsManagerComponent implements OnInit, OnDestroy, AfterViewInit 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 = ''; diff --git a/src/app/core/facets-manager/facets-manager.module.ts b/src/app/core/facets-manager/facets-manager.module.ts index ef208b744..37b153c9d 100644 --- a/src/app/core/facets-manager/facets-manager.module.ts +++ b/src/app/core/facets-manager/facets-manager.module.ts @@ -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: [ @@ -24,6 +26,8 @@ import { CodeDisplayModule } from '@gsrs-core/utils/code-display.module'; MatExpansionModule, MatFormFieldModule, MatInputModule, + MatOptionModule, + MatSelectModule, MatCheckboxModule, FormsModule, MatIconModule, diff --git a/src/app/core/substance-form/references/reference-form.component.html b/src/app/core/substance-form/references/reference-form.component.html index 88f1f125b..70098eb29 100644 --- a/src/app/core/substance-form/references/reference-form.component.html +++ b/src/app/core/substance-form/references/reference-form.component.html @@ -7,7 +7,7 @@
+ (valueChange)= "setSourceType($event)" name = "docType"> diff --git a/src/app/core/substance-form/references/reference-form.component.ts b/src/app/core/substance-form/references/reference-form.component.ts index 15c57635f..96093dba0 100644 --- a/src/app/core/substance-form/references/reference-form.component.ts +++ b/src/app/core/substance-form/references/reference-form.component.ts @@ -27,6 +27,7 @@ export class ReferenceFormComponent implements OnInit, AfterViewInit, OnDestroy showPrev = false; loading = false; error = false; + citationMapping: any; private subscriptions: Array = []; constructor( private cvService: ControlledVocabularyService, @@ -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() { @@ -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]; + } + + } + } diff --git a/src/app/core/substance-form/structure/structure-form.component.html b/src/app/core/substance-form/structure/structure-form.component.html index 00b942d00..8e0020817 100644 --- a/src/app/core/substance-form/structure/structure-form.component.html +++ b/src/app/core/substance-form/structure/structure-form.component.html @@ -1,7 +1,7 @@
- + diff --git a/src/app/core/substance/substance.service.ts b/src/app/core/substance/substance.service.ts index a5df8ec90..d9aaf68ac 100644 --- a/src/app/core/substance/substance.service.ts +++ b/src/app/core/substance/substance.service.ts @@ -812,10 +812,12 @@ export class SubstanceService extends BaseHttpService { - getSubstanceFacets(facet: Facet, searchTerm?: string, nextUrl?: string, otherFacets?: string, pageQuery?: string): Observable { + getSubstanceFacets(facet: Facet, searchTerm?: string, nextUrl?: string, otherFacets?: string, pageQuery?: string, sort?: string, order?: string): Observable { 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}`; } @@ -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(url); }