diff --git a/src/app/group-monitor/booklet.service.spec.ts b/src/app/group-monitor/booklet.service.spec.ts index 719ddf26196c7a98e7712e0c287c380e04892e33..d6dacc9e7aa26d5282e6fd5358f8acc89fe04507 100644 --- a/src/app/group-monitor/booklet.service.spec.ts +++ b/src/app/group-monitor/booklet.service.spec.ts @@ -4,7 +4,6 @@ import { TestBed } from '@angular/core/testing'; import { Observable, of } from 'rxjs'; import { BookletService } from './booklet.service'; import { BackendService } from './backend.service'; -import { TestSessionService } from './test-session.service'; import { unitTestExampleBooklets } from './test-data.spec'; class MockBackendService { @@ -41,31 +40,14 @@ describe('BookletService', () => { expect(BookletService.getFirstUnit(unitTestExampleBooklets.example_booklet_2.units.children[2])).toBeNull(); }); - describe('getNextBlock()', () => { - // eslint-disable-next-line @typescript-eslint/dot-notation,prefer-destructuring - const getCurrent = TestSessionService['getCurrent']; - - it('should get next block at root-level, when blockless unit is selected', () => { - const result = BookletService.getNextBlock( - getCurrent(unitTestExampleBooklets.example_booklet_1.units, 'unit-1'), - unitTestExampleBooklets.example_booklet_1 - ); - expect(result.id).toEqual('zara'); - }); - - it('should get next block at root-level, when unit in nested testlet is selected', () => { - const result = BookletService.getNextBlock( - getCurrent(unitTestExampleBooklets.example_booklet_1.units, 'unit-3'), - unitTestExampleBooklets.example_booklet_1 - ); - expect(result.id).toEqual('ellie'); + describe('getBlockById()', () => { + it('should return the block by id', () => { + const result = BookletService.getBlockById('block-2', unitTestExampleBooklets.example_booklet_1); + expect(result.id).toEqual('alf'); }); - it('should return null, if there is no next block on root-level', () => { - const result = BookletService.getNextBlock( - getCurrent(unitTestExampleBooklets.example_booklet_1.units, 'unit-9'), - unitTestExampleBooklets.example_booklet_1 - ); + it('should return null when blockId is not found in booklet', () => { + const result = BookletService.getBlockById('not-existing', unitTestExampleBooklets.example_booklet_1); expect(result).toBeNull(); }); }); diff --git a/src/app/group-monitor/booklet.service.ts b/src/app/group-monitor/booklet.service.ts index d608f6d53315e0a521ba6617ae1279e54ce75311..7b192bf6b09f9c592c0edfcd15885cb3d79954e1 100644 --- a/src/app/group-monitor/booklet.service.ts +++ b/src/app/group-monitor/booklet.service.ts @@ -6,7 +6,7 @@ import { map, shareReplay } from 'rxjs/operators'; import { MainDataService } from '../maindata.service'; import { BackendService } from './backend.service'; import { - Booklet, BookletError, BookletMetadata, isUnit, Restrictions, Testlet, Unit, UnitContext + Booklet, BookletError, BookletMetadata, isUnit, Restrictions, Testlet, Unit } from './group-monitor.interfaces'; // eslint-disable-next-line import/extensions import { BookletConfig } from '../config/booklet-config'; @@ -40,27 +40,20 @@ export class BookletService { return null; } - static getNextBlock(current: UnitContext, booklet: Booklet): Testlet|null { - if (!current.ancestor) { - return null; - } - const startIndex = !current.ancestor.id ? - booklet.units.children.indexOf(current.unit) : booklet.units.children.indexOf(current.ancestor); - for (let i = startIndex + 1; i < booklet.units.children.length; i++) { - if (!isUnit(booklet.units.children[i])) { - return <Testlet>booklet.units.children[i]; - } - } - return null; + static getBlockById(blockId: string, booklet: Booklet): Testlet { + return <Testlet>booklet.units.children + .filter(testletOrUnit => !isUnit(testletOrUnit)) + .reduce((found: Testlet, block: Testlet) => ((block.blockId === blockId) ? block : found), null); } static addBookletStructureInformation(booklet: Booklet): void { booklet.species = BookletService.getBookletSpecies(booklet); booklet.units.children .filter(testletOrUnit => !isUnit(testletOrUnit)) - .forEach((testletOrUnit, index) => { - if (!isUnit(testletOrUnit)) { - testletOrUnit.blockId = `block ${index + 1}`; + .forEach((block: Testlet, index, blocks) => { + block.blockId = `block ${index + 1}`; + if (index < blocks.length - 1) { + block.nextBlockId = `block ${index + 2}`; } }); } diff --git a/src/app/group-monitor/group-monitor.component.ts b/src/app/group-monitor/group-monitor.component.ts index 3f0d8f3835ee7aa2b6b49373bf5e688cf7e980a6..ccd98042a264813efcb38bf143f80b3723e130d1 100644 --- a/src/app/group-monitor/group-monitor.component.ts +++ b/src/app/group-monitor/group-monitor.component.ts @@ -14,9 +14,10 @@ import { BackendService } from './backend.service'; import { GroupData, TestViewDisplayOptions, - TestViewDisplayOptionKey, Selected, TestSession, TestSessionSetStats, CommandResponse, UIMessage + TestViewDisplayOptionKey, Selected, TestSession, TestSessionSetStats, CommandResponse, UIMessage, isBooklet } from './group-monitor.interfaces'; import { GroupMonitorService } from './group-monitor.service'; +import { BookletService } from './booklet.service'; @Component({ selector: 'app-group-monitor', @@ -212,10 +213,30 @@ export class GroupMonitorComponent implements OnInit, OnDestroy { text: 'Kein Zielblock ausgewählt' }); } else { - this.gms.testCommandGoto(this.selectedElement); + this.gms.testCommandGoto(this.selectedElement) + .subscribe(() => this.selectNextBlock()); } } + private selectNextBlock(): void { + if (!isBooklet(this.selectedElement.originSession.booklet)) { + return; + } + // if (!this.selectedElement.element.nextBlockId) { + // return; + // } + this.selectElement({ + element: this.selectedElement.element.nextBlockId ? + BookletService.getBlockById( + this.selectedElement.element.nextBlockId, + this.selectedElement.originSession.booklet + ) : null, + inversion: this.selectedElement.inversion, + originSession: this.selectedElement.originSession, + spreading: this.selectedElement.spreading + }); + } + unlockCommand(): void { this.gms.testCommandUnlock(); } diff --git a/src/app/group-monitor/group-monitor.interfaces.ts b/src/app/group-monitor/group-monitor.interfaces.ts index 8d086bbdf66a2b1ad8390635e844a371af7206cd..90a801d4fc9c5e1424a19f167d4a0e6f23e7a5e5 100644 --- a/src/app/group-monitor/group-monitor.interfaces.ts +++ b/src/app/group-monitor/group-monitor.interfaces.ts @@ -67,6 +67,7 @@ export interface Testlet { children: (Unit|Testlet)[]; descendantCount: number; blockId?: string; + nextBlockId?: string; } export interface Unit { diff --git a/src/app/group-monitor/group-monitor.service.ts b/src/app/group-monitor/group-monitor.service.ts index ac2afc175fd969cb1c5d84d43b181d59a6b506c6..4db7e54f431475a10dfe46749a21c13bb6484a17 100644 --- a/src/app/group-monitor/group-monitor.service.ts +++ b/src/app/group-monitor/group-monitor.service.ts @@ -272,17 +272,20 @@ export class GroupMonitorService { ); } - testCommandGoto(selection: Selected): void { + testCommandGoto(selection: Selected): Observable<true> { const gfd = GroupMonitorService.groupForGoto(this.checked, selection); const allTestIds = this.checked.map(s => s.data.testId); - zip( + return zip( ...Object.keys(gfd).map(key => this.bs.command('goto', ['id', gfd[key].firstUnitId], gfd[key].testIds)) - ).subscribe(() => { - this._commandResponses$.next({ - commandType: 'goto', - testIds: allTestIds - }); - }); + ).pipe( + tap(() => { + this._commandResponses$.next({ + commandType: 'goto', + testIds: allTestIds + }); + }), + map(() => true) + ); } private static groupForGoto(sessionsSet: TestSession[], selection: Selected): GotoCommandData {