Welcome to mirror list, hosted at ThFree Co, Russian Federation.

contributors.vue « components « contributors « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bcca0dfe8ef22175e2c55b8d05422f371ffeac8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<script>
import { s__ } from '~/locale';
import { mapGetters, mapActions, mapState } from 'vuex';
import { engineeringNotation, sum, average } from '@gitlab/ui/utils/number_utils';
import { GlLoadingIcon } from '@gitlab/ui';
import { GlChartLegend } from '@gitlab/ui/charts';
import { GlAreaChart } from '@gitlab/ui/dist/charts';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import ContributorsStatGraphUtil from '../../pages/projects/graphs/show/stat_graph_contributors_util';

const chartOptions = {
  'xAxis': {
    'type': 'time',
    'name': 'Time',
    'axisLabel': {},
    minInterval: 3600 * 24 * 1000 * 365,
  },
  yAxis: {
    name: 'Number of commits',
  }
};

export default {
  components: {
    GlAreaChart,
    GlLoadingIcon,
    GlChartLegend,
  },
  props: {
    endpoint: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      svgs: {},
      chart: null,
      chartOptions,
    };
  },
  computed: {
    ...mapState('contributors', ['chartData', 'loading']),
    ...mapGetters('contributors', ['hasFilters', 'appliedFilters']),
    chartData2() {
      // const { chartData, chartHasData } = this;
      // const data = [];
      //
      // if (chartHasData()) {
      //   Object.keys(chartData).forEach(key => {
      //     const date = new Date(key);
      //     const label = `${getMonthNames(true)[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
      //     const val = chartData[key];
      //
      //     data.push([label, val]);
      //   });
      // }
      //
      // return data;
      if (!this.chartHasData) return;

      const data = this.totalCommits.map((item) => {
        return [new Date(item.date), item.commits];
      });

      return [
        {
          name: 'Commits',
          data
        },
      ];
    },
    chartHasData() {
      return !this.loading && this.chartData;
    },
    chartLabels() {
      return this.data.map(val => val[0]);
    },
    chartDateRange() {
      return `${this.chartLabels[0]} - ${this.chartLabels[this.chartLabels.length - 1]}`;
    },
    showChart() {
      return !this.loading && this.chartHasData();
    },

    contributors() {
      const commitsByAuthor = ContributorsStatGraphUtil.get_author_data(this.parsedLog, 'commits').slice(0, 5);
      return commitsByAuthor.map((item) => {
        return {
          ...item,
          dates: [{
            name: 'Commits',
            data: Object.keys(item.dates).map((date) => {
              return [new Date(date), item.dates[date]];
            }),
          }],
        };
      });
    },
    // chartOptions() {
    //   return {
    //     dataZoom: [
    //       {
    //         type: 'slider',
    //         startValue: 0,
    //         handleIcon: this.svgs['scroll-handle'],
    //       },
    //     ],
    //   };
    // },
    parsedLog() {
      return ContributorsStatGraphUtil.parse_log(this.chartData);
    },
    totalCommits() {
      return ContributorsStatGraphUtil.get_total_data(this.parsedLog, 'commits');
    },
  },
  watch: {
    appliedFilters() {
      this.fetchChartData(this.endpoint);
    },
    showNoDataEmptyState(showEmptyState) {
      if (showEmptyState) {
        this.$nextTick(() => this.filterBlockEl.classList.add('hide'));
      }
    },
  },
  created() {
    this.setSvg('scroll-handle');
  },
  mounted() {
    this.fetchChartData(this.endpoint);
  },
  methods: {
    ...mapActions('contributors', ['fetchChartData']),
    onCreated(chart) {
      this.chart = chart;
    },
    chartHasData() {
      if (!this.chartData) {
        return false;
      }

      return Object.values(this.chartData).some(val => val > 0);
    },
    setSvg(name) {
      getSvgIconPathContent(name)
        .then(path => {
          if (path) {
            this.$set(this.svgs, name, `path://${path}`);
          }
        })
        .catch(() => {});
    },
    getTotalData(){
      return ContributorsStatGraphUtil.get_total_data(this.parsed_log, this.field);
    }
  },
};
</script>
<template>
    <div class="issues-analytics-wrapper">
        <div v-if="loading" class="issues-analytics-loading text-center">
            <gl-loading-icon :inline="true" :size="4"/>
        </div>
        <gl-area-chart v-if="!loading"
                       :data="chartData2"
                       :option="chartOptions"/>
        <div class="contributors-list row" v-if="!loading">
            <div class="person col-6" v-for="contributor in contributors">
                <h4>{{contributor.author_name}}</h4>
                <p>{{contributor.author_email}}</p>
                <p>{{contributor.commits}}</p>
                <gl-area-chart :data="contributor.dates"
                               :option="chartOptions"/>
            </div>
        </div>
    </div>
</template>