aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-01-20 15:01:03 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-01-20 15:01:21 +0100
commit1d8bdc592ad2f615c1fc7d358327fb77171baec3 (patch)
tree585451daa819af6f85c253678105222c20f17bcb /server/sonar-web
parentbbda3cfd4c3463509430a0d9cf4e283167c9769a (diff)
downloadsonarqube-1d8bdc592ad2f615c1fc7d358327fb77171baec3.tar.gz
sonarqube-1d8bdc592ad2f615c1fc7d358327fb77171baec3.zip
use new WS on overview page
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/api/measures.js32
-rw-r--r--server/sonar-web/src/main/js/apps/overview/domains/coverage-domain.js18
-rw-r--r--server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js17
-rw-r--r--server/sonar-web/src/main/js/apps/overview/domains/duplications-domain.js18
-rw-r--r--server/sonar-web/src/main/js/apps/overview/domains/structure-domain.js20
-rw-r--r--server/sonar-web/src/main/js/apps/overview/main/main.js17
-rw-r--r--server/sonar-web/src/main/js/apps/overview/main/structure.js2
7 files changed, 58 insertions, 66 deletions
diff --git a/server/sonar-web/src/main/js/api/measures.js b/server/sonar-web/src/main/js/api/measures.js
index c1ab153b2ac..96dd50b7753 100644
--- a/server/sonar-web/src/main/js/api/measures.js
+++ b/server/sonar-web/src/main/js/api/measures.js
@@ -21,33 +21,7 @@ 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;
- });
+ const url = baseUrl + '/api/measures/component';
+ const data = { componentKey, metricKeys: metrics.join(',') };
+ return getJSON(url, data).then(r => r.component.measures);
}
diff --git a/server/sonar-web/src/main/js/apps/overview/domains/coverage-domain.js b/server/sonar-web/src/main/js/apps/overview/domains/coverage-domain.js
index 653e9dc08d8..8ea481be0da 100644
--- a/server/sonar-web/src/main/js/apps/overview/domains/coverage-domain.js
+++ b/server/sonar-web/src/main/js/apps/overview/domains/coverage-domain.js
@@ -17,10 +17,11 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import _ from 'underscore';
import d3 from 'd3';
import React from 'react';
-import { getMeasuresAndVariations } from '../../../api/measures';
+import { getMeasures } from '../../../api/measures';
import { DomainTimeline } from '../components/domain-timeline';
import { DomainTreemap } from '../components/domain-treemap';
import { DomainBubbleChart } from '../components/domain-bubble-chart';
@@ -50,8 +51,8 @@ export const CoverageMain = React.createClass({
componentDidMount() {
this.requestMeasures().then(r => {
- let measures = this.getMeasuresValues(r, 'value');
- let leak = this.getMeasuresValues(r, 'var' + this.props.leakPeriodIndex);
+ let measures = this.getMeasuresValues(r);
+ let leak = this.getMeasuresValues(r, Number(this.props.leakPeriodIndex));
this.setState({
ready: true,
measures,
@@ -61,10 +62,13 @@ export const CoverageMain = React.createClass({
});
},
- getMeasuresValues (measures, fieldKey) {
+ getMeasuresValues (measures, period) {
let values = {};
- Object.keys(measures).forEach(measureKey => {
- values[measureKey] = measures[measureKey][fieldKey];
+ measures.forEach(measure => {
+ const container = period ? _.findWhere(measure.periods, { index: period }) : measure;
+ if (container) {
+ values[measure.metric] = container.value;
+ }
});
return values;
},
@@ -84,7 +88,7 @@ export const CoverageMain = React.createClass({
},
requestMeasures () {
- return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
+ return getMeasures(this.props.component.key, this.getMetricsForDomain());
},
renderLoading () {
diff --git a/server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js b/server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js
index dc5b513757c..3f998f684a3 100644
--- a/server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js
+++ b/server/sonar-web/src/main/js/apps/overview/domains/debt-domain.js
@@ -21,7 +21,7 @@ import _ from 'underscore';
import d3 from 'd3';
import React from 'react';
-import { getMeasuresAndVariations } from '../../../api/measures';
+import { getMeasures } from '../../../api/measures';
import { DetailedMeasure } from '../components/detailed-measure';
import { DomainTimeline } from '../components/domain-timeline';
import { DomainTreemap } from '../components/domain-treemap';
@@ -64,18 +64,21 @@ export const DebtMain = React.createClass({
this.requestIssues(),
this.requestAssignees()
]).then(responses => {
- let measures = this.getMeasuresValues(responses[0], 'value');
- let leak = this.getMeasuresValues(responses[0], 'var' + this.props.leakPeriodIndex);
+ let measures = this.getMeasuresValues(responses[0]);
+ let leak = this.getMeasuresValues(responses[0], Number(this.props.leakPeriodIndex));
let tags = responses[1].facet;
let assignees = extractAssignees(responses[2].facet, responses[2].response);
this.setState({ ready: true, measures, leak, tags, assignees });
});
},
- getMeasuresValues (measures, fieldKey) {
+ getMeasuresValues (measures, period) {
let values = {};
- Object.keys(measures).forEach(measureKey => {
- values[measureKey] = measures[measureKey][fieldKey];
+ measures.forEach(measure => {
+ const container = period ? _.findWhere(measure.periods, { index: period }) : measure;
+ if (container) {
+ values[measure.metric] = container.value;
+ }
});
return values;
},
@@ -95,7 +98,7 @@ export const DebtMain = React.createClass({
},
requestMeasures () {
- return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
+ return getMeasures(this.props.component.key, this.getMetricsForDomain());
},
getFacet (facets, facetKey) {
diff --git a/server/sonar-web/src/main/js/apps/overview/domains/duplications-domain.js b/server/sonar-web/src/main/js/apps/overview/domains/duplications-domain.js
index 7b26dcfb95c..6946cbdf962 100644
--- a/server/sonar-web/src/main/js/apps/overview/domains/duplications-domain.js
+++ b/server/sonar-web/src/main/js/apps/overview/domains/duplications-domain.js
@@ -17,10 +17,11 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import _ from 'underscore';
import d3 from 'd3';
import React from 'react';
-import { getMeasuresAndVariations } from '../../../api/measures';
+import { getMeasures } from '../../../api/measures';
import { DetailedMeasure } from '../components/detailed-measure';
import { DomainTimeline } from '../components/domain-timeline';
import { DomainTreemap } from '../components/domain-treemap';
@@ -49,16 +50,19 @@ export const DuplicationsMain = React.createClass({
componentDidMount() {
this.requestMeasures().then(r => {
- let measures = this.getMeasuresValues(r, 'value');
- let leak = this.getMeasuresValues(r, 'var' + this.props.leakPeriodIndex);
+ let measures = this.getMeasuresValues(r);
+ let leak = this.getMeasuresValues(r, Number(this.props.leakPeriodIndex));
this.setState({ ready: true, measures, leak });
});
},
- getMeasuresValues (measures, fieldKey) {
+ getMeasuresValues (measures, period) {
let values = {};
- Object.keys(measures).forEach(measureKey => {
- values[measureKey] = measures[measureKey][fieldKey];
+ measures.forEach(measure => {
+ const container = period ? _.findWhere(measure.periods, { index: period }) : measure;
+ if (container) {
+ values[measure.metric] = container.value;
+ }
});
return values;
},
@@ -78,7 +82,7 @@ export const DuplicationsMain = React.createClass({
},
requestMeasures () {
- return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
+ return getMeasures(this.props.component.key, this.getMetricsForDomain());
},
renderLoading () {
diff --git a/server/sonar-web/src/main/js/apps/overview/domains/structure-domain.js b/server/sonar-web/src/main/js/apps/overview/domains/structure-domain.js
index a4451c32c29..7caa737642f 100644
--- a/server/sonar-web/src/main/js/apps/overview/domains/structure-domain.js
+++ b/server/sonar-web/src/main/js/apps/overview/domains/structure-domain.js
@@ -17,12 +17,13 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import _ from 'underscore';
import React from 'react';
import { LanguageDistribution } from './../components/language-distribution';
import { ComplexityDistribution } from './../components/complexity-distribution';
import { NclocDistribution } from '../components/ncloc-distribution';
-import { getMeasuresAndVariations } from '../../../api/measures';
+import { getMeasures } from '../../../api/measures';
import { DetailedMeasure } from '../components/detailed-measure';
import { DomainTimeline } from '../components/domain-timeline';
import { getPeriodLabel, getPeriodDate } from './../helpers/periods';
@@ -45,16 +46,19 @@ export const StructureMain = React.createClass({
componentDidMount() {
this.requestMeasures().then(r => {
- let measures = this.getMeasuresValues(r, 'value');
- let leak = this.getMeasuresValues(r, 'var' + this.props.leakPeriodIndex);
+ let measures = this.getMeasuresValues(r);
+ let leak = this.getMeasuresValues(r, Number(this.props.leakPeriodIndex));
this.setState({ ready: true, measures, leak });
});
},
- getMeasuresValues (measures, fieldKey) {
+ getMeasuresValues (measures, period) {
let values = {};
- Object.keys(measures).forEach(measureKey => {
- values[measureKey] = measures[measureKey][fieldKey];
+ measures.forEach(measure => {
+ const container = period ? _.findWhere(measure.periods, { index: period }) : measure;
+ if (container) {
+ values[measure.metric] = container.value;
+ }
});
return values;
},
@@ -74,7 +78,7 @@ export const StructureMain = React.createClass({
},
requestMeasures () {
- return getMeasuresAndVariations(this.props.component.key, this.getMetricsForDomain());
+ return getMeasures(this.props.component.key, this.getMetricsForDomain());
},
renderLoading () {
@@ -118,7 +122,7 @@ export const StructureMain = React.createClass({
if (distribution == null) {
return null;
}
- return <LanguageDistribution lines={this.state.measures['ncloc']} distribution={distribution}/>;
+ return <LanguageDistribution lines={Number(this.state.measures['ncloc'])} distribution={distribution}/>;
},
renderComplexityDistribution(distribution, props) {
diff --git a/server/sonar-web/src/main/js/apps/overview/main/main.js b/server/sonar-web/src/main/js/apps/overview/main/main.js
index 454b65d0016..b30234371c5 100644
--- a/server/sonar-web/src/main/js/apps/overview/main/main.js
+++ b/server/sonar-web/src/main/js/apps/overview/main/main.js
@@ -27,7 +27,7 @@ import { GeneralDuplications } from './duplications';
import { GeneralStructure } from './structure';
import { CoverageSelectionMixin } from '../components/coverage-selection-mixin';
import { getPeriodLabel, getPeriodDate } from './../helpers/periods';
-import { getMeasuresAndVariations } from '../../../api/measures';
+import { getMeasures } from '../../../api/measures';
import { getIssuesCount } from '../../../api/issues';
import { getTimeMachineData } from '../../../api/time-machine';
@@ -76,13 +76,13 @@ export default React.createClass({
this.requestIssuesAndDebt(),
this.requestLeakIssuesAndDebt()
]).then(responses => {
- let measures = this.getMeasuresValues(responses[0], 'value');
+ let measures = this.getMeasuresValues(responses[0]);
measures.issues = responses[1].issues;
measures.debt = responses[1].debt;
let leak;
if (this.state.leakPeriodDate) {
- leak = this.getMeasuresValues(responses[0], 'var' + this.props.leakPeriodIndex);
+ leak = this.getMeasuresValues(responses[0], Number(this.props.leakPeriodIndex));
leak.issues = responses[2].issues;
leak.debt = responses[2].debt;
}
@@ -97,13 +97,16 @@ export default React.createClass({
},
requestMeasures () {
- return getMeasuresAndVariations(this.props.component.key, METRICS_LIST);
+ return getMeasures(this.props.component.key, METRICS_LIST);
},
- getMeasuresValues (measures, fieldKey) {
+ getMeasuresValues (measures, period) {
let values = {};
- Object.keys(measures).forEach(measureKey => {
- values[measureKey] = measures[measureKey][fieldKey];
+ measures.forEach(measure => {
+ const container = period ? _.findWhere(measure.periods, { index: period }) : measure;
+ if (container) {
+ values[measure.metric] = container.value;
+ }
});
return values;
},
diff --git a/server/sonar-web/src/main/js/apps/overview/main/structure.js b/server/sonar-web/src/main/js/apps/overview/main/structure.js
index 8ca70fa06f3..0e794d06126 100644
--- a/server/sonar-web/src/main/js/apps/overview/main/structure.js
+++ b/server/sonar-web/src/main/js/apps/overview/main/structure.js
@@ -63,7 +63,7 @@ export const GeneralStructure = React.createClass({
}
return <Measure composite={true}>
<div style={{ width: 200 }}>
- <LanguageDistribution lines={this.props.measures['ncloc']}
+ <LanguageDistribution lines={Number(this.props.measures['ncloc'])}
distribution={this.props.measures['ncloc_language_distribution']}/>
</div>
</Measure>;