index.html 5.82 KB
Newer Older
pythongosssss's avatar
pythongosssss committed
1
2
<!DOCTYPE html>
<html lang="en">
pythongosssss's avatar
pythongosssss committed
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
	<head>
		<link rel="stylesheet" type="text/css" href="lib/litegraph.css" />
		<link rel="stylesheet" type="text/css" href="style.css" />
		<script type="text/javascript" src="lib/litegraph.core.js"></script>

		<script type="module">
			import { app } from "/scripts/app.js";
			await app.setup();
			window.app = app;
			window.graph = app.graph;
		</script>
	</head>
	<body>
		<script>
			return;

			let runningNodeId = null;
			let progress = null;
			let clientId = null;

			function clearGraph() {
				graph.clear();
			}

			function loadTxt2Img() {
				loadGraphData(graph, default_graph);
			}

			function saveGraph() {
				var json = JSON.stringify(graph.serialize()); // convert the data to a JSON string
				var blob = new Blob([json], { type: "application/json" });
				var url = URL.createObjectURL(blob);
				var a = document.createElement("a");
				a.style = "display: none";
				a.href = url;
				a.download = "workflow.json";
				document.body.appendChild(a);
				a.click();
				setTimeout(function () {
					document.body.removeChild(a);
					window.URL.revokeObjectURL(url);
				}, 0);
			}

			var input = document.createElement("input");
			input.setAttribute("type", "file");
			input.setAttribute("accept", ".json,image/png");
			input.style.display = "none";
			document.body.appendChild(input);

			input.addEventListener("change", function () {
				var file = input.files[0];
				prompt_file_load(file);
			});

			function loadGraph() {
				input.click();
			}

			document.addEventListener("paste", (e) => {
				let data = (e.clipboardData || window.clipboardData).getData("text/plain");
				console.log(data);

				try {
					data = data.slice(data.indexOf("{"));
					j = JSON.parse(data);
				} catch (err) {
					data = data.slice(data.indexOf("workflow\n"));
					data = data.slice(data.indexOf("{"));
					j = JSON.parse(data);
				}

				if (Object.hasOwn(j, "version") && Object.hasOwn(j, "nodes") && Object.hasOwn(j, "extra")) {
					loadGraphData(graph, j);
				}
			});

			function deleteQueueElement(type, delete_id, then) {
				fetch("/" + type, {
					method: "POST",
					headers: {
						"Content-Type": "application/json",
					},
					body: JSON.stringify({ delete: [delete_id] }),
				})
					.then((data) => {
						console.log(data);
						then();
					})
					.catch((error) => console.error(error));
			}

			function loadQueue() {
				loadItems("queue");
			}
			function loadHistory() {
				loadItems("history");
			}
			function loadItems(type) {
				fetch("/" + type)
					.then((response) => response.json())
					.then((data) => {
						var queue_div = document.getElementById(type + "button-content");
						queue_div.style.display = "block";
						var see_queue_button = document.getElementById("see" + type + "button");
						let old_w = see_queue_button.style.width;
						see_queue_button.innerHTML = "Close";

						let runningcontents;
						if (type === "queue") {
							runningcontents = document.getElementById("runningcontents");
							runningcontents.innerHTML = "";
						}
						let queuecontents = document.getElementById(type + "contents");
						queuecontents.innerHTML = "";
						function append_to_list(list_element, append_to_element, append_delete, state) {
							let number = list_element[0];
							let id = list_element[1];
							let prompt = list_element[2];
							let workflow = list_element[3].extra_pnginfo.workflow;
							let a = document.createElement("a");
							a.innerHTML = number + ": ";
							append_to_element.appendChild(a);
							let button = document.createElement("button");
							button.innerHTML = "Load";
							button.style.fontSize = "10px";
							button.workflow = workflow;
							button.onclick = function (event) {
								loadGraphData(graph, event.target.workflow);
								if (state) {
									nodeOutputs = state;
								}
							};

							append_to_element.appendChild(button);
							if (append_delete) {
								let button = document.createElement("button");
								button.innerHTML = "Delete";
								button.style.fontSize = "10px";
								button.delete_id = id;
								button.onclick = function (event) {
									deleteQueueElement(type, event.target.delete_id, () => loadItems(type));
								};
								append_to_element.appendChild(button);
							}
							append_to_element.appendChild(document.createElement("br"));
						}

						if (runningcontents) {
							for (let x in data.queue_running) {
								append_to_list(data.queue_running[x], runningcontents, false);
							}
						}

						let items;
						if (type === "queue") {
							items = data.queue_pending;
						} else {
							items = Object.values(data);
						}
						items.sort((a, b) => a[0] - b[0]);
						for (let i of items) {
							append_to_list(type === "queue" ? i : i.prompt, queuecontents, true, i.outputs);
						}
					})
					.catch((response) => {
						console.log(response);
					});
			}

			function seeItems(type) {
				var queue_div = document.getElementById(type + "button-content");
				if (queue_div.style.display == "block") {
					closeItems(type);
				} else {
					loadItems(type);
				}
			}

			function seeQueue() {
				closeItems("history");
				seeItems("queue");
			}

			function seeHistory() {
				closeItems("queue");
				seeItems("history");
			}

			function closeItems(type) {
				var queue_div = document.getElementById(type + "button-content");
				queue_div.style.display = "none";
				var see_queue_button = document.getElementById("see" + type + "button");
				see_queue_button.innerHTML = "See " + type[0].toUpperCase() + type.substr(1);
			}

			function clearItems(type) {
				fetch("/" + type, {
					method: "POST",
					headers: {
						"Content-Type": "application/json",
					},
					body: JSON.stringify({ clear: true }),
				})
					.then((data) => {
						loadItems(type);
					})
					.catch((error) => console.error(error));
			}
		</script>
	</body>
pythongosssss's avatar
pythongosssss committed
214
</html>