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

Local omnibar nav and routes rename #152

Merged
merged 2 commits into from
May 16, 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
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.3.2",
"@blackbaud/auth-client": "1.4.0",
"@blackbaud/help-client": "1.0.1",
"@ngtools/webpack": "1.2.14",
"@types/jasmine": "2.5.40",
Expand Down
5 changes: 4 additions & 1 deletion runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export interface SkyuxConfig {
mode?: string;
name?: string;
plugins?: string[];
publicRoutes?: any[];
routes?: {
public: any[],
referenced: any[]
};
omnibar?: any;
}

Expand Down
54 changes: 48 additions & 6 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@ import {
require('style-loader!@blackbaud/skyux/dist/css/sky.css');
require('style-loader!./app.component.scss');

function fixUpNavItems(items: any[], baseUrl: string) {
for (const item of items) {
if (!item.url && item.route) {
item.url = baseUrl + item.route;
}

if (item.items) {
fixUpNavItems(item.items, baseUrl);
}
}
}

function fixUpNav(nav: any, baseUrl: string) {
const services = nav.services;

if (services && services.length > 0) {
let foundSelectedService = false;

for (const service of services) {
if (service.items) {
fixUpNavItems(service.items, baseUrl);
}

if (service.selected) {
foundSelectedService = true;
}
}

if (!foundSelectedService) {
services[0].selected = true;
}
}
}

@Component({
selector: 'sky-pages-app',
templateUrl: './app.component.html'
Expand Down Expand Up @@ -73,13 +107,22 @@ export class AppComponent implements OnInit {
}

private setNav(omnibarConfig: any) {
const skyuxConfig = this.config.skyux;

const baseUrl =
(
this.config.skyux.host.url +
skyuxConfig.host.url +
this.config.runtime.app.base.substr(0, this.config.runtime.app.base.length - 1)
).toLowerCase();

const nav = new BBOmnibarNavigation();
let nav: BBOmnibarNavigation;

if (omnibarConfig.nav) {
nav = omnibarConfig.nav;
fixUpNav(nav, baseUrl);
} else {
nav = omnibarConfig.nav = new BBOmnibarNavigation();
}

nav.beforeNavCallback = (item: BBOmnibarNavigationItem) => {
const url = item.url.toLowerCase();
Expand All @@ -94,8 +137,9 @@ export class AppComponent implements OnInit {
if (this.config.runtime.command === 'serve') {
// Add any global routes to the omnibar as a convenience to the developer.
const globalRoutes =
this.config.skyux.publicRoutes &&
this.config.skyux.publicRoutes.filter((value: any) => {
skyuxConfig.routes &&
skyuxConfig.routes.public &&
skyuxConfig.routes.public.filter((value: any) => {
return value.global;
});

Expand All @@ -113,8 +157,6 @@ export class AppComponent implements OnInit {
nav.localNavItems = localNavItems;
}
}

omnibarConfig.nav = nav;
}

private initShellComponents() {
Expand Down