99 </ div >
1010</ script >
1111< script type ="text/javascript ">
12- RED . nodes . registerType ( 'api-credentials' , {
12+ RED . nodes . registerType ( 'api-credentials' , {
1313 category : 'config' ,
1414 defaults : {
1515 } ,
1616 credentials : {
17- username : { type :"text" } ,
17+ username : { type : "text" } ,
1818 password : { type : "password" }
1919 } ,
20- label : function ( ) {
20+ label : function ( ) {
2121 return this . name || "api credentials" ;
2222 }
2323 } ) ;
4444 color : "#a6bbcf" ,
4545 defaults : {
4646 name : { value : "" } ,
47- config : { value :"" , type :"api-credentials" , required :false }
47+ config : { value : "" , type : "api-credentials" , required : false }
4848 } ,
4949 inputs : 1 ,
5050 outputs : 1 ,
457457 $ ( "#node-input-typed-entities" ) . typedInput ( 'value' , this . entities ) ;
458458
459459
460- $ . getJSON ( 'api_roles' , function ( data ) {
461- $ . each ( data , function ( i , ele ) {
462- $ ( '#node-input-targetid-select' ) . append ( $ ( '<option>' , {
460+ $ . getJSON ( 'api_roles' , function ( data ) {
461+ $ . each ( data , function ( i , ele ) {
462+ $ ( '#node-input-targetid-select' ) . append ( $ ( '<option>' , {
463463 value : ele . _id ,
464- text : ele . name
464+ text : ele . name
465465 } ) ) ;
466466 } ) ;
467467 $ ( '#node-input-targetid-select' ) . val ( $ ( '#node-input-targetid' ) . val ( ) ) ;
535535 $ ( "#node-input-typed-entities" ) . typedInput ( 'value' , this . entities ) ;
536536
537537
538- $ . getJSON ( 'api_roles' , function ( data ) {
539- $ . each ( data , function ( i , ele ) {
540- $ ( '#node-input-targetid-select' ) . append ( $ ( '<option>' , {
538+ $ . getJSON ( 'api_roles' , function ( data ) {
539+ $ . each ( data , function ( i , ele ) {
540+ $ ( '#node-input-targetid-select' ) . append ( $ ( '<option>' , {
541541 value : ele . _id ,
542- text : ele . name
542+ text : ele . name
543543 } ) ) ;
544544 } ) ;
545545 $ ( '#node-input-targetid-select' ) . val ( $ ( '#node-input-targetid' ) . val ( ) ) ;
614614 </ select >
615615 </ div >
616616 < div class = "form-row" >
617- < label for = "node-input-outcol" > < i class = "fa fa-tag" > </ i > Out collection</ label >
618- < input type = "text" id = "node-input-outcol" placeholder = "Output collection" >
617+ < label for = "node-input-collection" > < i class = "fa fa-tag" > </ i > Collection</ label >
618+ < input type = "text" id = "node-input-collection" placeholder = "Run reduce on this Collection" >
619+ </ div >
620+ < div class = "form-row" >
621+ < label for = "node-input-query" > < i class = "fa fa-tag" > </ i > Query</ label >
622+ < input type = "text" id = "node-input-query" placeholder = "Query limiting reduced documents" >
619623 </ div >
620624 < div class = "form-row" >
621- < label for = "node-input-query " > < i class = "fa fa-tag" > </ i > Out collection</ label >
622- < input type = "text" id = "node-input-query " placeholder = "Output collection" >
625+ < label for = "node-input-outcol " > < i class = "fa fa-tag" > </ i > Out collection</ label >
626+ < input type = "text" id = "node-input-outcol " placeholder = "Output collection" >
623627 </ div >
624628
625629</ script >
640644 defaults : {
641645 name : { value : "" } ,
642646 collection : { value : "entities" , required : true } ,
643- map : { value :
644- `function map(this) {
647+ map : {
648+ value :
649+ `function map() {
645650 emit(this._type, this);
646- }` , required : true } ,
647- reduce : { value :
648- `function reduce(key, values) {
651+ }` , required : true
652+ } ,
653+ reduce : {
654+ value :
655+ `function reduce(key, values) {
649656 var reducedObject = { count: 0, value: 0, avg: 0, _acl: [] };
650657 values.forEach(function (value) {
651658 reducedObject.value += value.value;
652659 reducedObject.count += value.count;
653660 reducedObject._acl = value._acl;
654661 });
655662 return reducedObject;
656- }` , required : true } ,
657- finalize : { value :
658- `function finalize(key, reducedValue) {
663+ }` , required : true
664+ } ,
665+ finalize : {
666+ value :
667+ `function finalize(key, reducedValue) {
659668 if (reducedValue.count > 0) {
660669 reducedValue.avg = reducedValue.value / reducedValue.count;
661670 }
666675 outcol : { value : "1" , required : true } ,
667676 query : { value : "{}" , required : true } ,
668677
669- noerr : { value :0 , required :true , validate :function ( v ) { return ( ( ! v ) || ( v === 0 ) ) ? true : false ; } }
678+ noerr : { value : 0 , required : true , validate : function ( v ) { return ( ( ! v ) || ( v === 0 ) ) ? true : false ; } }
670679 } ,
671680 inputs : 1 ,
672681 outputs : 1 ,
741750 } ) ;
742751
743752 var that = this ;
744- $ ( "#node-function-expand-js-map" ) . click ( function ( e ) {
753+ $ ( "#node-function-expand-js-map" ) . click ( function ( e ) {
745754 e . preventDefault ( ) ;
746755 var value = that . mapeditor . getValue ( ) ;
747756 RED . editor . editJavaScript ( {
748757 value : value ,
749758 width : "Infinity" ,
750759 cursor : that . mapeditor . getCursorPosition ( ) ,
751760 mode : "ace/mode/nrjavascript" ,
752- complete : function ( v , cursor ) {
761+ complete : function ( v , cursor ) {
753762 that . mapeditor . setValue ( v , - 1 ) ;
754- that . mapeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
755- setTimeout ( function ( ) {
763+ that . mapeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
764+ setTimeout ( function ( ) {
756765 that . mapeditor . focus ( ) ;
757- } , 300 ) ;
766+ } , 300 ) ;
758767 }
759768 } )
760769 } ) ;
761- $ ( "#node-function-expand-js-reduce" ) . click ( function ( e ) {
770+ $ ( "#node-function-expand-js-reduce" ) . click ( function ( e ) {
762771 e . preventDefault ( ) ;
763772 var value = that . reduceeditor . getValue ( ) ;
764773 RED . editor . editJavaScript ( {
765774 value : value ,
766775 width : "Infinity" ,
767776 cursor : that . reduceeditor . getCursorPosition ( ) ,
768777 mode : "ace/mode/nrjavascript" ,
769- complete : function ( v , cursor ) {
778+ complete : function ( v , cursor ) {
770779 that . reduceeditor . setValue ( v , - 1 ) ;
771- that . reduceeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
772- setTimeout ( function ( ) {
780+ that . reduceeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
781+ setTimeout ( function ( ) {
773782 that . reduceeditor . focus ( ) ;
774- } , 300 ) ;
783+ } , 300 ) ;
775784 }
776785 } )
777786 } ) ;
778- $ ( "#node-function-expand-js-finalize" ) . click ( function ( e ) {
787+ $ ( "#node-function-expand-js-finalize" ) . click ( function ( e ) {
779788 e . preventDefault ( ) ;
780789 var value = that . finalizeeditor . getValue ( ) ;
781790 RED . editor . editJavaScript ( {
782791 value : value ,
783792 width : "Infinity" ,
784793 cursor : that . finalizeeditor . getCursorPosition ( ) ,
785794 mode : "ace/mode/nrjavascript" ,
786- complete : function ( v , cursor ) {
795+ complete : function ( v , cursor ) {
787796 that . finalizeeditor . setValue ( v , - 1 ) ;
788- that . finalizeeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
789- setTimeout ( function ( ) {
797+ that . finalizeeditor . gotoLine ( cursor . row + 1 , cursor . column , false ) ;
798+ setTimeout ( function ( ) {
790799 that . finalizeeditor . focus ( ) ;
791- } , 300 ) ;
800+ } , 300 ) ;
792801 }
793802 } )
794803 } ) ;
805814
806815 var annot = this . mapeditor . getSession ( ) . getAnnotations ( ) ;
807816 $ ( "#node-input-noerr-map" ) . val ( 0 ) ;
808- for ( var k = 0 ; k < annot . length ; k ++ ) {
809- console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
817+ for ( var k = 0 ; k < annot . length ; k ++ ) {
818+ console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
810819 if ( annot [ k ] . type === "error" ) {
811820 $ ( "#node-input-noerr-map" ) . val ( annot . length ) ;
812821 this . noerr = annot . length ;
815824
816825 annot = this . reduceeditor . getSession ( ) . getAnnotations ( ) ;
817826 $ ( "#node-input-noerr-reduce" ) . val ( 0 ) ;
818- for ( var k = 0 ; k < annot . length ; k ++ ) {
819- console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
827+ for ( var k = 0 ; k < annot . length ; k ++ ) {
828+ console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
820829 if ( annot [ k ] . type === "error" ) {
821830 $ ( "#node-input-noerr-reduce" ) . val ( annot . length ) ;
822831 this . noerr = annot . length ;
825834
826835 annot = this . finalizeeditor . getSession ( ) . getAnnotations ( ) ;
827836 $ ( "#node-input-noerr-finalize" ) . val ( 0 ) ;
828- for ( var k = 0 ; k < annot . length ; k ++ ) {
829- console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
837+ for ( var k = 0 ; k < annot . length ; k ++ ) {
838+ console . log ( annot [ k ] . type , ":" , annot [ k ] . text , "on line" , annot [ k ] . row ) ;
830839 if ( annot [ k ] . type === "error" ) {
831840 $ ( "#node-input-noerr-finalize" ) . val ( annot . length ) ;
832841 this . noerr = annot . length ;
848857 $ ( "#node-input-scope" ) . val ( $ ( "#node-input-typed-scope" ) . typedInput ( 'value' ) ) ;
849858
850859 } ,
851- oneditcancel : function ( ) {
860+ oneditcancel : function ( ) {
852861 this . mapeditor . destroy ( ) ;
853862 delete this . mapeditor ;
854863
858867 this . finalizeeditor . destroy ( ) ;
859868 delete this . finalizeeditor ;
860869 } ,
861- oneditresize : function ( size ) {
870+ oneditresize : function ( size ) {
862871 // var rows = $("#dialog-form>div:not(.node-text-editor-row)");
863872 // var height = $("#dialog-form").height();
864873 // for (var i=0; i<rows.size(); i++) {
873882 }
874883
875884 } ) ;
876- </ script >
885+ </ script >
0 commit comments