2018-01-20 00:46:47 -08:00
|
|
|
import Route from '@ember/routing/route';
|
|
|
|
import { setProperties } from '@ember/object';
|
2017-09-19 13:32:04 -07:00
|
|
|
import fetch from 'fetch';
|
2017-02-13 11:35:15 -08:00
|
|
|
|
2017-05-15 12:45:28 -07:00
|
|
|
const metricsUrlRoot = '/api/v1/metrics';
|
2017-02-13 11:35:15 -08:00
|
|
|
|
2017-05-15 12:45:28 -07:00
|
|
|
/**
|
|
|
|
* Takes an object representing a metric and generates a list of breadcrumb items for each level in the
|
|
|
|
* hierarchy
|
|
|
|
* @param {Object} metric properties for the current metric
|
|
|
|
* @return {[*,*,*,*]}
|
|
|
|
*/
|
|
|
|
const makeMetricsBreadcrumbs = (metric = {}) => {
|
|
|
|
let { id, dashboardName, group, category, name } = metric;
|
|
|
|
dashboardName || (dashboardName = '(Other)');
|
|
|
|
group || (group = '(Other)');
|
|
|
|
name = category ? `{${category}} ${name}` : name;
|
2017-02-13 11:35:15 -08:00
|
|
|
|
2017-05-15 12:45:28 -07:00
|
|
|
return [
|
|
|
|
{ crumb: 'Metrics', name: '' },
|
|
|
|
{ crumb: dashboardName, name: dashboardName },
|
|
|
|
{ crumb: group, name: `${dashboardName}/${group}` },
|
|
|
|
{ crumb: name, name: id }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Route.extend({
|
|
|
|
setupController(controller, model) {
|
|
|
|
const { metric } = model;
|
|
|
|
|
|
|
|
// Set the metric as the model and create breadcrumbs
|
|
|
|
setProperties(controller, {
|
|
|
|
model: metric,
|
|
|
|
breadcrumbs: makeMetricsBreadcrumbs(metric)
|
2017-02-13 11:35:15 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-05-15 12:45:28 -07:00
|
|
|
/**
|
|
|
|
* Fetches the metric with the id specified in the route
|
|
|
|
* @param metric_id
|
2018-01-20 00:46:47 -08:00
|
|
|
* @return {Promise<any>}
|
2017-05-15 12:45:28 -07:00
|
|
|
*/
|
|
|
|
model({ metric_id }) {
|
|
|
|
const metricsUrl = `${metricsUrlRoot}/${metric_id}`;
|
|
|
|
return fetch(metricsUrl).then(response => response.json());
|
2017-02-13 11:35:15 -08:00
|
|
|
}
|
|
|
|
});
|