-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.gs.txt
More file actions
421 lines (363 loc) · 13.7 KB
/
Copy pathCode.gs.txt
File metadata and controls
421 lines (363 loc) · 13.7 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
const sheet = SpreadsheetApp.getActiveSheet();
const appTable = { hdrRow: 1, entryRow: 2, strtRow: 3, numCols: 9, strtCol: "B", cmpnyCol: "B", dateCol: "C", posCol: "D", typeCol: "E",
seasonCol: "F", idCol: "G", stsCol: "H", linkCol: "I", insCol: "J" };
const colors = { lblRow: 1, clrRow: 2, updCol: "K", hdrClrCol: "L", insClrCol: "M", tblClrCol: "N" , errClrCol: "O", rejClrCol: "P",
assClrCol: "Q", intClrCol: "R", offClrCol: "S" };
const shpeTable = { hdrRow: 1, strtRow: 2, numCols: 3, cmpnyCol: "A", linkCol: "B", intCol: "C" };
const white = '#ffffff';
const darkGrnOne = '#6aa84f';
const darkRedOne = '#cc0000';
function colToNum(col)
{
var num = 0;
var offset = 1;
for (let i = col.length - 1; i >= 0; i--)
{
var charNum = col[i].charCodeAt(0) - 'A'.charCodeAt(0) + 1;
if (i < col.length - 1)
offset *= 26;
num += charNum * offset;
}
return num;
}
const strtCol = colToNum(appTable.strtCol);
const cmpnyCol = colToNum(appTable.cmpnyCol);
const dateCol = colToNum(appTable.dateCol);
const posCol = colToNum(appTable.posCol);
const typeCol = colToNum(appTable.typeCol);
const seasonCol = colToNum(appTable.seasonCol);
const idCol = colToNum(appTable.idCol);
const stsCol = colToNum(appTable.stsCol);
const linkCol = colToNum(appTable.linkCol);
const insCol = colToNum(appTable.insCol);
const updCol = colToNum(colors.updCol);
const shpeCmpnyCol = colToNum(shpeTable.cmpnyCol);
const shpeLinkCol = colToNum(shpeTable.linkCol);
const shpeIntCol = colToNum(shpeTable.intCol);
const hdrClr = sheet.getRange(colors.clrRow, colToNum(colors.hdrClrCol)).getBackground();
const insClr = sheet.getRange(colors.clrRow, colToNum(colors.insClrCol)).getBackground();
const tblClr = sheet.getRange(colors.clrRow, colToNum(colors.tblClrCol)).getBackground();
const errClr = sheet.getRange(colors.clrRow, colToNum(colors.errClrCol)).getBackground();
const rejClr = sheet.getRange(colors.clrRow, colToNum(colors.rejClrCol)).getBackground();
const assClr = sheet.getRange(colors.clrRow, colToNum(colors.assClrCol)).getBackground();
const intClr = sheet.getRange(colors.clrRow, colToNum(colors.intClrCol)).getBackground();
const offClr = sheet.getRange(colors.clrRow, colToNum(colors.offClrCol)).getBackground();
function deleteEmptyRows()
{
var rows = sheet.getRange(appTable.strtRow, strtCol, sheet.getLastRow() - 1, appTable.numCols - 1).getValues();
if (rows.length == 1)
return false;
for (let row = rows.length - 1; row >= 0; row--)
if (sheet.getRange(row + appTable.strtRow, strtCol).getBackground() != '#ffffff')
{
var isEmpty = true;
var cmpnyFlag = false;
for (let col = 0; col < rows[row].length; col++)
if (rows[row][col] != "")
{
isEmpty = false;
break;
}
else if (col == cmpnyCol - strtCol)
{
cmpnyFlag = true;
}
if (isEmpty && !(row == 0 && sheet.getRange(appTable.strtRow + 1, strtCol).getBackground() == white))
{
sheet.deleteRow(row + appTable.strtRow);
}
else if (isEmpty == false && cmpnyFlag)
{
sheet.getRange(row + appTable.strtRow, cmpnyCol).setValue("Please insert a company");
sheet.getRange(row + appTable.strtRow, cmpnyCol).setBackground(errClr);
}
}
return true;
}
function checkColors()
{
sheet.getRange(appTable.hdrRow, strtCol, 1, appTable.numCols - 1).setBackground(hdrClr);
sheet.getRange(appTable.entryRow, strtCol, 1, appTable.numCols - 1).setBackground(insClr);
var status = sheet.getRange(appTable.strtRow, stsCol, sheet.getLastRow() - 1).getValues().flat();
for (let row = 0; row < status.length; row++)
{
if (status.length > 1 && row == status.length - 1)
break;
if (status[row].toLowerCase() == "interviewed")
{
sheet.getRange(row + appTable.strtRow, strtCol, 1, appTable.numCols - 1).setBackground(intClr);
}
else if (status[row].toLowerCase() == "assessed")
{
sheet.getRange(row + appTable.strtRow, strtCol, 1, appTable.numCols - 1).setBackground(assClr);
}
else if (status[row].toLowerCase() == "rejected")
{
sheet.getRange(row + appTable.strtRow, strtCol, 1, appTable.numCols - 1).setBackground(rejClr);
}
else if (status[row].toLowerCase() == "offered")
{
sheet.getRange(row + appTable.strtRow, strtCol, 1, appTable.numCols - 1).setBackground(offClr);
}
else
{
sheet.getRange(row + appTable.strtRow, strtCol, 1, appTable.numCols - 1).setBackground(tblClr);
if (status[row].toLowerCase() == "not applied!")
sheet.getRange(row + appTable.strtRow, stsCol).setBackground(errClr);
}
}
}
function findInsertIndex(company, companies, date, dates, position, positions)
{
// Find insertion index in column A
let idx = 0;
for (; idx < companies.length; idx++)
if (company.toLowerCase() <= companies[idx].toLowerCase() || companies[idx] == "")
break;
var ipMonth, ipDay, ipYear, month, day, year;
if (date != "")
{
ipMonth = date[0];
ipDay = date[1];
ipYear = date[2];
}
while (idx < companies.length && company.toLowerCase() == companies[idx].toLowerCase() && date != "")
{
if (dates[idx] == "")
{
idx++;
continue;
}
var timeZone = dates[idx].toString().split(" ")[5];
var mdy = Utilities.formatDate(dates[idx], timeZone, "MM/dd/yyyy").split("/");
month = parseInt(mdy[0]);
day = parseInt(mdy[1]);
year = parseInt(mdy[2]);
if (ipYear == year)
{
if (ipMonth == month)
{
if (ipDay >= day)
{
break;
}
else
{
idx++;
continue;
}
}
else if (ipMonth > month)
{
break;
}
else
{
idx++;
continue;
}
}
else if (ipYear > year)
{
break;
}
else
{
idx++;
continue;
}
}
while (idx < companies.length && company.toLowerCase() == companies[idx].toLowerCase() && (date == "" ? (date == dates[idx]): (ipYear == year &&
ipMonth == month && ipDay == day)))
{
if (dates[idx+1] != "")
{
var timeZone = dates[idx+1].toString().split(" ")[5];
var mdy = Utilities.formatDate(dates[idx+1], timeZone, "MM/dd/yyyy").split("/");
month = parseInt(mdy[0]);
day = parseInt(mdy[1]);
year = parseInt(mdy[2]);
}
if (position.toLowerCase() <= positions[idx].toLowerCase())
break;
else
idx++;
}
return idx;
}
function addAppInfo(appInfo)
{
var companies = sheet.getRange(appTable.strtRow, cmpnyCol, sheet.getLastRow() - 1).getValues().flat();
var dates = sheet.getRange(appTable.strtRow, dateCol, sheet.getLastRow() - 1).getValues().flat();
var positions = sheet.getRange(appTable.strtRow, posCol, sheet.getLastRow() - 1).getValues().flat();
var insRow = findInsertIndex(appInfo[cmpnyCol-strtCol], companies, appInfo[dateCol-strtCol], dates, appInfo[posCol-strtCol], positions) +
appTable.strtRow;
var insRange = sheet.getRange(insRow, strtCol, 1, appTable.numCols - 1);
if (appInfo[dateCol-strtCol] != "")
appInfo[dateCol-strtCol] = appInfo[dateCol-strtCol].join("/");
if (insRow == appTable.strtRow)
{
if (sheet.getRange(appTable.strtRow, cmpnyCol).getValue() != "")
sheet.insertRows(insRow);
if (appInfo[stsCol-strtCol].toLowerCase() == "interviewed")
insRange.setBackground(intClr);
else if (appInfo[stsCol-strtCol].toLowerCase() == "rejected")
insRange.setBackground(rejClr);
else if (appInfo[stsCol-strtCol].toLowerCase() == "offered")
insRange.setBackground(offClr);
else
insRange.setBackground(tblClr);
insRange.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
insRange.setHorizontalAlignment("center");
insRange.setValues([Object.values(appInfo)]);
}
else
{
sheet.insertRows(insRow);
if (appInfo[stsCol-strtCol].toLowerCase() == "interviewed")
insRange.setBackground(intClr);
else if (appInfo[stsCol-strtCol].toLowerCase() == "rejected")
insRange.setBackground(rejClr);
else if (appInfo[stsCol-strtCol].toLowerCase() == "offered")
insRange.setBackground(offClr);
else
insRange.setBackground(tblClr);
insRange.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID);
insRange.setHorizontalAlignment("center");
insRange.setValues([Object.values(appInfo)]);
}
var stsCell = sheet.getRange(insRow, stsCol);
if (appInfo[dateCol-strtCol] == "")
{
stsCell.setValue("Not Applied!");
stsCell.setBackground(errClr);
}
else if (appInfo[stsCol-strtCol] == "Not Applied!")
{
stsCell.setValue("");
}
}
function onEdit(e)
{
var editRow = e.range.getRow();
var editCol = e.range.getColumn();
var whiteFlag = (sheet.getRange(editRow, editCol).getBackground() != white);
var moreThanOneFlag = true;
if (sheet.getName() == "Companies" && editRow != shpeTable.hdrRow && editCol == shpeIntCol)
{
var shpeIntCell = sheet.getRange(editRow, shpeIntCol);
var val = shpeIntCell.getValue().toLowerCase();
if (val.indexOf("y") != -1)
{
shpeIntCell.setHorizontalAlignment("center");
shpeIntCell.setValue("Yes");
shpeIntCell.setBackground(darkGrnOne);
}
else if (val.indexOf("n") != -1)
{
shpeIntCell.setHorizontalAlignment("center");
shpeIntCell.setValue("No");
shpeIntCell.setBackground(darkRedOne);
}
}
if (sheet.getName() != "Companies" && whiteFlag)
moreThanOneFlag = deleteEmptyRows();
whiteFlag = (sheet.getRange(editRow, editCol).getBackground() != white);
if (sheet.getName() != "Companies" && editRow == colors.clrRow && editCol == updCol)
{
var cell = sheet.getRange(editRow, updCol);
if (cell.getValue().toLowerCase() != "update" && cell.getValue() != "")
{
sheet.getRange(colors.lblRow, updCol).setValue("Please type \"update\"");
return;
}
else if (cell.getValue().toLowerCase() == "update")
{
checkColors();
}
cell.setValue("");
cell.setHorizontalAlignment("center");
sheet.getRange(colors.lblRow, editCol).setValue("Type \"update\" to change colors \u2193");
}
if (sheet.getName() != "Companies" && editRow == appTable.entryRow && (editCol == insCol || editCol == cmpnyCol || editCol == dateCol))
{
if (sheet.getRange(editRow, insCol).getValue().toLowerCase() != "insert")
{
if (sheet.getRange(editRow, insCol).getValue().toLowerCase() != "")
sheet.getRange(appTable.hdrRow, insCol).setValue("Please type \"insert\"");
return;
}
var appInfo = sheet.getRange(editRow, strtCol, 1, appTable.numCols - 1).getValues().flat();
if (appInfo[cmpnyCol-strtCol] == "")
{
sheet.getRange(editRow, cmpnyCol).setValue("Please insert a company");
sheet.getRange(editRow, cmpnyCol).setBackground(errClr);
return;
}
if (appInfo[dateCol-strtCol] instanceof Object)
{
var timeZone = appInfo[dateCol-strtCol].toString().split("")[5];
appInfo[dateCol-strtCol] = Utilities.formatDate(appInfo[dateCol-strtCol], timeZone, "MM/dd/yyyy").split("/");
}
else if (appInfo[dateCol-strtCol] == "")
{
sheet.getRange(editRow, dateCol).setValue("Please insert a date");
sheet.getRange(editRow, dateCol).setBackground(errClr);
return;
}
for (let col = insCol; col >= strtCol; col--)
sheet.getRange(editRow, col).setValue("");
sheet.getRange(editRow, strtCol, 1, appTable.numCols - 1).setBackground(insClr);
sheet.getRange(editRow, strtCol, 1, appTable.numCols - 1).setBorder(true, true, true, true, true, true, "black",
SpreadsheetApp.BorderStyle.SOLID);
sheet.getRange(editRow, strtCol, 1, appTable.numCols).setHorizontalAlignment("center");
sheet.getRange(editRow, strtCol, 1, appTable.numCols - 1).setFontFamily("Arial");
addAppInfo(appInfo);
sheet.getRange(appTable.hdrRow, insCol).setValue("Type \"insert\" when ready \u2193");
}
else if (sheet.getName() != "Companies" && whiteFlag && moreThanOneFlag && editRow != appTable.hdrRow && editRow != appTable.entryRow &&
(editCol == cmpnyCol || editCol == dateCol || editCol == posCol))
{
var appInfo = sheet.getRange(editRow, colToNum(appTable.strtCol), 1, appTable.numCols - 1).getValues().flat();
if (appInfo[cmpnyCol-strtCol] == "")
{
sheet.getRange(editRow, cmpnyCol).setValue("Please insert a company");
sheet.getRange(editRow, cmpnyCol).setBackground(errClr)
return;
}
else if (appInfo[cmpnyCol-strtCol] == "Please insert a company")
{
return;
}
if (appInfo[dateCol-strtCol] instanceof Object)
{
var timeZone = appInfo[dateCol-strtCol].toString().split("")[5];
appInfo[dateCol-strtCol] = Utilities.formatDate(appInfo[dateCol-strtCol], timeZone, "MM/dd/yyyy").split("/");
}
else if (appInfo[dateCol-strtCol] == "")
{
sheet.getRange(editRow, dateCol).setValue("Please insert a date");
sheet.getRange(editRow, dateCol).setBackground(errClr);
return;
}
sheet.deleteRow(editRow);
addAppInfo(appInfo);
}
else if (sheet.getName() != "Companies" && whiteFlag && editRow != appTable.hdrRow && editRow != appTable.entryRow && editCol == stsCol)
{
var rowRange = sheet.getRange(editRow, strtCol, 1, appTable.numCols - 1);
var status = sheet.getRange(editRow, stsCol).getValue().toLowerCase();
if (status == "interviewed")
rowRange.setBackground(intClr);
else if (status == "assessed")
rowRange.setBackground(assClr);
else if (status == "rejected")
rowRange.setBackground(rejClr);
else if (status == "offered")
rowRange.setBackground(offClr);
else if (status.indexOf("not applied") != -1)
sheet.getRange(editRow, stsCol).setBackground(errClr);
else
rowRange.setBackground(tblClr);
}
}