Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 27f2e6c

Browse files
committed
Load latest issues on request
Switch between repos and issues tables via tabs Organize coder html/vue markup in several templates to be better maintainable
1 parent 1eb6573 commit 27f2e6c

File tree

10 files changed

+192
-123
lines changed

10 files changed

+192
-123
lines changed

src/js/coder.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ document.getElementsByClassName('brand')[0].textContent = short_title;
2020

2121
let url_user = `https://api.github.com/users/${github_user}`,
2222
url_repos = `${url_user}/repos?sort=pushed&per_page=100`,
23+
url_issues = `https://api.github.com/search/issues?q=user:${github_user}&sort=updated&order=desc`,
2324
months_short = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
2425

2526
if (DEV) {
2627
url_user = '/data/user.json';
2728
url_repos = '/data/repos.json';
29+
url_issues = '/data/issues.json';
2830
}
2931

3032
let coder = new Vue({
3133
el: '#coder',
3234
data: {
35+
activetab: 'repos',
36+
latest_issues: null,
3337
repos: [],
3438
response: {},
3539
sort_orders: {},
@@ -135,6 +139,12 @@ let coder = new Vue({
135139
series: this.repo_types.values});
136140
},
137141
methods: {
142+
fetchIssues: function() {
143+
this.$http.get(url_issues).then(response => {
144+
this.response.issues = response;
145+
this.latest_issues = response.body.items;
146+
});
147+
},
138148
fetchRepos: function() {
139149
this.$http.get(url_repos).then(response => {
140150
this.response.repos = response;
@@ -164,11 +174,17 @@ let coder = new Vue({
164174
return this.repos_pushed.filter(d => d[property])
165175
.sort((a, b) => b[property] - a[property]);
166176
},
167-
sortBy: function(key, type='number') {
177+
showTab: function(name) {
178+
this.activetab = name;
179+
if (!this.latest_issues) {
180+
this.fetchIssues();
181+
}
182+
},
183+
sortBy: function(key, type='number', property='repos') {
168184
let default_value = type === 'string' ? '' : 0;
169185
this.sort_key = key;
170186
this.sort_orders[key] = (this.sort_orders[key] || 1) * -1;
171-
this.repos.sort((a, b) => {
187+
this[property].sort((a, b) => {
172188
let x = a[key] || default_value,
173189
y = b[key] || default_value;
174190
if (type === 'string') {

src/scss/coder.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,13 @@
5858

5959
.meta {
6060
background-color: $color4;
61+
}
62+
63+
// tabs
64+
.button.active {
65+
background-color: $color3;
66+
}
67+
68+
.content {
69+
border-top: 1px solid $color5;
6170
}

src/scss/table.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ th.active .arrow {
2525
.arrow.asc {
2626
border-left: 4px solid transparent;
2727
border-right: 4px solid transparent;
28-
border-bottom: 4px solid $color4;
28+
border-bottom: 4px solid $color1;
2929
}
3030

3131
.arrow.dsc {
3232
border-left: 4px solid transparent;
3333
border-right: 4px solid transparent;
34-
border-top: 4px solid $color4;
34+
border-top: 4px solid $color1;
3535
}

templates/coder.html

Lines changed: 17 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -19,139 +19,37 @@
1919
</div>
2020
</nav></div>
2121

22-
{% raw %}
2322
<div id="coder">
2423
<div v-if="user" class="row">
2524
<div class="col-12 col-2-xl col-3-l col-4-m meta">
26-
<div class="padh">
27-
<header>
28-
<h3>{{ user.name }}</h3>
29-
</header>
30-
<img :src="user.avatar_url" :alt="user.name" class="img-fluid">
31-
<p>Joined GitHub {{ user.created_at|formatDate }}</p>
32-
<a :href="'https://github.com/' + user.login" class="block"><i class="fa fa-github" aria-hidden="true"></i> {{ user.login }}</a>
33-
<a v-if="user.blog" :href="user.blog | fixURL" class="block"><i class="fa fa-home" aria-hidden="true"></i> {{ user.blog | formatURL }}</a>
34-
<span v-if="user.location" class="block"><i class="fa fa-globe" aria-hidden="true"></i> {{ user.location }}</span>
35-
<span v-if="user.company" class="block"><i class="fa fa-money" aria-hidden="true"></i> {{ user.company }}</span>
36-
<blockquote v-if="user.bio"><p>{{ user.bio }}</p></blockquote>
37-
38-
<div v-if="repo_types" class="padv">
39-
<h3>Repo types</h3>
40-
<div id="repo-types-chart"></div>
41-
</div>
42-
</div>
25+
{% include 'coder/meta.html' %}
4326
</div>
4427
<div v-if="repos_pushed.length < 2" class="col-12 error">
45-
{{ user.name }} has not pushed changes to enough public repositories to show any interesting data here.
28+
{% raw %}{{ user.name }} has not pushed changes to enough public repositories to show any interesting data here.{% endraw %}
4629
</div>
4730
<div v-else class="col-12 col-10-xl col-9-l col-8-m no-padding main">
48-
<div class="flex flex-wrap boxes">
49-
<div class="box-stat" title="The number of loaded repositories this user has pushed to.">
50-
<i class="fa fa-code" aria-hidden="true"></i> Pushed to repos
51-
<h4>{{ repos_pushed.length }}</h4>
52-
</div>
53-
<div class="box-stat" title="The number of different main languages in repositories this user has pushed to.">
54-
<i class="fa fa-language" aria-hidden="true"></i> Main languages
55-
<h4>{{ languages.length }}</h4>
56-
</div>
57-
<div class="box-stat" title="The sum of issues across repositories this user has pushed to.">
58-
<i class="fa fa-bug" aria-hidden="true"></i> Total issues
59-
<h4>{{ total_issues }}</h4>
60-
</div>
61-
<div class="box-stat" title="The sum of forks across repositories this user has pushed to.">
62-
<i class="fa fa-code-fork" aria-hidden="true"></i> Total forks
63-
<h4>{{ total_forks }}</h4>
64-
</div>
65-
<div class="box-stat" title="The sum of stars across repositories this user has pushed to.">
66-
<i class="fa fa-star" aria-hidden="true"></i> Total stars
67-
<h4>{{ total_stars }}</h4>
68-
</div>
69-
<div class="box-stat" title="The number of users who follow this user on GitHub">
70-
<i class="fa fa-user" aria-hidden="true"></i> Followers
71-
<h4>{{ user.followers }}</h4>
72-
</div>
73-
<div class="box-stat" title="The number of users this user follows on GitHub">
74-
<i class="fa fa-user" aria-hidden="true"></i> Following
75-
<h4>{{ user.following }}</h4>
76-
</div>
77-
</div>
78-
79-
<div class="padh">
80-
<h2 id="summary">Summary</h2>
81-
<p v-if="repos_pushed.length > 1">{{ user.name }} has {{ user.public_repos }} repositories on GitHub, the latest {{ repos.length }} with user activity were loaded from GitHub's web service for this evaluation. {{ user.name }} has pushed to <strong>{{ repos_pushed.length }}</strong> of these repositories.
82-
<span v-if="repos_pushed_ratio > .8">This is a high ratio congratulations!</span>
83-
<span v-else-if="repos_pushed_ratio < .4">This is a low ratio.</span>
84-
</p>
85-
<p v-if="languages.length > 1"><strong>{{ languages.length }}</strong> different main languages were identified across all repos pushed to. The main language is the one with the largest amount of code in a given repository, as identified by GitHub's <a href="https://github.com/github/linguist">linguist</a>.
86-
<span v-if="languages.length > 5">Assuming a basic level of proficiency in all these languages {{ user.name }} can be considered hyperpolyglot in the world of computer languages.</span>
87-
<strong>{{ languages[0].key }}</strong> occurs most frequently ‒ {{ languages[0].value }} times ‒ as the main repo language.
88-
</p>
89-
<p v-if="total_forks / repos_pushed.length > 20">The total number of forks across all pushed to repositories indicates that the GitHub projects {{ user.name }} contributes to are actually used by other people as well.</p>
90-
</div>
91-
92-
<div class="padh">
93-
<h2 id="rankings">Rankings</h2>
94-
<div class="row">
95-
<div v-if="languages.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
96-
<h3>Languages</h3>
97-
<graph id="language-ranking" class="ct-major-third"></graph>
98-
</div>
99-
<div v-if="issues.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
100-
<h3>Issues</h3>
101-
<graph id="issues-ranking" class="ct-major-third"></graph>
102-
</div>
103-
<div v-if="forks.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
104-
<h3>Forks</h3>
105-
<graph id="forks-ranking" class="ct-major-third"></graph>
106-
</div>
107-
<div v-if="stars.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
108-
<h3>Stars</h3>
109-
<graph id="stars-ranking" class="ct-major-third"></graph>
110-
</div>
111-
</div>
112-
</div>
31+
{% include 'coder/boxes.html' %}
32+
{% include 'coder/summary.html' %}
33+
{% include 'coder/rankings.html' %}
11334
</div>
11435
</div>
11536

11637
<div v-if="repos_pushed.length" class="padh padv">
117-
<h2 id="repos">Repositories</h2>
118-
<table>
119-
<thead>
120-
<tr>
121-
<th>#</th>
122-
<th @click="sortBy('name', 'string')" :class="{ active: sort_key == 'name' }">Name <span class="arrow" :class="order('name')"></span></th>
123-
<th @click="sortBy('language', 'string')" :class="{ active: sort_key == 'language' }">Language <span class="arrow" :class="order('language')"></span></th>
124-
<th class="text-right" @click="sortBy('created_at')" :class="{ active: sort_key == 'created_at' }">Created at <span class="arrow" :class="order('created_at')"></span></th>
125-
<th class="text-right" @click="sortBy('pushed_at')" :class="{ active: sort_key == 'pushed_at' }">Pushed at <span class="arrow" :class="order('pushed_at')"></span></th>
126-
<th class="text-right" @click="sortBy('open_issues_count')" :class="{ active: sort_key == 'open_issues_count' }">Issues <span class="arrow" :class="order('open_issues_count')"></span></th>
127-
<th class="text-right" @click="sortBy('forks_count')" :class="{ active: sort_key == 'forks_count' }">Forks <span class="arrow" :class="order('forks_count')"></span></th>
128-
<th class="text-right" @click="sortBy('watchers_count')" :class="{ active: sort_key == 'watchers_count' }">Stars <span class="arrow" :class="order('watchers_count')"></span></th>
129-
<th class="text-right" @click="sortBy('size')" :class="{ active: sort_key == 'size' }">Size <span class="arrow" :class="order('size')"></span></th>
130-
</tr>
131-
</thead>
132-
<tbody>
133-
<tr v-for="(repo, idx) in repos_pushed" :title="repo.description">
134-
<td>{{ idx + 1}}</td>
135-
<td>
136-
<strong><a v-bind:href="repo.html_url">{{ repo.name }}</a></strong>
137-
<i v-if="repo.fork" class="fa fa-code-fork" aria-hidden="true" title="Forked Repository"></i>
138-
<i v-if="repo.archived" class="fa fa-archive" aria-hidden="true" title="Archived Repository"></i>
139-
</td>
140-
<td>{{ repo.language }}</td>
141-
<td class="text-right">{{ repo.created_at | formatDate }}</td>
142-
<td class="text-right">{{ repo.pushed_at | formatDate }}</td>
143-
<td class="text-right">{{ repo.open_issues_count }}</td>
144-
<td class="text-right">{{ repo.forks_count }}</td>
145-
<td class="text-right">{{ repo.watchers_count }}</td>
146-
<td class="text-right">{{ repo.size }}</td>
147-
</tr>
148-
</tbody>
149-
</table>
38+
<div class="tabs padv">
39+
<a v-on:click="showTab('repos')" v-bind:class="[ activetab === 'repos' ? 'active' : '' ]" class="button inline">Repositories</a>
40+
<a v-on:click="showTab('issues')" v-bind:class="[ activetab === 'issues' ? 'active' : '' ]" class="button inline">Latest Issues</a>
41+
</div>
42+
<div class="content">
43+
<div v-if="activetab === 'repos'" class="tabcontent">
44+
{% include 'coder/repos.html' %}
45+
</div>
46+
<div v-if="activetab === 'issues'" class="tabcontent">
47+
{% include 'coder/issues.html' %}
48+
</div>
49+
</div>
15050
<a href="#"></a>
15151
</div>
152-
15352
</div>
154-
{% endraw %}
15553
{% endblock %}
15654

15755
{% block scripts %}

templates/coder/boxes.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{% raw %}
2+
<div class="flex flex-wrap boxes">
3+
<div class="box-stat" title="The number of loaded repositories this user has pushed to.">
4+
<i class="fa fa-code" aria-hidden="true"></i> Pushed to repos
5+
<h4>{{ repos_pushed.length }}</h4>
6+
</div>
7+
<div class="box-stat" title="The number of different main languages in repositories this user has pushed to.">
8+
<i class="fa fa-language" aria-hidden="true"></i> Main languages
9+
<h4>{{ languages.length }}</h4>
10+
</div>
11+
<div class="box-stat" title="The sum of issues across repositories this user has pushed to.">
12+
<i class="fa fa-bug" aria-hidden="true"></i> Total issues
13+
<h4>{{ total_issues }}</h4>
14+
</div>
15+
<div class="box-stat" title="The sum of forks across repositories this user has pushed to.">
16+
<i class="fa fa-code-fork" aria-hidden="true"></i> Total forks
17+
<h4>{{ total_forks }}</h4>
18+
</div>
19+
<div class="box-stat" title="The sum of stars across repositories this user has pushed to.">
20+
<i class="fa fa-star" aria-hidden="true"></i> Total stars
21+
<h4>{{ total_stars }}</h4>
22+
</div>
23+
<div class="box-stat" title="The number of users who follow this user on GitHub">
24+
<i class="fa fa-user" aria-hidden="true"></i> Followers
25+
<h4>{{ user.followers }}</h4>
26+
</div>
27+
<div class="box-stat" title="The number of users this user follows on GitHub">
28+
<i class="fa fa-user" aria-hidden="true"></i> Following
29+
<h4>{{ user.following }}</h4>
30+
</div>
31+
</div>
32+
{% endraw %}

templates/coder/issues.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% raw %}
2+
<table>
3+
<thead>
4+
<tr>
5+
<th @click="sortBy('repository_url', 'string', 'latest_issues')" :class="{ active: sort_key == 'repository_url' }">Repo <span class="arrow" :class="order('repository_url')"></span></th>
6+
<th>Title</th>
7+
<th @click="sortBy('state', 'string', 'latest_issues')" :class="{ active: sort_key == 'state' }">State <span class="arrow" :class="order('state')"></span></th>
8+
<th>Created by</th>
9+
<th class="text-right" @click="sortBy('created_at', 'string', 'latest_issues')" :class="{ active: sort_key == 'created_at' }">Created at <span class="arrow" :class="order('created_at')"></span></th>
10+
<th class="text-right" @click="sortBy('updated_at', 'string', 'latest_issues')" :class="{ active: sort_key == 'updated_at' }">Latest update <span class="arrow" :class="order('updated_at')"></span></th>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<tr v-for="issue in latest_issues">
15+
<td><a :href="issue.repository_url">{{ issue.repository_url.split('/').slice(-2).join('/') }}</a></td>
16+
<td><a :href="issue.html_url">{{ issue.title }}</a></td>
17+
<td>{{ issue.state }}</td>
18+
<td><a :href="issue.user.url">{{ issue.user.login }}</a></td>
19+
<td class="text-right">{{ issue.created_at | formatDate }}</td>
20+
<td class="text-right">{{ issue.updated_at | formatDate }}</td>
21+
</tr>
22+
</tbody>
23+
</table>
24+
{% endraw %}

templates/coder/meta.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% raw %}
2+
<div class="padh">
3+
<header>
4+
<h3>{{ user.name }}</h3>
5+
</header>
6+
<img :src="user.avatar_url" :alt="user.name" class="img-fluid">
7+
<p>Joined GitHub {{ user.created_at|formatDate }}</p>
8+
<a :href="'https://github.com/' + user.login" class="block"><i class="fa fa-github" aria-hidden="true"></i> {{ user.login }}</a>
9+
<a v-if="user.blog" :href="user.blog | fixURL" class="block"><i class="fa fa-home" aria-hidden="true"></i> {{ user.blog | formatURL }}</a>
10+
<span v-if="user.location" class="block"><i class="fa fa-globe" aria-hidden="true"></i> {{ user.location }}</span>
11+
<span v-if="user.company" class="block"><i class="fa fa-money" aria-hidden="true"></i> {{ user.company }}</span>
12+
<blockquote v-if="user.bio"><p>{{ user.bio }}</p></blockquote>
13+
14+
<div v-if="repo_types" class="padv">
15+
<h3>Repo types</h3>
16+
<div id="repo-types-chart"></div>
17+
</div>
18+
</div>
19+
{% endraw %}

templates/coder/rankings.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% raw %}
2+
<div class="padh">
3+
<h2 id="rankings">Rankings</h2>
4+
<div class="row">
5+
<div v-if="languages.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
6+
<h3>Languages</h3>
7+
<graph id="language-ranking" class="ct-major-third"></graph>
8+
</div>
9+
<div v-if="issues.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
10+
<h3>Issues</h3>
11+
<graph id="issues-ranking" class="ct-major-third"></graph>
12+
</div>
13+
<div v-if="forks.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
14+
<h3>Forks</h3>
15+
<graph id="forks-ranking" class="ct-major-third"></graph>
16+
</div>
17+
<div v-if="stars.length > 1" class="col-12 col-3-xl col-6-l col-6-m">
18+
<h3>Stars</h3>
19+
<graph id="stars-ranking" class="ct-major-third"></graph>
20+
</div>
21+
</div>
22+
</div>
23+
{% endraw %}

0 commit comments

Comments
 (0)