Skip to content

Commit a56d5a7

Browse files
feat(Site): Remove unit library from teacher home (#2162)
Co-authored-by: Hiroki Terashima <[email protected]>
1 parent d50460f commit a56d5a7

File tree

38 files changed

+298
-814
lines changed

38 files changed

+298
-814
lines changed

src/app/app-routing.module.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { HTTP_INTERCEPTORS, HttpRequest, HttpHandler, HttpInterceptor } from '@a
22
import { Injectable, NgModule } from '@angular/core';
33
import { RouterModule, Routes } from '@angular/router';
44
import { FormsModule } from '@angular/forms';
5+
import { PublicLibraryComponent } from './modules/library/public-library/public-library.component';
6+
import { PersonalLibraryComponent } from './modules/library/personal-library/personal-library.component';
57

68
const routes: Routes = [
79
{ path: '', loadChildren: () => import('./home/home.module').then((m) => m.HomeModule) },
@@ -16,7 +18,13 @@ const routes: Routes = [
1618
{
1719
path: 'curriculum',
1820
loadComponent: () =>
19-
import('./curriculum/curriculum.component').then((m) => m.CurriculumComponent)
21+
import('./curriculum/curriculum.component').then((m) => m.CurriculumComponent),
22+
children: [
23+
{ path: '', redirectTo: 'public', pathMatch: 'full' },
24+
{ path: 'public', component: PublicLibraryComponent },
25+
{ path: 'personal', component: PersonalLibraryComponent },
26+
{ path: '**', redirectTo: 'public' }
27+
]
2028
},
2129
{
2230
path: 'features',

src/app/curriculum/curriculum.component.html

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<div class="main app-background">
22
<div class="content">
33
<header class="content__header">
4-
<div class="flex flex-col sm:flex-row sm:justify-between mb-4 sm:mb-0">
4+
<div class="flex flex-wrap justify-between mb-4 gap-2">
55
<h1 class="accent flex items-center gap-2 mat-headline-4">
66
<mat-icon>menu_book</mat-icon>
77
<span i18n>Unit Library</span>
88
</h1>
99
@if (showMyUnits) {
10-
<a
11-
mat-flat-button
12-
color="primary"
13-
class="self-start"
14-
href="{{ configService.getAuthoringToolLink() }}"
15-
i18n
16-
>Authoring Tool</a
17-
>
10+
<div class="self-start flex gap-2">
11+
<a mat-raised-button color="primary" routerLink="/teacher"
12+
><mat-icon>calendar_month</mat-icon> <span i18n>Class Schedule</span></a
13+
>
14+
<a mat-raised-button color="primary" href="{{ configService.getAuthoringToolLink() }}"
15+
><mat-icon>edit_square</mat-icon> <span i18n>Authoring Tool</span></a
16+
>
17+
</div>
1818
}
1919
</div>
2020
<p class="pb-4" i18n>
@@ -28,16 +28,25 @@ <h1 class="accent flex items-center gap-2 mat-headline-4">
2828
</div>
2929
<div class="md:w-2/3 lg:w-3/4">
3030
@if (showMyUnits) {
31-
<mat-tab-group dynamicHeight>
32-
<mat-tab [label]="getPublicTabLabel()">
33-
<public-library />
34-
</mat-tab>
35-
<mat-tab [label]="getMyUnitsTabLabel()">
36-
<app-personal-library />
37-
</mat-tab>
38-
</mat-tab-group>
31+
<nav
32+
mat-tab-nav-bar
33+
i18n-aria-label
34+
aria-label="Unit library navigation"
35+
[tabPanel]="tabPanel"
36+
>
37+
<a mat-tab-link routerLink="/curriculum/public" [active]="isPublicRoute()">
38+
{{ getPublicTabLabel() }}
39+
</a>
40+
<a mat-tab-link routerLink="/curriculum/personal" [active]="isPersonalRoute()">
41+
{{ getMyUnitsTabLabel() }}
42+
</a>
43+
</nav>
44+
<mat-tab-nav-panel #tabPanel>
45+
<public-library [hidden]="!isPublicRoute()"></public-library>
46+
<app-personal-library [hidden]="!isPersonalRoute()"></app-personal-library>
47+
</mat-tab-nav-panel>
3948
} @else {
40-
<public-library />
49+
<public-library></public-library>
4150
}
4251
</div>
4352
</div>

src/app/curriculum/curriculum.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55

66
@apply md:rounded-md md:rounded-se-none md:rounded-ee-none;
77
}
8+
9+
.mat-headline-4 {
10+
margin-bottom: 0;
11+
}

src/app/curriculum/curriculum.component.spec.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { MockComponents, MockProvider, MockProviders } from 'ng-mocks';
88
import { PersonalLibraryComponent } from '../modules/library/personal-library/personal-library.component';
99
import { PublicLibraryComponent } from '../modules/library/public-library/public-library.component';
1010
import { UserService } from '../services/user.service';
11+
import { provideRouter } from '@angular/router';
1112

1213
describe('CurriculumComponent', () => {
1314
let component: CurriculumComponent;
@@ -26,7 +27,8 @@ describe('CurriculumComponent', () => {
2627
communityLibraryProjectsSource$: of([]),
2728
numberOfPublicProjectsVisible$: of(3),
2829
numberOfPersonalProjectsVisible$: of(2)
29-
})
30+
}),
31+
provideRouter([])
3032
]
3133
}).compileComponents();
3234
spyOn(TestBed.inject(ConfigService), 'getAuthoringToolLink').and.returnValue('');
@@ -41,23 +43,23 @@ describe('CurriculumComponent', () => {
4143
component.ngOnInit();
4244
fixture.detectChanges();
4345
expect(numAuthoringToolButtonElements(fixture)).toEqual(0);
44-
expect(numTabGroupElements(fixture)).toEqual(0);
46+
expect(numTabNavBarElements(fixture)).toEqual(0);
4547
});
4648

