-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.js
341 lines (315 loc) · 12.6 KB
/
dashboard.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
'use strict';
var card = document.querySelector(".card");
userCall();
projectsCall();
setInterval(projectsCall, 10000);
function showAvatarImage(data) {
var avatar = document.querySelector(".avatar");
if (data.photo === null) {
avatar.innerHTML = '<img class="avatar-photo" src="img/nonAvatar.svg">';
} else {
avatar.innerHTML = '<img class="avatar-photo" src="'+ data.photo +'">';
}
}
function userCall() {
var userRequest = new XMLHttpRequest();
userRequest.open ('GET', 'https://api.taiga.io/api/v1/users/me', true);
userRequest.setRequestHeader("Content-Type", "application/json");
userRequest.setRequestHeader("Authorization", "Bearer " + JSON.parse(sessionStorage.getItem('token')));
userRequest.onload = function () {
var greeting = document.querySelector(".greeting");
if (userRequest.status >= 200 && userRequest.status < 400) {
var data = JSON.parse(userRequest.responseText);
greeting.innerHTML = "Hello, " + data.full_name;
showAvatarImage(data);
} else {
console.log("La respuesta del servidor ha devuelto un error");
}
};
userRequest.onerror = function() {
console.log("Error al tratar de conectarse con el servidor");
};
userRequest.send();
}
function projectsCall() {
var projectsRequest = new XMLHttpRequest();
var user = JSON.parse(sessionStorage.getItem('user'));
projectsRequest.open ('GET', 'https://api.taiga.io/api/v1/projects?member=' + user.id + '&order_by= -total_activity', true);
projectsRequest.setRequestHeader("Content-Type", "application/json");
projectsRequest.setRequestHeader("Authorization", "Bearer " + JSON.parse(sessionStorage.getItem('token')));
projectsRequest.onload = function () {
if (projectsRequest.status >= 200 && projectsRequest.status < 400) {
var dataProject = JSON.parse(projectsRequest.responseText);
for (var i = 0; i < dataProject.length; i++) {
printProject(dataProject[i]);
}
} else {
console.log("La respuesta del servidor ha devuelto un error");
}
};
projectsRequest.onerror = function() {
console.log("Error al tratar de conectarse con el servidor");
};
projectsRequest.send();
}
function printProject(project) {
var divId = "d" + project.id + "_user";
if (document.getElementById(divId) === null) {
generateCardHtml(divId, project.slug, project.name);
}
basicInfoUpdate(project, divId);
modulesCall(project, divId, project.slug);
callProgressProject(project, divId);
}
function generateProjectInfo(projectSlug, projectName) {
return "<div class='project-info truncate'>"+
"<div class='img-project flex'>"+
"<div class='project-img'>"+
"</div>"+
"<a href='https://tree.taiga.io/project/" + projectSlug + "'>" +
"<h5 class='project-title truncate-title' title='" + projectName + "'></h5></a>"+
"</div>"+
"<small class='description-project truncate-description'></small>"+
"<div class='like-watch flex'>"+
"<div class='like-div flex'>"+
"<img class='logolike' src='img/heart.png' alt='logo likes'>"+
"<small > Likes: </small>"+
"<small class='like'></small>"+
"</div>"+
"<div class='watch-div'>"+
"<img class='logowatch' src='img/eye.png' alt='logo watching'>"+
"<small> Views: </small>"+
"<small class='watch'></small>"+
"</div>"+
"</div>"+
"</div>";
}
function generateProjectTimeline(projectSlug) {
return "<div class='timeline-project flex'>"+
"<div class='modules-div'>" +
"<small>Modules: </small>" +
"<small class='modules'></small>"+
"<div>" +
"<div class='modules-div'>" +
"<small>Team: </small>" +
"<a href='https://tree.taiga.io/project/" + projectSlug + "/team'><small class='team'></small></a>"+
"</div>"+
"</div>"+
"</div>"+
"</div>";
}
function genearteProjectProgres(projectSlug) {
return "<div class='progress-project'>"+
"<div class='stories-issues flex'>"+
"<a href='https://tree.taiga.io/project/" + projectSlug + "/backlog'><div class='progress-stories flex'>"+
"<p class='number-stories'></p>"+
"<div class='progress flex'>"+
"<p class= 'margin-paragraph'>IN PROGRESS</p>"+
"<p class= 'margin-paragraph'>user stories</p>"+
"</div>"+
"</div></a>"+
"<a href=' https://tree.taiga.io/project/" + projectSlug + "/issues'><div class='number-progress flex'>"+
"<p class='number-issues'></p>"+
"<div class='issues flex'>"+
"<p class= 'margin-paragraph'>NEW</p>"+
"<p class= 'margin-paragraph'>issues</p>"+
"</div>"+
"</div></a>"+
"</div>"+
"<div class='line-progress flex'>"+
"<div class='sprint-div'>" +
"<p>Sprint: </p>"+
"<p class= 'sprints'></p>" +
"</div>"+
"<div class='points-div'>" +
"<p class= 'closed-points'></p>"+
"<p class = 'p-user-stories'>user stories closed</p>"+
"</div>"+
"</div>"+
"<div class='bar'>"+
"<progress class='progress-bar' value='0' max='100'></progress>"+
"<span class ='percentage-bar'></span>"+
"</div>"+
"</div>";
}
function generateCardHtml(divId, projectSlug, projectName){
card.innerHTML += "<div id='" + divId + "' class= 'projects_user'>"+
generateProjectInfo(projectSlug, projectName) +
generateProjectTimeline(projectSlug) +
genearteProjectProgres(projectSlug) +
"</div>";
}
function basicInfoUpdate(project, divId) {
var projectTitle = document.querySelector("#" + divId + " .project-title");
var imgProject = document.querySelector("#" + divId + " .project-img");
var descriptionProject = document.querySelector("#" + divId + " .description-project");
var teamProject = document.querySelector("#" + divId + " .team");
var likesProject = document.querySelector("#" + divId + " .like");
var watchProject = document.querySelector("#" + divId + " .watch");
if (projectTitle.innerHTML !== project.name) {
projectTitle.innerHTML = project.name;
}
if (project.logo_small_url === null) {
imgProject.innerHTML = '<img class="img-nullProject" src="img/photo-null-project.svg">';
} else {
imgProject.innerHTML= '<img src="'+ project.logo_small_url +'" title="">';
}
if (descriptionProject.innerHTML !== project.description) {
descriptionProject.innerHTML = project.description;
}
if (teamProject.innerHTML !== project.members.length) {
teamProject.innerHTML = project.members.length;
}
if (likesProject.innerHTML !== project.total_fans) {
likesProject.innerHTML = project.total_fans;
}
if (watchProject.innerHTML !== project.total_watchers) {
watchProject.innerHTML = project.total_watchers;
}
}
function modulesCall(project, divId, projectSlug) {
var modulesProject = document.querySelector("#" + divId + " .modules");
var modules = [
{
property: "is_backlog_activated",
label: '<img class="img-modules" src="img/backlog.svg">',
link: "https://tree.taiga.io/project/" + projectSlug + "/backlog",
description:"Backlog"
},
{
property: "is_epics_activated",
label: '<img class="img-modules" src="img/epics.svg">',
link: "https://tree.taiga.io/project/" + projectSlug + "/epics",
description:"Epics"
},
{
property: "is_issues_activated",
label: '<img class="img-modules" src="img/issues.svg">',
link: "https://tree.taiga.io/project/" + projectSlug + "/issues",
description:"Issues"
},
{
property: "is_kanban_activated",
label: '<img class="img-modules" src="img/kanban.svg">',
link: "https://tree.taiga.io/project/" + projectSlug + "/kanban",
description:"Kanban"
},
{
property: "is_wiki_activated",
label: '<img class="img-modules" src="img/wiki.svg">',
link: "https://tree.taiga.io/project/" + projectSlug + "/wiki",
description:"Wiki"
},
{
property: "is_contact_activated",
label: '<img class="img-modules" src="img/meetUp.svg">',
link: "#",
description:"meetUp"
},
];
modulesProject.innerHTML = "";
for (var i = 0; i < modules.length; i++) {
var module = modules[i];
if (project[module.property] === true) {
generateModuleSection(modulesProject, module, i);
} else {
console.log("no found");
}
if (modulesProject.innerHTML !== project[module.property]) {
modulesProject.innerHTML === project[module.property];
}
}
}
function generateModuleSection(modulesProject, module, uniqueId) {
modulesProject.innerHTML +=
'<div class="tooltip tooltip'+ uniqueId +'">'
+ '<a href="' + module.link + '">' + module.label + '</a>'
+ '<span class="tooltip-text">' + module.description + '</span>'
+ '</div>';
}
function callProgressProject(project, divId) {
var idProject = project.id;
var userStoriesRequest = new XMLHttpRequest();
userStoriesRequest.open ('GET', 'https://api.taiga.io/api/v1/userstories?project='+ idProject, true);
userStoriesRequest.setRequestHeader("Content-Type", "application/json");
userStoriesRequest.setRequestHeader("Authorization", "Bearer " + JSON.parse(sessionStorage.getItem('token')));
userStoriesRequest.setRequestHeader("x-disable-pagination", true);
userStoriesRequest.onload = function () {
if (userStoriesRequest.status >= 200 && userStoriesRequest.status < 400) {
var userStoriesProject = document.querySelector("#" + divId + " .number-stories");
var data = JSON.parse(userStoriesRequest.responseText);
if (userStoriesProject.innerHTML !== data.length) {
userStoriesProject.innerHTML = data.length;
}
} else {
console.log("La respuesta del servidor ha devuelto un error");
}
};
userStoriesRequest.onerror = function() {
console.log("Error al tratar de conectarse con el servidor");
};
userStoriesRequest.send();
var issuesRequest = new XMLHttpRequest();
issuesRequest.open ('GET', 'https://api.taiga.io/api/v1/projects/' + idProject +'/issues_stats' , true);
issuesRequest.setRequestHeader("Content-Type", "application/json");
issuesRequest.setRequestHeader("Authorization", "Bearer " + JSON.parse(sessionStorage.getItem('token')));
issuesRequest.setRequestHeader("x-disable-pagination", true);
issuesRequest.onload = function () {
if (issuesRequest.status >= 200 && issuesRequest.status < 400) {
var issuesProject = document.querySelector("#" + divId + " .number-issues");
var data = JSON.parse(issuesRequest.responseText);
if (issuesProject.innerHTML !== data.total_issues) {
issuesProject.innerHTML = data.total_issues;
}
} else {
console.log("La respuesta del servidor ha devuelto un error");
}
};
issuesRequest.onerror = function() {
console.log("Error al tratar de conectarse con el servidor");
};
issuesRequest.send();
var pointRequest = new XMLHttpRequest();
pointRequest.open ('GET', 'https://api.taiga.io/api/v1/projects/'+ idProject +'/stats',true);
console.log(idProject);
pointRequest.setRequestHeader("Content-Type", "application/json");
pointRequest.setRequestHeader("x-disable-pagination", true);
pointRequest.onload = function () {
if (pointRequest.status >= 200 && pointRequest.status < 400) {
var closedPoints = document.querySelector("#" + divId + " .closed-points");
var percentageBar = document.querySelector("#" + divId + " .percentage-bar");
var progressBar = document.querySelector("#" + divId + " .progress-bar");
var sprintProject = document.querySelector("#" + divId + " .sprints");
var data = JSON.parse(pointRequest.responseText);
if (closedPoints.innerHTML !== data.closed_points + "/" + data.defined_points ) {
closedPoints.innerHTML = data.closed_points + "/" + data.defined_points;
}
if (sprintProject.innerHTML !== data.total_milestones) {
sprintProject.innerHTML = data.total_milestones;
}
var number = calculatePointPercentage(data);
if (percentageBar.innerHTML !== number + "%") {
percentageBar.innerHTML = number + "%";
}
progressBar.value = number;
if (progressBar.innerHTML !== number) {
progressBar.innerHTML = number;
}
} else {
console.log("La respuesta del servidor ha devuelto un error");
}
};
pointRequest.onerror = function() {
console.log("Error al tratar de conectarse con el servidor");
};
pointRequest.send();
}
function calculatePointPercentage(data) {
var number;
if (data.defined_points === 0) {
number = 0;
} else {
number = Math.ceil(data.closed_points * 100/data.defined_points);
}
return number;
}