@@ -15,6 +15,7 @@ export default class ServerlessDashboardView {
1515 this . properties = {
1616 consoleOutput : ''
1717 }
18+ this . inputJson = { }
1819 etch . initialize ( this )
1920 this . action = new ServerlessAction ( path . dirname ( this . yamlPath ) )
2021 }
@@ -72,18 +73,22 @@ export default class ServerlessDashboardView {
7273
7374 slsAction ( action , functionName ) {
7475 this . resetCosnoleOutput ( )
76+ const inputJson = this . inputJson && this . inputJson [ functionName ] && this . inputJson [ functionName ] . absolute
77+ ? this . inputJson [ functionName ] . absolute : false
7578 switch ( action ) {
7679 case 'deploy-function' :
7780 this . properties . consoleOutput = `$ serverless deploy function --function ${ functionName } --stage ${ this . refs . stage . value } --region ${ this . refs . region . value } <br/><br/>`
7881 break
7982 case 'invoke' :
80- this . properties . consoleOutput = `$ serverless invoke --function ${ functionName } --stage ${ this . refs . stage . value } --region ${ this . refs . region . value } <br/><br/>`
83+ this . properties . consoleOutput = `$ serverless invoke --function ${ functionName } --stage ${ this . refs . stage . value } --region ${ this . refs . region . value } `
84+ this . properties . consoleOutput += inputJson ? ` --path ${ inputJson } ` : ''
85+ this . properties . consoleOutput += '<br/><br/>'
8186 break
8287 case 'logs' :
8388 this . properties . consoleOutput = `$ serverless logs --function ${ functionName } --stage ${ this . refs . stage . value } --region ${ this . refs . region . value } <br/><br/>`
8489 break
8590 }
86- const sls = this . action . action ( action , functionName , this . refs . region . value , this . refs . stage . value )
91+ const sls = this . action . action ( action , functionName , this . refs . region . value , this . refs . stage . value , inputJson )
8792 sls . stdout . on ( 'data' , ( data ) => {
8893 this . update ( {
8994 consoleOutput : `${ this . properties . consoleOutput } ${ data . toString ( ) } `
@@ -111,6 +116,18 @@ export default class ServerlessDashboardView {
111116 this . update ( )
112117 }
113118
119+ parseJson ( functionName ) {
120+ const remote = require ( 'electron' ) . remote
121+ const files = remote . dialog . showOpenDialog ( remote . getCurrentWindow ( ) , { properties : [ 'openFile' ] } )
122+ if ( files && files . length ) {
123+ this . inputJson [ functionName ] = {
124+ absolute : files [ 0 ] ,
125+ file : files [ 0 ] . split ( path . sep ) . pop ( )
126+ }
127+ this . update ( )
128+ }
129+ }
130+
114131 render ( ) {
115132 let functions = [ ]
116133 if ( this . slsObject . functions ) {
@@ -191,6 +208,7 @@ export default class ServerlessDashboardView {
191208
192209 functionsRender ( functionElem , functionName ) {
193210 const events = [ ]
211+ const jsxFunctionName = `sls-action-${ functionName } `
194212 if ( functionElem . events ) {
195213 _ . forEach ( functionElem . events , ( event ) => {
196214 if ( typeof event === 'object' ) {
@@ -385,15 +403,21 @@ export default class ServerlessDashboardView {
385403 </ ul >
386404 < div class = "apply-block" >
387405 < div class = "select-container" >
388- < select class = "form-control" ref = 'sls-action' >
406+ < select class = "form-control" ref = { jsxFunctionName } >
389407 < option value = "deploy-function" > Deploy Function</ option >
390408 < option value = "invoke" > Invoke</ option >
391409 < option value = "logs" > Logs</ option >
392410 </ select >
393411 < button class = "btn" onClick = { ( ) => {
394- this . slsAction ( this . refs [ ' sls-action' ] . value , functionName )
412+ this . slsAction ( this . refs [ ` sls-action- ${ functionName } ` ] . value , functionName )
395413 } } > Apply</ button >
396414 </ div >
415+ < div class = "pull-right" >
416+ < button class = "btn" onClick = { ( ) => {
417+ this . parseJson ( functionName )
418+ } } > Input JSON</ button > < br />
419+ { this . inputJson && this . inputJson [ functionName ] && this . inputJson [ functionName ] . file ? this . inputJson [ functionName ] . file : '' }
420+ </ div >
397421 </ div >
398422 </ div >
399423 </ div >
0 commit comments