Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Token search changes #129

Merged
merged 5 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/sky-pages-module-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ function getSource(skyAppConfig) {
let runtimeImports = [
'SkyAppBootstrapper',
'SkyAppConfig',
'SkyAppWindowRef'
'SkyAppWindowRef',
'SkyAuthTokenProvider'
];

let runtimeProviders = [
'SkyAppWindowRef',
'SkyAuthTokenProvider',
`{
provide: SkyAppConfig,
useValue: ${skyAppConfigAsString}
Expand All @@ -44,7 +47,7 @@ function getSource(skyAppConfig) {
runtimeProviders.push(`{
provide: SkyAuthHttp,
useClass: SkyAuthHttp,
deps: [XHRBackend, RequestOptions, SkyAppWindowRef]
deps: [XHRBackend, RequestOptions, SkyAppWindowRef, SkyAuthTokenProvider]
}`);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@angular/platform-browser": "2.4.8",
"@angular/platform-browser-dynamic": "2.4.8",
"@angular/router": "3.4.8",
"@blackbaud/auth-client": "1.1.0",
"@blackbaud/auth-client": "1.2.0",
"@blackbaud/help-client": "blackbaud/help-client",
"@ngtools/webpack": "1.2.1",
"@types/jasmine": "2.5.40",
Expand Down
2 changes: 2 additions & 0 deletions runtime/auth-http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BBAuth } from '@blackbaud/auth-client';
import { SkyAuthHttp } from './auth-http';

import { SkyAppWindowRef } from './window-ref';
import { SkyAuthTokenProvider } from './auth-token-provider';

describe('SkyAuthHttp', () => {

Expand All @@ -16,6 +17,7 @@ describe('SkyAuthHttp', () => {
function setupInjector(windowLocationSearch: string) {

const injector = ReflectiveInjector.resolveAndCreate([
SkyAuthTokenProvider,
{
provide: ConnectionBackend,
useClass: MockBackend
Expand Down
7 changes: 4 additions & 3 deletions runtime/auth-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import 'rxjs/add/operator/mergeMap';

import { SkyAppWindowRef } from '@blackbaud/skyux-builder/runtime/window-ref';

import { BBAuth } from '@blackbaud/auth-client';
import { SkyAuthTokenProvider } from '@blackbaud/skyux-builder/runtime/auth-token-provider';

@Injectable()
export class SkyAuthHttp extends Http {

constructor(
backend: ConnectionBackend,
defaultOptions: RequestOptions,
private windowRef: SkyAppWindowRef
private windowRef: SkyAppWindowRef,
private authTokenProvider: SkyAuthTokenProvider
) {
super(backend, defaultOptions);
}
Expand All @@ -36,7 +37,7 @@ export class SkyAuthHttp extends Http {
url: string | Request,
options?: RequestOptionsArgs
): Observable<Response> {
return Observable.fromPromise(BBAuth.getToken())
return Observable.fromPromise(this.authTokenProvider.getToken())
.flatMap((token: string) => {
let authOptions: Request | RequestOptionsArgs;

Expand Down
22 changes: 22 additions & 0 deletions runtime/auth-token-provider.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BBAuth } from '@blackbaud/auth-client';

import { SkyAuthTokenProvider } from './auth-token-provider';

describe('Auth token provider', () => {

it('should call BBAuth.getToken and add return its promise', (done) => {
const expectedToken = 'my-fake-token';

spyOn(BBAuth, 'getToken')
.and
.returnValue(Promise.resolve(expectedToken));

const provider = new SkyAuthTokenProvider();

provider.getToken().then((token: string) => {
expect(token).toBe(expectedToken);
done();
});
});

});
9 changes: 9 additions & 0 deletions runtime/auth-token-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BBAuth } from '@blackbaud/auth-client';

export class SkyAuthTokenProvider {

public getToken(): Promise<string> {
return BBAuth.getToken();
}

}
2 changes: 2 additions & 0 deletions runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from './auth-http';
export * from './auth-token-provider';
export * from './bootstrapper';
export * from './config';
export * from './search-results-provider';
export * from './window-ref';
5 changes: 5 additions & 0 deletions runtime/search-results-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export abstract class SkyAppSearchResultsProvider {

public abstract getSearchResults(searchArgs: { searchText: string }): Promise<any>;

}
24 changes: 20 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Component,
OnInit
OnInit,
Optional
} from '@angular/core';

import {
Expand All @@ -16,12 +17,17 @@ import {
BBOmnibar,
BBOmnibarConfig,
BBOmnibarNavigation,
BBOmnibarNavigationItem
BBOmnibarNavigationItem,
BBOmnibarSearchArgs
} from '@blackbaud/auth-client';

import { BBHelp } from '@blackbaud/help-client';

import { SkyAppConfig, SkyAppWindowRef } from '@blackbaud/skyux-builder/runtime';
import {
SkyAppConfig,
SkyAppSearchResultsProvider,
SkyAppWindowRef
} from '@blackbaud/skyux-builder/runtime';

require('style!@blackbaud/skyux/dist/css/sky.css');
require('style!./app.component.scss');
Expand All @@ -34,7 +40,8 @@ export class AppComponent implements OnInit {
constructor(
private router: Router,
private windowRef: SkyAppWindowRef,
private config: SkyAppConfig
private config: SkyAppConfig,
@Optional() private searchProvider?: SkyAppSearchResultsProvider
) { }

public ngOnInit() {
Expand All @@ -58,6 +65,14 @@ export class AppComponent implements OnInit {
omnibarConfig.svcId = urlSearchParams.get('svcid');
}

private setOnSearch(omnibarConfig: BBOmnibarConfig) {
if (this.searchProvider) {
omnibarConfig.onSearch = (searchArgs: BBOmnibarSearchArgs) => {
return this.searchProvider.getSearchResults(searchArgs);
};
}
}

private setNav(omnibarConfig: BBOmnibarConfig) {
const baseUrl =
(
Expand Down Expand Up @@ -114,6 +129,7 @@ export class AppComponent implements OnInit {

this.setParamsFromQS(omnibarConfig);
this.setNav(omnibarConfig);
this.setOnSearch(omnibarConfig);

BBOmnibar.load(omnibarConfig);
}
Expand Down
2 changes: 1 addition & 1 deletion test/sky-pages-module-generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('SKY UX Builder module generator', () => {
const expectedProvider = `{
provide: SkyAuthHttp,
useClass: SkyAuthHttp,
deps: [XHRBackend, RequestOptions, SkyAppWindowRef]
deps: [XHRBackend, RequestOptions, SkyAppWindowRef, SkyAuthTokenProvider]
}`;

let source = generator.getSource({
Expand Down