File

src/app/group-monitor/booklet/booklet.util.ts

Index

Methods

Methods

Static getBlockById
getBlockById(blockId: string, booklet: Booklet)
Parameters :
Name Type Optional
blockId string No
booklet Booklet No
Returns : Testlet
Static getFirstUnit
getFirstUnit(testletOrUnit: Testlet | Unit)
Parameters :
Name Type Optional
testletOrUnit Testlet | Unit No
Returns : Unit | null
Static getFirstUnitOfBlock
getFirstUnitOfBlock(blockId: string, booklet: Booklet)
Parameters :
Name Type Optional
blockId string No
booklet Booklet No
Returns : Unit | null
import {
  Booklet, isUnit, Testlet, Unit
} from '../group-monitor.interfaces';

export class BookletUtil {
  static getFirstUnit(testletOrUnit: Testlet|Unit): Unit|null {
    while (!isUnit(testletOrUnit)) {
      if (!testletOrUnit.children.length) {
        return null;
      }
      // eslint-disable-next-line no-param-reassign,prefer-destructuring
      testletOrUnit = testletOrUnit.children[0];
    }
    return testletOrUnit;
  }

  static getFirstUnitOfBlock(blockId: string, booklet: Booklet): Unit|null {
    for (let i = 0; i < booklet.units.children.length; i++) {
      const child = booklet.units.children[i];
      if (!isUnit(child) && (child.blockId === blockId)) {
        return BookletUtil.getFirstUnit(child);
      }
    }
    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);
  }
}

result-matching ""

    No results matching ""