forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathRepository.js
More file actions
69 lines (57 loc) · 1.97 KB
/
Repository.js
File metadata and controls
69 lines (57 loc) · 1.97 KB
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
'use strict';
/* global Util */
// eslint-disable-next-line no-unused-vars
class Repository {
constructor(repository) {
this.repository = repository;
}
/**
* Render the repository info to the DOM.
* @param {HTMLElement} container The container element in which to render the repository.
*/
render(container) {
/* TODO: replace the next line with your code.
Util.createAndAppend('pre', container, JSON.stringify(this.repository, null, 2));*/
const repo = Object.assign({}, this.repository, {
updated_at: new Date(this.repository.updated_at).toLocaleString(),
});
const repoTitles = { description: 'Description: ', forks: 'Forks: ', updated_at: 'Updated: ' };
const table = Util.createAndAppend('table', container, { class: 'table' });
const tbody = Util.createAndAppend('tBody', table);
const firstRow = Util.createAndAppend('tr', tbody);
let leftCell = Util.createAndAppend('td', firstRow);
let rightCell = Util.createAndAppend('td', firstRow);
Util.createAndAppend('span', leftCell, { text: 'Repository: ', class: 'repo-child left-cell' });
Util.createAndAppend('a', rightCell, {
text: this.repository.name,
href: this.repository.html_url,
target: '_blank',
class: 'repo-child right-cell',
});
Object.keys(repoTitles).forEach(key => {
const tr = Util.createAndAppend('tr', tbody);
leftCell = Util.createAndAppend('td', tr);
rightCell = Util.createAndAppend('td', tr);
Util.createAndAppend('span', leftCell, {
text: repoTitles[key],
class: 'repo-child left-cell',
});
Util.createAndAppend('span', rightCell, {
text: repo[key],
class: 'repo-child right-cell',
});
});
}
/**
* Returns an array of contributors as a promise
*/
fetchContributors() {
return Util.fetchJSON(this.repository.contributors_url);
}
/**
* Returns the name of the repository
*/
name() {
return this.repository.name;
}
}