forked from Placekey/placekey-googlesheets-addon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapColumns.html
343 lines (295 loc) · 16.4 KB
/
mapColumns.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
<!DOCTYPE html>
<html>
<head>
<base target="_top" />
<?!= include('Stylesheet'); ?>
<script>
function insert() {
// google.script.run.withSuccessHandler(google.script.host.close).setUserProperties(els);
}
</script>
</head>
<body>
<main class="p-20">
<div id="stillWorking" class="text-center">
<i class="spinner"></i>
</div>
<div id="emptySheet" style="display: none">
<p><strong>This Sheet looks empty.</strong><br />Fill with sample data?</p>
<a id="generate" onclick="insertSample()" class="btn-solid w-full mt-20">Fill with sample data</a>
</div>
<div id="mapTitle" style="display: none">
<h2 class="type-h5">Data Location:</h2>
<div class="form__group mt-10" style="width:100%">
<label id="labelsheets" for="sheets" class="form__label">Sheets</label>
<select name="sheets" id="sheets" onChange="changeSheet()" class="form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div style="
position: absolute;
right: 22px;
top: 22px;
height: 20px;
cursor: pointer;
width: 20px;
" onclick="refreshUpdateSheet()"><img src='https://www.svgrepo.com/show/37313/refresh.svg'></div>
<h2 class="type-h5 mt-20">Match the headers in your document to the fields below.</h2>
<div class="form__group mt-20">
<label for="location" class="form__label"> <strong>Location Name</strong> - e.g. Twin Peaks Petroleum </label>
<select id="location" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="street" class="form__label"> <strong>Street Address</strong> - e.g. 598 Portola Dr </label>
<select id="street" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="city" class="form__label"> <strong>City</strong> - e.g. San Fransisco </label>
<select id="city" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="region" class="form__label"> <strong>Region</strong> - e.g. California or CA </label>
<select id="region" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="postcode" class="form__label"> <strong>Postal Code</strong> - e.g. 94131 </label>
<select id="postcode" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="latitude" class="form__label"> <strong>Latitude</strong> - e.g. 37.7371 </label>
<select id="latitude" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="longitude" class="form__label"> <strong>Longitude</strong> - e.g. -122.44283 </label>
<select id="longitude" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group mt-20">
<label for="country" class="form__label"> <strong>Country</strong> - e.g. US </label>
<select id="country" class="selectCols form__control">
<option value="Sheet1">Sheet1</option>
<option value="Sheet1">Sheet1</option>
</select>
</div>
<div class="form__group text-12 mt-25">
<div class="flex items-center">
<input id="addressMatch" type="checkbox" name="addressMatch" value="addressMatch" class="form__control" />
<label for="addressMatch" class="ml-10"> Check for exact address matches only</label>
</div>
<div class="flex items-center mt-5">
<input id="nameMatch" type="checkbox" name="nameMatch" value="nameMatch" class="form__control" />
<label for="nameMatch" class="ml-10"> Check for exact name matches only</label>
</div>
<div class="flex items-center mt-5">
<input id="insertError" type="checkbox" name="insertError" value="insertError" class="form__control" />
<label for="insertError" class="ml-10"> Insert errors in new column</label>
</div>
<div class="flex items-center mt-5">
<input id="overwritePlacekey" type="checkbox" name="overwritePlacekey" value="overwritePlacekey" class="form__control" disabled />
<label for="overwritePlacekey" class="ml-10">Overwrite existing Placekey column</label>
</div>
</div>
<button id="generate" onclick="generateKeys()" class="btn-solid w-full mt-20">Generate Placekeys</button>
<!-- Point 4 -->
<div id="generateToast" style="font-style: italic; color: #484852; margin-top: 12px"></div>
</div>
<footer class="mt-20">
<div class="flex justify-between">
<a id="docs" href="https://docs.placekey.io/" target="_blank" class="cursor-pointer text-blue-dodger">View API Docs</a>
<a id="changeKey" onclick="google.script.run.changeKey()" class="cursor-pointer text-blue-dodger">Change
API Key</a>
</div>
<hr class="hr mt-15" />
<a href="https://www.placekey.io/" target="_blank" rel="noopener">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 81 23" width="80" height="25" class="ml-auto mt-20">
<path
d="M78.5 23h-76C1.1 23 0 21.9 0 20.5v-18C0 1.1 1.1 0 2.5 0h76C79.9 0 81 1.1 81 2.5v18c0 1.4-1.1 2.5-2.5 2.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.8-.6-.3-.1-.7-.2-1.1-.2z"
fill="#fff" />
</svg>
</a>
</footer>
</main>
<script>
document.addEventListener(
"DOMContentLoaded",
function() {
google.script.run.withSuccessHandler(getSheetsToast).getSheets();
// var inputKey = document.getElementById("storedKey").value;
// document.getElementById("key").value = inputKey;
},
false
);
function getSheetsToast(e) {
console.log(e);
document.getElementById("stillWorking").style.display = "none";
var select = document.getElementById("sheets");
var appendSelect = "";
for (var i = 0; i < e[1].length; i++) {
if (e[1][i] == e[0]) {
appendSelect += '<option value="' + e[1][i] + '" selected>' + e[1][i] + "</option>";
} else {
appendSelect += '<option value="' + e[1][i] + '">' + e[1][i] + "</option>";
}
}
select.innerHTML = appendSelect;
changeSheetToast(e[2]);
// google.script.run.withSuccessHandler(google.script.host.close).setUserProperties(els);
}
function changeSheet() {
// document.getElementById("overwritePlacekey").disabled = true;
document.getElementById("overwritePlacekey").checked = false;
var selectedSheet = document.getElementById("sheets").value;
console.log(selectedSheet);
google.script.run
.withSuccessHandler(changeSheetToast)
.changeSheet(selectedSheet);
}
function changeSheetToast(e) {
console.log('changeSheetToast : ' + e);
if (e == false) {
console.log("yes");
document.getElementById("emptySheet").style.display = "block";
document.getElementById("mapTitle").style.display = "none";
} else {
document.getElementById("mapTitle").style.display = "block";
document.getElementById("emptySheet").style.display = "none";
var columnsToAppend = '<option value="--">--</option>';
for (var i = 0; i < e[0].length; i++) {
if (e[0][i] != "") {
columnsToAppend += ' <option value="' + e[0][i] + '">' + e[0][i] + "</option>";
if (e[0][i] == "Placekey") {
document.getElementById("overwritePlacekey").disabled = false;
document.getElementById("overwritePlacekey").checked = true;
}
}
}
var selectCols = document.getElementsByClassName("selectCols");
for (var j = 0; j < selectCols.length; j++) {
selectCols[j].innerHTML = columnsToAppend;
}
}
}
function generateKeys() {
document.getElementById("generate").disabled = true;
var selectCols = document.getElementsByClassName("selectCols");
var address = [];
for (var j = 0; j < selectCols.length; j++) {
address.push(selectCols[j].value);
}
if ((address[1] == "--" || address[3] == "--") && (address[5] == "--" || address[6] == "--") && (address[1] == "--" || address[2] == "--" || address[4] == "--")) {
google.script.run.Alert("Please select either latitude and longitude or street address and state");
// document.getElementById("didNotSelected").style.display = 'block';
document.getElementById("generate").disabled = false;
return false;
}
for (var k = 0; k < address.length; k++) {
if (address[k] != "--" && address[k] != true && address[k] != false) {
var count = countInArray(address, address[k]);
console.log(count);
if (count > 1) {
google.script.run.Alert("The same column is mapped to more than one field. Please map only one column per field.");
document.getElementById("generate").disabled = false;
return false;
}
}
}
document.getElementById("generateToast").innerHTML = "Working...";
setTimeout(function() {
document.getElementById("generateToast").innerHTML = "Please wait...";
}, 1000);
var addressMatch = document.getElementById("addressMatch").checked;
var nameMatch = document.getElementById("nameMatch").checked;
var overWrite = document.getElementById("overwritePlacekey").checked;
var insertError = document.getElementById("insertError").checked;
address.push(addressMatch);
address.push(nameMatch);
address.push(overWrite);
address.push(insertError);
console.log(address);
google.script.run
.withFailureHandler(failedAPI)
.withSuccessHandler(generateKeysToast)
.generateKeys(address);
}
function failedAPI() {
document.getElementById("generateToast").innerHTML = "Something went wrong. Please try again!";
document.getElementById("generate").disabled = false;
}
function generateKeysToast(e) {
document.getElementById("overwritePlacekey").disabled = false;
document.getElementById("overwritePlacekey").checked = true;
document.getElementById("generateToast").innerHTML = "Done! Generated " + e + " Placekeys.";
setTimeout(function() {
document.getElementById("generateToast").innerHTML = "";
}, 5000);
document.getElementById("generate").disabled = false;
console.log("sent");
}
function countInArray(array, what) {
var count = 0;
for (var i = 0; i < array.length; i++) {
if (array[i] === what) {
count++;
}
}
return count;
}
function insertSample() {
google.script.run.withSuccessHandler(changeSheetToast).insertSample();
}
function refreshUpdateSheet() {
console.log('refreshing')
google.script.run.withSuccessHandler(refreshUpdateSheetToast).refreshUpdateSheet();
var select = document.getElementById('sheets');
document.getElementById("labelsheets").style.display = 'none'
select.disabled = true;
select.style.background = '#dedede'
select.style.color = '#9a9a9a';
}
function refreshUpdateSheetToast(e) {
console.log(e)
var select = document.getElementById('sheets')
document.getElementById("labelsheets").style.display = 'block'
select.disabled = false;
select.style.background = ''
select.style.color = '';
console.log('updated')
// var e = value[2]
var select = document.getElementById("sheets");
var appendSelect = "";
for (var i = 0; i < e[1].length; i++) {
if (e[1][i] == e[0]) {
appendSelect += '<option value="' + e[1][i] + '" selected>' + e[1][i] + "</option>";
} else {
appendSelect += '<option value="' + e[1][i] + '">' + e[1][i] + "</option>";
}
}
select.innerHTML = appendSelect;
changeSheetToast(e[2]);
}
</script>
</body>
</html>