Skip to content

Commit a051599

Browse files
authored
156 fix and handle database failure for long time queries (#157)
* feat: removed nested study and task objects and minor bug fixes * feat: deploy script removed for security
1 parent 1b49b1f commit a051599

23 files changed

+436
-310
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"build-dev": "ng build --configuration development --aot",
5959
"test": "ng test",
6060
"lint": "ng lint",
61-
"deploy": "cd dist && scp -r . [email protected]:/home/nlee30",
61+
"deploy": "cd dist && scp ...",
6262
"build-deploy": "npm run build && npm run sentry:generate-sourcemaps && npm run sentry:upload-sourcemaps && npm run remove-maps && npm run deploy",
6363
"lint-fix": "ng lint --fix=true",
6464
"sentry:generate-sourcemaps": "sentry-cli sourcemaps inject ./dist",

src/app/CustomErrorHandler.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,53 @@ import { environment } from 'src/environments/environment';
55
import { TaskManagerService } from './services/task-manager.service';
66
import { UserStateService } from './services/user-state-service';
77
import { IErrorNavigationState } from './pages/error-page/error-page.component';
8+
import { HttpErrorResponse } from '@angular/common/http';
9+
import { SnackbarService } from './services/snackbar/snackbar.service';
810

911
@Injectable()
1012
export default class CustomErrorHandler extends SentryErrorHandler {
1113
constructor(
1214
private _router: Router,
1315
private taskManager: TaskManagerService,
1416
private userStateService: UserStateService,
15-
private injector: Injector
17+
private injector: Injector,
18+
private snackbarService: SnackbarService
1619
) {
1720
super();
1821
}
1922

20-
handleError(error: string | Error): void {
23+
handleError(error: string | Error | HttpErrorResponse): void {
2124
const ngZone = this.injector.get(NgZone);
22-
ngZone.run(() => {
23-
this._router.navigate(['task-error'], {
24-
state: {
25-
taskIndex: this.taskManager?.currentStudyTask?.taskOrder,
26-
studyId: this.taskManager?.currentStudyTask?.studyId,
27-
stackTrace: error instanceof Error ? error.stack : error,
28-
userId: this.userStateService.currentlyLoggedInUserId,
29-
} as IErrorNavigationState,
25+
26+
// check specifically to see if the CSRF is not responding...usually this means the server is offline
27+
if (error instanceof HttpErrorResponse && error?.url?.includes('/api/auth/csrf') && error?.status === 504) {
28+
this.snackbarService.openErrorSnackbar(
29+
'The server is not responding. Please try again later.',
30+
undefined,
31+
10000
32+
);
33+
ngZone.run(() => {
34+
this._router.navigate(['task-error'], {
35+
state: {
36+
taskIndex: undefined,
37+
studyId: undefined,
38+
stackTrace: error.message,
39+
userId: this.userStateService.currentlyLoggedInUserId,
40+
} as IErrorNavigationState,
41+
});
42+
});
43+
} else {
44+
ngZone.run(() => {
45+
this._router.navigate(['task-error'], {
46+
state: {
47+
taskIndex: this.taskManager?.currentStudyTask?.taskOrder,
48+
studyId: this.taskManager?.currentStudyTask?.studyId,
49+
stackTrace: error instanceof Error ? error.stack : error,
50+
userId: this.userStateService.currentlyLoggedInUserId,
51+
} as IErrorNavigationState,
52+
});
3053
});
31-
});
54+
}
3255

3356
if (environment.production) {
3457
super.handleError(error);

src/app/ErrorHttpInterceptor.ts

Whitespace-only changes.

src/app/models/StudyUser.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { SupportedLangs } from './enums';
22
import { NullTime } from './InternalDTOs';
3-
import { Study } from './Study';
4-
import { User } from './User';
53

64
export class StudyUser {
7-
user: Partial<User>;
8-
study: Partial<Study>;
5+
userId: number;
6+
studyId: number;
97
completionCode: string;
108
registerDate: string;
119
dueDate: NullTime;

src/app/pages/admin/admin-dashboard/data/data-tree/data-tree.component.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export function getStudyUserDataAsDataTableFormat(studyUsers: StudyUser[]): Data
6464

6565
return {
6666
fields: {
67-
userId: studyUser.user.id,
68-
studyId: studyUser.study.id,
67+
userId: studyUser.userId,
68+
studyId: studyUser.studyId,
6969
completionCode: studyUser.completionCode,
7070
registerDate: formatDate(studyUser.registerDate),
7171
dueDate: studyUser.dueDate.Valid ? formatDate(studyUser.dueDate.Time) : 'NONE',

src/app/pages/admin/admin-dashboard/data/data-tree/data-tree.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
<button
77
[disabled]="node.disabled"
88
(click)="node.clickAction()"
9-
style="font-size: 1.25rem; padding: 1rem"
9+
style="font-size: 1.25rem; padding: 0.5rem; width: 100%; text-align: left"
1010
mat-button
1111
color="primary"
1212
>
13-
{{ node.studyTask?.taskOrder !== null ? node.studyTask.taskOrder + ': ' : '' }} {{ node.name }}
13+
<mat-icon style="margin-right: 1rem">download</mat-icon>
14+
{{ node.studyTask?.taskOrder !== null ? 'Task ' + (node.studyTask.taskOrder + 1) + ': ' : '' }}
15+
{{ node.name }}
1416
</button>
1517
</mat-tree-node>
1618
<!-- This is the tree node template for expandable nodes -->

src/app/pages/admin/admin-dashboard/data/data-tree/data-tree.component.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class DataTreeComponent implements OnInit {
161161
this._study = study;
162162
this.dataSource.data = [
163163
{
164-
name: 'Download Study Snapshots',
164+
name: 'Study Snapshots',
165165
clickAction: undefined,
166166
disabled: Object.keys(study.snapshots).length === 0,
167167
children: [
@@ -189,27 +189,39 @@ export class DataTreeComponent implements OnInit {
189189
],
190190
},
191191
{
192-
name: 'Download user data for Account Holders',
193-
clickAction: () => {
194-
this.downloadStudyUserData(study);
195-
},
196-
children: [],
192+
name: 'User Data',
193+
clickAction: undefined,
194+
children: [
195+
{
196+
name: 'Download user data for Account Holders',
197+
clickAction: () => {
198+
this.downloadStudyUserData(study);
199+
},
200+
children: [],
201+
},
202+
{
203+
name: 'Download user data for Crowdsourced Users',
204+
clickAction: () => {
205+
this.downloadCrowdsourcedUserData(study);
206+
},
207+
children: [],
208+
},
209+
],
197210
},
198211
{
199-
name: 'Download user data for Crowdsourced Users',
200-
clickAction: () => {
201-
this.downloadCrowdsourcedUserData(study);
202-
},
203-
children: [],
212+
name: 'Task Data',
213+
clickAction: undefined,
214+
children: [
215+
...(this._study.studyTasks || []).map((studyTask) => ({
216+
name: `Download ${studyTask.task.name} Participant Data`,
217+
studyTask: studyTask,
218+
clickAction: () => {
219+
this.downloadParticipantData(study, studyTask);
220+
},
221+
children: [],
222+
})),
223+
],
204224
},
205-
...(this._study.studyTasks || []).map((studyTask) => ({
206-
name: `Download ${studyTask.task.name} Participant Data`,
207-
studyTask: studyTask,
208-
clickAction: () => {
209-
this.downloadParticipantData(study, studyTask);
210-
},
211-
children: [],
212-
})),
213225
];
214226
}
215227

src/app/pages/admin/admin-dashboard/data/data.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<div *ngIf="!studyExists" class="error-text p-4">Could not find study</div>
1+
<div *ngIf="!studyExists && !isLoading" class="error-text p-4">Could not find study</div>
22

3-
<div *ngIf="studyExists" class="container-fluid">
3+
<div *ngIf="studyExists && !isLoading" class="container-fluid">
44
<div class="d-flex flex-column">
55
<div>
66
<span class="badge"> Study Id: {{ study?.id }} </span>

src/app/pages/admin/admin-dashboard/data/data.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class DataComponent implements OnInit, OnDestroy {
3535
tableData: DataTableFormat[]; // json table to populate table component
3636
fileName: string = null;
3737
subscriptions: Subscription[] = [];
38+
isLoading: boolean = false;
3839

3940
constructor(
4041
private studyService: StudyService,
@@ -49,7 +50,15 @@ export class DataComponent implements OnInit, OnDestroy {
4950
) {}
5051

5152
ngOnInit(): void {
52-
const sub = this.studyService.getOrUpdateStudies().subscribe(() => {});
53+
this.isLoading = true;
54+
this.loaderService.showLoader();
55+
const sub = this.studyService
56+
.getOrUpdateStudies()
57+
.subscribe(() => {})
58+
.add(() => {
59+
this.isLoading = false;
60+
this.loaderService.hideLoader();
61+
});
5362
this.idFromURL = this.route.snapshot.paramMap.get('id');
5463
this.subscriptions.push(sub);
5564
}
@@ -212,8 +221,8 @@ export class DataComponent implements OnInit, OnDestroy {
212221

213222
return {
214223
fields: {
215-
userId: studyUser.user.id,
216-
studyId: studyUser.study.id,
224+
userId: studyUser.userId,
225+
studyId: studyUser.studyId,
217226
completionCode: studyUser.completionCode,
218227
registerDate: this.formatDate(studyUser.registerDate),
219228
dueDate: studyUser.dueDate.Valid ? this.formatDate(studyUser.dueDate.Time) : 'NONE',

src/app/pages/error-page/error-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div style="width: 100%; min-height: 100vh; padding: 4rem 0">
22
<div class="flex-column-center">
3-
<div style="width: 50%">
3+
<div style="width: 70%">
44
<h6 style="font-size: 2rem; color: salmon" class="mb-4">We encountered an error.</h6>
55
<div style="font-size: 1.5rem; line-height: normal" class="mb-4">
66
While running the platform, we ran into an error. In order to report this and help us fix it as fast as

0 commit comments

Comments
 (0)