11import { Component , Input , OnDestroy , OnInit } from '@angular/core' ;
2- import { FileNavigator , LongRunningTaskState , SlowValueUpdate } from "../fileNavigator" ;
3- import { BreadcrumbEvent } from "../../breadcrumbs/breadcrumbs.component" ;
4- import { FileActionEvent } from "../file-navigator/file-navigator.component" ;
5- import { ModelFile , WorkflowServiceService } from "../../../api" ;
2+ import { FileNavigator , LongRunningTaskState , SlowValueUpdate } from '../fileNavigator' ;
3+ import { BreadcrumbEvent } from '../../breadcrumbs/breadcrumbs.component' ;
4+ import { FileActionEvent } from '../file-navigator/file-navigator.component' ;
5+ import { ModelFile , WorkflowServiceService } from '../../../api' ;
6+ import { GenericFileViewComponent } from '../file-viewer/generic-file-view/generic-file-view.component' ;
67
78@Component ( {
89 selector : 'app-file-browser' ,
@@ -12,47 +13,49 @@ import { ModelFile, WorkflowServiceService } from "../../../api";
1213export class FileBrowserComponent implements OnInit , OnDestroy {
1314 private filePathChangedSubscriber ;
1415 private fileChangedSubscriber ;
16+
17+ // tslint:disable-next-line:variable-name
1518 private _fileNavigator : FileNavigator ;
1619
1720 @Input ( ) displayedColumns = [ ] ;
1821
1922 showingFile = false ;
2023
21- loading : boolean = false ;
24+ loading = false ;
2225
23- @Input ( ) rootName : string = '' ;
26+ @Input ( ) rootName = '' ;
2427 @Input ( ) set fileNavigator ( value : FileNavigator ) {
2528 this . _fileNavigator = value ;
2629
27- if ( this . filePathChangedSubscriber ) {
30+ if ( this . filePathChangedSubscriber ) {
2831 this . filePathChangedSubscriber . unsubscribe ( ) ;
2932 }
3033
3134 this . filePathChangedSubscriber = value . path . valueChanged . subscribe ( ( change : SlowValueUpdate < string > ) => {
32- if ( change . state === LongRunningTaskState . Succeeded ) {
35+ if ( change . state === LongRunningTaskState . Succeeded ) {
3336 this . updatePathParts ( change . value ) ;
3437 }
3538 } ) ;
3639
37- if ( this . fileChangedSubscriber ) {
40+ if ( this . fileChangedSubscriber ) {
3841 this . fileChangedSubscriber . unsubscribe ( ) ;
3942 }
4043
4144 this . fileChangedSubscriber = value . file . valueChanged . subscribe ( ( change : SlowValueUpdate < ModelFile > ) => {
42- if ( ! this . showingFile && change . state === LongRunningTaskState . Started ) {
45+ if ( ! this . showingFile && change . state === LongRunningTaskState . Started ) {
4346 this . loading = true ;
4447 }
4548
46- if ( change . state === LongRunningTaskState . Succeeded ) {
49+ if ( change . state === LongRunningTaskState . Succeeded ) {
4750 this . updateFile ( change . value ) ;
4851
49- if ( ! this . showingFile ) {
52+ if ( ! this . showingFile ) {
5053 this . loading = false ;
5154 }
5255 }
5356
54- if ( change . state === LongRunningTaskState . Failed ) {
55- if ( ! this . showingFile ) {
57+ if ( change . state === LongRunningTaskState . Failed ) {
58+ if ( ! this . showingFile ) {
5659 this . loading = false ;
5760 }
5861 }
@@ -81,7 +84,7 @@ export class FileBrowserComponent implements OnInit, OnDestroy {
8184 }
8285
8386 updateFile ( newFile : ModelFile ) {
84- if ( newFile . directory ) {
87+ if ( newFile . directory ) {
8588 this . showingFile = false ;
8689 return ;
8790 }
@@ -90,7 +93,7 @@ export class FileBrowserComponent implements OnInit, OnDestroy {
9093 }
9194
9295 ngOnDestroy ( ) : void {
93- if ( this . filePathChangedSubscriber ) {
96+ if ( this . filePathChangedSubscriber ) {
9497 this . filePathChangedSubscriber . unsubscribe ( ) ;
9598 this . filePathChangedSubscriber = null ;
9699 }
@@ -109,29 +112,29 @@ export class FileBrowserComponent implements OnInit, OnDestroy {
109112 const path = this . fileNavigator . path . value ;
110113 const subPath = path . substring ( this . fileNavigator . rootPath . length ) ;
111114
112- let parts = subPath . split ( '/' ) . filter ( value => value . length != 0 ) ;
115+ const parts = subPath . split ( '/' ) . filter ( value => value . length != 0 ) ;
113116
114117 const partUntil = parts . slice ( 0 , index + 1 ) . join ( '/' ) ;
115118
116119 return this . fileNavigator . rootPath + '/' + partUntil ;
117120 }
118121
119122 onFileEvent ( e : FileActionEvent ) {
120- if ( e . action === 'download' ) {
123+ if ( e . action === 'download' ) {
121124 this . onFileDownload ( e . file ) ;
122125 }
123126 }
124127
125128 onFileDownload ( file : ModelFile ) {
126- if ( file . directory ) {
127- throw 'Unable to download a directory' ;
129+ if ( file . directory ) {
130+ throw new Error ( 'Unable to download a directory' ) ;
128131 }
129132
130133 this . workflowService . getArtifact ( this . namespace , this . name , file . path )
131134 . subscribe ( ( res : any ) => {
132- const link = < HTMLAnchorElement > document . createElement ( 'a' ) ;
135+ const link = document . createElement ( 'a' ) as HTMLAnchorElement ;
133136 let downloadName = `${ this . namespace } -${ this . name } -${ file . name } ` ;
134- if ( file . extension ) {
137+ if ( file . extension ) {
135138 downloadName += `.${ file . extension } ` ;
136139 }
137140
@@ -142,14 +145,20 @@ export class FileBrowserComponent implements OnInit, OnDestroy {
142145 document . body . appendChild ( link ) ;
143146 link . click ( ) ;
144147 document . body . removeChild ( link ) ;
145- } )
148+ } ) ;
146149 }
147150
148151 onFileLoadingChange ( value : boolean ) {
149- if ( this . showingFile ) {
152+ if ( this . showingFile ) {
150153 setTimeout ( ( ) => {
151154 this . loading = value ;
152155 } ) ;
153156 }
154157 }
158+
159+ canDownload ( file : ModelFile ) {
160+ return ! file . directory &&
161+ parseInt ( file . size , 10 ) < GenericFileViewComponent . MAX_DOWNLOAD_SIZE
162+ ;
163+ }
155164}
0 commit comments