Skip to content
Open
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: 1 addition & 6 deletions src/client/core/top-menu/top-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ export default class TopMenuComponent {
private topMenuService: TopMenuService,
private userService: UserService) {
const self = this;
this.links = topMenuService.fetchLinks({
isAdmin: userService.isAdmin(),
isLoggedIn: userService.isLoggedIn(),
isInstructor: userService.isInstructor(),
isStudent: userService.isStudent()
});
this.links = topMenuService.fetchLinks();
}

public isLoggedIn() {
Expand Down
66 changes: 5 additions & 61 deletions src/client/core/top-menu/top-menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,16 @@ import { TopMenuLink } from './top-menu-link.model';

@Injectable()
export default class TopMenuService {
public fetchLinks(config: TopMenuLinkConfig): TopMenuLink[] {
const sharedLinks = this.DEFAULT_LINKS;
if (!config.isLoggedIn) {
return sharedLinks.concat(this.UNAUTH_LINKS);
} else if (config.isAdmin) {
return sharedLinks.concat(this.ADMIN_LINKS);
} else if (config.isInstructor) {
return sharedLinks.concat(this.INSTRUCTOR_LINKS);
} else if (config.isStudent) {
return sharedLinks.concat(this.STUDENT_LINKS);
} else {
return sharedLinks;
}
}

private ADMIN_LINKS: TopMenuLink[] = [
{
href: '/admin',
name: 'Admin'
},
];

private INSTRUCTOR_LINKS: TopMenuLink[] = [
{
href: '/instructor/courses',
name: 'My Courses'
}
];

private STUDENT_LINKS: TopMenuLink[] = [
{
href: '/student/courses',
name: 'My Courses'
}
];

private UNAUTH_LINKS: TopMenuLink[] = [
{
href: '/login',
name: 'Login'
},
{
href: '/register',
name: 'Register'
}
];
public fetchLinks = (): TopMenuLink[] => this.DEFAULT_LINKS;

private DEFAULT_LINKS: TopMenuLink[] = [
{
href: '/courses',
name: 'Courses'
href: `/login`,
name: 'Login'
},
{
href: '/profile',
name: 'Profile'
href: `/register`,
name: `Register`
}
];

public links: TopMenuLink[] = [
{
href: '/courses',
name: 'Courses'
},
{
href: '/profile',
name: 'Profile'
}
]
};
10 changes: 10 additions & 0 deletions src/client/sidebar/sidebar-links.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable } from '@angular/core';

@Injectable()
export class SidebarLinksService {

public fetchLinks = () => {

};
}

9 changes: 8 additions & 1 deletion src/client/sidebar/sidebar.component.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ ul.side-nav#aom-sidebar
div.userView
div.background
img(src="http://artofmetrics.com/wp-content/uploads/2016/01/header-retina.png")
a([routerLink]="'/profile'") {{ user?.profile.name.first }}
i.material-icons account_circle
li
a#sidebar-logout((click)="logout()") Logout
div.divider
li
a.subheader Modules
li
a#sidebar-logout((click)="logout()") Logout

26 changes: 23 additions & 3 deletions src/client/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// NPM Deps
import { Component, ViewEncapsulation } from '@angular/core';
import { Component, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';

import { Subscription } from 'rxjs/Subscription';
// Our Deps
import { UserService } from 'client/core/user.service';

Expand All @@ -12,11 +12,31 @@ import { UserService } from 'client/core/user.service';
})


export class SidebarComponent {
export class SidebarComponent implements OnInit, OnDestroy {
NAV_SELECTOR: string = `#aom-sidebar`;
user: any;

subscriptions: {
userState?: Subscription;
} = { userState: undefined };

constructor(private userService: UserService, private router: Router) { }

ngOnInit() {
console.log(this.userService);
this.subscriptions.userState = this.userService.state$.subscribe(
(val: string) => {
if (val === 'LOGGED_IN') {
this.user = this.userService.$;
}
}
)
}

ngOnDestroy() {
this.subscriptions.userState.unsubscribe();
}

public logout = () => {
this.userService.logout();
this.router.navigate(['/register']);
Expand Down
4 changes: 3 additions & 1 deletion src/client/sidebar/sidebar.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// NPM Deps
import { NgModule } from '@angular/core'

import { RouterModule } from '@angular/router';
// Our Deps
import { SidebarComponent } from './sidebar.component';
import { SidebarLinksService } from './sidebar-links.service';
import { SidebarToggleComponent } from './sidebar-toggle.component';

@NgModule({
imports: [RouterModule],
declarations: [SidebarComponent, SidebarToggleComponent],
exports: [SidebarComponent, SidebarToggleComponent]
})
Expand Down