Juna190825 commited on
Commit
97860ae
·
verified ·
1 Parent(s): 8a2d2c4

Create proxy/templates/index.html

Browse files
Files changed (1) hide show
  1. proxy/templates/index.html +136 -0
proxy/templates/index.html ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>ConlluEditor Online</title>
6
+ <style>
7
+ body {
8
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
9
+ margin: 1.5rem;
10
+ }
11
+ #dropzone {
12
+ border: 2px dashed #888;
13
+ border-radius: 8px;
14
+ padding: 20px;
15
+ text-align: center;
16
+ color: #555;
17
+ cursor: pointer;
18
+ margin-bottom: 1rem;
19
+ }
20
+ #dropzone.dragover {
21
+ border-color: #007bff;
22
+ background-color: #f0f8ff;
23
+ }
24
+ #fileList {
25
+ margin-bottom: 1rem;
26
+ }
27
+ iframe {
28
+ width: 100%;
29
+ height: 70vh;
30
+ border: 1px solid #ccc;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <h1>ConlluEditor Online</h1>
36
+
37
+ <!-- Drag-and-drop upload panel -->
38
+ <div id="dropzone">
39
+ <p>Drag & drop a .conllu file here, or click to select</p>
40
+ <input id="fileInput" type="file" accept=".conllu" style="display:none;">
41
+ </div>
42
+
43
+ <!-- File list + download -->
44
+ <div id="fileList">
45
+ <label for="fileSelect"><strong>Available files:</strong></label>
46
+ <select id="fileSelect"></select>
47
+ <button id="openBtn">Open in editor</button>
48
+ <button id="downloadBtn">Download</button>
49
+ </div>
50
+
51
+ <!-- Embedded ConlluEditor -->
52
+ <iframe id="editorFrame" src="/editor"></iframe>
53
+
54
+ <script>
55
+ const dropzone = document.getElementById("dropzone");
56
+ const fileInput = document.getElementById("fileInput");
57
+ const fileSelect = document.getElementById("fileSelect");
58
+ const openBtn = document.getElementById("openBtn");
59
+ const downloadBtn = document.getElementById("downloadBtn");
60
+ const editorFrame = document.getElementById("editorFrame");
61
+
62
+ // Drag & drop behavior
63
+ dropzone.addEventListener("click", () => fileInput.click());
64
+
65
+ dropzone.addEventListener("dragover", (e) => {
66
+ e.preventDefault();
67
+ dropzone.classList.add("dragover");
68
+ });
69
+
70
+ dropzone.addEventListener("dragleave", (e) => {
71
+ e.preventDefault();
72
+ dropzone.classList.remove("dragover");
73
+ });
74
+
75
+ dropzone.addEventListener("drop", (e) => {
76
+ e.preventDefault();
77
+ dropzone.classList.remove("dragover");
78
+ const files = e.dataTransfer.files;
79
+ if (files.length > 0) uploadFile(files[0]);
80
+ });
81
+
82
+ fileInput.addEventListener("change", () => {
83
+ if (fileInput.files.length > 0) uploadFile(fileInput.files[0]);
84
+ });
85
+
86
+ function uploadFile(file) {
87
+ if (!file.name.toLowerCase().endsWith(".conllu")) {
88
+ alert("Please upload a .conllu file");
89
+ return;
90
+ }
91
+ const formData = new FormData();
92
+ formData.append("file", file);
93
+ fetch("/api/upload", {
94
+ method: "POST",
95
+ body: formData
96
+ }).then(r => {
97
+ if (!r.ok) throw new Error("Upload failed");
98
+ return r.text();
99
+ }).then(() => {
100
+ loadFiles();
101
+ }).catch(err => alert(err));
102
+ }
103
+
104
+ function loadFiles() {
105
+ fetch("/api/files")
106
+ .then(r => r.json())
107
+ .then(files => {
108
+ fileSelect.innerHTML = "";
109
+ files.forEach(f => {
110
+ const opt = document.createElement("option");
111
+ opt.value = f;
112
+ opt.textContent = f;
113
+ fileSelect.appendChild(opt);
114
+ });
115
+ });
116
+ }
117
+
118
+ openBtn.addEventListener("click", () => {
119
+ const f = fileSelect.value;
120
+ if (!f) return;
121
+ // Assuming ConlluEditor can take a filename via query or internal logic.
122
+ // If not, you’ll adapt this to whatever mechanism it uses.
123
+ editorFrame.src = "/editor?file=" + encodeURIComponent(f);
124
+ });
125
+
126
+ downloadBtn.addEventListener("click", () => {
127
+ const f = fileSelect.value;
128
+ if (!f) return;
129
+ window.location.href = "/api/download/" + encodeURIComponent(f);
130
+ });
131
+
132
+ // Initial load
133
+ loadFiles();
134
+ </script>
135
+ </body>
136
+ </html>