|
1052 | 1052 | clearInterval: false |
1053 | 1053 | } |
1054 | 1054 | }); |
| 1055 | + var that = this; |
1055 | 1056 | $("#node-function-expand-js-updatedocument").click(function (e) { |
1056 | 1057 | e.preventDefault(); |
1057 | 1058 | var value = that.updatedocumenteditor.getValue(); |
1058 | 1059 | RED.editor.editJavaScript({ |
1059 | 1060 | value: value, |
1060 | 1061 | width: "Infinity", |
1061 | 1062 | cursor: that.updatedocumenteditor.getCursorPosition(), |
1062 | | - mode: "ace/mode/nrjavascript", |
| 1063 | + mode: "ace/mode/json", |
1063 | 1064 | complete: function (v, cursor) { |
1064 | 1065 | that.updatedocumenteditor.setValue(v, -1); |
1065 | 1066 | that.updatedocumenteditor.gotoLine(cursor.row + 1, cursor.column, false); |
|
1099 | 1100 |
|
1100 | 1101 |
|
1101 | 1102 |
|
| 1103 | + |
| 1104 | + |
| 1105 | + |
| 1106 | +<script type="text/x-red" data-template-name="api aggregate"> |
| 1107 | + <div class="form-row" style="margin-bottom: 0px;"> |
| 1108 | + <label for="node-input-aggregates"><i class="fa fa-wrench"></i> Aggregates</label> |
| 1109 | + <input type="hidden" id="node-input-aggregates" autofocus="autofocus"> |
| 1110 | + <input type="hidden" id="node-input-noerr-aggregates"> |
| 1111 | + </div> |
| 1112 | + <div class="form-row node-text-editor-row" style="position:relative"> |
| 1113 | + <div style="position: absolute; right:0; bottom:calc(100% + 3px);"><button id="node-function-expand-js-aggregates" class="editor-button editor-button-small"><i class="fa fa-expand"></i></button></div> |
| 1114 | + <div style="height: 100px; min-height:100px;" class="node-text-editor" id="node-input-aggregates-editor" ></div> |
| 1115 | + </div> |
| 1116 | + <div class="form-row"> |
| 1117 | + <label><i class="fa fa-tag"></i> Collection</label> |
| 1118 | + <input type="text" id="node-input-collection" placeholder="Collection"> |
| 1119 | + </div> |
| 1120 | + <div class="form-row"> |
| 1121 | + <label><i class="fa fa-tag"></i> Name</label> |
| 1122 | + <input type="text" id="node-input-name" placeholder="Name"> |
| 1123 | + </div> |
| 1124 | +</script> |
| 1125 | +<script type="text/x-red" data-help-name="api aggregate"> |
| 1126 | + <p>Send an aggregate request to an collection |
| 1127 | + read more about the |
| 1128 | + <a tagret="_blank" href="https://docs.mongodb.com/manual/reference/command/aggregate/index.html/"> |
| 1129 | + aggregate here</a> and the <a tagret="_blank" href="https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline//">aggregation-pipeline</a> |
| 1130 | + </p> |
| 1131 | +</script> |
| 1132 | +<script type="text/javascript"> |
| 1133 | + RED.nodes.registerType('api aggregate', { |
| 1134 | + category: 'api', |
| 1135 | + color: "#a6bbcf", |
| 1136 | + defaults: { |
| 1137 | + name: { value: "" }, |
| 1138 | + aggregates: { value: "[ {\"$group\" : {\"_id\":\"$_type\", \"count\":{\"$sum\":1}} } ]", required: true }, |
| 1139 | + collection: { value: "entities", required: true } |
| 1140 | + }, |
| 1141 | + inputs: 1, |
| 1142 | + outputs: 1, |
| 1143 | + icon: "bridge.png", |
| 1144 | + label: function () { |
| 1145 | + return this.name || "api aggregate"; |
| 1146 | + }, |
| 1147 | + labelStyle: function () { |
| 1148 | + return this.name ? "node_label_italic" : ""; |
| 1149 | + }, |
| 1150 | + oneditprepare: function () { |
| 1151 | + this.aggregateseditor = RED.editor.createEditor({ |
| 1152 | + id: 'node-input-aggregates-editor', |
| 1153 | + mode: 'ace/mode/json', |
| 1154 | + value: $("#node-input-aggregates").val(), |
| 1155 | + globals: { |
| 1156 | + msg: false, |
| 1157 | + context: false, |
| 1158 | + RED: false, |
| 1159 | + util: false, |
| 1160 | + flow: false, |
| 1161 | + global: false, |
| 1162 | + console: false, |
| 1163 | + Buffer: false, |
| 1164 | + setTimeout: false, |
| 1165 | + clearTimeout: false, |
| 1166 | + setInterval: false, |
| 1167 | + clearInterval: false |
| 1168 | + } |
| 1169 | + }); |
| 1170 | + var that = this; |
| 1171 | + $("#node-function-expand-js-aggregates").click(function (e) { |
| 1172 | + e.preventDefault(); |
| 1173 | + var value = that.aggregateseditor.getValue(); |
| 1174 | + RED.editor.editJavaScript({ |
| 1175 | + value: value, |
| 1176 | + width: "Infinity", |
| 1177 | + cursor: that.aggregateseditor.getCursorPosition(), |
| 1178 | + mode: "ace/mode/json", |
| 1179 | + complete: function (v, cursor) { |
| 1180 | + that.aggregateseditor.setValue(v, -1); |
| 1181 | + that.aggregateseditor.gotoLine(cursor.row + 1, cursor.column, false); |
| 1182 | + setTimeout(function () { |
| 1183 | + that.aggregateseditor.focus(); |
| 1184 | + }, 300); |
| 1185 | + } |
| 1186 | + }) |
| 1187 | + }); |
| 1188 | + |
| 1189 | + }, |
| 1190 | + oneditcancel: function () { |
| 1191 | + this.aggregateseditor.destroy(); |
| 1192 | + delete this.aggregateseditor; |
| 1193 | + }, |
| 1194 | + oneditsave: function () { |
| 1195 | + annot = this.aggregateseditor.getSession().getAnnotations(); |
| 1196 | + $("#node-input-noerr-aggregates").val(0); |
| 1197 | + for (var k = 0; k < annot.length; k++) { |
| 1198 | + if (annot[k].type === "error") { |
| 1199 | + $("#node-input-noerr-aggregates").val(annot.length); |
| 1200 | + this.noerr = annot.length; |
| 1201 | + } |
| 1202 | + } |
| 1203 | + |
| 1204 | + $("#node-input-aggregates").val(this.aggregateseditor.getValue()); |
| 1205 | + this.aggregateseditor.destroy(); |
| 1206 | + delete this.aggregateseditor; |
| 1207 | + } |
| 1208 | + |
| 1209 | + }); |
| 1210 | + |
| 1211 | +</script> |
| 1212 | + |
| 1213 | + |
| 1214 | + |
| 1215 | + |
1102 | 1216 | <script type="text/x-red" data-template-name="api download file"> |
1103 | 1217 | <div class="form-row"> |
1104 | 1218 | <label><i class="fa fa-tag"></i> fileid</label> |
|
0 commit comments