|
1 | 1 | <template> |
2 | | - <div> |
3 | | - <div v-show="isLoading"> |
4 | | - <slot name="loading"></slot> |
5 | | - </div> |
6 | | - <h4 class="total-contributions" v-if="!isLoading"> |
7 | | - {{ totalContributions }} total contributions in the last 12 months |
8 | | - </h4> |
9 | | - <calendar-heatmap v-show="!isLoading" :locale="locale" :no-data-text="locale.no_contributions" :tooltip-unit="locale.contributions" :end-date="endDate" :values="values" :range-color="colorRange"/> |
| 2 | + <div> |
| 3 | + <div v-show="isLoading"> |
| 4 | + <slot name="loading"/> |
10 | 5 | </div> |
| 6 | + <h4 v-if="!isLoading" class="total-contributions"> |
| 7 | + {{ values.length }} total contributions in the last 12 months |
| 8 | + </h4> |
| 9 | + <calendar-heatmap |
| 10 | + v-show="!isLoading" |
| 11 | + :locale="locale" |
| 12 | + :no-data-text="locale.no_contributions" |
| 13 | + :tooltip-unit="locale.contributions" |
| 14 | + :end-date="endDate" |
| 15 | + :values="values" |
| 16 | + :range-color="colorRange" |
| 17 | + /> |
| 18 | + </div> |
11 | 19 | </template> |
12 | | - |
13 | 20 | <script> |
14 | 21 | import {CalendarHeatmap} from 'vue-calendar-heatmap'; |
15 | 22 | const {AppSubUrl, heatmapUser} = window.config; |
16 | 23 |
|
17 | 24 | export default { |
18 | | - name: "ActivityHeatmap", |
19 | | - components: { |
20 | | - CalendarHeatmap |
21 | | - }, |
22 | | - data() { |
23 | | - return { |
24 | | - isLoading: true, |
25 | | - colorRange: [], |
26 | | - endDate: null, |
27 | | - values: [], |
28 | | - totalContributions: 0, |
29 | | - suburl: AppSubUrl, |
30 | | - user: heatmapUser, |
31 | | - locale: { |
32 | | - contributions: 'contributions', |
33 | | - no_contributions: 'No contributions', |
34 | | - }, |
35 | | - }; |
| 25 | + name: 'ActivityHeatmap', |
| 26 | + components: {CalendarHeatmap}, |
| 27 | + data: () => ({ |
| 28 | + isLoading: true, |
| 29 | + colorRange: [], |
| 30 | + endDate: null, |
| 31 | + values: [], |
| 32 | + suburl: AppSubUrl, |
| 33 | + user: heatmapUser, |
| 34 | + locale: { |
| 35 | + contributions: 'contributions', |
| 36 | + no_contributions: 'No contributions', |
36 | 37 | }, |
37 | | - mounted() { |
38 | | - this.colorRange = [ |
39 | | - this.getColor(0), |
40 | | - this.getColor(1), |
41 | | - this.getColor(2), |
42 | | - this.getColor(3), |
43 | | - this.getColor(4), |
44 | | - this.getColor(5) |
45 | | - ]; |
46 | | - this.endDate = new Date(); |
47 | | - this.loadHeatmap(this.user); |
48 | | - }, |
49 | | - methods: { |
50 | | - loadHeatmap(userName) { |
51 | | - const self = this; |
52 | | - $.get(`${this.suburl}/api/v1/users/${userName}/heatmap`, (chartRawData) => { |
53 | | - const chartData = []; |
54 | | - for (let i = 0; i < chartRawData.length; i++) { |
55 | | - self.totalContributions += chartRawData[i].contributions; |
56 | | - chartData[i] = {date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions}; |
57 | | - } |
58 | | - self.values = chartData; |
59 | | - self.isLoading = false; |
60 | | - }); |
61 | | - }, |
62 | | - getColor(idx) { |
63 | | - const el = document.createElement('div'); |
64 | | - el.className = `heatmap-color-${idx}`; |
65 | | - document.body.appendChild(el); |
66 | | -
|
67 | | - const color = getComputedStyle(el).backgroundColor; |
68 | | -
|
69 | | - document.body.removeChild(el); |
70 | | -
|
71 | | - return color; |
72 | | - } |
| 38 | + }), |
| 39 | + mounted() { |
| 40 | + this.colorRange = [ |
| 41 | + this.getColor(0), |
| 42 | + this.getColor(1), |
| 43 | + this.getColor(2), |
| 44 | + this.getColor(3), |
| 45 | + this.getColor(4), |
| 46 | + this.getColor(5) |
| 47 | + ]; |
| 48 | + this.endDate = new Date(); |
| 49 | + this.loadHeatmap(this.user); |
| 50 | + }, |
| 51 | + methods: { |
| 52 | + async loadHeatmap(userName) { |
| 53 | + const res = await fetch(`${this.suburl}/api/v1/users/${userName}/heatmap`); |
| 54 | + const data = await res.json(); |
| 55 | + this.values = data.map(({contributions, timestamp}) => { |
| 56 | + return {date: new Date(timestamp * 1000), count: contributions}; |
| 57 | + }); |
| 58 | + this.isLoading = false; |
73 | 59 | }, |
74 | | -} |
| 60 | + getColor(idx) { |
| 61 | + const el = document.createElement('div'); |
| 62 | + el.className = `heatmap-color-${idx}`; |
| 63 | + document.body.appendChild(el); |
| 64 | + const color = getComputedStyle(el).backgroundColor; |
| 65 | + document.body.removeChild(el); |
| 66 | + return color; |
| 67 | + } |
| 68 | + }, |
| 69 | +}; |
75 | 70 | </script> |
76 | | - |
77 | | -<style scoped> |
78 | | -
|
79 | | -</style> |
| 71 | +<style scoped/> |
0 commit comments