forked from CS3219-AY2425S1/cs3219-ay2425s1-project-g03
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into combine-room-and-collab-1
* main: Add and integrate match service (CS3219-AY2425S1#56) Add Match Page (CS3219-AY2425S1#44) # Conflicts: # compose.dev.yml # compose.yml # frontend/src/app/app.routes.ts
- Loading branch information
Showing
58 changed files
with
6,693 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,50 @@ | ||
import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { ApiService } from './api.service'; | ||
import { MatchRequest, MatchResponse } from '../app/matching/match.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class MatchService extends ApiService { | ||
protected apiPath = 'match/request'; | ||
|
||
private httpOptions = { | ||
headers: new HttpHeaders({ | ||
'Content-Type': 'application/json', | ||
}), | ||
}; | ||
|
||
constructor(private http: HttpClient) { | ||
super(); | ||
} | ||
|
||
/** | ||
* Creates a match request with the provided details. The match request will | ||
* be valid for one minute. | ||
*/ | ||
createMatchRequest(matchRequest: MatchRequest) { | ||
return this.http.post<MatchResponse>(this.apiUrl, matchRequest, this.httpOptions); | ||
} | ||
|
||
/** | ||
* Retrieves the match request and its current status | ||
*/ | ||
retrieveMatchRequest(id: string) { | ||
return this.http.get<MatchResponse>(this.apiUrl + '/' + id); | ||
} | ||
|
||
/** | ||
* Refreshes the match request, effectively resetting its validity to one minute. | ||
*/ | ||
updateMatchRequest(id: string) { | ||
return this.http.put<MatchResponse>(this.apiUrl + '/' + id, {}, this.httpOptions); | ||
} | ||
|
||
/** | ||
* Deletes the match request | ||
*/ | ||
deleteMatchRequest(id: string) { | ||
return this.http.delete<MatchResponse>(this.apiUrl + '/' + id); | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import { Routes } from '@angular/router'; | ||
import { QuestionsComponent } from './questions/questions.component'; | ||
import { MatchingComponent } from './matching/matching.component'; | ||
import { AuthGuardService } from '../_services/auth.guard.service'; | ||
import { CollaborationComponent } from './collaboration/collaboration.component'; | ||
|
||
const accountModule = () => import('./account/account.module').then(x => x.AccountModule); | ||
|
||
export const routes: Routes = [ | ||
{ | ||
path: 'account', | ||
loadChildren: accountModule, | ||
}, | ||
{ | ||
path: 'questions', | ||
component: QuestionsComponent, | ||
canActivate: [AuthGuardService], | ||
}, | ||
{ | ||
path: 'start', | ||
component: CollaborationComponent, | ||
}, | ||
{ | ||
path: 'account', | ||
loadChildren: accountModule, | ||
}, | ||
{ | ||
path: 'questions', | ||
component: QuestionsComponent, | ||
canActivate: [AuthGuardService], | ||
}, | ||
{ | ||
path: 'start', | ||
component: CollaborationComponent, | ||
}, | ||
{ | ||
path: 'matching', | ||
component: MatchingComponent, | ||
}, | ||
]; |
20 changes: 20 additions & 0 deletions
20
frontend/src/app/matching/_validators/has-questions.validator.ts
This file contains 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,20 @@ | ||
import { AbstractControl, AsyncValidatorFn, ValidationErrors } from '@angular/forms'; | ||
import { QuestionService } from '../../../_services/question.service'; | ||
import { map, Observable, of } from 'rxjs'; | ||
|
||
export const HAS_NO_QUESTIONS = 'hasNoQuestions'; | ||
|
||
export function hasQuestionsValidator(questionService: QuestionService): AsyncValidatorFn { | ||
return (formGroup: AbstractControl): Observable<ValidationErrors | null> => { | ||
const topics = formGroup.get('topics')?.value; | ||
const difficulty = formGroup.get('difficulty')?.value; | ||
|
||
if (!(topics.length && difficulty)) { | ||
return of({ [HAS_NO_QUESTIONS]: true }); | ||
} | ||
|
||
return questionService | ||
.getQuestionByParam(topics, difficulty) | ||
.pipe(map(res => (res.data?.length ? null : { [HAS_NO_QUESTIONS]: true }))); | ||
}; | ||
} |
11 changes: 11 additions & 0 deletions
11
frontend/src/app/matching/finding-match/finding-match.component.css
This file contains 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,11 @@ | ||
::ng-deep .easy-chip .p-chip { | ||
background-color: var(--green-700); | ||
} | ||
|
||
::ng-deep .medium-chip .p-chip { | ||
background-color: var(--orange-600); | ||
} | ||
|
||
::ng-deep .hard-chip .p-chip { | ||
background-color: var(--red-700); | ||
} |
62 changes: 62 additions & 0 deletions
62
frontend/src/app/matching/finding-match/finding-match.component.html
This file contains 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,62 @@ | ||
<p-dialog | ||
styleClass="w-11 sm:w-22rem" | ||
[(visible)]="isVisible" | ||
[modal]="true" | ||
[draggable]="false" | ||
[closeOnEscape]="false" | ||
(onShow)="onDialogShow()" | ||
[closable]="false"> | ||
<ng-template pTemplate="header"> | ||
<div class="flex flex-column w-full align-items-center justify-content-center gap-2"> | ||
@if (isFindingMatch) { | ||
<p-progressSpinner styleClass="w-2rem h-2rem mt-0" strokeWidth="6" /> | ||
<h2 class="mt-0 mb-0">Finding a Match...</h2> | ||
<div class="flex gap-2 align-items-center"> | ||
<i class="pi pi-stopwatch"></i> | ||
<p class="m-0">Time Left: {{ matchTimeLeft }}</p> | ||
</div> | ||
} @else { | ||
<i class="pi pi-check text-4xl text-green-300"></i> | ||
<h2 class="mt-0 mb-0">Match Found!</h2> | ||
} | ||
</div> | ||
</ng-template> | ||
|
||
<div class="flex flex-column gap-4"> | ||
<div class="flex flex-column gap-2 align-items-center"> | ||
<p class="m-0">Topics selected</p> | ||
<div class="flex flex-wrap gap-2 justify-content-center"> | ||
@for (topic of userCriteria.topics; track topic) { | ||
<p-chip [label]="topic" styleClass="text-sm" /> | ||
} | ||
</div> | ||
</div> | ||
|
||
<div class="flex flex-column gap-2 align-items-center"> | ||
<p class="m-0">Difficulty selected</p> | ||
<p-chip | ||
[label]="userCriteria.difficulty" | ||
styleClass="text-sm" | ||
[ngClass]="{ | ||
'easy-chip': userCriteria.difficulty === 'Easy', | ||
'medium-chip': userCriteria.difficulty === 'Medium', | ||
'hard-chip': userCriteria.difficulty === 'Hard', | ||
}" /> | ||
</div> | ||
</div> | ||
|
||
<ng-template pTemplate="footer"> | ||
<div class="flex w-full justify-content-center align-items-center"> | ||
@if (isFindingMatch) { | ||
<p-button | ||
type="button" | ||
label="Cancel Match" | ||
severity="danger" | ||
[outlined]="true" | ||
(click)="closeDialog()" /> | ||
} @else { | ||
<p class="mb-0 font-medium text-blue-300">Redirecting you to the workspace...</p> | ||
} | ||
</div> | ||
</ng-template> | ||
</p-dialog> |
22 changes: 22 additions & 0 deletions
22
frontend/src/app/matching/finding-match/finding-match.component.spec.ts
This file contains 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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { FindingMatchComponent } from './finding-match.component'; | ||
|
||
describe('FindingMatchComponent', () => { | ||
let component: FindingMatchComponent; | ||
let fixture: ComponentFixture<FindingMatchComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [FindingMatchComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(FindingMatchComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.