Commit 8ec30e75 authored by Jose's avatar Jose

Add environments endpoint, also added store and service capabilities for said endpoint

parent b80f819b
...@@ -80,6 +80,10 @@ export default { ...@@ -80,6 +80,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
environmentsEndpoint: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -96,6 +100,7 @@ export default { ...@@ -96,6 +100,7 @@ export default {
this.service = new MonitoringService({ this.service = new MonitoringService({
metricsEndpoint: this.metricsEndpoint, metricsEndpoint: this.metricsEndpoint,
deploymentEndpoint: this.deploymentEndpoint, deploymentEndpoint: this.deploymentEndpoint,
environmentsEndpoint: this.environmentsEndpoint,
}); });
eventHub.$on('toggleAspectRatio', this.toggleAspectRatio); eventHub.$on('toggleAspectRatio', this.toggleAspectRatio);
eventHub.$on('hoverChanged', this.hoverChanged); eventHub.$on('hoverChanged', this.hoverChanged);
...@@ -123,12 +128,17 @@ export default { ...@@ -123,12 +128,17 @@ export default {
.getDeploymentData() .getDeploymentData()
.then(data => this.store.storeDeploymentData(data)) .then(data => this.store.storeDeploymentData(data))
.catch(() => new Flash('Error getting deployment information.')), .catch(() => new Flash('Error getting deployment information.')),
this.service
.getEnvironmentsData()
.then((data) => this.store.storeEnvironmentsData(data))
.catch(() => new Flash('Error getting environments information.')),
]) ])
.then(() => { .then(() => {
if (this.store.groups.length < 1) { if (this.store.groups.length < 1) {
this.state = 'noData'; this.state = 'noData';
return; return;
} }
// Populate the environments dropdown
this.showEmptyState = false; this.showEmptyState = false;
}) })
.catch(() => { .catch(() => {
...@@ -170,12 +180,9 @@ export default { ...@@ -170,12 +180,9 @@ export default {
<i class="fa fa-chevron-down"></i> <i class="fa fa-chevron-down"></i>
</button> </button>
<div class="dropdown-menu dropdown-menu-selectable dropdown-menu-drop-up"> <div class="dropdown-menu dropdown-menu-selectable dropdown-menu-drop-up">
<a <button class="dropdown-item">
href="#"
class="dropdown-item"
>
Staging Staging
</a> </button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -23,9 +23,10 @@ function backOffRequest(makeRequestCallback) { ...@@ -23,9 +23,10 @@ function backOffRequest(makeRequestCallback) {
} }
export default class MonitoringService { export default class MonitoringService {
constructor({ metricsEndpoint, deploymentEndpoint }) { constructor({ metricsEndpoint, deploymentEndpoint, environmentsEndpoint }) {
this.metricsEndpoint = metricsEndpoint; this.metricsEndpoint = metricsEndpoint;
this.deploymentEndpoint = deploymentEndpoint; this.deploymentEndpoint = deploymentEndpoint;
this.environmentsEndpoint = environmentsEndpoint;
} }
getGraphsData() { getGraphsData() {
...@@ -52,4 +53,15 @@ export default class MonitoringService { ...@@ -52,4 +53,15 @@ export default class MonitoringService {
return response.deployments; return response.deployments;
}); });
} }
getEnvironmentsData() {
return axios.get(this.environmentsEndpoint)
.then(resp => resp.data)
.then((response) => {
if (!response || !response.environments) {
throw new Error('There was an error fetching the environments data, please try again');
}
return response.environments;
});
}
} }
...@@ -37,6 +37,10 @@ export default class MonitoringStore { ...@@ -37,6 +37,10 @@ export default class MonitoringStore {
this.deploymentData = deploymentData; this.deploymentData = deploymentData;
} }
storeEnvironmentsData(environmentsData = []) {
this.environmentsData = environmentsData;
}
getMetricsCount() { getMetricsCount() {
return this.groups.reduce((count, group) => count + group.metrics.length, 0); return this.groups.reduce((count, group) => count + group.metrics.length, 0);
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"empty-unable-to-connect-svg-path": image_path('illustrations/monitoring/unable_to_connect.svg'), "empty-unable-to-connect-svg-path": image_path('illustrations/monitoring/unable_to_connect.svg'),
"metrics-endpoint": additional_metrics_project_environment_path(@project, @environment, format: :json), "metrics-endpoint": additional_metrics_project_environment_path(@project, @environment, format: :json),
"deployment-endpoint": project_environment_deployments_path(@project, @environment, format: :json), "deployment-endpoint": project_environment_deployments_path(@project, @environment, format: :json),
"environments": project_environments_path(@project, format: :json), "environments-endpoint": project_environments_path(@project, format: :json),
"project-path": project_path(@project), "project-path": project_path(@project),
"tags-path": project_tags_path(@project), "tags-path": project_tags_path(@project),
"has-metrics": "#{@environment.has_metrics?}" } } "has-metrics": "#{@environment.has_metrics?}" } }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment