@@ -11,18 +11,65 @@ import {
1111 VariantAnalysisRepoTask ,
1212 VariantAnalysisScannedRepository as ApiVariantAnalysisScannedRepository
1313} from './gh-api/variant-analysis' ;
14- import { VariantAnalysis } from './shared/variant-analysis' ;
14+ import {
15+ VariantAnalysis ,
16+ VariantAnalysisScannedRepositoryDownloadStatus ,
17+ VariantAnalysisScannedRepositoryState
18+ } from './shared/variant-analysis' ;
1519import { getErrorMessage } from '../pure/helpers-pure' ;
20+ import { VariantAnalysisView } from './variant-analysis-view' ;
21+ import { VariantAnalysisViewManager } from './variant-analysis-view-manager' ;
1622
17- export class VariantAnalysisManager extends DisposableObject {
23+ export class VariantAnalysisManager extends DisposableObject implements VariantAnalysisViewManager < VariantAnalysisView > {
1824 private readonly variantAnalysisMonitor : VariantAnalysisMonitor ;
25+ private readonly views = new Map < number , VariantAnalysisView > ( ) ;
1926
2027 constructor (
2128 private readonly ctx : ExtensionContext ,
2229 logger : Logger ,
2330 ) {
2431 super ( ) ;
25- this . variantAnalysisMonitor = new VariantAnalysisMonitor ( ctx , logger ) ;
32+ this . variantAnalysisMonitor = this . push ( new VariantAnalysisMonitor ( ctx , logger ) ) ;
33+ this . variantAnalysisMonitor . onVariantAnalysisChange ( this . onVariantAnalysisUpdated . bind ( this ) ) ;
34+ }
35+
36+ public async showView ( variantAnalysisId : number ) : Promise < void > {
37+ if ( ! this . views . has ( variantAnalysisId ) ) {
38+ // The view will register itself with the manager, so we don't need to do anything here.
39+ this . push ( new VariantAnalysisView ( this . ctx , variantAnalysisId , this ) ) ;
40+ }
41+
42+ const variantAnalysisView = this . views . get ( variantAnalysisId ) ! ;
43+ await variantAnalysisView . openView ( ) ;
44+ return ;
45+ }
46+
47+ public registerView ( view : VariantAnalysisView ) : void {
48+ if ( this . views . has ( view . variantAnalysisId ) ) {
49+ throw new Error ( `View for variant analysis with id: ${ view . variantAnalysisId } already exists` ) ;
50+ }
51+
52+ this . views . set ( view . variantAnalysisId , view ) ;
53+ }
54+
55+ public unregisterView ( view : VariantAnalysisView ) : void {
56+ this . views . delete ( view . variantAnalysisId ) ;
57+ }
58+
59+ public getView ( variantAnalysisId : number ) : VariantAnalysisView | undefined {
60+ return this . views . get ( variantAnalysisId ) ;
61+ }
62+
63+ private async onVariantAnalysisUpdated ( variantAnalysis : VariantAnalysis | undefined ) : Promise < void > {
64+ if ( ! variantAnalysis ) {
65+ return ;
66+ }
67+
68+ await this . getView ( variantAnalysis . id ) ?. updateView ( variantAnalysis ) ;
69+ }
70+
71+ private async onRepoStateUpdated ( variantAnalysisId : number , repoState : VariantAnalysisScannedRepositoryState ) : Promise < void > {
72+ await this . getView ( variantAnalysisId ) ?. updateRepoState ( repoState ) ;
2673 }
2774
2875 public async monitorVariantAnalysis (
@@ -37,11 +84,19 @@ export class VariantAnalysisManager extends DisposableObject {
3784 variantAnalysisSummary : VariantAnalysisApiResponse ,
3885 cancellationToken : CancellationToken
3986 ) : Promise < void > {
87+ const repoState = {
88+ repositoryId : scannedRepo . repository . id ,
89+ downloadStatus : VariantAnalysisScannedRepositoryDownloadStatus . Pending ,
90+ } ;
91+
92+ await this . onRepoStateUpdated ( variantAnalysisSummary . id , repoState ) ;
4093
4194 const credentials = await Credentials . initialize ( this . ctx ) ;
4295 if ( ! credentials ) { throw Error ( 'Error authenticating with GitHub' ) ; }
4396
4497 if ( cancellationToken && cancellationToken . isCancellationRequested ) {
98+ repoState . downloadStatus = VariantAnalysisScannedRepositoryDownloadStatus . Failed ;
99+ await this . onRepoStateUpdated ( variantAnalysisSummary . id , repoState ) ;
45100 return ;
46101 }
47102
@@ -53,10 +108,16 @@ export class VariantAnalysisManager extends DisposableObject {
53108 variantAnalysisSummary . id ,
54109 scannedRepo . repository . id
55110 ) ;
111+ } catch ( e ) {
112+ repoState . downloadStatus = VariantAnalysisScannedRepositoryDownloadStatus . Failed ;
113+ await this . onRepoStateUpdated ( variantAnalysisSummary . id , repoState ) ;
114+ throw new Error ( `Could not download the results for variant analysis with id: ${ variantAnalysisSummary . id } . Error: ${ getErrorMessage ( e ) } ` ) ;
56115 }
57- catch ( e ) { throw new Error ( `Could not download the results for variant analysis with id: ${ variantAnalysisSummary . id } . Error: ${ getErrorMessage ( e ) } ` ) ; }
58116
59117 if ( repoTask . artifact_url ) {
118+ repoState . downloadStatus = VariantAnalysisScannedRepositoryDownloadStatus . InProgress ;
119+ await this . onRepoStateUpdated ( variantAnalysisSummary . id , repoState ) ;
120+
60121 const resultDirectory = path . join (
61122 this . ctx . globalStorageUri . fsPath ,
62123 'variant-analyses' ,
@@ -77,5 +138,8 @@ export class VariantAnalysisManager extends DisposableObject {
77138 fs . mkdirSync ( resultDirectory , { recursive : true } ) ;
78139 await fs . writeFile ( storagePath , JSON . stringify ( result , null , 2 ) , 'utf8' ) ;
79140 }
141+
142+ repoState . downloadStatus = VariantAnalysisScannedRepositoryDownloadStatus . Succeeded ;
143+ await this . onRepoStateUpdated ( variantAnalysisSummary . id , repoState ) ;
80144 }
81145}
0 commit comments