@angular/router#Resolve TypeScript Examples

The following examples show how to use @angular/router#Resolve. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: assets.resolver.ts    From nica-os with MIT License 6 votes vote down vote up
@Injectable({ providedIn: 'root' })
export class AssetsResolver implements Resolve<any> {
  loadedAssets$ = this.store.pipe(select(selectLoadedAssets));
  constructor(
    public store: Store<AppState>
  ) {}

  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<any>|Promise<any>|any {
    this.store.dispatch(loadAssets());
    return this.loadedAssets$.pipe(take(1));
  }
}
Example #2
Source File: app-routing.module.ts    From bulwark with MIT License 6 votes vote down vote up
@Injectable()
export class TeamFormResolver implements Resolve<any> {
  constructor(
    private appService: AppService,
    private userService: UserService
  ) {}
  resolve(route: ActivatedRouteSnapshot) {
    return forkJoin([
      this.appService.getOrganizations(),
      this.userService.getAllUsers(),
    ]).pipe(
      map((result) => {
        return {
          organizations: result[0],
          activeUsers: result[1],
        };
      })
    );
  }
}
Example #3
Source File: app-routing.module.ts    From bulwark with MIT License 6 votes vote down vote up
@Injectable()
export class AssessmentResolver implements Resolve<any> {
  constructor(
    private apiService: AppService,
    private userService: UserService
  ) {}
  resolve(route: ActivatedRouteSnapshot) {
    if (
      route.params.assetId &&
      route.params.assessmentId &&
      route.params.orgId
    ) {
      return forkJoin([
        this.apiService.getAssessment(
          route.params.assetId,
          route.params.assessmentId
        ),
        this.userService.getTesters(route.params.orgId),
      ]).pipe(
        map((result) => {
          return {
            assessment: result[0],
            testers: result[1],
          };
        })
      );
    } else {
      return this.userService.getTesters(route.params.orgId);
    }
  }
}
Example #4
Source File: user.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 用户Resolve,根据路由参数中的userId来获得user
 */
@Injectable({
  providedIn: 'root',
})
export class UserResolve implements Resolve<User> {
  constructor(
    private userService: UserService,
    private globalData: GlobalData
  ) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User> | User {
    const userId = +route.params.userId;
    const { user } = this.globalData;

    return (user?.id === userId) ? user : this.userService.getUser(userId).pipe(
      map(({ data }: Result<User>) => data)
    );
  }
}
Example #5
Source File: friend-request.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 获取好友申请
 */
@Injectable({
  providedIn: 'root',
})
export class FriendRequestResolve implements Resolve<Result<FriendRequest>> {
  constructor(private friendService: FriendService) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Result<FriendRequest>> {
    const friendRequestId = +route.params.friendRequestId;

    return this.friendService.getRequestById(friendRequestId);
  }
}
Example #6
Source File: friend-request.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 获取对方(根据路由参数userId)给自己发起好友申请的Resolve
 */
@Injectable({
  providedIn: 'root',
})
export class FriendRequestBySelfIdResolve implements Resolve<Result<FriendRequest>> {
  constructor(private friendService: FriendService) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Result<FriendRequest>> {
    const userId = +route.params.userId;

    return this.friendService.getRequestByRequesterId(userId);
  }
}
Example #7
Source File: friend-request.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 获取自己给对方(根据路由参数userId)发起好友申请的Resolve
 */
@Injectable({
  providedIn: 'root',
})
export class FriendRequestByTargetIdResolve implements Resolve<Result<FriendRequest>> {
  constructor(private friendService: FriendService) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Result<FriendRequest>> {
    const userId = +route.params.userId;

    return this.friendService.getRequestByTargetId(userId);
  }
}
Example #8
Source File: chatroom.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 群聊成员Resolve,根据路由参数中的chatroomId来获得群聊成员
 */
