Commit b80f819b authored by Tiago Botelho's avatar Tiago Botelho Committed by Jose

Moves the request of the environments list to the index action

parent 95954a60
...@@ -6,11 +6,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -6,11 +6,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action :authorize_update_environment!, only: [:edit, :update] before_action :authorize_update_environment!, only: [:edit, :update]
before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize] before_action :authorize_admin_environment!, only: [:terminal, :terminal_websocket_authorize]
before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :metrics] before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :metrics]
before_action :environments, only: [:index]
before_action :verify_api_request!, only: :terminal_websocket_authorize before_action :verify_api_request!, only: :terminal_websocket_authorize
before_action :expire_etag_cache, only: [:index] before_action :expire_etag_cache, only: [:index]
def index def index
@environments = project.environments
.with_state(params[:scope] || :available)
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
...@@ -126,12 +128,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -126,12 +128,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json do format.json do
render json: { render json: @metrics, status: @metrics.any? ? :ok : :no_content
metrics: @metrics,
environments: EnvironmentSerializer
.new(project: project, current_user: current_user)
.represent(environments)
}, status: @metrics.any? ? :ok : :no_content
end end
end end
end end
...@@ -141,12 +138,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -141,12 +138,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
format.json do format.json do
additional_metrics = environment.additional_metrics || {} additional_metrics = environment.additional_metrics || {}
render json: { render json: additional_metrics, status: additional_metrics.any? ? :ok : :no_content
additional_metrics: additional_metrics,
environments: EnvironmentSerializer
.new(project: project, current_user: current_user)
.represent(environments)
}, status: additional_metrics.empty? ? :ok : :no_content
end end
end end
end end
...@@ -173,8 +165,4 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -173,8 +165,4 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def environment def environment
@environment ||= project.environments.find(params[:id]) @environment ||= project.environments.find(params[:id])
end end
def environments
@environments ||= project.environments.with_state(params[:scope] || :available)
end
end end
...@@ -11,6 +11,7 @@ ...@@ -11,6 +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),
"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