diff --git a/src/app/core/structure-editor/structure-editor-implementation.model.ts b/src/app/core/structure-editor/structure-editor-implementation.model.ts index a52292c9e..4e6830785 100644 --- a/src/app/core/structure-editor/structure-editor-implementation.model.ts +++ b/src/app/core/structure-editor/structure-editor-implementation.model.ts @@ -96,8 +96,7 @@ export class EditorImplementation implements Editor { getSmiles(): Observable { if (this.ketcher != null) { - return from(this.ketcher.getSmiles()).pipe(switchMap(data => { - return data;})); + return from(this.ketcher.getSmiles()); } else if (this.jsdraw != null) { return new Observable(observer => { observer.next(this.jsdraw.getSmiles()); @@ -143,6 +142,8 @@ export class EditorImplementation implements Editor { setMolecule(molfile: string): void { if (this.ketcher && this.ketcher != null) { + console.log('setting ketcher'); + this.ketcher.setMolecule(molfile); this.ketcher.setMolecule(molfile); } else if (this.jsdraw && this.jsdraw != null) { // from simple tests, this should push the current molecule down diff --git a/src/app/core/structure-editor/structure-editor.component.ts b/src/app/core/structure-editor/structure-editor.component.ts index 0d504a880..1e583c618 100644 --- a/src/app/core/structure-editor/structure-editor.component.ts +++ b/src/app/core/structure-editor/structure-editor.component.ts @@ -83,7 +83,7 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro window.removeEventListener('drop', this.preventDrag); window.removeEventListener('dragover', this.preventDrag); window.removeEventListener('paste', this.checkPaste); - (this.myCanvas.nativeElement).removeEventListener('click', this.click); + (this.myCanvas.nativeElement).removeEventListener('click', this.listener); delete this.ketcher; let parentElement = document.getElementById('ketcherwrapper'); let childElement = document.getElementById('root'); @@ -118,14 +118,14 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro } listener = () => { - /* var elmR=document.getElementById("root"); + var elmR=document.getElementById("root"); if(this.structureEditor==="ketcher"){ if( elmR && elmR.querySelector(":focus-within")){ this.getSketcher().activated=true; }else{ this.getSketcher().activated=false; } - }*/ + } } private preventDrag = (event: DragEvent) => { @@ -135,8 +135,8 @@ 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 ) => { - - if ((this.jsdraw || this.ketcher ) && this.getSketcher().activated) { + console.log('check paste'); + if ((this.jsdraw || this.ketcher )&& this.getSketcher().activated) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); @@ -156,7 +156,7 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro ngOnInit() { // window.addEventListener('keyup',this.listener); - // window.addEventListener('click',this.listener); + window.addEventListener('click',this.listener); this.overlayContainer = this.overlayContainerService.getContainerElement(); @@ -346,7 +346,6 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro this.ketcher.getMolfile().then(result => { let mfile = [null]; mfile[0]= result; - // this.getSketcher().setFile(mfile[0], "mol"); this.getSketcher().setFile(mfile[0], "mol"); }) } @@ -398,13 +397,38 @@ 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; - if (this.ketcher) { - // this.ketcher.setMolecule(mol); + console.log(response); + if (this.ketcher && this.structureEditor === 'ketcher') { + this.ketcher.setMolecule(mol); + setTimeout(() => { + this.editor.setMolecule(mol); + }, 100); + this.loadedMolfile.emit(mol); + + this.loadingService.setLoading(false); + this.structureService.molvec(img).subscribe(resp => { + setTimeout(() => { + this.editor.setMolecule(resp.molfile); + this.ketcher.setMolecule(mol); + }, 100); + }, error => { + this.canvasMessage = 'Structure not detectable'; + this.loadingService.setLoading(false); + }); + } - this.loadedMolfile.emit(mol); - this.loadingService.setLoading(false); + else { + console.log('not ketcher'); + this.jsdraw.setMolfile(mol); + this.loadingService.setLoading(false); + this.loadedMolfile.emit(mol); + + } + }, error => { this.canvasMessage = 'Structure not detectable'; this.loadingService.setLoading(false); @@ -450,6 +474,7 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro if (items[i].type.indexOf('image') !== -1) { event.preventDefault(); event.stopPropagation(); + this.canvasMessage = ''; valid = true; send.type = 'image'; const reader = new FileReader(); @@ -465,13 +490,30 @@ export class StructureEditorComponent implements OnInit, AfterViewInit, OnDestro } else if (items[i].type === 'text/plain') { const text = event.clipboardData.getData('text/plain'); if (text.indexOf(' { + if (response.structure && response.structure.molfile) { - this.ketcher.setMolecule(response.structure.molfile); + + this.editor.setMolecule(response.structure.molfile); + this.loadedMolfile.emit(response.structure.molfile); + + if(response.structure.smiles === '') { + this.canvasMessage = 'empty or invalid structure pasted'; + } + } else { + this.canvasMessage = 'Structure text not recognized'; } + this.loadingService.setLoading(false); + + },error =>{ + this.loadingService.setLoading(false); + this.canvasMessage = 'empty or invalid structure pasted'; }); } } 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 c7fbb0efe..a5f768d76 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 @@ -18,6 +18,8 @@ import { SubstanceFormStructuralUnitsService } from '../structural-units/substan import { SubstanceFormStructureService } from './substance-form-structure.service'; import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; import { StructureEditorComponent } from '@gsrs-core/structure-editor'; +import { take } from 'rxjs/operators'; +import { ConfigService } from '@gsrs-core/config'; @Component({ selector: 'app-substance-form-structure-card', @@ -49,7 +51,8 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple private substanceService: SubstanceService, private substanceFormStructuralUnitsService: SubstanceFormStructuralUnitsService, private activatedRoute: ActivatedRoute, - private router: Router + private router: Router, + private configService: ConfigService ) { super(); } @@ -155,6 +158,7 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple this.structureService.interpretStructure(molfile).subscribe(response => { this.processStructurePostResponse(response); this.structure.molfile = molfile; + this.smiles = response.structure.smiles; }); } } @@ -225,13 +229,13 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple } openStructureExportDialog(): void { - + this.structureEditor.getSmiles().pipe(take(1)).subscribe(resp => { const dialogRef = this.dialog.open(StructureExportComponent, { height: 'auto', width: '650px', data: { molfile: this.mol, - smiles: this.smiles, + smiles: resp, type: this.substanceType } }); @@ -242,6 +246,7 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple }, () => { this.overlayContainer.style.zIndex = null; }); + }); } openNameResolverDialog(): void { @@ -303,16 +308,20 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple 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 { - const url = this.router.serializeUrl( - this.router.createUrlTree(['/structure-search/'], { - queryParams: navigationExtras.queryParams}) - ); - - this.loadingService.setLoading(false); - window.open(url, '_blank'); - - + } + const urlTree = this.router.createUrlTree(['/structure-search/'], { + queryParams: navigationExtras.queryParams, + queryParamsHandling: 'merge', + preserveFragment: true + }); + console.log(urlTree); + window.open(urlTree.toString(), '_blank'); }, error => { this.loadingService.setLoading(false); });