-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[#14387] Create role selection page #14392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TobyCyan
wants to merge
14
commits into
TEAMMATES:master
Choose a base branch
from
TobyCyan:role-selection-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
677198d
Create role selection page
TobyCyan 34e7a15
Remove route data
TobyCyan cb4ad1f
Remove role description
TobyCyan 309048c
Merge branch 'master' into role-selection-page
TobyCyan eb2fd00
Remove support email text
TobyCyan f825a46
Merge branch 'master' into role-selection-page
TobyCyan 74ed8f4
Add link to getting started page
TobyCyan e5fd898
Merge branch 'master' into role-selection-page
TobyCyan 264b6a5
Use backend support email
TobyCyan 32a024d
Update text
TobyCyan a959a3e
Fix formatting
TobyCyan c2a353d
Update spec
TobyCyan 937bcf7
Remove New to TEAMMATES?
TobyCyan 0c838cc
Merge branch 'master' into role-selection-page
TobyCyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/web/app/page-role-selection/role-selection-page.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <div *tmIsLoading="isLoadingRoles()"> | ||
| <div class="card bg-light mx-auto" style="max-width: 600px"> | ||
| <div class="card-header bg-primary text-white"> | ||
| <h1 class="mb-0 h3">Welcome to TEAMMATES!</h1> | ||
| </div> | ||
| <div class="card-body"> | ||
| @if (hasRolePages()) { | ||
| <p>Choose a page to continue.</p> | ||
| <div style="margin-top: 20px"> | ||
| @for (rolePage of rolePages(); track rolePage.url) { | ||
| <div class="d-sm-flex align-items-center justify-content-between border-top py-3"> | ||
| <div class="mb-2 mb-sm-0"> | ||
| <strong>{{ rolePage.role }}</strong> | ||
| </div> | ||
| <a class="btn btn-success" [routerLink]="rolePage.url">Continue</a> | ||
| </div> | ||
| } | ||
| </div> | ||
| } @else { | ||
| <p>You do not have access to any instructor or student pages yet.</p> | ||
| <p> | ||
| If you expected access, please contact your instructor or | ||
| <a href="mailto:{{ supportEmail() }}">email us</a>. | ||
| </p> | ||
| <p><a routerLink="/web/front/help/getting-started">New to TEAMMATES?</a></p> | ||
|
TobyCyan marked this conversation as resolved.
Outdated
|
||
| <div class="text-center" style="margin-top: 20px"> | ||
| <a class="btn btn-primary" routerLink="/web/front/">Return to main page</a> | ||
| </div> | ||
| } | ||
| </div> | ||
| </div> | ||
| </div> | ||
57 changes: 57 additions & 0 deletions
57
src/web/app/page-role-selection/role-selection-page.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { provideRouter } from '@angular/router'; | ||
| import { of } from 'rxjs'; | ||
| import { AuthService } from '../../services/auth.service'; | ||
| import { AuthInfo } from '../../types/api-output'; | ||
| import { RoleSelectionPageComponent } from './role-selection-page.component'; | ||
|
|
||
| const authInfoFor = (roles: { | ||
| isStudent?: boolean; | ||
| isInstructor?: boolean; | ||
| isAdmin?: boolean; | ||
| isMaintainer?: boolean; | ||
| }): AuthInfo => ({ | ||
| masquerade: false, | ||
| user: { | ||
| accountId: 'account-id', | ||
| accountEmail: 'user@example.com', | ||
| isStudent: !!roles.isStudent, | ||
| isInstructor: !!roles.isInstructor, | ||
| isAdmin: !!roles.isAdmin, | ||
| isMaintainer: !!roles.isMaintainer, | ||
| }, | ||
| }); | ||
|
|
||
| describe('RoleSelectionPageComponent', () => { | ||
| let fixture: ComponentFixture<RoleSelectionPageComponent>; | ||
| let authService: AuthService; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| providers: [provideRouter([])], | ||
| }).compileComponents(); | ||
| fixture = TestBed.createComponent(RoleSelectionPageComponent); | ||
| authService = TestBed.inject(AuthService); | ||
| }); | ||
|
|
||
| it('should show available role pages', () => { | ||
| vi.spyOn(authService, 'getAuthUser').mockReturnValue(of(authInfoFor({ isStudent: true, isInstructor: true }))); | ||
|
|
||
| fixture.detectChanges(); | ||
|
|
||
| const pageText = fixture.nativeElement.textContent; | ||
| expect(pageText).toContain('Student'); | ||
| expect(pageText).toContain('Instructor'); | ||
| expect(pageText).not.toContain('Return to main page'); | ||
| }); | ||
|
|
||
| it('should prompt users with no roles to return to the main page', () => { | ||
| vi.spyOn(authService, 'getAuthUser').mockReturnValue(of(authInfoFor({}))); | ||
|
|
||
| fixture.detectChanges(); | ||
|
|
||
| const pageText = fixture.nativeElement.textContent; | ||
| expect(pageText).toContain('You do not have access to any instructor or student pages yet.'); | ||
| expect(pageText).toContain('Return to main page'); | ||
| }); | ||
| }); |
81 changes: 81 additions & 0 deletions
81
src/web/app/page-role-selection/role-selection-page.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { ChangeDetectionStrategy, Component, OnInit, computed, inject, signal } from '@angular/core'; | ||
| import { RouterLink } from '@angular/router'; | ||
| import { map, finalize } from 'rxjs/operators'; | ||
| import { AuthService } from '../../services/auth.service'; | ||
| import { AuthInfo } from '../../types/api-output'; | ||
| import { LoadingSpinnerDirective } from '../components/loading-spinner/loading-spinner.directive'; | ||
| import { ConfigService } from '../../services/config.service'; | ||
| import { toSignal } from '@angular/core/rxjs-interop'; | ||
|
|
||
| interface RolePage { | ||
| role: string; | ||
| url: string; | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'tm-role-selection-page', | ||
| templateUrl: './role-selection-page.component.html', | ||
| imports: [RouterLink, LoadingSpinnerDirective], | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class RoleSelectionPageComponent implements OnInit { | ||
| private readonly authService = inject(AuthService); | ||
| private readonly configService = inject(ConfigService); | ||
|
|
||
| readonly isLoadingRoles = signal(true); | ||
| readonly rolePages = signal<RolePage[]>([]); | ||
| readonly hasRolePages = computed(() => this.rolePages().length > 0); | ||
| readonly supportEmail = toSignal(this.configService.getConfig().pipe(map((config) => config.supportEmail)), { | ||
| initialValue: '', | ||
| }); | ||
|
|
||
| ngOnInit(): void { | ||
| this.isLoadingRoles.set(true); | ||
| this.authService | ||
| .getAuthUser() | ||
| .pipe( | ||
| finalize(() => { | ||
| this.isLoadingRoles.set(false); | ||
| }), | ||
| ) | ||
| .subscribe({ | ||
| next: (authInfo: AuthInfo) => { | ||
| const user = authInfo.user; | ||
| const rolePages: RolePage[] = []; | ||
|
|
||
| if (user?.isStudent) { | ||
| rolePages.push({ | ||
| role: 'Student', | ||
| url: '/web/student', | ||
| }); | ||
| } | ||
|
|
||
| if (user?.isInstructor) { | ||
| rolePages.push({ | ||
| role: 'Instructor', | ||
| url: '/web/instructor', | ||
| }); | ||
| } | ||
|
|
||
| if (user?.isAdmin) { | ||
| rolePages.push({ | ||
| role: 'Admin', | ||
| url: '/web/admin', | ||
| }); | ||
| } | ||
|
|
||
| if (user?.isMaintainer) { | ||
| rolePages.push({ | ||
| role: 'Maintainer', | ||
| url: '/web/maintainer', | ||
| }); | ||
| } | ||
|
|
||
| this.rolePages.set(rolePages); | ||
| }, | ||
| error: () => { | ||
| this.rolePages.set([]); | ||
| }, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.