Skip to content
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

Profile history pages #80

Merged
merged 30 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1f4562d
Create Profile Page
LimZiJia Nov 2, 2024
d69f7d6
Merge branch 'main' into profile-and-hostory-pages
LimZiJia Nov 2, 2024
d08088e
Add webpage for history
LimZiJia Nov 2, 2024
81dc5dc
Merge branch 'main' into profile-and-hostory-pages
LimZiJia Nov 5, 2024
407d3e8
Working History page
LimZiJia Nov 5, 2024
d21134e
Fix linting
LimZiJia Nov 5, 2024
c7b5239
Merge remote-tracking branch 'origin/main' into profile-history-pages
samuelim01 Nov 7, 2024
06ac329
Fix merge
samuelim01 Nov 7, 2024
cca95bc
Fix suggestions on the PR
LimZiJia Nov 9, 2024
d8d1c1e
Merge remote-tracking branch 'origin/main' into profile-history-pages
samuelim01 Nov 9, 2024
286ec54
Improve error messages
samuelim01 Nov 9, 2024
34ec12f
Enable viewing of code in history page
LimZiJia Nov 12, 2024
8adba39
Fix linting
LimZiJia Nov 12, 2024
4475d8c
Fix test case
LimZiJia Nov 12, 2024
e1218cc
Fix bug where histories cannot be loaded during colab session
LimZiJia Nov 12, 2024
d7a70ab
Fix lint
samuelim01 Nov 12, 2024
bfe5a72
Merge remote-tracking branch 'origin/main' into profile-history-pages
samuelim01 Nov 12, 2024
b4ee292
Add new routes to user service to handle update to user details
McNaBry Nov 12, 2024
2b6c943
Update frontend to call the correct routes when updating user profile
McNaBry Nov 12, 2024
2cdd900
Fix linting
McNaBry Nov 12, 2024
c98b79f
Add dialogs for editing user profile and password
McNaBry Nov 12, 2024
741f923
Update styles for profile page
McNaBry Nov 12, 2024
5f05e3c
Merge branch 'main' into profile-history-pages
samuelim01 Nov 13, 2024
7a6641c
Refactor backend to handle history snapshot
samuelim01 Nov 13, 2024
c354d38
Fix history panel appearing when no code history exists
samuelim01 Nov 13, 2024
1c1f6ad
Add description to question
samuelim01 Nov 13, 2024
c048ba0
Fix history code being editable
samuelim01 Nov 13, 2024
48066d2
Remove redundant login calls
samuelim01 Nov 13, 2024
5560837
Redirect to the collab session if in progress
samuelim01 Nov 13, 2024
fead1be
Merge branch 'main' into profile-history-pages
samuelim01 Nov 13, 2024
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
4 changes: 0 additions & 4 deletions compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ services:
- /app/node_modules
- ./services/collaboration:/app

collaboration-db:
ports:
- 27020:27017

history:
command: npm run dev
ports:
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/_services/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ export class AuthenticationService extends ApiService {
.pipe(switchMap(() => this.login(username, password))); // auto login after registration
}

updateUsernameAndEmail(username: string, email: string, password: string) {
return this.http
.patch<UServRes>(
`${this.apiUrl}/users/username-email/${this.userValue!.id}`,
{ username: username, email: email, password: password },
{ observe: 'response' },
)
.pipe(switchMap(() => this.login(username, password))); // login to update local storage and subject
}

updatePassword(username: string, oldPassword: string, newPassword: string) {
return this.http
.patch<UServRes>(
`${this.apiUrl}/users/password/${this.userValue!.id}`,
{ oldPassword: oldPassword, newPassword: newPassword },
{ observe: 'response' },
)
.pipe(switchMap(() => this.login(username, newPassword))); // login to update local storage and subject
}

logout() {
// remove user from local storage to log user out
localStorage.removeItem('user');
Expand Down
87 changes: 87 additions & 0 deletions frontend/src/_services/form.utils.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Injectable } from '@angular/core';
import { AbstractControl, FormGroup } from '@angular/forms';
import { PASSWORD_LOWERCASE } from '../app/account/_validators/lowercase-password';
import { PASSWORD_UPPERCASE } from '../app/account/_validators/uppercase-password';
import { PASSWORD_NUMERIC } from '../app/account/_validators/numeric-password';
import { PASSWORD_SPECIAL } from '../app/account/_validators/special-password';
import { PASSWORD_SHORT } from '../app/account/_validators/short-password';
import { PASSWORD_WEAK } from '../app/account/_validators/weak-password.validator';
import { PASSWORD_MISMATCH } from '../app/account/_validators/mismatch-password.validator';
import { USERNAME_INVALID } from '../app/account/_validators/invalid-username.validator';
import { PASSWORD_INVALID } from '../app/account/_validators/invalid-password.validator';

@Injectable({
providedIn: 'root',
})

// This service is used to validate the form fields in the register and profile components
export class FormUtilsService {
samuelim01 marked this conversation as resolved.
Show resolved Hide resolved
get isUsernameInvalid(): (form: FormGroup) => boolean {
return (form: FormGroup) => {
const usernameControl = form.controls['username'];
return usernameControl.dirty && usernameControl.hasError(USERNAME_INVALID);
};
}

get isEmailInvalid(): (form: FormGroup) => boolean {
return (form: FormGroup) => {
const emailControl = form.controls['email'];
return emailControl.dirty && emailControl.invalid;
};
}

get passwordControl(): (form: FormGroup) => AbstractControl {
return (form: FormGroup) => form.controls['password'];
}

get isPasswordControlDirty(): (form: FormGroup) => boolean {
return (form: FormGroup) => this.passwordControl(form).dirty;
}

get passwordHasNoLowercase(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_LOWERCASE);
}

get passwordHasNoUppercase(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_UPPERCASE);
}

get passwordHasNoNumeric(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_NUMERIC);
}

get passwordHasNoSpecial(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SPECIAL);
}

get isPasswordShort(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).pristine || this.passwordControl(form).hasError(PASSWORD_SHORT);
}

get isPasswordWeak(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_WEAK);
}

get isPasswordStrong(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).dirty && !this.passwordControl(form).hasError(PASSWORD_WEAK);
}

get isPasswordInvalid(): (form: FormGroup) => boolean {
return (form: FormGroup) =>
this.passwordControl(form).dirty && this.passwordControl(form).hasError(PASSWORD_INVALID);
}

get hasPasswordMismatch(): (form: FormGroup) => boolean {
return (form: FormGroup) => {
const confirmPasswordControl = form.controls['confirmPassword'];
return this.passwordControl(form).valid && confirmPasswordControl.dirty && form.hasError(PASSWORD_MISMATCH);
};
}
}
36 changes: 36 additions & 0 deletions frontend/src/_services/history.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { historyResponse, MatchingHistory } from '../app/account/history/history.model';
import { ApiService } from './api.service';

@Injectable({
providedIn: 'root',
})
export class HistoryService extends ApiService {
protected apiPath = 'history/history';

constructor(private http: HttpClient) {
super();
}

getHistories(): Observable<MatchingHistory[]> {
return this.http.get<historyResponse>(`${this.apiUrl}`).pipe(
map(response =>
response.data.map(item => ({
id: item._id,
roomId: item.roomId,
collaborator: item.collaborator.username,
question: item.question,
topics: item.question.topics,
difficulty: item.question.difficulty,
status: item.status,
time: item.createdAt,
language: item.snapshot?.language,
code: item.snapshot?.code,
})),
),
);
}
}
8 changes: 6 additions & 2 deletions frontend/src/app/account/account.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { LoginComponent } from './login.component';
import { RegisterComponent } from './register.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
import { LayoutComponent } from './layout.component';
import { ProfileComponent } from './profile/profile.component';
import { HistoryComponent } from './history/history.component';

const routes: Routes = [
{
Expand All @@ -13,6 +15,8 @@ const routes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'profile', component: ProfileComponent },
{ path: 'history', component: HistoryComponent },
],
},
];
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/app/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';

import { LoginComponent } from './login.component';
import { RegisterComponent } from './register.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
import { LayoutComponent } from './layout.component';
import { AccountRoutingModule } from './account.component';
import { ProfileComponent } from './profile/profile.component';
import { HistoryComponent } from './history/history.component';

