Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. let reminders = await Reminder.incompleteDueThisWeek()
  2. reminders.sort(function(a, b) { return a.dueDate - b.dueDate })
  3.  
  4. let days = 24 * 60 * 60 * 1000
  5.  
  6. let count = reminders.length
  7. let summary
  8. if (count == 0) {
  9. summary = "You have nothing due this week. good job!"
  10. } else {
  11. summary = "You have " + count + " tasks left:"
  12. }
  13.  
  14. let t = await tableUp(summary)
  15.  
  16.  
  17. // when run with Siri, Siri speaks the summary string
  18. if (config.runsWithSiri) {
  19. Speech.speak(summary)
  20. }
  21.  
  22. async function tableUp(summary) {
  23. let table = new UITable()
  24.  
  25. // when not run with Siri, adds a summary header
  26. if (!config.runsWithSiri) {
  27. let row = new UITableRow()
  28. row.isHeader = true
  29. row.addText(summary)
  30. table.addRow(row)
  31. }
  32.  
  33. // this part is building the table
  34. for (reminder of reminders) {
  35. let row = new UITableRow()
  36. let title = reminder.title
  37.  
  38. // this part is to show how far is the due date
  39. let dateDifference = reminder.dueDate - new Date()
  40. let date = Math.round(dateDifference / days)
  41. let subtitle = "Due in " + date + " days"
  42.  
  43. //this part is to implement mark-as-done on select functionality
  44. row.dismissOnSelect = false
  45. row.onSelect = (number) => {
  46. // the number - 1 part is because of the header row
  47. // the whole tap to done doesn't work in Siri
  48. // so this will only matter when the header row exists
  49. let task = reminders[number - 1]
  50. task.isCompleted = true
  51. task.completionDate = new Date()
  52. task.save()
  53. reminders.splice(number,1)
  54. table.removeRow(row)
  55. table.reload()
  56. }
  57.  
  58.  
  59. let titleCell = row.addText(title, subtitle)
  60. titleCell.widthWeight = 90
  61. row.height = 90
  62.  
  63. table.addRow(row)
  64. }
  65.  
  66. // showing the table
  67. return QuickLook.present(table)
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement