Commit c319cc5a authored by Kamil Trzcinski's avatar Kamil Trzcinski

Make environments to be close able

parent fd4e0703
...@@ -7,11 +7,12 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -7,11 +7,12 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def index def index
@scope = params[:scope] @scope = params[:scope]
@environments = project.environments @all_environments = project.environments
@environments =
# TODO: fix the values of this vars to show the correct results case @scope
@available_environments_count = project.environments.count when 'closed' then @all_environments.closed
@stopped_environments_count = project.environments.count else @all_environments.opened
end
end end
def show def show
......
...@@ -1302,7 +1302,7 @@ class Project < ActiveRecord::Base ...@@ -1302,7 +1302,7 @@ class Project < ActiveRecord::Base
environment_ids.where(ref: ref) environment_ids.where(ref: ref)
end end
environments.where(id: environment_ids).select do |environment| environments.opened.where(id: environment_ids).select do |environment|
environment.includes_commit?(commit) environment.includes_commit?(commit)
end end
end end
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
= custom_icon('icon_play') = custom_icon('icon_play')
%span= action.name.humanize %span= action.name.humanize
.inline - if local_assigns.fetch(:allow_close, false) && deployment.closeable?
%a.close-env-link.btn .inline
= icon('stop', class: 'close-env-icon') %a.close-env-link.btn
= link_to [:play, @project.namespace.becomes(Namespace), @project, deployment.close_action], method: :post, rel: 'nofollow', data: { confirm: 'Are you sure you want to close this environment?' } do
= icon('stop', class: 'close-env-icon')
- if local_assigns.fetch(:allow_rollback, false) - if local_assigns.fetch(:allow_rollback, false)
= link_to [:retry, @project.namespace.becomes(Namespace), @project, deployment.deployable], method: :post, class: 'btn' do = link_to [:retry, @project.namespace.becomes(Namespace), @project, deployment.deployable], method: :post, class: 'btn' do
......
...@@ -21,4 +21,4 @@ ...@@ -21,4 +21,4 @@
#{time_ago_with_tooltip(last_deployment.created_at)} #{time_ago_with_tooltip(last_deployment.created_at)}
%td.hidden-xs %td.hidden-xs
= render 'projects/deployments/actions', deployment: last_deployment = render 'projects/deployments/actions', deployment: last_deployment, allow_close: environment.opened?
...@@ -3,26 +3,26 @@ ...@@ -3,26 +3,26 @@
= render "projects/pipelines/head" = render "projects/pipelines/head"
%div{ class: container_class } %div{ class: container_class }
- if can?(current_user, :create_environment, @project) && !@environments.blank? .top-area
.top-area %ul.nav-links
%ul.nav-links %li{class: ('active' if @scope.nil?)}
%li{class: ('active' if @scope.nil?)} = link_to project_environments_path(@project) do
= link_to project_environments_path(@project) do Availabe
Availabe %span.badge.js-avaibale-environments-count
%span.badge.js-avaibale-environments-count = number_with_delimiter(@all_environments.opened.count)
= number_with_delimiter(@available_environments_count)
%li{class: ('active' if @scope == 'stopped')}
= link_to project_environments_path(@project, scope: :stopped) do
Stopped
%span.badge.js-stopped-environments-count
= number_with_delimiter(@stopped_environments_count)
.nav-controls %li{class: ('active' if @scope == 'closed')}
= link_to project_environments_path(@project, scope: :stopped) do
Stopped
%span.badge.js-stopped-environments-count
= number_with_delimiter(@all_environments.closed.count)
.nav-controls
- if can?(current_user, :create_environment, @project) && !@all_environments.blank?
= link_to new_namespace_project_environment_path(@project.namespace, @project), class: 'btn btn-create' do = link_to new_namespace_project_environment_path(@project.namespace, @project), class: 'btn btn-create' do
New environment New environment
- if @environments.blank? - if @all_environments.blank?
.blank-state.blank-state-no-icon .blank-state.blank-state-no-icon
%h2.blank-state-title %h2.blank-state-title
You don't have any environments right now. You don't have any environments right now.
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
- page_title "Environments" - page_title "Environments"
= render "projects/pipelines/head" = render "projects/pipelines/head"
- last_deployment = @environment.last_deployment
%div{ class: container_class } %div{ class: container_class }
.top-area .top-area
.col-md-9 .col-md-9
...@@ -10,8 +12,9 @@ ...@@ -10,8 +12,9 @@
.nav-controls .nav-controls
- if can?(current_user, :update_environment, @environment) - if can?(current_user, :update_environment, @environment)
= link_to 'Edit', edit_namespace_project_environment_path(@project.namespace, @project, @environment), class: 'btn' = link_to 'Edit', edit_namespace_project_environment_path(@project.namespace, @project, @environment), class: 'btn'
/ TODO: Confirm if the method is :delete - if @environment.opened? && last_deployment.try(:close_action)
= link_to 'Close', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure you want to delete this environment?' }, class: 'btn btn-danger', method: :delete = link_to 'Close', [:play, @project.namespace.becomes(Namespace), @project, last_deployment.close_action], data: { confirm: 'Are you sure you want to close this environment?' }, class: 'btn btn-danger', method: :post
= link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure you want to delete this environment?' }, class: 'btn btn-danger', method: :delete
- if @deployments.blank? - if @deployments.blank?
.blank-state.blank-state-no-icon .blank-state.blank-state-no-icon
......
...@@ -58,5 +58,6 @@ ...@@ -58,5 +58,6 @@
= link_to external_url, target: '_blank' do = link_to external_url, target: '_blank' do
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true) = icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true)
%span.close-env-container %span.close-env-container
= link_to '#', class: 'close-evn-link' do - if environment.closeable?
= icon('stop-circle-o', text: 'Stop environment') = link_to [:play, @project.namespace.becomes(Namespace), @project, environment.close_action], method: :post, class: 'close-evn-link', rel: 'nofollow', data: { confirm: 'Are you sure you want to close this environment?' } do
= icon('stop-circle-o', text: 'Stop environment')
class AddStateToEnvironment < ActiveRecord::Migration class AddStateToEnvironment < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false DOWNTIME = false
def change def up
add_column :environments, :state, :string add_column_with_default(:environments, :state, :string, default: :opened)
end
def down
remove_column(:environments, :state)
end end
end end
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