Skip to content

Commit

Permalink
Merge branch 'master' into VIH-11019-hearing-model
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-scott authored Dec 20, 2024
2 parents 1fa8a5c + 382d697 commit de7a839
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export class HearingScheduleComponent extends BookingBaseComponent implements On

this.refDataService.getCourts().subscribe({
next: data => {
this.availableCourts = data;
this.availableCourts = [...data];
this.logger.debug(`${this.loggerPrefix} Updating list of available courts.`, { courts: data.length });
const pleaseSelect = new HearingVenueResponse();
pleaseSelect.name = Constants.PleaseSelect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class VenuesMenuComponent extends MenuBase {
loadItems(): void {
this.refDataService.getCourts().subscribe({
next: (data: HearingVenueResponse[]) => {
this.venues = this.items = data;
this.venues = this.items = [...data];
this.logger.debug(`${this.loggerPrefix} Updating list of venues.`, { venues: data.length });
},
error: error => this.handleListError(error, 'venues')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import { Constants } from 'src/app/common/constants';
import { DatePipe } from '@angular/common';
import { HttpClient, HttpHandler } from '@angular/common/http';
import { JusticeUsersService } from 'src/app/services/justice-users.service';
import { VideoHearingsService } from 'src/app/services/video-hearings.service';
import { SharedModule } from '../../shared/shared.module';
import { Logger } from 'src/app/services/logger';
import { SelectComponent, SelectOption } from 'src/app/shared/select';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { ReferenceDataService } from 'src/app/services/reference-data.service';
import { MockValues } from 'src/app/testing/data/test-objects';

describe('AllocateHearingsComponent', () => {
let component: AllocateHearingsComponent;
Expand All @@ -29,7 +30,7 @@ describe('AllocateHearingsComponent', () => {
let testData: AllocationHearingsResponse[];

const loggerMock = jasmine.createSpyObj('Logger', ['debug']);
const hearingServiceMock = jasmine.createSpyObj('VideoHearingsService', ['getUsers', 'getHearingTypes']);
const referenceDataServiceMock = jasmine.createSpyObj<ReferenceDataService>('ReferenceDataService', ['getHearingTypes']);
const allUsers$ = new BehaviorSubject<JusticeUserResponse[]>([]);
beforeEach(async () => {
justiceUsersServiceSpy = jasmine.createSpyObj<JusticeUsersService>('JusticeUsersService', [
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('AllocateHearingsComponent', () => {
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: AllocateHearingsService, useValue: allocateServiceSpy },
{ provide: JusticeUsersService, useValue: justiceUsersServiceSpy },
{ provide: VideoHearingsService, useValue: hearingServiceMock },
{ provide: ReferenceDataService, useValue: referenceDataServiceMock },
{ provide: Logger, useValue: loggerMock }
],
imports: [SharedModule, FontAwesomeModule]
Expand All @@ -91,7 +92,7 @@ describe('AllocateHearingsComponent', () => {
describe('ngOnInit', () => {
let searchForHearingsSpy;

hearingServiceMock.getHearingTypes.and.returnValue(of(['Type1', 'Type2']));
referenceDataServiceMock.getHearingTypes.and.returnValue(of(MockValues.HearingTypesList));

beforeEach(() => {
searchForHearingsSpy = spyOn(component, 'searchForHearings');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { AllocateHearingsService } from '../services/allocate-hearings.service';
import { AllocationHearingsResponse, JusticeUserResponse } from '../../services/clients/api-client';
import { AllocationHearingsResponse, HearingTypeResponse, JusticeUserResponse } from '../../services/clients/api-client';
import { faCircleExclamation, faHourglassStart, faTriangleExclamation, faClock } from '@fortawesome/free-solid-svg-icons';
import { AllocateHearingItemModel, AllocateHearingModel } from './models/allocate-hearing.model';
import { Transform } from '@fortawesome/fontawesome-svg-core';
Expand All @@ -10,23 +10,24 @@ import { SelectComponent, SelectOption } from 'src/app/shared/select/select.comp
import { JusticeUsersService } from 'src/app/services/justice-users.service';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { VideoHearingsService } from 'src/app/services/video-hearings.service';
import { BookingPersistService } from 'src/app/services/bookings-persist.service';
import { map, tap } from 'rxjs/operators';
import { map, takeUntil, tap } from 'rxjs/operators';
import { ReferenceDataService } from 'src/app/services/reference-data.service';
import { Subject } from 'rxjs';

@Component({
selector: 'app-allocate-hearings',
templateUrl: './allocate-hearings.component.html',
styleUrls: ['./allocate-hearings.component.scss']
})
export class AllocateHearingsComponent implements OnInit {
export class AllocateHearingsComponent implements OnInit, OnDestroy {
constructor(
private readonly route: ActivatedRoute,
private readonly fb: FormBuilder,
private readonly allocateService: AllocateHearingsService,
private readonly datePipe: DatePipe,
private readonly justiceUserService: JusticeUsersService,
private readonly videoHearingService: VideoHearingsService,
private readonly referenceDataService: ReferenceDataService,
private readonly bookingPersistService: BookingPersistService
) {
this.form = fb.group({
Expand Down Expand Up @@ -65,6 +66,8 @@ export class AllocateHearingsComponent implements OnInit {
caseTypesSelectOptions: SelectOption[];
selectedCaseTypeIds: string[] = [];

private readonly destroy$ = new Subject<void>();

ngOnInit() {
this.route.queryParams.subscribe(params => {
const fromDt = params['fromDt'] ?? null;
Expand All @@ -83,19 +86,32 @@ export class AllocateHearingsComponent implements OnInit {
}
});

this.form.get('isUnallocated').valueChanges.subscribe(val => {
if (val) {
this.onIsAllocatedCheckboxChecked();
} else {
this.onIsAllocatedCheckboxUnchecked();
}
});
this.form
.get('isUnallocated')
.valueChanges.pipe(takeUntil(this.destroy$))
.subscribe(val => {
if (val) {
this.onIsAllocatedCheckboxChecked();
} else {
this.onIsAllocatedCheckboxUnchecked();
}
});

this.selectedJusticeUserIds = this.bookingPersistService.selectedUsers;
this.selectedCaseTypeIds = this.bookingPersistService.selectedCaseTypes;
this.referenceDataService
.getHearingTypes()
.pipe(takeUntil(this.destroy$))
.subscribe((data: HearingTypeResponse[]) => {
this.caseTypesSelectOptions = data
.map(item => item.group)
.sort((a, b) => a.localeCompare(b))
.map(group => ({ entityId: group, label: group }));
});

this.justiceUserService.allUsers$
.pipe(
takeUntil(this.destroy$),
map(users => users.filter(user => !user.deleted)),
tap(() => this.selectFilterCso?.clear())
)
Expand All @@ -109,6 +125,11 @@ export class AllocateHearingsComponent implements OnInit {
});
}

ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}

searchForHearings(keepExistingMessage: boolean = false) {
const retrieveDate = (date: any): Date => (date === null || date === '' ? null : new Date(date));

Expand Down

0 comments on commit de7a839

Please sign in to comment.