|
| 1 | +<!-- |
| 2 | + Copyright 2013 Kris Daniels. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +<script type="text/x-red" data-template-name="postgresdb"> |
| 18 | + <div class="form-row"> |
| 19 | + <label for="node-config-input-hostname"><i class="icon-bookmark"></i> Host</label> |
| 20 | + <input class="input-append-left" type="text" id="node-config-input-hostname" placeholder="localhost" style="width: 40%;" > |
| 21 | + <label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label> |
| 22 | + <input type="text" id="node-config-input-port" placeholder="5432" style="width:45px"> |
| 23 | + </div> |
| 24 | + <div class="form-row"> |
| 25 | + <label for="node-config-input-db"><i class="icon-briefcase"></i> Database</label> |
| 26 | + <input type="text" id="node-config-input-db" placeholder="test"> |
| 27 | + </div> |
| 28 | + <div class="form-row"> |
| 29 | + <label for="node-config-input-name"><i class="icon-user"></i> Username</label> |
| 30 | + <input type="text" id="node-config-input-user" placeholder="postgres"> |
| 31 | + <label for="node-config-input-password"><i class="icon-lock"></i> Password</label> |
| 32 | + <input type="password" id="node-config-input-password" placeholder="postgres"> |
| 33 | + </div> |
| 34 | +</script> |
| 35 | + |
| 36 | +<script type="text/javascript"> |
| 37 | + RED.nodes.registerType('postgresdb',{ |
| 38 | + category: 'config', |
| 39 | + color:"rgb(218, 196, 180)", |
| 40 | + defaults: { |
| 41 | + hostname: { value:"localhost",required:true}, |
| 42 | + port: { value: 5432,required:true}, |
| 43 | + db: { value:"postgres",required:true} |
| 44 | + }, |
| 45 | + label: function() { |
| 46 | + return this.name||this.hostname+":"+this.port+"/"+this.db; |
| 47 | + }, |
| 48 | + oneditprepare: function() { |
| 49 | + |
| 50 | + $.getJSON('postgresdb/'+this.id,function(data) { |
| 51 | + if (data.user) { |
| 52 | + $('#node-config-input-user').val(data.user); |
| 53 | + } |
| 54 | + if (data.hasPassword) { |
| 55 | + $('#node-config-input-password').val('__PWRD__'); |
| 56 | + } else { |
| 57 | + $('#node-config-input-password').val(''); |
| 58 | + } |
| 59 | + }); |
| 60 | + }, |
| 61 | + oneditsave: function() { |
| 62 | + |
| 63 | + var newUser = $('#node-config-input-user').val(); |
| 64 | + var newPass = $('#node-config-input-password').val(); |
| 65 | + var credentials = {}; |
| 66 | + credentials.user = newUser; |
| 67 | + if (newPass != '__PWRD__') { |
| 68 | + credentials.password = newPass; |
| 69 | + } |
| 70 | + $.ajax({ |
| 71 | + url: 'postgresdb/'+this.id, |
| 72 | + type: 'POST', |
| 73 | + data: credentials, |
| 74 | + success:function(result){} |
| 75 | + }); |
| 76 | + }, |
| 77 | + ondelete: function() { |
| 78 | + $.ajax({ |
| 79 | + url: 'postgresdb/'+this.id, |
| 80 | + type: 'DELETE', |
| 81 | + success: function(result) {} |
| 82 | + }); |
| 83 | + } |
| 84 | + }); |
| 85 | +</script> |
| 86 | + |
| 87 | +<script type="text/x-red" data-template-name="postgres"> |
| 88 | + <div class="form-row"> |
| 89 | + <label for="node-input-name"><i class="icon-tag"></i> Name</label> |
| 90 | + <input type="text" id="node-input-name" placeholder="Name"> |
| 91 | + </div> |
| 92 | + <div class="form-row"> |
| 93 | + <label for="node-input-postgresdb"><i class="icon-tag"></i> Server</label> |
| 94 | + <input type="text" id="node-input-postgresdb"> |
| 95 | + </div> |
| 96 | + <div class="form-row"> |
| 97 | + <label> </label> |
| 98 | + <input type="checkbox" id="node-input-output" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;"> |
| 99 | + <label for="node-input-output" style="width: 70%;">Receive query output ?</label> |
| 100 | + </div> |
| 101 | +</script> |
| 102 | + |
| 103 | +<script type="text/x-red" data-help-name="postgres"> |
| 104 | + <p>A PostgreSql I/O node. </p> |
| 105 | + <p>Executes the query specified in msg.payload with optional query parameters in msg.queryParameters</p> |
| 106 | + <p>The queryParameters in the query must be specified as $propertyname</p> |
| 107 | + <p>See the node-postgres-named package for more info</p> |
| 108 | + <p>When receiving data from the query, the msg.payload on the output will be a json array of the returned records</p> |
| 109 | + |
| 110 | +</script> |
| 111 | + |
| 112 | +<script type="text/javascript"> |
| 113 | + RED.nodes.registerType('postgres',{ |
| 114 | + category: 'storage-output', |
| 115 | + color:"rgb(148, 226, 252)", |
| 116 | + defaults: { |
| 117 | + postgresdb: { type:"postgresdb",required:true}, |
| 118 | + name: {value:""}, |
| 119 | + output: {value:false}, |
| 120 | + outputs: {value:0} |
| 121 | + }, |
| 122 | + inputs: 1, |
| 123 | + outputs: 0, |
| 124 | + icon: "postgres.png", |
| 125 | + align: "right", |
| 126 | + label: function() { |
| 127 | + return this.name||(this.sqlquery?this.sqlquery:"postgres"); |
| 128 | + }, |
| 129 | + labelStyle: function() { |
| 130 | + return this.name?"node_label_italic":""; |
| 131 | + }, |
| 132 | + oneditprepare: function() { |
| 133 | + |
| 134 | + $( "#node-input-output" ).prop( "checked", this.output ); |
| 135 | + $("#node-input-name").focus(); |
| 136 | + |
| 137 | + }, |
| 138 | + oneditsave: function() { |
| 139 | + |
| 140 | + var hasOutput = $( "#node-input-output" ).prop( "checked" ); |
| 141 | + this.outputs = hasOutput ? 1:0; |
| 142 | + |
| 143 | + } |
| 144 | + }); |
| 145 | + |
| 146 | +</script> |
0 commit comments