File tree Expand file tree Collapse file tree
services/language_translation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 </ div >
2323 < div id = "credentials-not-found" class = "form-row" >
2424 < div class = "form-tips" >
25- < i class = "fa fa-question-circle" > </ i > < b > Could not retrieve models . </ b > < span id = "try-again" > Click here to ry again. </ span >
25+ < i class = "fa fa-question-circle" > </ i > < b > Could not bind to service . </ b > Try other credentials?
2626 </ div >
2727 < / d i v >
2828 < div class = "form-row" >
124124
125125( function ( ) {
126126
127- $ ( 'span#try-again' ) . on ( 'click' , function ( ) {
128- oneditprepare ( ) ;
129- } )
130-
131127 // sorting functions
132128 function onlyUnique ( value , index , self ) {
133129 return self . indexOf ( value ) === index ;
330326 }
331327
332328 function getModels ( ) {
333- $ . getJSON ( 'watson-translate/models/' ) . done ( function ( data ) {
329+ var username = $ ( 'input#node-input-username' ) . val ( ) ;
330+ var password = $ ( 'input#node-input-password' ) . val ( ) ;
331+ $ . getJSON ( 'watson-translate/models/' , { un : username , pwd : password } ) . done ( function ( data ) {
334332 models = data . models ;
335- handlersUI ( ) ;
336333 selectAction ( ) ;
337334 } ) . fail ( function ( err ) {
338335 console . log ( err ) ;
336+ $ ( '#credentials-not-found' ) . show ( ) ;
339337 } ) . always ( function ( ) { } ) ;
340338 }
341339
342340 function oneditprepare ( ) {
341+ console . log ( "zfsqdfqsg" ) ;
342+ console . log ( models ) ;
343343 var node = this ;
344+ handlersUI ( ) ;
344345 $ . getJSON ( 'watson-translate/vcap/' )
345346 . done ( function ( sids ) {
346- console . log ( sids ) ;
347347 $ ( '.credentials' ) . toggle ( ! sids ) ;
348348 if ( first_launch || ! models ) {
349349 $ ( '#credentials-not-found' ) . hide ( ) ;
350350 getModels ( ) ;
351351 first_launch = false ;
352352 } else if ( models ) {
353353 $ ( '#credentials-not-found' ) . hide ( ) ;
354- handlersUI ( ) ;
355354 selectAction ( ) ;
356355 } else {
357356 $ ( '#credentials-not-found' ) . show ( ) ;
Original file line number Diff line number Diff line change @@ -37,11 +37,19 @@ module.exports = function (RED) {
3737 } ) ;
3838
3939 RED . httpAdmin . get ( '/watson-translate/models' , function ( req , res ) {
40- language_translation = watson . language_translation ( {
41- username : username ,
42- password : password ,
43- version : 'v2'
44- } ) ;
40+ if ( ! username && ! password ) {
41+ language_translation = watson . language_translation ( {
42+ username : req . query . un ,
43+ password : req . query . pwd ,
44+ version : 'v2'
45+ } ) ;
46+ } else {
47+ language_translation = watson . language_translation ( {
48+ username : username ,
49+ password : password ,
50+ version : 'v2'
51+ } ) ;
52+ }
4553 language_translation . getModels ( { } , function ( err , models ) {
4654 if ( err ) {
4755 res . json ( err ) ;
@@ -69,6 +77,9 @@ module.exports = function (RED) {
6977 } ) ;
7078
7179 function SMTNode ( config ) {
80+ RED . nodes . createNode ( this , config ) ;
81+ var node = this ;
82+
7283 this . on ( 'input' , function ( msg ) {
7384 var message = '' ;
7485
@@ -163,9 +174,6 @@ module.exports = function (RED) {
163174 }
164175 } ) ;
165176
166- RED . nodes . createNode ( this , config ) ;
167- var node = this ;
168-
169177 this . doTranslate = function ( msg , model_id ) {
170178 node . status ( {
171179 fill : 'blue' ,
You can’t perform that action at this time.
0 commit comments