Skip to content

Commit 446c21a

Browse files
author
Your Name
committed
Firebase & AngularFire In Depth
1 parent cf0fd09 commit 446c21a

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/app/courses-card-list/courses-card-list.component.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
VIEW COURSE
1919
</button>
2020

21-
<ng-container>
22-
<ng-container>
23-
<button mat-button class="mat-raised-button mat-accent"
24-
(click)="editCourse(course)">
25-
EDIT
26-
</button>
27-
<button mat-mini-fab color="warn" (click)="onDeleteCourse(course)">
28-
<mat-icon>delete</mat-icon>
29-
</button>
30-
</ng-container>
21+
<ng-container *ngIf="(user.roles$ | async) as roles">
22+
23+
<ng-container *ngIf="roles.admin">
24+
25+
<button mat-button class="mat-raised-button mat-accent"
26+
(click)="editCourse(course)">
27+
EDIT
28+
</button>
29+
<button mat-mini-fab color="warn" (click)="onDeleteCourse(course)">
30+
<mat-icon>delete</mat-icon>
31+
</button>
32+
33+
</ng-container>
34+
3135
</ng-container>
3236

3337
</mat-card-actions>

src/app/courses-card-list/courses-card-list.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {catchError, tap} from 'rxjs/operators';
66
import {throwError} from 'rxjs';
77
import {Router} from '@angular/router';
88
import {CoursesService} from "../services/courses.service";
9+
import {UserService} from "../services/user.service";
910

1011
@Component({
1112
selector: 'courses-card-list',
@@ -26,7 +27,8 @@ export class CoursesCardListComponent implements OnInit {
2627
constructor(
2728
private dialog: MatDialog,
2829
private router: Router,
29-
private coursesService:CoursesService) {
30+
private coursesService:CoursesService,
31+
public user: UserService) {
3032
}
3133

3234
ngOnInit() {

src/app/home/home.component.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55

66
<h2 class="title">All Courses</h2>
77

8-
<button mat-mini-fab color="accent" routerLink="/create-course">
9-
<mat-icon class="add-course-btn">add</mat-icon>
10-
</button>
8+
<ng-container *ngIf="(user.roles$ | async) as roles">
9+
10+
<ng-container *ngIf="roles.admin">
11+
12+
<button mat-mini-fab color="accent" routerLink="/create-course">
13+
<mat-icon class="add-course-btn">add</mat-icon>
14+
</button>
15+
16+
</ng-container>
17+
18+
</ng-container>
19+
20+
1121

1222
</div>
1323

src/app/home/home.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {catchError, map} from 'rxjs/operators';
55
import {AngularFirestore} from '@angular/fire/firestore';
66
import {Router} from '@angular/router';
77
import {CoursesService} from "../services/courses.service";
8+
import {UserService} from "../services/user.service";
89

910

1011
@Component({
@@ -20,7 +21,8 @@ export class HomeComponent implements OnInit {
2021

2122
constructor(
2223
private router: Router,
23-
private coursesService: CoursesService) {
24+
private coursesService: CoursesService,
25+
public user: UserService) {
2426

2527
}
2628

0 commit comments

Comments
 (0)