Skip to content

Commit

Permalink
Merge pull request #526 from ncats/searchFromEdit
Browse files Browse the repository at this point in the history
open structure search from edit page
  • Loading branch information
NikoAnderson authored Jul 23, 2024
2 parents 9769a85 + e01c9f9 commit e7adf9f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, PLATFORM_ID, Inject } from '@angular/core';
import { ConfigService } from '../config/config.service';
import { Auth, Role, UserGroup } from './auth.model';
import { Observable, Subject } from 'rxjs';
import { Observable, Subject, of } from 'rxjs';
import { map, take, catchError } from 'rxjs/operators';
import { HttpClient, HttpParams } from '@angular/common/http';
import { isPlatformBrowser } from '@angular/common';
Expand Down Expand Up @@ -57,7 +57,11 @@ export class AuthService {

public checkAuth(): Observable<Auth> {
const url = `${(this.configService.configData && this.configService.configData.apiBaseUrl) || '/'}api/v1/`;
return this.http.get<any>(`${url}whoami`);
if (this.configService.configData && this.configService.configData.dummyWhoami) {
return of(this.configService.configData.dummyWhoami);
} else {
return this.http.get<any>(`${url}whoami`);
}
}

login(username: string, password: string): Observable<Auth> {
Expand All @@ -70,7 +74,12 @@ export class AuthService {
};

const url = `${(this.configService.configData && this.configService.configData.apiBaseUrl) || '/'}api/v1/`;
return this.http.get<Auth>(`${url}whoami`, options).pipe(

let obs = this.http.get<Auth>(`${url}whoami`, options);
if (this.configService.configData && this.configService.configData.dummyWhoami) {
obs = of(this.configService.configData.dummyWhoami);
}
return obs.pipe(
map(auth => {
if (auth && auth.computedToken) {
this._auth = auth;
Expand Down Expand Up @@ -295,6 +304,9 @@ export class AuthService {
return new Observable(observer => {
this.configService.afterLoad().then(cd => {
const url = `${(this.configService.configData && this.configService.configData.apiBaseUrl) || '/'}api/v1/`;
if (this.configService.configData && this.configService.configData.dummyWhoami) {
observer.next(this.configService.configData.dummyWhoami);
} else {
this.http.get<Auth>(`${url}whoami`)
.subscribe(
auth => {
Expand All @@ -309,6 +321,7 @@ export class AuthService {
},
() => observer.complete()
);
}
});
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/config/config.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Auth } from "@gsrs-core/auth";

export interface Config {
apiBaseUrl?: string;
gsrsHomeBaseUrl?: string;
Expand Down Expand Up @@ -78,6 +80,7 @@ export interface Config {
jsdrawLicense?: boolean;
disableKetcher?: boolean;
useApprovalAPI?: boolean;
dummyWhoami?: Auth;
}

export interface StagingAreaSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
<mat-icon svgIcon="search"></mat-icon>
Check for duplicates
</button>
<button (click)="structureSearch()" matTooltip="open structure search in new tab" mat-button
color="primary" class="dupe-check">
<mat-icon svgIcon="search"></mat-icon>
Structure Search
<mat-icon svgIcon="open_in_new" class = "superscript-icon"></mat-icon>
</button>
</span>

<span class="middle-fill"></span>
<span class="right-buttons">
<button mat-button color="primary" matTooltip="Import options" [matMenuTriggerFor]="importMenu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

align-content: flex-start;
display: flex;
button {
margin-right:20px;
}
}
}

Expand Down Expand Up @@ -104,3 +107,9 @@
.z-index {
z-index: 9999 !important;
}

.superscript-icon {
height: 18px;
width: 18px;
vertical-align: top;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Subscription } from 'rxjs';
import { SubstanceService } from '@gsrs-core/substance/substance.service';
import { SubstanceFormStructuralUnitsService } from '../structural-units/substance-form-structural-units.service';
import { SubstanceFormStructureService } from './substance-form-structure.service';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { StructureEditorComponent } from '@gsrs-core/structure-editor';

@Component({
Expand Down Expand Up @@ -48,7 +48,8 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
private gaService: GoogleAnalyticsService,
private substanceService: SubstanceService,
private substanceFormStructuralUnitsService: SubstanceFormStructuralUnitsService,
private activatedRoute: ActivatedRoute
private activatedRoute: ActivatedRoute,
private router: Router
) {
super();
}
Expand Down Expand Up @@ -292,6 +293,31 @@ export class SubstanceFormStructureCardComponent extends SubstanceFormBase imple
});
}

structureSearch() {
this.loadingService.setLoading(true);

this.structureService.interpretStructure(this.structure.molfile).subscribe(response => {

const navigationExtras: NavigationExtras = {
queryParams: {
structure: response.structure.id
}
};

const url = this.router.serializeUrl(
this.router.createUrlTree(['/structure-search/'], {
queryParams: navigationExtras.queryParams})
);

this.loadingService.setLoading(false);
window.open(url, '_blank');


}, error => {
this.loadingService.setLoading(false);
});
}

dismissErrorMessage(index: number) {
this.structureErrorsArray.splice(index, 1);
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/core/substance-form/substance-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,10 @@ export class SubstanceFormService implements OnDestroy {
substanceString = JSON.stringify(substanceCopy);

deletedUuids.forEach(uuid => {
substanceString = substanceString.replace(new RegExp(`"${uuid}"`, 'g'), '');
const pattern = /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/;
if(pattern.test(uuid)) {
substanceString = substanceString.replace(new RegExp(`"${uuid}"`, 'g'), '');
}
});
substanceString = substanceString.replace(/,[,]+/g, ',');
substanceString = substanceString.replace(/\[,/g, '[');
Expand Down

0 comments on commit e7adf9f

Please sign in to comment.