@Injectable({
  providedIn: 'root',
})
export class ChatMembersResolve implements Resolve<Result<ChatMember[]>> {
  constructor(private chatroomService: ChatroomService) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Result<ChatMember[]>> {
    const chatroomId = +route.params.chatroomId;

    return this.chatroomService.getChatMembers(chatroomId);
  }
}
Example #9
Source File: chat-request.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 群聊申请Resolve,根据路由参数中的chatRequestId来获得我发送的ChatRequest
 */
@Injectable({
  providedIn: 'root',
})
export class SendChatRequestResolve implements Resolve<ChatRequest> {
  constructor(
    private chatService: ChatService,
    private globalData: GlobalData
  ) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ChatRequest> | ChatRequest {
    const chatRequestId = +route.params.chatRequestId;
    const chatRequest = this.globalData.sendChatRequests.find(o => o.id === chatRequestId);

    if (chatRequest) { return chatRequest; }

    return this.chatService.getSendRequestById(chatRequestId).pipe(
      map(({ data }: Result<ChatRequest>) => data)
    );
  }
}
Example #10
Source File: chat-request.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 群聊申请Resolve,根据路由参数中的chatRequestId来获得我收到的ChatRequest
 */
@Injectable({
  providedIn: 'root',
})
export class ReceiveChatRequestResolve implements Resolve<ChatRequest> {
  constructor(
    private chatService: ChatService,
    private globalData: GlobalData
  ) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ChatRequest> | ChatRequest {
    const chatRequestId = +route.params.chatRequestId;
    const chatRequest = this.globalData.receiveChatRequests.find(o => o.id === chatRequestId);

    if (chatRequest) { return chatRequest; }

    return this.chatService.getReceiveChatRequestById(chatRequestId).pipe(
      map(({ data }: Result<ChatRequest>) => data)
    );
  }
}
Example #11
Source File: chatroom.resolver.ts    From onchat-web with Apache License 2.0 6 votes vote down vote up
/**
 * 聊天室Resolve,根据路由参数中的chatroomId来获得chatroom
 */
@Injectable({
  providedIn: 'root',
})
export class ChatroomResolve implements Resolve<Result<Chatroom>> {
  constructor(private chatroomService: ChatroomService) { }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Result<Chatroom>> {
    const chatroomId = +route.params.chatroomId;

    return this.chatroomService.getChatroom(chatroomId);
  }
}
Example #12
Source File: expenseCategory.resolver.ts    From budget-angular with GNU General Public License v3.0 6 votes vote down vote up
@Injectable()
export class ExpenseCategoryResolver implements Resolve<ExpenseCategory[]> {
  constructor(private settingsFacade: CategoriesFacade) {}

  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<ExpenseCategory[]> {
    return this.settingsFacade.loadExpenseCategories();
  }
}
Example #13
Source File: AemPageDataResolver.ts    From aem-angular-editable-components with Apache License 2.0 6 votes vote down vote up
@Injectable()
export class AemPageDataResolver implements Resolve < string > {
  constructor() { /* empty */ }

  /**
   * Returns the absolute resource path without extension.
   * @example
   * // returns: '/content/aa/bb' for route.url [ 'content', 'aa', 'bb.html' ]
   * resolve(route)
   * @param route - route
   * @returns absolute resource path without extension
   */
  resolve(route: ActivatedRouteSnapshot): string {
    return '/' + route.url.join('/').replace(/\.[^/.]+$/, '');
  }
}
Example #14
Source File: start-platform-via-resolver.snippets.ts    From scion-microfrontend-platform with Eclipse Public License 2.0 6 votes vote down vote up
// tag::resolver[]
@Injectable({providedIn: 'root'})
export class PlatformInitializer implements Resolve<void> {

  constructor(private _zone: NgZone) { // <1>
  }

  public resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<void> {
    return this._zone.runOutsideAngular(() => MicrofrontendPlatform.connectToHost('<SYMBOLIC NAME>')); // <2>
  }
}
Example #15
Source File: staking-round.resolver.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
@Injectable()
export class StakingRoundResolver implements Resolve<boolean> {
  constructor(private readonly stakingService: StakingService) {}

