-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented span-based searching via a new URL route, route guard, an…
…d service call.
- Loading branch information
1 parent
eaf7a6c
commit c8c900b
Showing
8 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { DefaultSearchGuard } from "./default-search.guard"; | ||
import { MultiGuard } from "./multi.guard"; | ||
import { SearchGuard } from "./search.guard"; | ||
import { SpanSearchGuard } from "./span-search.guard"; | ||
|
||
export const guards: any[] = [ | ||
DefaultSearchGuard, | ||
MultiGuard, | ||
SearchGuard, | ||
SpanSearchGuard, | ||
]; | ||
|
||
export * from "./default-search.guard"; | ||
export * from "./multi.guard"; | ||
export * from "./search.guard"; | ||
export * from "./span-search.guard"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Angular | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; | ||
import { Observable, throwError } from "rxjs"; | ||
import { catchError, map, tap } from "rxjs/operators"; | ||
// store | ||
import { Store } from "@ngrx/store"; | ||
import * as routerActions from "../store/actions/router.actions"; | ||
import * as fromRoot from "../store/reducers"; | ||
// app | ||
import { MicroTracksService } from "../services"; | ||
|
||
@Injectable() | ||
export class SpanSearchGuard implements CanActivate { | ||
|
||
constructor( | ||
private microTracksService: MicroTracksService, | ||
private router: Router, | ||
private store: Store<fromRoot.State>) { } | ||
|
||
// this guard is only triggered when no server is provided, which Search needs, | ||
// so instead of activating it always redirects to the default server | ||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { | ||
const span = route.params.span.split("-"); | ||
return this.microTracksService.getSearchFromSpan( | ||
route.params.chromosome, | ||
span[0], | ||
(span.length === 1 ? span[0] : span[1]), | ||
route.params.source) | ||
.pipe( | ||
tap((context) => { | ||
const url = "/search" + "/" + route.params.source + "/" + context.gene; | ||
this.store.dispatch(new routerActions.Go({ | ||
path: [url], // TODO: update url so back button skips search | ||
query: {"neighbors": context.neighbors}})); | ||
}), | ||
catchError((error) => { | ||
// TODO: update url so back button skips search | ||
this.store.dispatch(new routerActions.Go({path: ["/instructions"]})); | ||
return throwError(error); | ||
}), | ||
map((context) => false) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ export class Server { | |
plotGlobal: Request; | ||
nearestGene: Request; | ||
chromosome: Request; | ||
spanToSearch: Request; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters