-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.html
364 lines (336 loc) · 10.4 KB
/
Index.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h3 {
color: #333;
}
form {
margin-bottom: 20px;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
}
input[type="text"], input[type="number"] {
width: 100%;
padding: 8px;
box-sizing: border-box;
margin-top: 5px;
}
.button-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 20px;
}
input[type="button"] {
padding: 10px 20px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 5px;
cursor: pointer;
}
input[type="button"]:hover {
background-color: #0056b3;
}
.spinner {
display: none;
width: 24px;
height: 24px;
border: 4px solid lightgray;
border-top-color: blue;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-left: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.checklist {
list-style-type: none;
padding: 0;
margin-top: 20px;
}
.checklist li {
display: flex;
align-items: center;
padding: 10px 0;
font-weight: bold;
color: #555;
}
.checklist li.in-progress {
color: orange;
}
.checklist li.completed {
color: green;
}
.disabled {
pointer-events: none;
opacity: 0.6;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
padding-top: 60px;
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-height: 80vh;
overflow-y: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#modalMessage ol {
max-height: 60vh;
overflow-y: auto;
padding-left: 40px; /* Increased padding */
}
#modalMessage li {
margin-bottom: 5px;
padding-left: 10px; /* Added padding */
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<form id="imageForm">
<label for="folderUrl">Folder URL:</label>
<input type="text" id="folderUrl" name="folderUrl" placeholder="Enter Google Drive folder URL" required>
<label for="startRow">Start Row:</label>
<input type="number" id="startRow" name="startRow" placeholder="Enter start row number" required>
<label for="startCol">Start Column:</label>
<input type="number" id="startCol" name="startCol" placeholder="Enter start column number" required>
<div class="button-container">
<input type="button" id="submitButton" value="Insert Images" onclick="submitForm()">
<div id="mainSpinner" class="spinner"></div>
<input type="button" id="previewButton" value="Preview Sort Order" onclick="previewSortOrder()">
<div id="previewSpinner" class="spinner"></div>
</div>
</form>
<ul class="checklist">
<li id="step1">Initializing process</li>
<li id="step2">Collecting files from folder</li>
<li id="step3">Sorting files</li>
<li id="step4">Inserting images into sheet</li>
<li id="step5">Process completed</li>
</ul>
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<div id="modalMessage"></div>
</div>
</div>
<script>
function submitForm() {
const folderUrl = document.getElementById('folderUrl').value;
const startRow = document.getElementById('startRow').value;
const startCol = document.getElementById('startCol').value;
if (!folderUrl || !startRow || !startCol) {
alert('Please fill in all the fields.');
return;
}
disableForm(true);
showSpinner('mainSpinner');
document.getElementById('submitButton').value = 'Stop';
document.getElementById('submitButton').onclick = stopScript;
updateChecklist('step1', 'in-progress');
google.script.run
.withSuccessHandler(function() {
updateChecklist('step1', 'completed');
updateChecklist('step2', 'in-progress');
google.script.run
.withSuccessHandler(function() {
updateChecklist('step2', 'completed');
updateChecklist('step3', 'in-progress');
google.script.run
.withSuccessHandler(function() {
updateChecklist('step3', 'completed');
updateChecklist('step4', 'in-progress');
google.script.run
.withSuccessHandler(handleImageInsertionResult)
.withFailureHandler(handleImageInsertionError)
.handleImageInsertion();
})
.withFailureHandler(function(error) {
resetForm();
showModal('Failed to sort files: ' + error);
})
.sortFiles();
})
.withFailureHandler(function(error) {
resetForm();
showModal('Failed to collect files: ' + error);
})
.collectFiles(folderUrl);
})
.withFailureHandler(function(error) {
resetForm();
showModal('Failed to initialize process: ' + error);
})
.initializeProcess(folderUrl, startRow, startCol);
}
function handleImageInsertionResult(result) {
console.log("Image insertion result:", result);
if (result === 'completed') {
updateChecklist('step4', 'completed');
updateChecklist('step5', 'completed');
resetForm();
showModal('Process completed. All images inserted.');
} else if (result === 'continuing') {
updateChecklist('step4', 'in-progress');
showModal('Batch completed. Processing will continue automatically.');
} else if (result === 'stopped') {
resetForm();
showModal('Process stopped by user.');
} else {
resetForm();
showModal('An error occurred during image insertion: ' + result);
}
}
function handleImageInsertionError(error) {
console.error("Image insertion error:", error);
resetForm();
showModal('Failed to insert images: ' + error);
}
function previewSortOrder() {
const folderUrl = document.getElementById('folderUrl').value;
if (!folderUrl) {
alert('Please enter the folder URL.');
return;
}
showSpinner('previewSpinner');
google.script.run
.withSuccessHandler(function(sortedFiles) {
resetForm();
hideSpinner('previewSpinner');
displaySortedFiles(sortedFiles);
})
.withFailureHandler(function(error) {
resetForm();
hideSpinner('previewSpinner');
alert('Failed to preview sorted files: ' + error);
})
.collectAndSortFiles(folderUrl);
}
function displaySortedFiles(sortedFiles) {
const modal = document.getElementById('myModal');
const modalContent = document.querySelector('.modal-content');
const message = document.getElementById('modalMessage');
// Clear previous content
message.innerHTML = '';
// Add title
const title = document.createElement('h3');
title.textContent = 'Sorted Files';
message.appendChild(title);
// Add file list
const fileList = document.createElement('ol');
sortedFiles.forEach(file => {
const li = document.createElement('li');
li.textContent = file;
fileList.appendChild(li);
});
message.appendChild(fileList);
// Add file count
const count = document.createElement('p');
count.textContent = `Total files: ${sortedFiles.length}`;
message.appendChild(count);
modal.style.display = 'block';
}
function stopScript() {
google.script.run
.withSuccessHandler(function(result) {
if (result) {
resetForm();
showModal('Process stopped by user.');
}
})
.stopImageInsertion();
}
function resetForm() {
disableForm(false);
hideSpinner('mainSpinner');
resetChecklist();
document.getElementById('submitButton').value = 'Insert Images';
document.getElementById('submitButton').onclick = submitForm;
}
function updateChecklist(stepId, status) {
const stepElement = document.getElementById(stepId);
stepElement.classList.remove('in-progress', 'completed');
stepElement.classList.add(status);
}
function resetChecklist() {
const checklistItems = document.querySelectorAll('.checklist li');
checklistItems.forEach(item => {
item.classList.remove('in-progress', 'completed');
});
}
function disableForm(disable) {
const formElements = document.querySelectorAll('#imageForm input[type="text"], #imageForm input[type="number"]');
formElements.forEach(element => {
element.disabled = disable;
if (disable) {
element.classList.add('disabled');
} else {
element.classList.remove('disabled');
}
});
}
function showSpinner(spinnerId) {
document.getElementById(spinnerId).style.display = 'inline-block';
}
function hideSpinner(spinnerId) {
document.getElementById(spinnerId).style.display = 'none';
}
function showModal(message) {
const modal = document.getElementById('myModal');
const modalMessage = document.getElementById('modalMessage');
modalMessage.innerText = message;
modal.style.display = 'block';
}
function closeModal() {
const modal = document.getElementById('myModal');
modal.style.display = 'none';
}
window.onclick = function(event) {
const modal = document.getElementById('myModal');
if (event.target == modal) {
modal.style.display = 'none';
}
}
</script>
</body>
</html>