Created
February 8, 2018 13:41
-
-
Save heesienooi/8a5729622e77c6385294bdef0c8dc2e1 to your computer and use it in GitHub Desktop.
Butterfly Flow autologing script
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
async function logTime(url, hour, min, date, desc) { | |
console.group('Log', Array.prototype.slice.call(arguments).join(',')); | |
const logTimeAPI = url + 'log-time?action=add&log_id='; | |
const formId = await $.get(logTimeAPI).then(res => { | |
const html = $('<div/>').html(res); | |
return html.find('#form_id').val();; | |
}); | |
console.log('Submitting time...'); | |
const saveTimeAPI = url + 'save-log-time'; | |
const success = await $.post(saveTimeAPI, { | |
form_id: formId, | |
hour: hour, | |
minute: min, | |
occurred_datetime: date, | |
description: desc, | |
}).then(res => { | |
const success = res.success; | |
if (success) { | |
console.log('%cSuccess!', 'color: green;'); | |
} else { | |
console.log('%cFailed!', 'color: red;', res); | |
} | |
return success; | |
}); | |
console.groupEnd(); | |
return success; | |
} | |
function Report(logEntry, result) { | |
this.logEntry = logEntry.join(','); | |
this.result = success; | |
} | |
async function batchLogTime(logEntries) { | |
let reports = []; | |
console.groupCollapsed('Time logging...'); | |
while (logEntries.length) { | |
const entry = logEntries.shift(); | |
success = await logTime.apply(null, entry); | |
reports.push(new Report(entry, success)); | |
} | |
console.groupEnd(); | |
console.group('Summary timelogs'); | |
console.table(reports); | |
console.groupEnd(); | |
} | |
// Auto run function which should contain call to batchLogTime with entires | |
ExecuteAutoLog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment