|
1 | 1 | import Vue from 'vue';
|
2 | 2 |
|
3 |
| -const {AppSubUrl, heatmapUser} = window.config; |
| 3 | +import ActivityHeatmap from '../components/ActivityHeatmap.vue'; |
4 | 4 |
|
5 |
| -export default async function initHeatmap() { |
| 5 | +export default async function initUserHeatmap() { |
6 | 6 | const el = document.getElementById('user-heatmap');
|
7 | 7 | if (!el) return;
|
8 |
| - |
9 |
| - const {CalendarHeatmap} = await import(/* webpackChunkName: "userheatmap" */'vue-calendar-heatmap'); |
10 |
| - Vue.component('calendarHeatmap', CalendarHeatmap); |
11 |
| - |
12 |
| - const vueDelimeters = ['${', '}']; |
13 |
| - |
14 |
| - Vue.component('activity-heatmap', { |
15 |
| - delimiters: vueDelimeters, |
16 |
| - |
17 |
| - props: { |
18 |
| - user: { |
19 |
| - type: String, |
20 |
| - required: true |
21 |
| - }, |
22 |
| - suburl: { |
23 |
| - type: String, |
24 |
| - required: true |
25 |
| - }, |
26 |
| - locale: { |
27 |
| - type: Object, |
28 |
| - required: true |
29 |
| - } |
30 |
| - }, |
31 |
| - |
32 |
| - data() { |
33 |
| - return { |
34 |
| - isLoading: true, |
35 |
| - colorRange: [], |
36 |
| - endDate: null, |
37 |
| - values: [], |
38 |
| - totalContributions: 0, |
39 |
| - }; |
40 |
| - }, |
41 |
| - |
42 |
| - mounted() { |
43 |
| - this.colorRange = [ |
44 |
| - this.getColor(0), |
45 |
| - this.getColor(1), |
46 |
| - this.getColor(2), |
47 |
| - this.getColor(3), |
48 |
| - this.getColor(4), |
49 |
| - this.getColor(5) |
50 |
| - ]; |
51 |
| - this.endDate = new Date(); |
52 |
| - this.loadHeatmap(this.user); |
53 |
| - }, |
54 |
| - |
55 |
| - methods: { |
56 |
| - loadHeatmap(userName) { |
57 |
| - const self = this; |
58 |
| - $.get(`${this.suburl}/api/v1/users/${userName}/heatmap`, (chartRawData) => { |
59 |
| - const chartData = []; |
60 |
| - for (let i = 0; i < chartRawData.length; i++) { |
61 |
| - self.totalContributions += chartRawData[i].contributions; |
62 |
| - chartData[i] = {date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions}; |
63 |
| - } |
64 |
| - self.values = chartData; |
65 |
| - self.isLoading = false; |
66 |
| - }); |
67 |
| - }, |
68 |
| - |
69 |
| - getColor(idx) { |
70 |
| - const el = document.createElement('div'); |
71 |
| - el.className = `heatmap-color-${idx}`; |
72 |
| - document.body.appendChild(el); |
73 |
| - |
74 |
| - const color = getComputedStyle(el).backgroundColor; |
75 |
| - |
76 |
| - document.body.removeChild(el); |
77 |
| - |
78 |
| - return color; |
79 |
| - } |
80 |
| - }, |
81 |
| - |
82 |
| - template: '<div><div v-show="isLoading"><slot name="loading"></slot></div><h4 class="total-contributions" v-if="!isLoading"><span v-html="totalContributions"></span> total contributions in the last 12 months</h4><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"/></div>' |
83 |
| - }); |
84 |
| - |
85 |
| - new Vue({ |
86 |
| - delimiters: vueDelimeters, |
87 |
| - el, |
88 |
| - |
89 |
| - data: { |
90 |
| - suburl: AppSubUrl, |
91 |
| - heatmapUser, |
92 |
| - locale: { |
93 |
| - contributions: 'contributions', |
94 |
| - no_contributions: 'No contributions', |
95 |
| - }, |
96 |
| - }, |
97 |
| - }); |
| 8 | + const View = Vue.extend(ActivityHeatmap); |
| 9 | + new View().$mount(el); |
98 | 10 | }
|
0 commit comments