@NgModule({
imports: [
Expand All @@ -15,6 +17,8 @@ import { AccountRoutingModule } from './account.component';
LayoutComponent,
LoginComponent,
RegisterComponent,
ProfileComponent,
HistoryComponent,
],
})
export class AccountModule {}
39 changes: 39 additions & 0 deletions frontend/src/app/account/history/history.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.sliding-panel {
position: fixed;
top: 0;
right: -600px; /* Adjust the width as needed */
width: 600px;
height: 100%;
background-color: #181818 !important;
color: var(--text-color); /* Use theme variable */
box-shadow: -2px 0 5px rgba(0,0,0,0.5);
transition: right 0.3s ease;
z-index: 1000;
}

.sliding-panel.open {
right: 0;
}

.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
background-color: #181818 !important;
border-bottom: 1px solid #000000; /* Use theme variable */
}

.panel-content {
padding: 1rem;
line-height: 1.6; /* Adjust line height for better readability */
color: #ffffff; /* Ensure text color is readable */
}

.panel-content p {
margin-bottom: 1rem; /* Add margin to paragraphs for spacing */
}

tr:hover {
background-color: rgba(0, 0, 0, 0.1);
}
84 changes: 84 additions & 0 deletions frontend/src/app/account/history/history.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<div class="table-container">
<p-table
samuelim01 marked this conversation as resolved.
Show resolved Hide resolved
#dt
sortField="time"
[sortOrder]="1"
[value]="histories"
datakey="id"
[tableStyle]="{ 'table-layout': 'auto', width: '100%', 'text-align': 'center' }"
[paginator]="true"
[rows]="10"
[rowsPerPageOptions]="[10, 25, 50]"
[globalFilterFields]="['question', 'difficulty', 'topics', 'collaborator', 'status', 'time']"
styleClass="p-datatable-gridlines-striped">
<ng-template pTemplate="caption">
<div class="flex">
<h3 class="m-0">Matching History</h3>
</div>
</ng-template>
<ng-template pTemplate="caption">
<div class="flex">
<p-iconField iconPosition="left" class="ml-auto">
<p-inputIcon>
<i class="pi pi-search"></i>
</p-inputIcon>
<input
pInputText
type="text"
(input)="dt.filterGlobal($any($event.target).value, 'contains')"
placeholder="Search keyword" />
</p-iconField>
</div>
</ng-template>
Comment on lines +19 to +32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search.mp4

I think we might need to ensure that the size doesn't keep changing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD in another branch

<ng-template pTemplate="header" let-columns>
<tr>
<th pSortableColumn="question" style="width: 20%">
Question<p-sortIcon field="question"></p-sortIcon>
</th>
<th pSortableColumn="difficulty" style="width: 14%">
Difficulty<p-sortIcon field="difficulty"></p-sortIcon>
</th>
<th pSortableColumn="topics" style="width: 25%">Topics<p-sortIcon field="topics"></p-sortIcon></th>
<th pSortableColumn="collaborator" style="width: 17%">
Collaborator<p-sortIcon field="collaborator"></p-sortIcon>
</th>
<th pSortableColumn="status" style="width: 12%">Status<p-sortIcon field="status"></p-sortIcon></th>
<th pSortableColumn="time" style="width: 12%">Time<p-sortIcon field="time"></p-sortIcon></th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-history>
<tr (click)="onRowSelect(history)">
<td>{{ history.question.title }}</td>
<td>{{ history.difficulty }}</td>
<td>{{ history.topics.join(', ') }}</td>
<td>{{ history.collaborator }}</td>
<td>
@if (history.status === 'COMPLETED') {
<i class="pi pi-check" style="color: green; font-size: large"></i>
} @else if (history.status === 'FORFEITED') {
<i class="pi pi-times" style="color: red; font-size: large"></i>
} @else if (history.status === 'IN_PROGRESS') {
<i class="pi pi-spin pi-spinner" style="color: white; font-size: large"></i>
}
</td>
<td>{{ history.time }}</td>
</tr>
</ng-template>
</p-table>
</div>
<div class="sliding-panel" [class.open]="isPanelVisible">
<div class="panel-header">
<h4>{{ panelHistory?.question?.title }}</h4>
<p-button
icon="pi pi-times"
severity="secondary"
label="Close"
(onClick)="closePanel()"
class="p-button-text" />
</div>
<div class="panel-content">
<p>{{ panelHistory?.question?.description }}</p>
<div #editor class="editor-content"></div>
</div>
</div>
<p-toast position="bottom-right" [breakpoints]="{ '920px': { width: '90%' } }" />
Loading