Skip to content

Commit

Permalink
Merge pull request #634 from encorelab/develop
Browse files Browse the repository at this point in the history
feature add oct 29 2024 research study request updates
  • Loading branch information
JoelWiebe authored Oct 30, 2024
2 parents ffc4e15 + 5fb041b commit 32d172b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion backend/src/services/vertexAI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function isValidJSON(jsonObject: any): boolean {
function postsToKeyValuePairs(posts: any[]): string {
let output = '';
for (const post of posts) {
output += `Post with title "${post.title}" (postID: ${post.postID}):\n`;
output += `Post with title "${post.title}" (postID: ${post.postID}) by ${post.author}:\n`;
output += ` - Content: ${post.desc}\n`;
output += ` - Upvotes: ${post.numUpvotes}\n`;

Expand Down
8 changes: 6 additions & 2 deletions backend/src/socket/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ class Socket {
});

// Error handling within the connection handler
socket.on('error', (error) => {
console.error(`Socket ${socket.id} error:`, error);
socket.on('error', (error: any) => {
if (error.code === 'ECONNRESET') {
console.error(`Socket ${socket.id} connection reset. Attempting to reconnect...`);
} else {
console.error(`Socket ${socket.id} error:`, error);
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
>
<mat-icon>star_border</mat-icon>
</button>
<button mat-icon-button [matMenuTriggerFor]="bucketMenu">
<button mat-icon-button [matMenuTriggerFor]="bucketMenu" *ngIf="user.role === Role.TEACHER">
<mat-icon>library_add</mat-icon>
</button>
<mat-menu #bucketMenu="matMenu">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class PostModalComponent {
tagOptions: Tag[] = [];

user: User;
Role: typeof Role = Role;
board: Board;
project: Project;
post: Post;
Expand Down Expand Up @@ -144,7 +145,9 @@ export class PostModalComponent {
this.editingDesc = linkifyStr(p.desc, {
defaultProtocol: 'https',
target: '_blank',
}).replace(/(?:\r\n|\r|\n)/g, '<br>');
}).replace(/ /g, '&nbsp;') // Replace spaces with &nbsp;
.replace(/\t/g, '&emsp;') // Replace tabs with &emsp;
.replace(/(?:\r\n|\r|\n)/g, '<br>');
this.tags = p.tags;
this.tagOptions = data.board.tags.filter(
(n) => !this.tags.map((b) => b.name).includes(n.name)
Expand Down Expand Up @@ -244,7 +247,9 @@ export class PostModalComponent {
this.editingDesc = linkifyStr(this.desc, {
defaultProtocol: 'https',
target: '_blank',
}).replace(/(?:\r\n|\r|\n)/g, '<br>');
}).replace(/ /g, '&nbsp;') // Replace spaces with &nbsp;
.replace(/\t/g, '&emsp;') // Replace tabs with &emsp;
.replace(/(?:\r\n|\r|\n)/g, '<br>');

const update: Partial<Post> = {
postID: this.post.postID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@
<mat-icon>settings</mat-icon>
Adjust Settings
</button>
<a href="https://score.oise.utoronto.ca/" style="text-decoration:none;color:black" target="_blank" >
<button mat-menu-item style="text-decoration:none;color:black">
<mat-icon>launch</mat-icon>
Go to SCORE
</button>
</a>
<button mat-menu-item (click)="signOut()">
<mat-icon class="material-icons-outlined">logout</mat-icon>
Log Out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export class TaskModalComponent {
this.message = linkifyStr(data.message, {
defaultProtocol: 'https',
target: '_blank',
});
}).replace(/ /g, '&nbsp;') // Replace spaces with &nbsp;
.replace(/\t/g, '&emsp;') // Replace tabs with &emsp;
.replace(/(?:\r\n|\r|\n)/g, '<br>');
}

ngOnInit(): void {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@
<mat-icon>settings</mat-icon>
Adjust Settings
</button>
<!-- <button mat-menu-item *ngIf="!(user.role === Role.STUDENT && !board.permissions.showBucketStudent) && board.scope === BoardScope.PROJECT_SHARED" (click)="showBucketsModal()">
<mat-icon>shopping_basket</mat-icon>
View Buckets
</button> -->
<a href="https://score.oise.utoronto.ca/" style="text-decoration:none;color:black" target="_blank">
<button mat-menu-item style="text-decoration:none;color:black">
<mat-icon>launch</mat-icon>
Go to SCORE
</button>
</a>
<button mat-menu-item (click)="signOut()">
<mat-icon class="material-icons-outlined">logout</mat-icon>
Log Out
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/app/components/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
<ng-content select="[navbarMenu]"></ng-content>

<mat-menu #menu="matMenu">
<a href="https://score.oise.utoronto.ca/" style="text-decoration:none;color:black" target="_blank" >
<button mat-menu-item style="text-decoration:none;color:black">
<mat-icon>launch</mat-icon>
Go to SCORE
</button>
</a>
<button mat-menu-item (click)="signOut()">
<mat-icon class="material-icons-outlined">logout</mat-icon>
Log Out
Expand Down
41 changes: 26 additions & 15 deletions frontend/src/app/services/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export class SocketService {
private maxRetries = 10;
private retryInterval = 5000;

constructor(private socket: Socket, private traceService: TraceService) {}
constructor(private socket: Socket, private traceService: TraceService) {
this.socket.on('connect_error', (error) => {
console.error('WebSocket connection error:', error);
// Do NOT attempt to reconnect here.
// Instead, display an error message to the user or handle it appropriately.
});
}

/**
* Connect to specific board's websocket connection.
Expand All @@ -37,13 +43,14 @@ export class SocketService {
* @returns subscription object to unsubscribe from in the future
*/
listen(event: SocketEvent, handler: Function): Subscription {
const observable = this.socket.fromEvent<any>(event).pipe(
catchError((error: Error) => {
console.error(`Error handling event ${event}:`, error);
return of(null); // Return a default value
})
);
return observable.subscribe((value) => handler(value));
try {
const observable = this.socket.fromEvent<any>(event);
return observable.subscribe((value) => handler(value));
} catch (error) {
console.error('Error listening for event:', error);
// Handle the error appropriately, e.g., by returning an empty observable
return new Subscription(); // Do nothing
}
}

/**
Expand All @@ -61,7 +68,7 @@ export class SocketService {
return of(null); // Return a default value
})
);
return observable.subscribe((value) => handler(value));
return observable.subscribe((value) => handler(value));
}

/**
Expand All @@ -72,12 +79,16 @@ export class SocketService {
* @returns void
*/
emit(event: SocketEvent, value: any): void {
const trace = this.traceService.getTraceContext();
const socketPayload: SocketPayload = {
trace,
eventData: value,
};
this.socket.emit(event, socketPayload);
try {
const trace = this.traceService.getTraceContext();
const socketPayload: SocketPayload = {
trace,
eventData: value,
};
this.socket.emit(event, socketPayload);
} catch (error: any) {
console.error('Error emitting event:', error);
}
}

/**
Expand Down

0 comments on commit 32d172b

Please sign in to comment.