-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgql-sub.html
167 lines (163 loc) · 5.73 KB
/
gql-sub.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<script type="text/x-red" data-template-name="gql-sub-server">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" data-i18n="[placeholder]node-red:common.label.name">
</div>
<div class="form-row">
<label for="node-config-input-endpoint"><i class="fa fa-bookmark"></i> Endpoint</label>
<input type="text" id="node-config-input-endpoint">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('gql-sub-server', {
category: 'config',
color: "rgb(218, 196, 180)",
defaults: {
endpoint: { value: "", required: true },
token: { value: "", required: false },
user: { value: "", required: false },
password: { value: "", required: false },
name: { value: "", required: false }
},
credentials: {
user: { type: "text" },
password: { type: "password" },
serviceTicket: { type: "password" },
token: { type: "password" }
},
align: 'left',
label: function () {
return this.name || this.endpoint;
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('gql-sub', {
category: 'input',
color: '#a6bbcf',
defaults: {
name: { value: "", required: false },
active: { value: true, required: true },
graphql: { type: "gql-sub-server", required: true },
format: { value: "handlebars", required: false },
syntax: { value: "mustache", required: false },
template: { value: "subscription NewUsers{\n userCreated {\n firstName\n lastName\n email\n }\n}", required: true }
},
button: {
enabled() {
return this.active
},
onclick: function () {
var label = this.name || this.endpoint;
var node = this
node.active = !node.active
var historyEvent = {
t: 'edit',
node: node,
changes: {
active: !node.active
},
dirty: node.dirty,
changed: node.changed
};
node.changed = true;
node.dirty = true;
RED.nodes.dirty(true);
RED.history.push(historyEvent);
RED.view.redraw();
}
},
outputs: 1,
// align: "right",
icon: "bridge-dash.png",
label: function () {
return this.name || "gql-sub";
},
oneditprepare: function () {
var that = this;
if (!this.fieldType) {
this.fieldType = 'msg';
}
if (!this.syntax) {
this.syntax = 'mustache';
$("#node-input-syntax").val(this.syntax);
}
$("#node-input-field").typedInput({
default: 'msg',
types: ['msg', 'flow', 'global'],
typeField: $("#node-input-fieldType")
});
this.editor = RED.editor.createEditor({
id: 'node-input-template-editor',
mode: 'ace/mode/html',
value: $("#node-input-template").val()
});
RED.library.create({
url: "functions", // where to get the data from
type: "function", // the type of object the library is for
editor: that.editor, // the field name the main text body goes to
fields: ['name', 'outputs']
});
this.editor.focus();
$("#node-input-format").change(function () {
var mod = "ace/mode/" + $("#node-input-format").val();
that.editor.getSession().setMode({
path: mod,
v: Date.now()
})
});
},
oneditsave: function () {
$("#node-input-template").val(this.editor.getValue())
delete this.editor;
},
oneditresize: function (size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i = 0; i < rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop")) + parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height", height + "px");
this.editor.resize();
}
});
</script>
<script type="text/x-red" data-template-name="gql-sub">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-graphql"><i class="fa fa-bookmark"></i> Endpoint</label>
<input type="text" id="node-input-graphql">
</div>
<div class="form-row" style="position: relative; margin-bottom: 0px;">
<label for="node-input-template"><i class="fa fa-file-code-o"></i> Subscription</label>
<input type="hidden" id="node-input-template" autofocus="autofocus">
<div style="position: absolute; right:0;display:inline-block; text-align: right; font-size: 0.8em;">
Format:
<select id="node-input-format" style="width:110px; font-size: 10px !important; height: 24px; padding:0;">
<option value="handlebars">mustache</option>
<option value="html">HTML</option>
<option value="json">JSON</option>
<option value="markdown">Markdown</option>
<option value="text">none</option>
</select>
</div>
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px;" class="node-text-editor" id="node-input-template-editor" ></div>
</div>
<div class="form-row">
<label for="node-input-syntax"><i class="fa fa-code"></i> Syntax</label>
<select id="node-input-syntax" style="width:180px;">
<option value="mustache">Mustache</option>
<option value="plain">Plain</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="gql-sub">
<p>A simple node that converts the message payloads into all lower-case characters</p>
</script>