Skip to content

Commit

Permalink
Updating files to accommodate new rxjs version
Browse files Browse the repository at this point in the history
  • Loading branch information
markiianbabiak committed Sep 28, 2024
1 parent 6faa2f8 commit d4654ff
Show file tree
Hide file tree
Showing 21 changed files with 411 additions and 184 deletions.
16 changes: 9 additions & 7 deletions frontend/src/app/components/ck-buckets/ck-buckets.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ export class CkBucketsComponent implements OnInit {
this.user = this.userService.user!;
await this.configureBoard();
await this.bucketService.getAllByBoard(this.boardID).then((buckets) => {
for (const bucket of buckets) {
if (bucket.addedToView) {
this.bucketsOnView.push(bucket);
this.loadBucketPosts(bucket);
} else {
this.buckets.push(bucket);
if (buckets) {
for (const bucket of buckets) {
if (bucket.addedToView) {
this.bucketsOnView.push(bucket);
this.loadBucketPosts(bucket);
} else {
this.buckets.push(bucket);
}
}
}
});
Expand All @@ -85,7 +87,7 @@ export class CkBucketsComponent implements OnInit {
}/${board.defaultView?.toLowerCase()}`
);
}
} else{
} else {
this.board = undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,25 @@ export class CreateWorkflowModalComponent implements OnInit {
Validators.required,
this._forbiddenNameValidator(),
]);
workflowNameFormControl = new UntypedFormControl('valid', [Validators.required]);
workflowNameFormControl = new UntypedFormControl('valid', [
Validators.required,
]);
sourceFormControl = new UntypedFormControl('valid', [Validators.required]);
destinationFormControl = new UntypedFormControl('valid', [Validators.required]);
destinationFormControl = new UntypedFormControl('valid', [
Validators.required,
]);

sourceDestinationMatchError = new UntypedFormControl(false);

groupsFormControl = new UntypedFormControl('valid', [Validators.required]);
promptFormControl = new UntypedFormControl('valid', [Validators.required]);

workflowTypeFormControl = new UntypedFormControl('valid', [Validators.required]);
removeFromSourceFormControl = new UntypedFormControl('valid', [Validators.required]);
workflowTypeFormControl = new UntypedFormControl('valid', [
Validators.required,
]);
removeFromSourceFormControl = new UntypedFormControl('valid', [
Validators.required,
]);

tagsFormControl = new UntypedFormControl();

Expand Down Expand Up @@ -152,19 +160,19 @@ export class CreateWorkflowModalComponent implements OnInit {
}
);

// Add project boards FIRST
this.destOptions = this.destOptions.concat(projectBoards);
this.sourceOptions = this.sourceOptions.concat(projectBoards);
// Add project boards FIRST (using fallback empty array if undefined)
this.destOptions = this.destOptions.concat(projectBoards || []);
this.sourceOptions = this.sourceOptions.concat(projectBoards || []);

// 2. Fetch Buckets
const buckets = await this.bucketService.getAllByBoard(
this.data.board.boardID
);
this.boardBuckets = this.boardBuckets.concat(buckets);
this.boardBuckets = this.boardBuckets.concat(buckets || []);

// 3. Add buckets SECOND
this.sourceOptions = this.sourceOptions.concat(buckets);
this.destOptions = this.destOptions.concat(buckets);
this.sourceOptions = this.sourceOptions.concat(buckets || []);
this.destOptions = this.destOptions.concat(buckets || []);
} catch (error) {
console.error('Error loading boards and buckets:', error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class PostModalComponent {
this.bucketService
.getAllByBoard(this.data.board.boardID)
.then((buckets) => {
this.buckets = buckets;
this.buckets = buckets || [];
});

const isStudent = this.user.role == Role.STUDENT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class ProjectDashboardComponent implements OnInit {
async getBoards() {
this.project = await this.projectService.get(this.projectID);
const boards = await this.boardService.getByProject(this.projectID);
boards.forEach((board) => {
// Ensure 'boards' is defined before iterating
boards?.forEach((board) => {
if (board.scope == BoardScope.PROJECT_PERSONAL) {
const isTeacher = this.project.teacherIDs.includes(board.ownerID);
if (isTeacher) this.teacherPersonalBoards.push(board);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ export class ViewNavigationComponent implements OnInit {
constructor(public boardService: BoardService) {}

async ngOnInit(): Promise<void> {
this.board = await this.boardService.get(this.boardID);
const board = await this.boardService.get(this.boardID);

if (!board) {
// Handle the case where board is undefined, e.g., throw an error or redirect
console.error(`Board with ID ${this.boardID} not found`);
return; // or handle it accordingly
}

this.board = board;

this.AppViews = [
{
viewType: ViewType.CANVAS,
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/app/guards/board.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,18 @@ export class BoardGuard implements CanActivate {
return true;
}

async isValidBoard(boardID: string) {
async isValidBoard(boardID: string): Promise<boolean> {
try {
this.board = await this.boardService.get(boardID);
const board = await this.boardService.get(boardID);

if (!board) {
this.router.navigate(['/error'], {
state: { code: 404, message: 'This board does not exist!' },
});
return false;
}

this.board = board; // Now board is guaranteed to be of type Board
} catch (e) {
const message = getErrorMessage(e);
const status = getErrorStatus(e);
Expand All @@ -85,7 +94,7 @@ export class BoardGuard implements CanActivate {
return false;
}

return this.board != undefined;
return true;
}

isVisibleBoard() {
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/app/services/bucket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import { SocketService } from './socket.service';
export class BucketService {
constructor(private http: HttpClient, private socketService: SocketService) {}

get(bucketID: string): Promise<any> {
get(bucketID: string): Promise<any | undefined> {
return this.http.get<any>('buckets/' + bucketID).toPromise();
}

getAllByBoard(boardID: string): Promise<any[]> {
getAllByBoard(boardID: string): Promise<any[] | undefined> {
return this.http.get<any[]>('buckets/board/' + boardID).toPromise();
}

create(bucket: Bucket): Promise<Bucket> {
create(bucket: Bucket): Promise<Bucket | undefined> {
return this.http.post<Bucket>('buckets/', bucket).toPromise();
}

add(bucketID: string, ...posts: string[]): Promise<Bucket> {
add(bucketID: string, ...posts: string[]): Promise<Bucket | undefined> {
this.socketService.emit(SocketEvent.BUCKET_ADD_POST, { bucketID, posts });
return this.http
.post<Bucket>('buckets/' + bucketID + '/add', { posts })
.toPromise();
}

remove(bucketID: string, ...posts: string[]): Promise<Bucket> {
remove(bucketID: string, ...posts: string[]): Promise<Bucket | undefined> {
this.socketService.emit(SocketEvent.BUCKET_REMOVE_POST, {
bucketID,
posts,
Expand All @@ -39,11 +39,14 @@ export class BucketService {
.toPromise();
}

update(bucketID: string, bucket: Partial<Bucket>) {
update(
bucketID: string,
bucket: Partial<Bucket>
): Promise<Bucket | undefined> {
return this.http.post<Bucket>('buckets/' + bucketID, bucket).toPromise();
}

delete(bucketID: string): Promise<Bucket> {
delete(bucketID: string): Promise<Bucket | undefined> {
return this.http.delete<Bucket>('buckets/' + bucketID).toPromise();
}
}
Loading

0 comments on commit d4654ff

Please sign in to comment.