mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
Refactor heatmap to vue component (#5401)
This commit is contained in:
parent
c03a9b3e42
commit
e09fe48773
18 changed files with 258 additions and 384 deletions
|
@ -2293,6 +2293,96 @@ function cancelStopwatch() {
|
|||
$("#cancel_stopwatch_form").submit();
|
||||
}
|
||||
|
||||
function initHeatmap(appElementId, heatmapUser, locale) {
|
||||
var el = document.getElementById(appElementId);
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
|
||||
locale = locale || {};
|
||||
|
||||
locale.contributions = locale.contributions || 'contributions';
|
||||
locale.no_contributions = locale.no_contributions || 'No contributions';
|
||||
|
||||
var vueDelimeters = ['${', '}'];
|
||||
|
||||
Vue.component('activity-heatmap', {
|
||||
delimiters: vueDelimeters,
|
||||
|
||||
props: {
|
||||
user: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
suburl: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
locale: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
isLoading: true,
|
||||
colorRange: [],
|
||||
endDate: null,
|
||||
values: []
|
||||
};
|
||||
},
|
||||
|
||||
mounted: function() {
|
||||
this.colorRange = [
|
||||
this.getColor(0),
|
||||
this.getColor(1),
|
||||
this.getColor(2),
|
||||
this.getColor(3),
|
||||
this.getColor(4),
|
||||
this.getColor(5)
|
||||
];
|
||||
console.log(this.colorRange);
|
||||
this.endDate = new Date();
|
||||
this.loadHeatmap(this.user);
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadHeatmap: function(userName) {
|
||||
var self = this;
|
||||
$.get(this.suburl + '/api/v1/users/' + userName + '/heatmap', function(chartRawData) {
|
||||
var chartData = [];
|
||||
for (var i = 0; i < chartRawData.length; i++) {
|
||||
chartData[i] = { date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions };
|
||||
}
|
||||
self.values = chartData;
|
||||
self.isLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
getColor: function(idx) {
|
||||
var el = document.createElement('div');
|
||||
el.className = 'heatmap-color-' + idx;
|
||||
|
||||
return getComputedStyle(el).backgroundColor;
|
||||
}
|
||||
},
|
||||
|
||||
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" />'
|
||||
});
|
||||
|
||||
new Vue({
|
||||
delimiters: vueDelimeters,
|
||||
el: el,
|
||||
|
||||
data: {
|
||||
suburl: document.querySelector('meta[name=_suburl]').content,
|
||||
heatmapUser: heatmapUser,
|
||||
locale: locale
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function initFilterBranchTagDropdown(selector) {
|
||||
$(selector).each(function() {
|
||||
var $dropdown = $(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue