This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
/
UserPage.js
418 lines (355 loc) · 11.1 KB
/
UserPage.js
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
app.controller('UserPageController', function($scope, $http, fn) {
$scope.fn = fn;
$http.get(window.location.pathname + "/index.json").success(function(response) {
$scope.showUser(response);
});
$scope.comleaders = [
'ScreapDK',
'mintsoft',
'TomBebbington',
'loganom',
'bradcater',
'mattr555',
'preemeijer',
'javathunderman',
'MrChrisW',
'killerfish',
'sebasorribas',
'NickCalabs',
'haseeb',
'iambibhas',
'codenirvana',
'Jedidiah',
'hemanth',
'gautamkrishnar',
'GuiltyDolphin',
'pjhampton',
'gaulrobe'
];
$scope.staff = [
'abeyang',
'AdamSC1-ddg',
'alohaas',
'andrey-p',
'b1ake',
'b2ddg',
'bbraithwaite',
'bsstoner',
'chrismorast',
'daxtheduck',
'edgesince84',
'jagtalon',
'jbarrett',
'jdorweiler',
'jkv',
'kablamo',
'malbin',
'marcantonio',
'MariagraziaAlastra',
'moollaza',
'mrshu',
'nilnilnil',
'russellholt',
'tagawa',
'thm',
'tommytommytommy',
'yegg',
'zachthompson',
'zekiel'
];
// for sorting instant answers (live should be first)
$scope.iaSort = function(ia) {
var issues = ia.issues.length;
if(issues > 0) {
var sorted = _.sortBy(ia.issues, function(issue) { return moment().diff(moment(issue.updated_at)); });
return -(1/moment().diff(moment(sorted[0].updated_at)));
}
switch (ia.dev_milestone) {
case 'live': return 0;
case 'complete': return 10;
case 'testing': return 20;
case 'development': return 30;
case 'planning': return 40;
default: return 1000;
}
};
$scope.iaPriority = function(ia) {
return ia.issues.length;
}
var initial = false;
// given a username, fill out the $scope variables appropriately, like IAs, etc.
$scope.showUser = function(response) {
$scope.response = response;
$scope.count = {};
$scope.topics = [];
$scope.role = 'regular';
if(window.location.hash) {
$scope.is_tutorial = window.location.hash === "#tutorial";
}
if ($scope.staff.indexOf($scope.response.gh_data.login) !== -1) {
$scope.role = 'staff';
} else if ($scope.comleaders.indexOf($scope.response.gh_data.login) !== -1) {
$scope.role = 'comleader';
}
$scope.imgUrl = 'https://duckduckgo.com/t/userpage_' + $scope.role + '_' + $scope.response.gh_data.login;
$scope.newImg = new Image();
$scope.newImg.src = $scope.imgUrl + '?' + Math.ceil(Math.random() * 1e7);
$scope.addImg = function(pre_id, element_id) {
var randomNum = Math.ceil(Math.random() * 1e7);
pre_id = pre_id? '_' + pre_id : '';
element_id = element_id? '_' + element_id.replace(/[^0-9A-Za-z]/g, '') : '';
var imgUrlSuffix = pre_id + element_id + '?' + randomNum;
$scope.newImg = new Image();
$scope.newImg.src = $scope.imgUrl + imgUrlSuffix;
};
$scope.ias = [];
_.each(response.ia, function(element, index) {
$scope.ias = $scope.ias.concat(element);
});
_.each($scope.ias, function(ia) {
if(ia.dev_milestone === "development") {
ia.dev_milestone = "dev";
}
});
$scope.ias_developed_only = _.filter($scope.ias, function(ia) {
return _.find(ia.developer, function(dev) {
return (dev.name === response.gh_data.login || dev.name === response.gh_data.name) && dev.type === "github";
}) && ia.dev_milestone !== "ghosted";
});
$scope.prs_open = _.filter(response.pulls, function(pull) {
return pull.state === "open";
});
$scope.prs_open_developed = _.filter(response.pulls_created, function(pull) {
return pull.state === "open" && !pull.ia_id;
});
$scope.prs_open_reviewed = _.filter(response.pulls_assigned, function(pull) {
return pull.state === "open";
});
$scope.maintained = _.filter(response.maintained, function(ia) {
return ia.dev_milestone !== "ghosted";
});
$scope.mapIssues = {};
_.each($scope.maintained.concat($scope.ias_developed_only), function(ia) {
ia.issues = [];
ia.pull_count = 0;
ia.issue_count = 0;
_.each(response.issues_assigned, function(v, k) {
if(v.ia_id === ia.id) {
ia.issues = ia.issues.concat(v);
ia.issue_count++;
}
});
_.each(response.issues_created, function(v, k) {
if(v.ia_id === ia.id) {
ia.issues = ia.issues.concat(v);
ia.issue_count++;
}
});
// Also add the PRs in here.
_.each(response.pulls_assigned, function(pull) {
if(pull.ia_id === ia.id) {
ia.issues = ia.issues.concat(pull);
ia.pull_count++;
}
});
_.each(response.pulls_created, function(pull) {
if(pull.ia_id === ia.id) {
ia.issues = ia.issues.concat(pull);
ia.pull_count++;
}
});
_.each(response.pulls_other, function(pull) {
if(pull.ia_id === ia.id) {
ia.issues = ia.issues.concat(pull);
ia.pull_count++;
}
});
_.each(response.issues_other, function(v, k) {
if(v.ia_id === ia.id) {
ia.issues = ia.issues.concat(v);
if(v.isa_pull_request === 1) {
ia.pull_count++;
} else {
ia.issue_count++;
}
}
});
_.each(ia.issues, function(issue) {
if(issue.title.length > 60) {
issue.title = issue.title.substring(0, 60) + "...";
}
if(issue.tags) {
var hasMaintainerApproved = _.filter(issue.tags, function(tag) {
if(tag.name === "Maintainer Input Requested") {
return true;
}
}).length > 0;
issue.hasMaintainer = hasMaintainerApproved;
}
});
_.each(ia.issues, function(issue) {
$scope.mapIssues[issue.id] = true;
});
});
$scope.count.mapIssues = _.size($scope.mapIssues);
$scope.issues_unassigned = _.filter(response.issues_assigned, function(v, k) {
return !v.ia_id;
});
$scope.count.maintained_ias = _.size($scope.maintained);
$scope.count.other = _.filter(response.issues_assigned, function(issue) {
return !$scope.mapIssues[issue.id];
}).length || 0;
$scope.count.other += _.filter(response.pulls_assigned, function(ia) {
return !$scope.mapIssues[ia.id];
}).length || 0;
$scope.count.other += _.filter(response.pulls_created, function(ia) {
return !$scope.mapIssues[ia.id];
}).length || 0;
$scope.count.developed_only_ias = _.size($scope.ias_developed_only);
$scope.count.open_issues = _.size(response.issues_assigned);
$scope.count.closed_issues = _.size(response.issues) - $scope.count.open_issues;
$scope.count.open_prs = _.size($scope.prs_open);
$scope.count.reviewed_prs = _.size(response.pulls_assigned);
$scope.count.developed_prs = _.size(response.pulls_assigned);
$scope.count.pulls_other = _.size(response.pulls_other);
$scope.count.issues_other = _.size(response.isues_other);
$scope.count.closed_prs = response.closed_pulls;
$scope.count.ias = _.size($scope.ias)
$scope.count.filtered = 0;
$scope.all_the_issues = _.toArray(response.issues_assigned).concat(_.toArray(response.pulls_assigned)).concat(_.toArray(response.pulls_created));
$scope.all_the_issues = _.sortBy($scope.all_the_issues, function(issue) {
return moment().diff(moment(issue.updated_at), 'days');
});
var seen = {};
var temp = [];
_.each($scope.maintained.concat($scope.ias_developed_only), function(ia) {
if(!seen[ia.id]) {
seen[ia.id] = true;
temp.push(ia);
}
});
_.each(_.filter(temp, function(ia) {
return ia.issues.length > 0;
}), function(ia) {
$scope.count.filtered += ia.issues.length;
});
$scope.count.assigned = _.size(response.issues_assigned);
$scope.ias_maintained = response.maintained;
$scope.selectPrevious = function(index, ia) {
var elm = document.querySelectorAll(".all")[index - 1];
if(index > 0 && /above/.test(elm.className)) {
if(/add\-space/.test(elm.className)) {
elm.className = "all add-space";
} else {
elm.className = "all";
}
} else if(index > 0 && ia.issues.length > 0) {
elm.className += " above";
}
};
$scope.topics = _.map(response.topics, function(key, num) {
return {count: key, topic: num};
});
$scope.count.total_ias = (function() {
var all = {};
_.each($scope.maintained.concat($scope.ias_developed_only), function(ia) {
all[ia.id] = true;
});
return _.size(all);
}());
var maxtopic = _.max($scope.topics, function(topic) {
return topic.count;
});
$scope.count.max_topics = maxtopic.count;
// by default. for 'filterable'
$scope.show_ias = ($scope.count.maintained_ias) ? $scope.maintained : $scope.ias_developed_only;
$scope.count.all_prs = 0;
$scope.count.all_issues = 0;
_.each(temp, function(ia) {
_.each(ia.issues, function(issue) {
if(issue.isa_pull_request === 1) {
$scope.count.all_prs++;
} else {
$scope.count.all_issues++;
}
});
});
_.each($scope.all_the_issues, function(issue) {
if(!$scope.mapIssues[issue.id]) {
if(issue.isa_pull_request === 1) {
$scope.count.all_prs++;
} else {
$scope.count.all_issues++;
}
}
});
$scope.changeShownIAs = function(which, open) {
if(open) {
var seen = {};
var temp = [];
_.each(which.concat(open), function(ia) {
if(!seen[ia.id]) {
seen[ia.id] = true;
temp.push(ia);
}
});
$scope.show_ias = _.filter(temp, function(ia) {
ia.expand = true;
return ia.issues.length > 0;
});
} else {
$scope.show_ias = _.each(which, function(ia) {
ia.expand = false;
});
}
var objKey = _.findKey($scope, which);
if(objKey) {
$scope.addImg(objKey.replace(/_/g, ''));
}
};
}
});
// helper functions
app.factory('fn', function() {
return {
// given an array, search for an attr (like 'username'): if found, return object
findByAttr: function(arr, attr, name) {
return _.find(arr, function(obj) {
return obj[attr] == name;
});
},
// return the first char in a dev's username (for when avatar is not available)
firstUsernameChar: function(username) {
username = username ? username.charAt(0) : '';
return username;
},
// get developers based on an instant answer; returns html
getDevs: function(ia) {
var html = '';
_.each(ia.developer, function(dev) {
html += '<span>' + dev.name + ' </span>';
});
return html;
},
// get topics based on an instant answer; returns html
getTopics: function(ia) {
var html = '';
_.each(ia.topic, function(topic) {
html += '<span>' + topic + ' </span>';
});
return html;
},
// get labels based on an issue; returns html
getLabels: function(issue) {
var html = '';
_.each(issue.labels, function(label) {
html += '<span>' + label.name + '; </span>';
});
return html;
},
// get "time ago" from date
getFromNow: function(datetimestr) {
return moment().diff(moment(datetimestr), 'days') + "d";
}
};
});