summaryrefslogtreecommitdiffstats
path: root/public/js/index.js
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-11-27 11:36:54 +0200
committerJonas Franz <info@jonasfranz.software>2018-11-27 10:36:54 +0100
commite09fe487734238708c2f9fc7c47dbb2132250400 (patch)
treebd302a98f3badfe9e2b74283e2d068bfd92bb5f8 /public/js/index.js
parentc03a9b3e422ded9d8200a83b94ab56ddb4740d94 (diff)
downloadgitea-e09fe487734238708c2f9fc7c47dbb2132250400.tar.gz
gitea-e09fe487734238708c2f9fc7c47dbb2132250400.zip
Refactor heatmap to vue component (#5401)
Diffstat (limited to 'public/js/index.js')
-rw-r--r--public/js/index.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 1e7dd4da19..6952cec7f6 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -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);