import { injectable } from "inversify" ; import { lazyInject } from "../../../../inversify.config" ; import AppStatusStore from "../../../../stores/AppStatusStore" ; import { BackendService } from "../../BackendService" ; import SonarQubeMeasuresService from "../SonarQubeMeasuresService" ; import { SonarQubeMeasurePagingResponse , SonarQubeMeasureResponse , SQ_QUALIFIER_DIRECTORY , SQ_QUALIFIER_FILE , SQ_QUALIFIER_UNIT_TEST_FILE , } from "./SonarQubeMeasureResponse" ; @ injectable ( ) export default class SonarQubeMeasuresApiService extends BackendService { @ lazyInject ( "AppStatusStore" ) private readonly appStatusStore ! : AppStatusStore ; public loadMeasures ( component , metricKeys , pageMax = 1 , pageCurrent = 1 ) { this . appStatusStore . loadStatusUpdate ( SonarQubeMeasuresService . LOAD_MEASURES . key , pageMax , pageCurrent ) ; const qualifiers = Array . from ( [ SQ_QUALIFIER_DIRECTORY , SQ_QUALIFIER_FILE , SQ_QUALIFIER_UNIT_TEST_FILE , ] ) . join ( "," ) ; return new Promise < SonarQubeMeasureResponse > ( ( resolve , reject ) => { const params = { component , p : pageCurrent , metricKeys , qualifiers , s : "path" , ps : 500 , } ; this . callApi ( "/measures/component_tree" , { params } ) . then ( ( response ) => { const result = response . data ; const allResults = { baseComponent : result . baseComponent , components : result . components , } ; const pagesMax = Math . floor ( result . paging . total / result . paging . pageSize ) + 1 ; if ( result . paging . pageIndex < pagesMax ) { return this . loadMeasures ( component , metricKeys , pagesMax , pageCurrent + 1 ) . then ( ( resultSecond ) => { allResults . components = allResults . components . concat ( resultSecond . components ) ; resolve ( allResults ) ; } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } else { resolve ( allResults ) ; } } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } ) ; } }