@kwirthmagnify/kwirth-plugin-echo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/back.js +1296 -0
  2. package/front.js +275 -0
  3. package/package.json +8 -0
package/front.js ADDED
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ (() => {
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+
29
+ // kwirth-globals:@kwirthmagnify/kwirth-common
30
+ var require_kwirth_common = __commonJS({
31
+ "kwirth-globals:@kwirthmagnify/kwirth-common"(exports, module) {
32
+ module.exports = window.__kwirth__.kwirthCommon;
33
+ }
34
+ });
35
+
36
+ // node_modules/@kwirthmagnify/kwirth-common-front/dist/index.js
37
+ var require_dist = __commonJS({
38
+ "node_modules/@kwirthmagnify/kwirth-common-front/dist/index.js"(exports) {
39
+ "use strict";
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.ENotifyLevel = exports.EChannelRefreshAction = void 0;
42
+ var kwirth_common_1 = require_kwirth_common();
43
+ Object.defineProperty(exports, "EChannelRefreshAction", { enumerable: true, get: function() {
44
+ return kwirth_common_1.EChannelRefreshAction;
45
+ } });
46
+ Object.defineProperty(exports, "ENotifyLevel", { enumerable: true, get: function() {
47
+ return kwirth_common_1.ENotifyLevel;
48
+ } });
49
+ }
50
+ });
51
+
52
+ // kwirth-globals:react
53
+ var require_react = __commonJS({
54
+ "kwirth-globals:react"(exports, module) {
55
+ module.exports = window.__kwirth__.React;
56
+ }
57
+ });
58
+
59
+ // kwirth-globals:@mui/material
60
+ var require_material = __commonJS({
61
+ "kwirth-globals:@mui/material"(exports, module) {
62
+ module.exports = window.__kwirth__.MUI.material;
63
+ }
64
+ });
65
+
66
+ // kwirth-globals:@mui/icons-material
67
+ var require_icons_material = __commonJS({
68
+ "kwirth-globals:@mui/icons-material"(exports, module) {
69
+ module.exports = window.__kwirth__.MUI.icons;
70
+ }
71
+ });
72
+
73
+ // src/front/EchoChannel.ts
74
+ var import_kwirth_common = __toESM(require_kwirth_common(), 1);
75
+ var import_kwirth_common_front = __toESM(require_dist(), 1);
76
+
77
+ // src/front/EchoConfig.ts
78
+ var EchoConfig = class {
79
+ constructor() {
80
+ this.maxLines = 3;
81
+ }
82
+ };
83
+ var EchoInstanceConfig = class {
84
+ constructor() {
85
+ this.interval = 5;
86
+ }
87
+ };
88
+
89
+ // src/front/EchoData.ts
90
+ var EchoData = class {
91
+ constructor() {
92
+ this.lines = [];
93
+ this.paused = false;
94
+ this.started = false;
95
+ }
96
+ };
97
+
98
+ // src/front/EchoSetup.tsx
99
+ var import_react = __toESM(require_react(), 1);
100
+ var import_material = __toESM(require_material(), 1);
101
+ var import_icons_material = __toESM(require_icons_material(), 1);
102
+ var EchoIcon = /* @__PURE__ */ import_react.default.createElement(import_icons_material.Science, null);
103
+ var EchoSetup = (props) => {
104
+ const echoInstanceConfig = props.setupConfig?.channelInstanceConfig || new EchoConfig();
105
+ const echoConfig = props.setupConfig?.channelConfig || new EchoConfig();
106
+ const [interval, setInterval] = (0, import_react.useState)(echoInstanceConfig.interval);
107
+ const [maxLines, setMaxLines] = (0, import_react.useState)(echoConfig.maxLines);
108
+ const [senderEntries, setSenderEntries] = (0, import_react.useState)([]);
109
+ const [selectedSender, setSelectedSender] = (0, import_react.useState)(
110
+ echoInstanceConfig.senderId && echoInstanceConfig.senderConfigName ? `${echoInstanceConfig.senderId}::${echoInstanceConfig.senderConfigName}` : ""
111
+ );
112
+ const defaultRef = (0, import_react.useRef)(null);
113
+ (0, import_react.useEffect)(() => {
114
+ const url = props.channelObject.clusterUrl;
115
+ const token = props.channelObject.accessString;
116
+ if (!url || !token) return;
117
+ fetch(`${url}/senders`, { headers: { Authorization: `Bearer ${token}` } }).then((r) => r.json()).then((data) => {
118
+ const entries = [];
119
+ for (const s of data) {
120
+ for (const cn of s.configNames ?? []) {
121
+ entries.push({ senderId: s.id, configName: cn });
122
+ }
123
+ }
124
+ setSenderEntries(entries);
125
+ }).catch(() => {
126
+ });
127
+ }, []);
128
+ const ok = () => {
129
+ echoConfig.maxLines = maxLines;
130
+ echoInstanceConfig.interval = interval;
131
+ if (selectedSender) {
132
+ const [sid, cn] = selectedSender.split("::");
133
+ echoInstanceConfig.senderId = sid;
134
+ echoInstanceConfig.senderConfigName = cn;
135
+ } else {
136
+ echoInstanceConfig.senderId = void 0;
137
+ echoInstanceConfig.senderConfigName = void 0;
138
+ }
139
+ props.onChannelSetupClosed(props.channel, {
140
+ channelId: props.channel.channelId,
141
+ channelConfig: echoConfig,
142
+ channelInstanceConfig: echoInstanceConfig
143
+ }, true, defaultRef.current?.checked || false);
144
+ };
145
+ const cancel = () => {
146
+ props.onChannelSetupClosed(props.channel, {
147
+ channelId: props.channel.channelId,
148
+ channelConfig: void 0,
149
+ channelInstanceConfig: void 0
150
+ }, false, false);
151
+ };
152
+ return /* @__PURE__ */ import_react.default.createElement(import_material.Dialog, { open: true, maxWidth: false, sx: { "& .MuiDialog-paper": { width: "25vw", maxWidth: "40vw", height: "50vh", maxHeight: "50vh" } } }, /* @__PURE__ */ import_react.default.createElement(import_material.DialogTitle, null, "Configure Echo channel"), /* @__PURE__ */ import_react.default.createElement(import_material.DialogContent, null, /* @__PURE__ */ import_react.default.createElement(import_material.Stack, { direction: "column", spacing: 2, sx: { m: 1 } }, /* @__PURE__ */ import_react.default.createElement(import_material.TextField, { value: maxLines, onChange: (e) => setMaxLines(+e.target.value), type: "number", variant: "standard", label: "Max lines", fullWidth: true }), /* @__PURE__ */ import_react.default.createElement(import_material.TextField, { value: interval, onChange: (e) => setInterval(+e.target.value), type: "number", variant: "standard", label: "Interval", fullWidth: true }), /* @__PURE__ */ import_react.default.createElement(import_material.Stack, { direction: "column", spacing: 0.5 }, /* @__PURE__ */ import_react.default.createElement(import_material.Typography, { variant: "caption", color: "text.secondary" }, "Sender config"), /* @__PURE__ */ import_react.default.createElement(import_material.Select, { value: selectedSender, onChange: (e) => setSelectedSender(e.target.value), displayEmpty: true, size: "small", variant: "standard" }, /* @__PURE__ */ import_react.default.createElement(import_material.MenuItem, { value: "" }, /* @__PURE__ */ import_react.default.createElement(import_material.Typography, { variant: "body2", color: "text.secondary" }, "(none)")), senderEntries.map((e) => /* @__PURE__ */ import_react.default.createElement(import_material.MenuItem, { key: `${e.senderId}::${e.configName}`, value: `${e.senderId}::${e.configName}` }, /* @__PURE__ */ import_react.default.createElement(import_material.Stack, { direction: "row", spacing: 1, alignItems: "center" }, /* @__PURE__ */ import_react.default.createElement(import_material.Chip, { label: e.senderId, size: "small", variant: "outlined", sx: { fontSize: "0.65rem", height: 18 } }), /* @__PURE__ */ import_react.default.createElement(import_material.Typography, { variant: "body2" }, e.configName)))))))), /* @__PURE__ */ import_react.default.createElement(import_material.DialogActions, null, /* @__PURE__ */ import_react.default.createElement(import_material.FormControlLabel, { control: /* @__PURE__ */ import_react.default.createElement(import_material.Checkbox, { slotProps: { input: { ref: defaultRef } } }), label: "Set as default", sx: { width: "100%", ml: "8px" } }), /* @__PURE__ */ import_react.default.createElement(import_material.Button, { onClick: ok }, "OK"), /* @__PURE__ */ import_react.default.createElement(import_material.Button, { onClick: cancel }, "CANCEL")));
153
+ };
154
+
155
+ // src/front/EchoTabContent.tsx
156
+ var import_react2 = __toESM(require_react(), 1);
157
+ var import_material2 = __toESM(require_material(), 1);
158
+ var import_icons_material2 = __toESM(require_icons_material(), 1);
159
+ var EchoTabContent = (props) => {
160
+ const echoData = props.channelObject.data;
161
+ const echoConfig = props.channelObject.config;
162
+ const echoInstanceConfig = props.channelObject.instanceConfig;
163
+ const echoBoxRef = (0, import_react2.useRef)(null);
164
+ const [echoBoxTop, setEchoBoxTop] = (0, import_react2.useState)(0);
165
+ (0, import_react2.useEffect)(() => {
166
+ if (echoBoxRef.current) setEchoBoxTop(echoBoxRef.current.getBoundingClientRect().top);
167
+ });
168
+ const formatContent = () => {
169
+ if (!echoData || !echoData.lines) return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null);
170
+ return echoData.lines.map((line, index) => /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { key: index }, line));
171
+ };
172
+ return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, echoData.started && /* @__PURE__ */ import_react2.default.createElement(import_material2.Card, { sx: { flex: 1, width: "98%", alignSelf: "center", m: 1 } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.CardHeader, { title: /* @__PURE__ */ import_react2.default.createElement(import_material2.Stack, { direction: "row", alignItems: "center" }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { mr: 4 }, /* @__PURE__ */ import_react2.default.createElement("b", null, "Lines:"), " ", echoData.lines.length, " / ", echoConfig.maxLines), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { mr: 4 }, /* @__PURE__ */ import_react2.default.createElement("b", null, "Interval:"), " ", echoInstanceConfig.interval), /* @__PURE__ */ import_react2.default.createElement(import_material2.Typography, { mr: 4 }, /* @__PURE__ */ import_react2.default.createElement(import_icons_material2.Info, { fontSize: "small", sx: { mb: 0.25 } }), /* @__PURE__ */ import_react2.default.createElement("b", null, "\xA0Status:"), " ", echoData.paused ? "paused" : echoData.started ? "started" : "stopped")) }), /* @__PURE__ */ import_react2.default.createElement(import_material2.CardContent, null, /* @__PURE__ */ import_react2.default.createElement(import_material2.Box, { ref: echoBoxRef, sx: { display: "flex", flexDirection: "column", overflowY: "auto", overflowX: "hidden", width: "100%", flexGrow: 1, height: `calc(100vh - ${echoBoxTop}px - 35px)` } }, /* @__PURE__ */ import_react2.default.createElement(import_material2.Box, { sx: { flex: 1, overflowY: "auto", ml: 1, mr: 1 } }, formatContent())))));
173
+ };
174
+
175
+ // src/front/EchoChannel.ts
176
+ var EchoChannel = class {
177
+ constructor() {
178
+ this.setupVisible = false;
179
+ this.SetupDialog = EchoSetup;
180
+ this.TabContent = EchoTabContent;
181
+ this.channelId = "echo";
182
+ this.requirements = {
183
+ accessString: true,
184
+ clusterUrl: true,
185
+ clusterInfo: false,
186
+ exit: false,
187
+ frontChannels: false,
188
+ metrics: false,
189
+ notifier: true,
190
+ notifications: true,
191
+ setup: true,
192
+ settings: false,
193
+ palette: false,
194
+ userSettings: false,
195
+ webSocket: false
196
+ };
197
+ }
198
+ getScope() {
199
+ return import_kwirth_common.EInstanceConfigScope.NONE;
200
+ }
201
+ getChannelIcon() {
202
+ return EchoIcon;
203
+ }
204
+ getSetupVisibility() {
205
+ return this.setupVisible;
206
+ }
207
+ setSetupVisibility(visibility) {
208
+ this.setupVisible = visibility;
209
+ }
210
+ processChannelMessage(channelObject, wsEvent) {
211
+ const msg = JSON.parse(wsEvent.data);
212
+ const echoData = channelObject.data;
213
+ const echoConfig = channelObject.config;
214
+ switch (msg.type) {
215
+ case import_kwirth_common.EInstanceMessageType.DATA:
216
+ echoData.lines.push(msg.text);
217
+ while (echoData.lines.length > echoConfig.maxLines) echoData.lines.shift();
218
+ return { action: import_kwirth_common_front.EChannelRefreshAction.REFRESH };
219
+ case import_kwirth_common.EInstanceMessageType.SIGNAL: {
220
+ const instanceMessage = JSON.parse(wsEvent.data);
221
+ if (instanceMessage.flow === import_kwirth_common.EInstanceMessageFlow.RESPONSE && instanceMessage.action === import_kwirth_common.EInstanceMessageAction.START) {
222
+ channelObject.instanceId = instanceMessage.instance;
223
+ }
224
+ echoData.lines.push("*** " + msg.text + " ***");
225
+ while (echoData.lines.length > echoConfig.maxLines) echoData.lines.shift();
226
+ return { action: import_kwirth_common_front.EChannelRefreshAction.REFRESH };
227
+ }
228
+ default:
229
+ return { action: import_kwirth_common_front.EChannelRefreshAction.NONE };
230
+ }
231
+ }
232
+ async initChannel(channelObject) {
233
+ channelObject.instanceConfig = new EchoInstanceConfig();
234
+ channelObject.config = new EchoConfig();
235
+ channelObject.data = new EchoData();
236
+ const echoData = channelObject.data;
237
+ echoData.lines = [];
238
+ return false;
239
+ }
240
+ startChannel(channelObject) {
241
+ const echoData = channelObject.data;
242
+ echoData.lines = ["Start"];
243
+ echoData.paused = false;
244
+ echoData.started = true;
245
+ return true;
246
+ }
247
+ pauseChannel(channelObject) {
248
+ const echoData = channelObject.data;
249
+ echoData.paused = true;
250
+ return true;
251
+ }
252
+ continueChannel(channelObject) {
253
+ const echoData = channelObject.data;
254
+ echoData.paused = false;
255
+ return true;
256
+ }
257
+ stopChannel(channelObject) {
258
+ const echoData = channelObject.data;
259
+ echoData.lines.push("==========================================================================");
260
+ echoData.paused = false;
261
+ echoData.started = false;
262
+ return true;
263
+ }
264
+ socketDisconnected(_channelObject) {
265
+ return false;
266
+ }
267
+ socketReconnect(_channelObject) {
268
+ return false;
269
+ }
270
+ };
271
+
272
+ // src/front/index.ts
273
+ window.__kwirth_plugins__ = window.__kwirth_plugins__ || {};
274
+ window.__kwirth_plugins__["echo"] = EchoChannel;
275
+ })();
package/package.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "id": "echo",
3
+ "name": "@kwirthmagnify/kwirth-plugin-echo",
4
+ "displayName": "Echo",
5
+ "version": "0.1.0",
6
+ "description": "Echo channel plugin for Kwirth - sends periodic test messages from watched resources",
7
+ "icon": "Science"
8
+ }