Skip to content

Commit e09fe48

Browse files
lafriksjonasfranz
authored andcommitted
Refactor heatmap to vue component (#5401)
1 parent c03a9b3 commit e09fe48

File tree

18 files changed

+258
-384
lines changed

18 files changed

+258
-384
lines changed

custom/conf/app.ini.sample

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ MAX_DISPLAY_FILE_SIZE = 8388608
8585
SHOW_USER_EMAIL = true
8686
; Set the default theme for the Gitea install
8787
DEFAULT_THEME = gitea
88-
; Set the color range to use for heatmap (default to `['#f4f4f4', '#459928']` but can use `['#2d303b', '#80bb46']` with the theme `arc-green`)
89-
HEATMAP_COLOR_RANGE = `['#f4f4f4', '#459928']`
9088

9189
[ui.admin]
9290
; Number of users that are displayed on one page

modules/setting/setting.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ var (
301301
MaxDisplayFileSize int64
302302
ShowUserEmail bool
303303
DefaultTheme string
304-
HeatmapColorRange string
305304

306305
Admin struct {
307306
UserPagingNum int
@@ -328,7 +327,6 @@ var (
328327
ThemeColorMetaTag: `#6cc644`,
329328
MaxDisplayFileSize: 8388608,
330329
DefaultTheme: `gitea`,
331-
HeatmapColorRange: `['#f4f4f4', '#459928']`,
332330
Admin: struct {
333331
UserPagingNum int
334332
RepoPagingNum int

modules/templates/helper.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ func NewFuncMap() []template.FuncMap {
193193
"DefaultTheme": func() string {
194194
return setting.UI.DefaultTheme
195195
},
196-
"HeatmapColorRange": func() string {
197-
return setting.UI.HeatmapColorRange
198-
},
199196
"dict": func(values ...interface{}) (map[string]interface{}, error) {
200197
if len(values) == 0 {
201198
return nil, errors.New("invalid dict call")

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/theme-arc-green.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,96 @@ function cancelStopwatch() {
22932293
$("#cancel_stopwatch_form").submit();
22942294
}
22952295

2296+
function initHeatmap(appElementId, heatmapUser, locale) {
2297+
var el = document.getElementById(appElementId);
2298+
if (!el) {
2299+
return;
2300+
}
2301+
2302+
locale = locale || {};
2303+
2304+
locale.contributions = locale.contributions || 'contributions';
2305+
locale.no_contributions = locale.no_contributions || 'No contributions';
2306+
2307+
var vueDelimeters = ['${', '}'];
2308+
2309+
Vue.component('activity-heatmap', {
2310+
delimiters: vueDelimeters,
2311+
2312+
props: {
2313+
user: {
2314+
type: String,
2315+
required: true
2316+
},
2317+
suburl: {
2318+
type: String,
2319+
required: true
2320+
},
2321+
locale: {
2322+
type: Object,
2323+
required: true
2324+
}
2325+
},
2326+
2327+
data: function () {
2328+
return {
2329+
isLoading: true,
2330+
colorRange: [],
2331+
endDate: null,
2332+
values: []
2333+
};
2334+
},
2335+
2336+
mounted: function() {
2337+
this.colorRange = [
2338+
this.getColor(0),
2339+
this.getColor(1),
2340+
this.getColor(2),
2341+
this.getColor(3),
2342+
this.getColor(4),
2343+
this.getColor(5)
2344+
];
2345+
console.log(this.colorRange);
2346+
this.endDate = new Date();
2347+
this.loadHeatmap(this.user);
2348+
},
2349+
2350+
methods: {
2351+
loadHeatmap: function(userName) {
2352+
var self = this;
2353+
$.get(this.suburl + '/api/v1/users/' + userName + '/heatmap', function(chartRawData) {
2354+
var chartData = [];
2355+
for (var i = 0; i < chartRawData.length; i++) {
2356+
chartData[i] = { date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions };
2357+
}
2358+
self.values = chartData;
2359+
self.isLoading = false;
2360+
});
2361+
},
2362+
2363+
getColor: function(idx) {
2364+
var el = document.createElement('div');
2365+
el.className = 'heatmap-color-' + idx;
2366+
2367+
return getComputedStyle(el).backgroundColor;
2368+
}
2369+
},
2370+
2371+
template: '<div><div v-show="isLoading"><slot name="loading"></slot></div><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" />'
2372+
});
2373+
2374+
new Vue({
2375+
delimiters: vueDelimeters,
2376+
el: el,
2377+
2378+
data: {
2379+
suburl: document.querySelector('meta[name=_suburl]').content,
2380+
heatmapUser: heatmapUser,
2381+
locale: locale
2382+
},
2383+
});
2384+
}
2385+
22962386
function initFilterBranchTagDropdown(selector) {
22972387
$(selector).each(function() {
22982388
var $dropdown = $(this);

public/less/_base.less

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,27 @@ footer {
605605
}
606606
}
607607
}
608+
609+
.heatmap-color-0 {
610+
background-color: #f4f4f4;
611+
}
612+
613+
.heatmap-color-1 {
614+
background-color: #d7e5db;
615+
}
616+
617+
.heatmap-color-2 {
618+
background-color: #adc7ab;
619+
}
620+
621+
.heatmap-color-3 {
622+
background-color: #83a87b;
623+
}
624+
625+
.heatmap-color-4 {
626+
background-color: #598a4b;
627+
}
628+
629+
.heatmap-color-5 {
630+
background-color: #2f6b1b;
631+
}

public/less/themes/arc-green.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,3 +818,7 @@
818818
color: #9e9e9e;
819819
}
820820
}
821+
822+
.heatmap-color-0 {
823+
background-color: #2d303b;
824+
}

public/vendor/librejs.html

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,9 @@
136136
<td><a href="https://github.com/swagger-api/swagger-ui/archive/v3.0.4.tar.gz">swagger-ui-v3.0.4.tar.gz</a></td>
137137
</tr>
138138
<tr>
139-
<td><a href="./plugins/d3/">d3</a></td>
140-
<td><a href="https://github.com/d3/d3/blob/master/LICENSE">BSD 3-Clause</a></td>
141-
<td><a href="https://github.com/d3/d3/releases/download/v4.13.0/d3.zip">d3.zip</a></td>
142-
</tr>
143-
<tr>
144-
<td><a href="./plugins/calendar-heatmap/">calendar-heatmap</a></td>
145-
<td><a href="https://github.com/DKirwan/calendar-heatmap/blob/master/LICENSE">MIT</a></td>
146-
<td><a href="https://github.com/DKirwan/calendar-heatmap/archive/master.zip">337b431.zip</a></td>
139+
<td><a href="./plugins/vue-calendar-heatmap">vue-calendar-heatmap</a></td>
140+
<td><a href="https://github.com/WildCodeSchool/vue-calendar-heatmap/blob/master/README.md">MIT</a></td>
141+
<td><a href="https://github.com/WildCodeSchool/vue-calendar-heatmap/archive/master.zip">7f48b20.zip</a></td>
147142
</tr>
148143
<tr>
149144
<td><a href="./plugins/moment/">moment.js</a></td>

public/vendor/plugins/calendar-heatmap/calendar-heatmap.css

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)