forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 5
/
allIssuesCtrl.js
executable file
·132 lines (112 loc) · 4.51 KB
/
allIssuesCtrl.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
App.filter('trust', function($sce) {
return function(text) {
return $sce.trustAsHtml(text);
};
});
/**
* @description Controller for the all issues page.
* @namespace allIssuesCtrl
* @param {Object} $scope dcgfdfh
* @param {Object} HebUtill
* @param {Object} commentsHandler
* @param {Object} $window
* @param {Object} arrayUtill
* @param {Object} $http
* @param {Object} $routeParams
*/
App.controller('allIssuesCtrl', function($scope, HebUtill, commentsHandler, $window, arrayUtill, $http, $routeParams) {
$scope.relativizePath = $window.CONFIG.relativizePath;
$scope.selectedLabels = new Array();
$scope.stateControls = {
showIssuesWithComments: true,
showIssuesWithOutComments: true
};
document.title = "הסדנא לידע ציבורי";
var http_request = $http({
method: 'GET',
url: "https://api.github.com/search/issues?per_page=100&sort=created&q=user:hasadna"
});
//http_request.error(function(data, status, headers, config) {});
http_request.success(function(data, status, headers, config) {
var labels = new Array();
commentsHandler.treatComments(data.items);
// Add title/body_lang attribute with hebrew Or english values - for text alignment.
commentsHandler.addRapoAttribute(data.items);
for (var i = 0; i < data.items.length; i ++) {// Collect the labels
data.items[i].textLimit = 30;
for (var j = 0; j < data.items[i].labels.length; j ++) {
labels.push(data.items[i].labels[j]);
}
}
$scope.issues = data.items;
$scope.total_count = data.total_count;
// window.console.log(JSON.stringify(data));
// Count labels and remove duplicates
$scope.labels = arrayUtill.clusterNcount(labels, 'name');
$scope.updateState = function() {
//debugger;$scope.stateControls = $scope.stateControls;
$scope.$apply();
};
$scope.setSelectedLabels = function() {
var name = this.lbl.name;
if (_.contains($scope.selectedLabels, name))
$scope.selectedLabels = _.without($scope.selectedLabels, name);
else
$scope.selectedLabels.push(name);
return false;
};
$scope.isChecked = function(name) {
if (_.contains($scope.selectedLabels, name))
return 'fa-check';
return false;
};
/**
* @description Load comments for issue
* @param {MouseEvent} evt <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent">Mouse event</a>
* @param {Object} issue <a href="https://developer.github.com/v3/issues/">Issue</a> object
* @memberOf allIssuesCtrl
*/
$scope.loadComments = function(evt, issue) {
$scope.readMore(evt, issue);
var http_request = $http({
method: 'GET',
url: issue.comments_url
});
http_request.success(function(data, status, headers, config) {
var comments_list = new Array();
/**
* @param {number} i
* @inner
*/
function loadComments(i) {
if (i === - 1){
commentsHandler.treatComments(comments_list);
// window.console.clear();
// window.console.log(JSON.stringify(comments_list));
issue.comments_list = comments_list;
return;
}
var comment_request = $http({
method: 'GET',
url: data[i].url
});
comment_request.success(function(comment, status, headers, config) {
comments_list.push(comment);
i --;
loadComments(i);
});
}
loadComments(data.length - 1);
});
};
/**
* @description Show all the text of issue.
* @param {MouseEvent} evt <a href="https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent">Mouse event</a>
* @param {Object} issue <a href="https://developer.github.com/v3/issues/">Issue</a> object
* @memberOf allIssuesCtrl
*/
$scope.readMore = function(evt, issue) {
issue.textLimit = 1000000;
};
});
});