Skip to content

Commit

Permalink
Updated the SpanSearch guard to immediately let the search view activ…
Browse files Browse the repository at this point in the history
…ate and not to redirect to the instructions view when the server returns an error. Subsequently, the Search component has been updated to also show alerts for span requests so users know that a span request is being processed and when it failes.
  • Loading branch information
alancleary committed Feb 12, 2019
1 parent 1477d0b commit a4b6c6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
2 changes: 2 additions & 0 deletions client/src/app/components/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export class SearchComponent implements AfterViewInit, OnDestroy, OnInit {
this._requestToAlertComponent(args.serverID, request, "query track", this.microAlerts);
} else if (args.requestType === "microSearch") {
this._requestToAlertComponent(args.serverID, request, "tracks", this.microAlerts);
} else if (args.requestType === "spanToSearch") {
this._requestToAlertComponent(args.serverID, request, "span", this.microAlerts);
}
});
this.plotsService.requests
Expand Down
27 changes: 9 additions & 18 deletions client/src/app/guards/span-search.guard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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";
Expand All @@ -20,26 +18,19 @@ export class SpanSearchGuard implements CanActivate {

// 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> {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
const span = route.params.span.split("-");
return this.microTracksService.getSearchFromSpan(
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)
)
.subscribe((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}}));
});
return true;
}
}

0 comments on commit a4b6c6d

Please sign in to comment.