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

Add goto button and board expanding/card highlighting for incoming cards #1844

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { IncomingFileService } from './incoming-file.service';
import { IncomingFileBoardMapDto } from './incomig-file.dto';
import { IncomingFileBoardMapDto } from './incoming-file.dto';
import { CardType } from '../../shared/card/card.component';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { HttpClient } from '@angular/common/http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { environment } from '../../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { ToastService } from '../toast/toast.service';
import { firstValueFrom } from 'rxjs';
import { IncomingFileBoardMapDto } from './incomig-file.dto';
import { IncomingFileBoardMapDto } from './incoming-file.dto';

@Injectable({
providedIn: 'root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h5 class="detail-heading">
</div>
</button>
<button
*ngIf="isCommissioner && hasMeetings"
*ngIf="isCommissioner && (hasMeetings || isIncoming)"
class="menu-item"
mat-flat-button
color="accent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { AuthenticationService, ROLES } from '../../services/authentication/auth
import { BoardService } from '../../services/board/board.service';
import { DecisionMeetingService } from '../../services/decision-meeting/decision-meeting.service';
import { UpcomingMeetingBoardMapDto } from '../../services/decision-meeting/decision-meeting.dto';
import { IncomingFileService } from '../../services/incoming-file/incoming-file.service';
import { IncomingFileBoardMapDto } from 'src/app/services/incoming-file/incoming-file.dto';

@Component({
selector: 'app-details-header[application]',
Expand Down Expand Up @@ -133,19 +135,25 @@ export class DetailsHeaderComponent implements OnInit, OnDestroy {

isCommissioner: boolean = false;
hasMeetings: boolean = false;
isIncoming: boolean = false;

$meetingsByBoard = new Subject<UpcomingMeetingBoardMapDto>();
$incomingFilesByBoard = new Subject<IncomingFileBoardMapDto>();
$application = new Subject<ApplicationDto | CommissionerApplicationDto | NoticeOfIntentDto | NotificationDto>();

private incomingFiles: IncomingFileBoardMapDto | undefined;

constructor(
private router: Router,
private authService: AuthenticationService,
private boardService: BoardService,
private meetingService: DecisionMeetingService,
private incomingFileService: IncomingFileService,
) {}

ngOnInit(): void {
this.loadMeetings();
this.loadIncomingFiles();

this.authService.$currentUser.pipe(takeUntil(this.$destroy)).subscribe((currentUser) => {
this.isCommissioner =
Expand All @@ -156,19 +164,27 @@ export class DetailsHeaderComponent implements OnInit, OnDestroy {
});

this.boardService.$boards
.pipe(combineLatestWith(this.$meetingsByBoard, this.$application))
.pipe(combineLatestWith(this.$meetingsByBoard, this.$incomingFilesByBoard, this.$application))
.pipe(takeUntil(this.$destroy))
.subscribe(([boards, meetingsByBoard, application]) => {
.subscribe(([boards, meetingsByBoard, incomingFilesByBoard, application]) => {
if (boards && meetingsByBoard && application) {
const visibleBoardCodes = boards.filter((board) => board.showOnSchedule).map((board) => board.code);

const visibleBoardCodeMeetingPairs = Object.entries(meetingsByBoard).filter(([code, _]) =>
visibleBoardCodes.includes(code),
);

const visibleBoardCodeIncomingFilePairs = Object.entries(incomingFilesByBoard!).filter(([code, _]) =>
visibleBoardCodes.includes(code),
);

this.hasMeetings = visibleBoardCodeMeetingPairs.some(([_, meetings]) =>
meetings.some((meeting) => meeting.fileNumber === application?.fileNumber),
);

this.isIncoming = visibleBoardCodeIncomingFilePairs.some(([_, incomingFiles]) =>
incomingFiles.some((file) => file.fileNumber === application?.fileNumber),
);
}
});
}
Expand All @@ -181,6 +197,14 @@ export class DetailsHeaderComponent implements OnInit, OnDestroy {
}
}

async loadIncomingFiles() {
const incomingFilesByBoard = await this.incomingFileService.fetchAndSort();

if (incomingFilesByBoard !== undefined) {
this.$incomingFilesByBoard.next(incomingFilesByBoard);
}
}

async onGoToCard(card: CardDto) {
const boardCode = card.boardCode;
const cardUuid = card.uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,4 @@ describe('MeetingOverviewComponent', () => {
await component.loadMeetings();
expect(component.viewData.length).toEqual(1);
});

it('should show an error toast if searched application is not found', async () => {
await sleep(1);

component.searchText = '5555';
component.onSearch();

expect(mockToastService.showErrorToast).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ToastService } from '../../services/toast/toast.service';
import { UserService } from '../../services/user/user.service';
import { CardType } from '../card/card.component';
import { IncomingFileService } from '../../services/incoming-file/incoming-file.service';
import { IncomingFileBoardMapDto, IncomingFileDto } from '../../services/incoming-file/incomig-file.dto';
import { IncomingFileBoardMapDto, IncomingFileDto } from '../../services/incoming-file/incoming-file.dto';
import { ActivatedRoute, Router } from '@angular/router';

type MeetingCollection = {
Expand All @@ -25,7 +25,7 @@ type BoardWithDecisionMeetings = {
pastMeetings: MeetingCollection[];
upcomingMeetings: MeetingCollection[];
nextMeeting: MeetingCollection | undefined;
incomingFiles: IncomingFileDto[];
incomingFiles: (IncomingFileDto & { isHighlighted?: boolean })[];
isExpanded: boolean;
};

Expand Down Expand Up @@ -165,10 +165,6 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
}
}

onSearch() {
this.findAndExpandAll(this.searchText);
}

findAndExpandAll(fileNumber: string) {
let foundResult = false;
this.viewData = this.viewData.map((board) => {
Expand All @@ -188,6 +184,17 @@ export class MeetingOverviewComponent implements OnInit, OnDestroy {
}
}

if (board.incomingFiles) {
board.incomingFiles.forEach((file) => {
if (file.fileNumber === fileNumber) {
board.isExpanded = true;
file.isHighlighted = true;
foundResult = true;
this.scrollToApplication(fileNumber);
}
});
}

board.upcomingMeetings = board.upcomingMeetings.map((meeting) => {
const res = this.findAndExpand(meeting, board, fileNumber);
if (res.isExpanded) {
Expand Down