47-
it('should show My Units tab and authoring tool link when logged in as teacher', () => {
49+
it('should show My Units tab and teacher home and authoring tool links when logged in as teacher', () => {
4850
spyOn(TestBed.inject(UserService), 'isTeacher').and.returnValue(true);
4951
component.ngOnInit();
5052
fixture.detectChanges();
51-
expect(numAuthoringToolButtonElements(fixture)).toEqual(1);
52-
expect(numTabGroupElements(fixture)).toEqual(1);
53+
expect(numAuthoringToolButtonElements(fixture)).toEqual(2);
54+
expect(numTabNavBarElements(fixture)).toEqual(1);
5355
expect(component['showMyUnits']).toBeTruthy();
5456
});
5557
});
5658

5759
function numAuthoringToolButtonElements(fixture: ComponentFixture<CurriculumComponent>) {
58-
return fixture.debugElement.nativeElement.querySelectorAll('a').length;
60+
return fixture.debugElement.nativeElement.querySelectorAll('header * a').length;
5961
}
6062

61-
function numTabGroupElements(fixture: ComponentFixture<CurriculumComponent>) {
62-
return fixture.debugElement.nativeElement.querySelectorAll('mat-tab-group').length;
63+
function numTabNavBarElements(fixture: ComponentFixture<CurriculumComponent>) {
64+
return fixture.debugElement.nativeElement.querySelectorAll('nav').length;
6365
}

src/app/curriculum/curriculum.component.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { PublicLibraryComponent } from '../modules/library/public-library/public
1010
import { Subscription } from 'rxjs';
1111
import { UserService } from '../services/user.service';
1212
import { MatButtonModule } from '@angular/material/button';
13+
import { Router, RouterModule } from '@angular/router';
1314

1415
@Component({
1516
imports: [
@@ -19,7 +20,8 @@ import { MatButtonModule } from '@angular/material/button';
1920
MatIconModule,
2021
MatTabsModule,
2122
PersonalLibraryComponent,
22-
PublicLibraryComponent
23+
PublicLibraryComponent,
24+
RouterModule
2325
],
2426
styleUrl: './curriculum.component.scss',
2527
templateUrl: './curriculum.component.html'
@@ -33,7 +35,8 @@ export class CurriculumComponent {
3335
constructor(
3436
protected configService: ConfigService,
3537
private libraryService: LibraryService,
36-
private userService: UserService
38+
private userService: UserService,
39+
private router: Router
3740
) {}
3841

3942
ngOnInit(): void {
@@ -76,4 +79,12 @@ export class CurriculumComponent {
7679
protected getMyUnitsTabLabel(): string {
7780
return $localize`My Units (${this.numMyUnitsVisible})`;
7881
}
82+
83+
protected isPublicRoute(): boolean {
84+
return this.router.url === '/curriculum/public';
85+
}
86+
87+
protected isPersonalRoute(): boolean {
88+
return this.router.url === '/curriculum/personal';
89+
}
7990
}
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
<nav [ngSwitch]="location" class="header__links flex flex-row items-center">
2-
<span class="mat-body-2">
3-
<ng-container *ngSwitchCase="'teacher'" i18n>Welcome {{ user.firstName }}!</ng-container>
4-
<ng-container *ngSwitchCase="'student'" i18n>Welcome {{ user.firstName }}!</ng-container>
5-
</span>
6-
<ng-container *ngSwitchDefault>
1+
<nav class="header__links flex flex-row items-center">
2+
@if (location === 'student') {
3+
<span class="mat-body-2" i18n>Welcome {{ user.firstName }}!</span>
4+
} @else {
75
<a
86
mat-button
97
routerLink="/features"
@@ -20,16 +18,11 @@
2018
i18n
2119
>About Us</a
2220
>
23-
<a
24-
mat-button
25-
routerLink="/curriculum"
26-
routerLinkActive="active"
27-
[routerLinkActiveOptions]="{ exact: true }"
28-
i18n
29-
>Curriculum</a
30-
>
21+
<a mat-button routerLink="/curriculum" routerLinkActive="active" i18n>Curriculum</a>
3122
<a mat-button href="https://wise-discuss.berkeley.edu" i18n>Community</a>
3223
<a mat-button href="https://wise-research.berkeley.edu" i18n>Research</a>
33-
</ng-container>
34-
<app-header-signin *ngIf="roles.length === 0"></app-header-signin>
24+
}
25+
@if (roles.length === 0) {
26+
<app-header-signin></app-header-signin>
27+
}
3528
</nav>

src/app/modules/header/header-links/header-links.component.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,15 @@ describe('HeaderLinksComponent', () => {
1414
});
1515
fixture = TestBed.createComponent(HeaderLinksComponent);
1616
component = fixture.componentInstance;
17-
const user: User = new User();
18-
user.id = 1;
19-
user.firstName = 'Amanda';
20-
user.lastName = 'Panda';
21-
user.roles = ['student'];
22-
user.username = 'AmandaP0101';
23-
component.user = user;
24-
component.location = 'student';
2517
fixture.detectChanges();
2618
});
2719

2820
it('should create', () => {
2921
expect(component).toBeTruthy();
3022
});
3123

32-
it('should show user welcome message', () => {
24+
it('should show header sign in if no user is logged in', () => {
3325
const compiled = fixture.debugElement.nativeElement;
34-
expect(compiled.querySelector('.header__links').textContent).toContain('Welcome Amanda!');
26+
expect(compiled.querySelectorAll('app-header-signin').length).toBe(1);
3527
});
3628
});

src/app/modules/header/header-links/header-links.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { FlexLayoutModule } from '@angular/flex-layout';
77
import { RouterModule } from '@angular/router';
88

99
@Component({
10-
selector: 'app-header-links',
11-
imports: [CommonModule, FlexLayoutModule, HeaderSigninComponent, MatButtonModule, RouterModule],
12-
templateUrl: './header-links.component.html',
13-
styleUrl: './header-links.component.scss'
10+
selector: 'app-header-links',
11+
imports: [CommonModule, FlexLayoutModule, HeaderSigninComponent, MatButtonModule, RouterModule],
12+
templateUrl: './header-links.component.html',
13+
styleUrl: './header-links.component.scss'
1414
})
1515
export class HeaderLinksComponent {
1616
@Input() location: string;

src/app/modules/library/community-library/community-library.component.html

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/app/modules/library/community-library/community-library.component.spec.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)