Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. async function logTime(url, hour, min, date, desc) {
  2. console.group('Log', Array.prototype.slice.call(arguments).join(','));
  3.  
  4. const logTimeAPI = url + 'log-time?action=add&log_id=';
  5. const formId = await $.get(logTimeAPI).then(res => {
  6. const html = $('<div/>').html(res);
  7. return html.find('#form_id').val();;
  8. });
  9.  
  10. console.log('Submitting time...');
  11. const saveTimeAPI = url + 'save-log-time';
  12. const success = await $.post(saveTimeAPI, {
  13. form_id: formId,
  14. hour: hour,
  15. minute: min,
  16. occurred_datetime: date,
  17. description: desc,
  18. }).then(res => {
  19. const success = res.success;
  20. if (success) {
  21. console.log('%cSuccess!', 'color: green;');
  22. } else {
  23. console.log('%cFailed!', 'color: red;', res);
  24. }
  25. return success;
  26. });
  27.  
  28. console.groupEnd();
  29. return success;
  30.  
  31. }
  32.  
  33. function Report(logEntry, result) {
  34. this.logEntry = logEntry.join(',');
  35. this.result = success;
  36. }
  37.  
  38. async function batchLogTime(logEntries) {
  39. let reports = [];
  40.  
  41. console.groupCollapsed('Time logging...');
  42. while (logEntries.length) {
  43. const entry = logEntries.shift();
  44. success = await logTime.apply(null, entry);
  45. reports.push(new Report(entry, success));
  46. }
  47. console.groupEnd();
  48.  
  49. console.group('Summary timelogs');
  50. console.table(reports);
  51. console.groupEnd();
  52. }
  53.  
  54. // Auto run function which should contain call to batchLogTime with entires
  55. ExecuteAutoLog();
Add Comment
Please, Sign In to add comment