@@ -15,24 +15,31 @@ export class Component extends OpenShiftItem {
1515 static async create ( application : OpenShiftObject ) : Promise < string > {
1616 // should use QuickPickItem with label and description
1717 const sourceTypes : vscode . QuickPickItem [ ] = [
18- {
19- label : 'Git Repository' ,
20- description : 'Use an existing git repository as a source for the component'
21- } ,
22- {
23- label : 'Workspace Directory' ,
24- description : 'Use workspace directory as a source for the component'
25- } ] ;
18+ {
19+ label : 'Git Repository' ,
20+ description : 'Use an existing git repository as a source for the component'
21+ } ,
22+ {
23+ label : 'Binary File' ,
24+ description : 'Use binary file as a source for the component'
25+ } ,
26+ {
27+ label : 'Workspace Directory' ,
28+ description : 'Use workspace directory as a source for the component'
29+ }
30+ ] ;
2631 const componentSource = await vscode . window . showQuickPick ( sourceTypes , {
2732 placeHolder : "Select source type for component"
2833 } ) ;
2934 if ( ! componentSource ) return null ;
3035
3136 let command : Promise < string > ;
3237 if ( componentSource . label === 'Git Repository' ) {
33- command = Component . createGit ( application ) ;
38+ command = Component . createFromGit ( application ) ;
39+ } else if ( componentSource . label === 'Binary File' ) {
40+ command = Component . createFromBinary ( application ) ;
3441 } else {
35- command = Component . createLocal ( application ) ;
42+ command = Component . createFromLocal ( application ) ;
3643 }
3744 return command . catch ( ( err ) => Promise . reject ( `Failed to create component with error '${ err } '` ) ) ;
3845 }
@@ -131,7 +138,7 @@ export class Component extends OpenShiftItem {
131138 return null ;
132139 }
133140
134- private static async createLocal ( application : OpenShiftObject ) : Promise < string > {
141+ private static async createFromLocal ( application : OpenShiftObject ) : Promise < string > {
135142 const folder = await vscode . window . showWorkspaceFolderPick ( {
136143 placeHolder : 'Select the target workspace folder'
137144 } ) ;
@@ -167,7 +174,7 @@ export class Component extends OpenShiftItem {
167174 . then ( ( ) => `Component '${ componentName } ' successfully created` ) ;
168175 }
169176
170- private static async createGit ( application : OpenShiftObject ) : Promise < string > {
177+ private static async createFromGit ( application : OpenShiftObject ) : Promise < string > {
171178 const repoURI = await vscode . window . showInputBox ( { prompt : 'Git repository URI' , validateInput :
172179 ( value : string ) => {
173180 if ( validator . isEmpty ( value . trim ( ) ) ) {
@@ -211,4 +218,38 @@ export class Component extends OpenShiftItem {
211218 . then ( ( ) => Component . explorer . refresh ( application ) )
212219 . then ( ( ) => `Component '${ componentName } ' successfully created` ) ;
213220 }
221+
222+ private static async createFromBinary ( application : OpenShiftObject ) : Promise < string > {
223+ const binaryFile = await vscode . window . showOpenDialog ( {
224+ openLabel : 'Select the binary file'
225+ } ) ;
226+
227+ if ( ! binaryFile ) return null ;
228+
229+ const componentName = await vscode . window . showInputBox ( { prompt : "Component name" , validateInput : ( value : string ) => {
230+ if ( validator . isEmpty ( value . trim ( ) ) ) {
231+ return 'Empty component name' ;
232+ }
233+ } } ) ;
234+
235+ if ( ! componentName ) return null ;
236+
237+ const componentTypeName = await vscode . window . showQuickPick ( Component . odo . getComponentTypes ( ) , { placeHolder : "Component type" } ) ;
238+
239+ if ( ! componentTypeName ) return null ;
240+
241+ const componentTypeVersion = await vscode . window . showQuickPick ( Component . odo . getComponentTypeVersions ( componentTypeName ) , { placeHolder : "Component type Version" } ) ;
242+
243+ if ( ! componentTypeVersion ) return null ;
244+
245+ const project = application . getParent ( ) ;
246+ return Progress . execWithProgress ( {
247+ cancellable : false ,
248+ location : vscode . ProgressLocation . Notification ,
249+ title : `Creating new component '${ componentName } '`
250+ } , [ { command : `odo create ${ componentTypeName } :${ componentTypeVersion } ${ componentName } --binary ${ binaryFile } --app ${ application . getName ( ) } --project ${ project . getName ( ) } ` , increment : 100 }
251+ ] , Component . odo )
252+ . then ( ( ) => Component . explorer . refresh ( application ) )
253+ . then ( ( ) => `Component '${ componentName } ' successfully created` ) ;
254+ }
214255}
0 commit comments