  resolve(route: ActivatedRouteSnapshot): boolean {
    if (route.routeConfig.path.includes('round-one')) {
      this.stakingService.setStakingContractAddress(ENVIRONMENT.staking.roundOneContractAddress);
      return true;
    }

    if (route.routeConfig.path.includes('round-two')) {
      this.stakingService.setStakingContractAddress(ENVIRONMENT.staking.roundTwoContractAddress);
      return true;
    }
  }
}
Example #16
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class SettingsResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getConfig();
  }
}
Example #17
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class UserResolver implements Resolve<any> {
  constructor(private userService: UserService) {}

  resolve() {
    return this.userService.getUser();
  }
}
Example #18
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class ReportResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getReport(route.params.assessmentId);
  }
}
Example #19
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class OrganizationResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getOrganizationById(route.params.id);
  }
}
Example #20
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class TeamResolver implements Resolve<any> {
  constructor(private teamService: TeamService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.teamService.getTeamById(route.params.teamId);
  }
}
Example #21
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class VulnerabilityResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getVulnerability(route.params.vulnId);
  }
}
Example #22
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class VulnerabilitiesResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getVulnerabilities(route.params.assessmentId);
  }
}
Example #23
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class AssessmentsResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getAssessments(route.params.assetId);
  }
}
Example #24
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class AssetResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}
  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getAsset(route.params.assetId, route.params.id);
  }
}
Example #25
Source File: app-routing.module.ts    From bulwark with MIT License 5 votes vote down vote up
@Injectable()
export class AssetsResolver implements Resolve<any> {
  constructor(private apiService: AppService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return this.apiService.getOrganizationAssets(route.params.orgId);
  }
}
Example #26
Source File: loading.resolver.ts    From blockcore-explorer with MIT License 5 votes vote down vote up
@Injectable({
   providedIn: 'root'
})
export class LoadingResolverService implements Resolve<any> {
   constructor(
      private api: ApiService,
      private setup: SetupService
   ) { }
   async resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Observable<any> | Observable<never>> {

      // When resolving the route, just get the latest always (defaults to 'BLOCKCORE').
      let explorerChain = this.setup.current;
      let wasInitilized = this.setup.initialized;

      // If not initialized yet, perform some operations:
      if (!this.setup.initialized) {
         console.log('Initilization of Explorer');

         try {
            // First make a request to the local API to check what chain instance it is runnign.
            const explorerChainRequest = await this.api.request('/api/explorer/chain');

            if (explorerChainRequest.status === 200) {
               explorerChain = await explorerChainRequest.text();

               console.log('API Chain:', explorerChain);
               this.setup.apiChain = explorerChain;

               this.setup.multiChain = (explorerChain === 'BLOCKCORE' || explorerChain === 'COINVAULT');
            } else { // If it fails... fallback
               this.setup.multiChain = true;
               this.setup.apiChain = 'BLOCKCORE';
            }
         } catch {
            this.setup.multiChain = true;
            this.setup.apiChain = 'BLOCKCORE';
         }

         if (this.setup.multiChain) {
            console.log('GO GET', explorerChain);
            await this.setup.getChains(explorerChain);
         }

         // If local is set to true, then we'll default to single chain and also not run normal initialization where the API is queried.
         if (environment.local) {
            this.setup.multiChain = false;
            this.setup.initialized = true;
            explorerChain = 'local'; // Used in the URLs, so make sure it is lowercase.
         }

         this.setup.initialized = true;
      }

      console.log('Explorer Chain:', explorerChain);

      // TODO: Figure out a better way to get path fragments pre-parsed into an array.
      const fragments = state.url.split('/');
      let chain = fragments[1];

      if (chain != '') {
         return this.setup.setChain(chain);
      } else {
         // We should reset to multichain configuration if user navigate back to home.
         // If already initilized and no chain in URL; we'll reset back to root.
         if (wasInitilized) {
            return this.setup.setChain(this.setup.apiChain);
         } else {
            return this.setup.setChain(explorerChain);
         }
      }
   }
}