-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
475 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function onEdit(e) { | ||
var ss = SpreadsheetApp.getActiveSpreadsheet(); | ||
var sheet = ss.getActiveSheet(); | ||
if (sheet.getName() != "Sheet1") { | ||
return; | ||
} | ||
|
||
var activeCell = ss.getActiveCell(); | ||
var columnNames = ["Related Department", "Language"]; | ||
var columnName = sheet.getRange(1, activeCell.getColumn()).getValue(); | ||
var pattern = /^Contributor Relator \d+$/; | ||
if (!columnNames.includes(columnName) && !pattern.test(columnName)) { | ||
return; | ||
} | ||
|
||
var delimiter = ' ; '; | ||
var newValue = e.value; | ||
var oldValue = e.oldValue; | ||
if (!newValue) { | ||
activeCell.setValue(""); | ||
} | ||
else { | ||
if (!oldValue) { | ||
activeCell.setValue(newValue); | ||
} else { | ||
activeCell.setValue(oldValue + delimiter + newValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"timeZone": "America/New_York", | ||
"dependencies": {}, | ||
"exceptionLogging": "STACKDRIVER", | ||
"runtimeVersion": "V8", | ||
"oauthScopes": [ | ||
"https://www.googleapis.com/auth/userinfo.email", | ||
"https://www.googleapis.com/auth/spreadsheets.currentonly", | ||
"https://www.googleapis.com/auth/script.external_request", | ||
"https://www.googleapis.com/auth/script.container.ui" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function onOpen() { | ||
var ui = SpreadsheetApp.getUi(); | ||
ui.createMenu('Lehigh Preserve') | ||
.addItem('Check My Work', 'sendSheetData') | ||
.addToUi(); | ||
} | ||
|
||
function sendSheetData() { | ||
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | ||
var data = sheet.getDataRange().getValues(); | ||
for (var i = 0; i < data.length; i++) { | ||
for (var j = 0; j < data[i].length; j++) { | ||
data[i][j] = data[i][j].toString(); | ||
} | ||
} | ||
var payload = JSON.stringify(data); | ||
var url = 'https://preserve.lehigh.edu/workbench/check'; | ||
const oauthToken = ScriptApp.getIdentityToken(); | ||
var options = { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Bearer ' + oauthToken | ||
}, | ||
contentType: 'application/json', | ||
payload: payload | ||
}; | ||
|
||
var lastRow = sheet.getLastRow(); | ||
var lastColumn = sheet.getLastColumn(); | ||
var range = sheet.getRange(2, 1, lastRow - 1, lastColumn); // A2 to last cell | ||
range.setBackground(null); | ||
range.clearNote(); | ||
|
||
var response = UrlFetchApp.fetch(url, options); | ||
var t = response.getContentText() | ||
if (t.length == 2) { | ||
SpreadsheetApp.getUi().alert('Looks good! 🚀'); | ||
return; | ||
} | ||
var result = JSON.parse(t); | ||
displayErrors(result); | ||
} | ||
|
||
function displayErrors(e) { | ||
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | ||
|
||
var count = 0; | ||
for (var cell in e) { | ||
var error = e[cell]; | ||
sheet.getRange(cell).setBackground('red').setNote(error); | ||
count += 1; | ||
} | ||
|
||
SpreadsheetApp.getUi().alert('Found ' + count + ' errors highlighted in the sheet.'); | ||
} |
Oops, something went wrong.