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