-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormItMCP_web.js
More file actions
78 lines (66 loc) · 3.29 KB
/
FormItMCP_web.js
File metadata and controls
78 lines (66 loc) · 3.29 KB
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
console.log("FormItMCP_web.js module starting to load...");
window.FormItMCP = window.FormItMCP || {};
let statusDiv = document.createElement('div');
statusDiv.style.padding = '10px';
/*** web/UI code - runs natively in the plugin process ***/
/*** note that FormItMCP_web.js runs on the FormIt side ***/
FormItMCP.initializeUI = function()
{
// create an overall container for all objects that comprise the "content" of the plugin
// everything except the footer
let contentContainer = document.createElement('div');
contentContainer.id = 'contentContainer';
contentContainer.className = 'contentContainer';
// this plugin doesn't have enough content to scroll
contentContainer.style.overflowY = 'hidden';
window.document.body.appendChild(contentContainer);
// create the header
contentContainer.appendChild(new FormIt.PluginUI.HeaderModule('FormIt MCP', 'Enable FormIt to be controlled by an MCP server').element);
// separator and space
contentContainer.appendChild(document.createElement('p'));
contentContainer.appendChild(document.createElement('hr'));
contentContainer.appendChild(document.createElement('p'));
// status - updated in the update function
contentContainer.appendChild(statusDiv);
contentContainer.appendChild(document.createElement('p'));
// basic body text (for now)
const staticTextDiv = contentContainer.appendChild(document.createElement('div'));
staticTextDiv.innerHTML = "This plugin will connect to a local MCP server automatically.<br><br>If needed, you can force a reconnect:";
// create the button to set the LCS on the selected face
contentContainer.appendChild(new FormIt.PluginUI.Button('Force Reconnect', () => {
FormItInterface.CallMethod("FormItMCP.initializeMCP", { })
}).element);
// create the footer
document.body.appendChild(new FormIt.PluginUI.FooterModule().element);
// add a listener for the current MCP server status
FormItInterface.SubscribeMessage("FormIt.Message.kFormItJSONMsg", function(msg)
{
// update the UI when the status changes
FormItMCP.updateUI(msg);
});
FormItInterface.CallMethod("FormItMCP.initializeMCP", { })
}
// update the status div
FormItMCP.updateUI = (currentStatus) => {
switch (currentStatus) {
case MCPPluginStatuses.connecting.id:
statusDiv.innerHTML = MCPPluginStatuses.connecting.message;
statusDiv.style.backgroundColor = MCPPluginStatuses.connecting.color;
break;
case MCPPluginStatuses.connected.id:
statusDiv.innerHTML = MCPPluginStatuses.connected.message;
statusDiv.style.backgroundColor = MCPPluginStatuses.connected.color;
break;
case MCPPluginStatuses.disconnected.id:
statusDiv.innerHTML = MCPPluginStatuses.disconnected.message;
statusDiv.style.backgroundColor = MCPPluginStatuses.disconnected.color;
break;
case MCPPluginStatuses.error.id:
statusDiv.innerHTML = MCPPluginStatuses.error.message;
statusDiv.style.backgroundColor = MCPPluginStatuses.error.color;
break;
default:
statusDiv.innerHTML = MCPPluginStatuses.unknown.message;
statusDiv.style.backgroundColor = MCPPluginStatuses.unknown.color;
}
}