This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.ts
197 lines (172 loc) · 5.15 KB
/
client.ts
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
'use strict'
import angular = require('angular')
import _ = require('lodash')
// this gets executed and put in global space
require('angular-ui-indeterminate')
var app = angular.module('publists', [
require('angular-ui-bootstrap'),
require('angular-sanitize'),
'ui.indeterminate'
])
app.service('subtaskFunctions', function() {
function round(num: number) {
return Math.round(num * 100) / 100
}
return {
subtaskPercentage: function(subtasks: Subtask[]):number {
var numComplete = subtasks.filter(function(val) {
return val.completed === true
}).length
console.log('completed ' + numComplete + ' out of ' + subtasks.length)
var res = numComplete / subtasks.length * 100
return round(res)
}
}
})
app.controller('SettingsController', ['$scope', '$http', '$timeout', function($scope, $http: ng.IHttpService, $timeout) {
$scope.init = function () {
$scope.model = {}
$scope.loading = true
$http.get('/api/lists').then(function(res: { data: {
lists: List[],
public_lists: {[s:string]: boolean},
folders: Folder[]
}}) {
$scope.loading = false
$scope.model.lists = res.data.lists
$scope.model.public_lists = res.data.public_lists || {}
$scope.model.nested_lids = <number[]> _.flatMap(res.data.folders, 'list_ids')
})
}
$scope.toggle = function (item: List | Folder) {
// cant use typeof becuase they come back from angular as objects
if (item.type === 'list') {
$scope.flip(item.id)
} else {
let folder = <Folder> item
folder.list_ids.forEach((lid) => {
$scope.flip(lid)
})
}
}
$scope.flip = function (id:string) {
$scope.model.public_lists[id] = !$scope.model.public_lists[id]
}
$scope.computeClasses = function(item: List | Folder) {
var classes:string[] = []
if (item.type === 'list') {
// can click everything
// classes.push('clickable')
if ($scope.model.nested_lids.indexOf(item.id) > -1) {
classes.push('subtask')
}
}
return classes
}
$scope.save = function () {
$scope.model.message = null
$http.post('/update', {
public_lists: $scope.model.public_lists
}).then(function (resp) {
$scope.model.message = 'Saved!'
$timeout(function () {
$scope.model.message = null
}, 2000)
}).catch(function (err) {
console.log(err)
$scope.model.message = `Error (${err.status}): ${err.data.message}`
})
}
$scope.init()
}])
interface ListsScope extends ng.IScope {
// init: function()
model: {
lists: List[],
wid: string,
message?: string
},
loading: boolean,
init(): void
}
app.controller('ListsController', ['$scope', '$http', function($scope: ListsScope, $http) {
$scope.init = function() {
$scope.loading = true
var urlParts = location.href.split('/')
$scope.model = {
lists: [],
wid: urlParts[4]
}
$http.get('/api/public_lists', {
params: { wid: $scope.model.wid }
}).then(function(res: {
data: {
name: string,
lists: List[]
}
}) {
$scope.model.lists = res.data.lists
// $scope.model.statics.name = res.data.name
$scope.loading = false
}).catch((err) => {
$scope.loading = false
$scope.model.lists = []
$scope.model.message = "Error! Looks like there's an issue with Wunderlist."
})
}
$scope.init()
}])
app.controller('TasksController', ['$scope', '$http', 'subtaskFunctions', function($scope, $http: ng.IHttpService, subtaskFunctions) {
$scope.init = function():void {
$scope.loading = true
$scope.model = { tasks: [] }
var urlParts = location.href.split('/')
$scope.model.wid = urlParts[4]
$scope.model.lid = urlParts[6]
$http.get('/api/tasks', {
params: { wid: $scope.model.wid, lid: $scope.model.lid }
}).then(function(res: {
data: {
list: List,
tasks: Task[]
}
}) {
$scope.loading = false
$scope.model.tasks = res.data.tasks || []
// console.log(res.data.list)
$scope.model.list = res.data.list
}).catch((err) => {
$scope.loading = false
$scope.model.tasks = []
$scope.model.message = "Error! Looks like there's an issue with Wunderlist."
})
}
$scope.subtaskPercentage = subtaskFunctions.subtaskPercentage
$scope.init()
}])
app.controller('TaskController', ['$scope', '$http', 'subtaskFunctions', function($scope, $http, subtaskFunctions) {
$scope.init = function(): void {
$scope.loading = true
$scope.model = { task: {} }
var urlParts = location.href.split('/')
$scope.model.wid = urlParts[4]
$scope.model.lid = urlParts[6]
$scope.model.tid = urlParts[8]
$http.get('/api/task_info', {
params: { wid: $scope.model.wid, lid: $scope.model.lid, tid: $scope.model.tid }
}).then(function(res: {
data: {
task: Task
}
}) {
$scope.loading = false
$scope.model.task = res.data.task
}).catch(function(err) {
// console.log(err)
$scope.loading = false
$scope.model.task = {title: 'Not Found'}
})
}
$scope.subtaskPercentage = subtaskFunctions.subtaskPercentage
$scope.init()
}])