This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
GTasks_init.gs
112 lines (92 loc) · 2.85 KB
/
GTasks_init.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const gtasksOptionalArgs = {
'maxResults': PropertiesService.getScriptProperties().getProperty("gtasks_maxresults"),
'showHidden':true
};
let gtasksListCompleted = [];
let gtasksListNotCompleted = [];
let gtasksTaskList = [];
class GoogleTask{
constructor(text, taskId, parentId, taskListId, taskListName, isCompleted, dueDate, notes){
this.text = text;
this.taskId = taskId;
this.parentId = parentId;
this.taskListId = taskListId;
this.taskListName = taskListName;
this.isCompleted = isCompleted;
this.dueDate = dueDate;
this.notes = notes;
}
convertToHabiticaPayload(){
var payload = {
"type" : "todo",
"text" : this.taskListName + ": " + this.text,
"alias" : this.taskId,
"notes" : this.notes,
}
if (this.parentId === undefined){
// placeholder
// TODO: implement subtasks as checklists
}
if (this.dueDate === undefined){
// pass
} else {
payload["date"] = this.dueDate;
}
return payload;
}
}
function getGoogleTaskLists(){
// Get the ID/Name of the task lists on GTasks
// Names will be used as tags on Habitica
// IDs will be used to get the tasks in each list
var taskLists = Tasks.Tasklists.list(gtasksOptionalArgs).getItems();
if (!taskLists) {
return [];
}
return taskLists.map(function(taskList) {
return {
id: taskList.getId(),
name: taskList.getTitle()
};
});
}
function getGTasksPerList(taskListData){
// Get all the tasks associated with a task list
// argument must be in the format {id: taskListId, name: taskListName}
//
// Note: For the purposes of this function, it's ok if the name/ID don't
// match, but the data passed to Habitica will be wrong
const listID = taskListData.id;
const listName = taskListData.name;
var completedTaskList = [];
var notCompletedTaskList = [];
var tasks = Tasks.Tasks.list(listID, gtasksOptionalArgs);
if (tasks.items) {
for (let t of tasks.items){
let task = new GoogleTask(t.title, t.id, t.parent, listID, listName, Boolean(t.completed), t.due, t.notes);
if (t.title === "Recurring task test"){
Logger.log("WATCH: " + t.id);
}
if (Boolean(t.completed)){
completedTaskList.push(task);
} else {
notCompletedTaskList.push(task);
}
}
}
return [completedTaskList, notCompletedTaskList];
}
function getGTasks(){
// Just get all of it.
gtasksTaskList = getGoogleTaskLists();
var completedList = [];
var notCompletedList = [];
for (let l of gtasksTaskList){
const [comp, ncomp] = getGTasksPerList(l);
completedList = completedList.concat(comp);
notCompletedList = notCompletedList.concat(ncomp);
}
// return [completedList, notCompletedList];
gtasksListCompleted = completedList;
gtasksListNotCompleted = notCompletedList;
}