summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/measures.js
blob: aeb33eb0ca9a0c8317b1b91b4f44469ef4b4c04b (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
import { getJSON } from '../helpers/request.js';


export function getMeasures (componentKey, metrics) {
  const url = baseUrl + '/api/resources/index';
  const data = { resource: componentKey, metrics: metrics.join(',') };
  return getJSON(url, data).then(r => {
    const msr = r[0].msr || [];
    const measures = {};
    msr.forEach(measure => {
      measures[measure.key] = measure.val || measure.data;
    });
    return measures;
  });
}


export function getMeasuresAndVariations (componentKey, metrics) {
  const url = baseUrl + '/api/resources/index';
  const data = { resource: componentKey, metrics: metrics.join(','), includetrends: 'true' };
  return getJSON(url, data).then(r => {
    const msr = r[0].msr || [];
    const measures = {};
    msr.forEach(measure => {
      measures[measure.key] = {
        value: measure.val != null ? measure.val : measure.data,
        var1: measure.var1,
        var2: measure.var2,
        var3: measure.var3
      };
    });
    return measures;
  });
}