-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from coderbunker/issue9-spreadsheet-calendar
issue #9: combine spreadsheet timesheet and calendar sync code
- Loading branch information
Showing
6 changed files
with
80 additions
and
21 deletions.
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
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,61 @@ | ||
function snapshotAllCalendarOfSpreadsheetTrigger() { | ||
snapshotAllCalendarOfSpreadsheet(getActiveSpreadsheet()); | ||
} | ||
|
||
function snapshotAllCalendarOfSpreadsheet(spreadsheet) { | ||
const sheet = spreadsheet.getSheetByName('Balance'); | ||
const mapping = getHeaderMapping(sheet); | ||
const accounts = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getDisplayValues(); | ||
const entries = convertToEntries(accounts, mapping); | ||
const responses = entries.map(function(entry) { | ||
Logger.log(entry.resource); | ||
Logger.log(entry.fullname); | ||
if(!entry.calendar) { | ||
Logger.log('No calendar associated to %s', entry.resource); | ||
return null; | ||
} | ||
const calendar = CalendarApp.getCalendarById(entry.calendarid); | ||
if(!calendar) { | ||
Logger.log('not a valid id: %s', entry.calendarid); | ||
return null; | ||
} | ||
return snapshotCalendar(calendar); | ||
}); | ||
Logger.log(responses); | ||
} | ||
|
||
function snapshotCalendar(calendar) { | ||
const exportData = exportCalendar(calendar); | ||
const snapshotEndpoint = PropertiesService.getScriptProperties().getProperty('SNAPSHOT_ENDPOINT'); | ||
exportData['category'] = 'Timesheet'; | ||
const result = postData(calendar.getId(), exportData, snapshotEndpoint); | ||
Logger.log(result); | ||
return result; | ||
} | ||
|
||
function exportCalendar(calendar) { | ||
const id = calendar.getId(); | ||
const name = calendar.getName(); | ||
const timezone = calendar.getTimeZone(); | ||
|
||
const obj = { | ||
id: id, | ||
name: name, | ||
timezone: timezone, | ||
apptype: 'Calendar', | ||
}; | ||
|
||
const events = calendar.getEvents(new Date('2018-01-01'), new Date()); | ||
const eventsArray = events.map(function(e) { | ||
return { | ||
name: e.getTitle(), | ||
startTime: e.getStartTime(), | ||
endTime: e.getEndTime(), | ||
creators: e.getCreators() | ||
} | ||
}); | ||
|
||
obj['events'] = eventsArray; | ||
|
||
return obj; | ||
} |
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