From e7bc4865aaff00ae88682497d44910357d59d09a Mon Sep 17 00:00:00 2001 From: NikoAnderson Date: Fri, 9 Aug 2024 13:31:46 -0400 Subject: [PATCH] setup for features, fixing broken link for search --- src/app/core/app-routing.module.ts | 6 +- .../structure-editor.component.ts | 10 +-- .../structure-post-response.model.ts | 2 +- src/app/core/structure/structure.service.ts | 2 +- ...bstance-form-structure-card.component.html | 11 ++- ...substance-form-structure-card.component.ts | 74 +++++++++++++------ .../substance-form.component.html | 3 +- .../substance-form.component.ts | 7 ++ .../substance-form/substance-form.service.ts | 1 - .../custom-multi-checkbox-widget.component.ts | 1 - .../custom-select-widget.component.ts | 1 - 11 files changed, 77 insertions(+), 41 deletions(-) diff --git a/src/app/core/app-routing.module.ts b/src/app/core/app-routing.module.ts index c28b77618..b4db649b8 100644 --- a/src/app/core/app-routing.module.ts +++ b/src/app/core/app-routing.module.ts @@ -126,7 +126,11 @@ const childRoutes: Routes = [ { path: 'user-downloads/:id', component: UserDownloadsComponent - } + }, + { + path: 'structure-features', + component: SubstanceFormComponent + }, ]; const routes: Routes = [ diff --git a/src/app/core/structure-editor/structure-editor.component.ts b/src/app/core/structure-editor/structure-editor.component.ts index 1e583c618..21287580d 100644 --- a/src/app/core/structure-editor/structure-editor.component.ts +++ b/src/app/core/structure-editor/structure-editor.component.ts @@ -135,7 +135,6 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro // override JSDraw for Molvec paste event. Using the JSDraw menu copy function seems to ignore this at first checkPaste = (event: ClipboardEvent ) => { - console.log('check paste'); if ((this.jsdraw || this.ketcher )&& this.getSketcher().activated) { event.preventDefault(); event.stopPropagation(); @@ -385,6 +384,10 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro } onDropHandler(object: any): void { + //rule out tiny icons / images accidentally being dragged from jsdraw UI + if(object.backup.size < 700) { + this.canvasMessage = 'The selected file is too small to be read (<700 bytes)'; + } if (object.invalidFlag) { this.canvasMessage = 'The selected file could not be read'; } else { @@ -397,11 +400,8 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro sendToMolvec(img: string) { this.canvasMessage = ''; this.loadingService.setLoading(true); - console.log('sending to molvec'); - console.log(img); this.structureService.molvec(img).subscribe(response => { const mol = response.molfile; - console.log(response); if (this.ketcher && this.structureEditor === 'ketcher') { this.ketcher.setMolecule(mol); setTimeout(() => { @@ -422,7 +422,6 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro } else { - console.log('not ketcher'); this.jsdraw.setMolfile(mol); this.loadingService.setLoading(false); this.loadedMolfile.emit(mol); @@ -490,7 +489,6 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro } else if (items[i].type === 'text/plain') { const text = event.clipboardData.getData('text/plain'); if (text.indexOf('; structuralUnits: Array; - featureList?: Array; + featureList?: any; } export interface ResolverResponse { diff --git a/src/app/core/structure/structure.service.ts b/src/app/core/structure/structure.service.ts index 3d3ae5161..ae400c82e 100644 --- a/src/app/core/structure/structure.service.ts +++ b/src/app/core/structure/structure.service.ts @@ -91,7 +91,7 @@ export class StructureService { } interpretStructure(mol: string, mode?: string, standardize?: string ): Observable { - const url = `${this.configService.configData.apiBaseUrl}api/v1/substances/interpretStructure?mode=${mode ? mode:''}&standardize=${(standardize ? standardize:'')}`; + const url = `${this.configService.configData.apiBaseUrl}api/v1/substances/interpretStructure?mode=${mode ? mode:''}&standardize=${(standardize ? standardize:'')}&appendNNOFeatures=true`; return this.http.post(url, mol); } diff --git a/src/app/core/substance-form/structure/substance-form-structure-card.component.html b/src/app/core/substance-form/structure/substance-form-structure-card.component.html index 2ed0c293e..363478979 100644 --- a/src/app/core/substance-form/structure/substance-form-structure-card.component.html +++ b/src/app/core/substance-form/structure/substance-form-structure-card.component.html @@ -1,5 +1,8 @@
+
+

Draw or import a structure using Ketcher. Then, if any features are detected a table will be automatically displayed under the editor.

+
@@ -8,13 +11,13 @@ {{userMessage}}
-
-
+
+
- Structure Features + {{feats.label}} - +
diff --git a/src/app/core/substance-form/structure/substance-form-structure-card.component.ts b/src/app/core/substance-form/structure/substance-form-structure-card.component.ts index de03874fb..9b53b5e7e 100644 --- a/src/app/core/substance-form/structure/substance-form-structure-card.component.ts +++ b/src/app/core/substance-form/structure/substance-form-structure-card.component.ts @@ -44,6 +44,8 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple enableStructureFeatures = true; sortedFeatures = new MatTableDataSource(); displayedColumns = ['key', 'value']; + featuresOnly = false; + hideFeaturesTable = false; @ViewChild(StructureEditorComponent) structureEditorComponent!: StructureEditorComponent; constructor( @@ -64,6 +66,9 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple } ngOnInit() { + if(this.activatedRoute.snapshot.routeConfig.path === 'structure-features') { + this.featuresOnly = true; + } this.overlayContainer = this.overlayContainerService.getContainerElement(); const definitionSubscription = this.substanceFormService.definition.subscribe(def => { this.substanceType = def.substanceClass; @@ -165,35 +170,58 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple this.processStructurePostResponse(response); this.structure.molfile = molfile; this.smiles = response.structure.smiles; + }); } } processStructurePostResponse(structurePostResponse?: InterpretStructureResponse): void { if (structurePostResponse && structurePostResponse.structure) { - if (structurePostResponse.featureList && structurePostResponse.featureList.length > 0) { - let temp = []; - Object.keys(structurePostResponse.featureList[0]).forEach(key => { - let label = key; - if(key === 'categoryScore'){ - label = 'Category Score'; - } - if(key === 'sumOfScores'){ - label = 'Sum Of Scores'; + let customSort = (array: any[]): any[] => { + return array.sort((a, b) => { + if (a.key === 'Category Score') return -1; + if (b.key === 'Category Score') return 1; + if (a.key === 'Sum Of Scores') return a.key === 'Category Score' ? 1 : -1; + if (b.key === 'Sum Of Scores') return b.key === 'Category Score' ? -1 : 1; + return a.key.localeCompare(b.key); + }); + }; + + if (structurePostResponse.featureList) { + this.hideFeaturesTable = false; + let tempArr = []; + let emptyFeatures = true; + if (JSON. stringify(structurePostResponse.featureList) !== '{}'){ + + Object.keys(structurePostResponse.featureList).forEach(type => { + let tempObj = {'label':null, 'features': null}; + + tempObj.label = (type.charAt(0).toUpperCase() + type.slice(1)).replace(/([A-Z])/g, ' $1').trim(); + let temp = []; + + if(structurePostResponse.featureList[type].length > 0) { + emptyFeatures = false; + Object.keys(structurePostResponse.featureList[type][0]).forEach(key => { + let label = key; + if(key === 'categoryScore'){ + label = 'Category Score'; + } + if(key === 'sumOfScores'){ + label = 'Sum Of Scores'; + } + temp.push({'key': label,'value': structurePostResponse.featureList[type][0][key] }); + }); } - temp.push({'key': label,'value': structurePostResponse.featureList[0][key] }); + tempObj.features = new MatTableDataSource(customSort(temp)); + tempArr.push(tempObj); }); - let customSort = (array: any[]): any[] => { - return array.sort((a, b) => { - if (a.key === 'Category Score') return -1; - if (b.key === 'Category Score') return 1; - if (a.key === 'Sum Of Scores') return a.key === 'Category Score' ? 1 : -1; - if (b.key === 'Sum Of Scores') return b.key === 'Category Score' ? -1 : 1; - return a.key.localeCompare(b.key); - }); - }; - this.features = customSort(temp); - this.sortedFeatures = new MatTableDataSource(this.features); + this.features = tempArr; + if (emptyFeatures) { + this.hideFeaturesTable = true; + } + } else { + this.hideFeaturesTable = true; + } } // we should only be dealing with this stuff if the total hash changes @@ -332,14 +360,13 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple this.loadingService.setLoading(true); this.structureService.interpretStructure(this.structure.molfile).subscribe(response => { - + this.loadingService.setLoading(false); const navigationExtras: NavigationExtras = { queryParams: { structure: response.structure.id } }; if (this.configService.configData && this.configService.configData.gsrsHomeBaseUrl) { - console.log(this.configService.configData.gsrsHomeBaseUrl); let url = this.configService.configData.gsrsHomeBaseUrl + '/structure-search?structure=' + response.structure.id; window.open(url, '_blank'); } else { @@ -350,7 +377,6 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple queryParamsHandling: 'merge', preserveFragment: true }); - console.log(urlTree); window.open(urlTree.toString(), '_blank'); }, error => { this.loadingService.setLoading(false); diff --git a/src/app/core/substance-form/substance-form.component.html b/src/app/core/substance-form/substance-form.component.html index 09dbb3f53..02dec0a30 100644 --- a/src/app/core/substance-form/substance-form.component.html +++ b/src/app/core/substance-form/substance-form.component.html @@ -3,7 +3,8 @@ x -
+ +
diff --git a/src/app/core/substance-form/substance-form.component.ts b/src/app/core/substance-form/substance-form.component.ts index 741016546..9e15c7769 100644 --- a/src/app/core/substance-form/substance-form.component.ts +++ b/src/app/core/substance-form/substance-form.component.ts @@ -103,6 +103,7 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy approvalType = 'lastEditedBy'; previousState: number; useApprovalAPI = false; + featuresOnly = false; constructor( private activatedRoute: ActivatedRoute, @@ -280,6 +281,9 @@ export class SubstanceFormComponent implements OnInit, AfterViewInit, OnDestroy ngOnInit() { + if(this.activatedRoute.snapshot.routeConfig.path === 'structure-features') { + this.featuresOnly = true; + } this.loadingService.setLoading(true); if (this.configService.configData && this.configService.configData.approvalType) { this.approvalType = this.configService.configData.approvalType; @@ -523,6 +527,9 @@ getDrafts() { } } } + if (this.featuresOnly && this.formSections[index].dynamicComponentName !== 'substance-form-structure') { + this.formSections[index].isHidden = true; + } setTimeout(() => { this.loadingService.setLoading(false); this.UNII = this.substanceFormService.getUNII(); diff --git a/src/app/core/substance-form/substance-form.service.ts b/src/app/core/substance-form/substance-form.service.ts index 0729e8722..6e1f0a892 100644 --- a/src/app/core/substance-form/substance-form.service.ts +++ b/src/app/core/substance-form/substance-form.service.ts @@ -1617,7 +1617,6 @@ export class SubstanceFormService implements OnDestroy { return new Observable(observer => { this.adminService.updateStagingArea(id, substanceCopy).subscribe(response => { - console.log(response); observer.next(response); observer.complete(); }, error => { diff --git a/src/app/core/substances-browse/export-dialog/custom-multi-checkbox-widget/custom-multi-checkbox-widget.component.ts b/src/app/core/substances-browse/export-dialog/custom-multi-checkbox-widget/custom-multi-checkbox-widget.component.ts index 6af0036fd..89e5fc3bc 100644 --- a/src/app/core/substances-browse/export-dialog/custom-multi-checkbox-widget/custom-multi-checkbox-widget.component.ts +++ b/src/app/core/substances-browse/export-dialog/custom-multi-checkbox-widget/custom-multi-checkbox-widget.component.ts @@ -24,7 +24,6 @@ export class CustomMultiCheckboxWidgetComponent extends CheckboxWidget implemen this.cvService.fetchFullVocabulary(this.schema.CVDomain).subscribe(response => { - console.log(response); if (response.content && response.content.length > 0) { this.options = response.content[0].terms; } diff --git a/src/app/core/substances-browse/export-dialog/custom-select-widget/custom-select-widget.component.ts b/src/app/core/substances-browse/export-dialog/custom-select-widget/custom-select-widget.component.ts index 4a1c638f6..d5126e79d 100644 --- a/src/app/core/substances-browse/export-dialog/custom-select-widget/custom-select-widget.component.ts +++ b/src/app/core/substances-browse/export-dialog/custom-select-widget/custom-select-widget.component.ts @@ -24,7 +24,6 @@ export class CustomSelectWidgetComponent extends SelectWidget implements OnInit this.cvService.fetchFullVocabulary(this.schema.CVDomain).subscribe(response => { - console.log(response); if (response.content && response.content.length > 0) { this.options = response.content[0].terms; }
Feature {{element.key}}