diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 722954a6b78ebe44efeb396bc745efa60f1207a1..c6a9a0a403acc20fba4710f49b5cf02f56c764fe 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -1,17 +1,44 @@ class Projects::EnvironmentsController < Projects::ApplicationController layout 'project' before_action :authorize_read_environment! - before_action :environment, only: [:show] + before_action :environment, only: [:show, :destroy] def index @environments = project.environments end def show + @deployments = environment.deployments.order(id: :desc).page(params[:page]).per(30) + end + + def new + @environment = project.environments.new + end + + def create + @environment = project.environments.create(create_params) + unless @environment.persisted? + render 'new' + return + end + + redirect_to namespace_project_environment_path(project.namespace, project, @environment) + end + + def destroy + if @environment.destroy + redirect_to namespace_project_environments_path(project.namespace, project), notice: 'Environment was successfully removed.' + else + redirect_to namespace_project_environments_path(project.namespace, project), alert: 'Failed to remove environment.' + end end private + def create_params + params.require(:environment).permit(:name) + end + def environment @environment ||= project.environments.find(params[:id].to_s) @environment || render_404 diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb index f745471913f4c5c76c2d7d7410ec266674c418ab..7408ec367f667550d35cf05a2e2cf0e10a197349 100644 --- a/app/services/create_deployment_service.rb +++ b/app/services/create_deployment_service.rb @@ -2,7 +2,8 @@ require_relative 'base_service' class CreateDeploymentService < BaseService def execute(deployable) - environment = find_or_create_environment(params[:environment]) + environment = find_environment(params[:environment]) + return error('no environment') unless environmnet deployment = create_deployment(environment, deployable) if deployment.persisted? @@ -14,14 +15,6 @@ class CreateDeploymentService < BaseService private - def find_or_create_environment(environment) - find_environment(environment) || create_environment(environment) - end - - def create_environment(environment) - project.environments.create(name: environment) - end - def find_environment(environment) project.environments.find_by(name: environment) end diff --git a/app/views/projects/deployments/_deployment.html.haml b/app/views/projects/deployments/_deployment.html.haml index 363c394d6d3d20beaa454ac614058b99a3c1ab05..539c297cad3d287f3d51bab5bdbb497f905537a6 100644 --- a/app/views/projects/deployments/_deployment.html.haml +++ b/app/views/projects/deployments/_deployment.html.haml @@ -1,11 +1,11 @@ %tr.deployment %td - %strong= "##{environment.id}" + %strong= "##{deployment.iid}" %td %div.branch-commit - if deployment.ref - = link_to last.ref, namespace_project_commits_path(@project.namespace, @project, deployment.ref), class: "monospace" + = link_to deployment.ref, namespace_project_commits_path(@project.namespace, @project, deployment.ref), class: "monospace" · = link_to deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-id monospace" @@ -18,15 +18,13 @@ %td - if deployment.deployable - = link_to [@project.namespace.becomes(Namespace), @project, deployment.deployable], class: "monospace" do + = link_to namespace_project_build_path(@project.namespace, @project, deployment.deployable), class: "monospace" do = "#{deployment.deployable.name} (##{deployment.deployable.id})" %td - %p - %i.fa.fa-calendar -   - #{time_ago_with_tooltip(deployment.created_at)} + #{time_ago_with_tooltip(deployment.created_at)} %td - if can?(current_user, :update_deployment, @project) && deployment.deployable - = link_to [@project.namespace.becomes(Namespace), @project, deployment.deployable, :retry], method: :post, title: 'Retry', class: 'btn btn-build' + .pull-right + = link_to 'Retry', retry_namespace_project_build_path(@project.namespace, @project, deployment.deployable), method: :post, class: 'btn btn-build' diff --git a/app/views/projects/environments/_environment.html.haml b/app/views/projects/environments/_environment.html.haml index a4c88fface2cc097282d1390c7c1ae489a8e8cc9..16d04832e1a0fc1d639f098c23e4e0d76aeaa87f 100644 --- a/app/views/projects/environments/_environment.html.haml +++ b/app/views/projects/environments/_environment.html.haml @@ -9,7 +9,7 @@ - if last_deployment %div.branch-commit - if last_deployment.ref - = link_to last.ref, namespace_project_commits_path(@project.namespace, @project, last_deployment.ref), class: "monospace" + = link_to last_deployment.ref, namespace_project_commits_path(@project.namespace, @project, last_deployment.ref), class: "monospace" · = link_to last_deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, last_deployment.sha), class: "commit-id monospace" @@ -24,9 +24,8 @@ No deployments yet %td - %p - %i.fa.fa-calendar -   - #{time_ago_with_tooltip(last_deployment.created_at)} + - if last_deployment + %p + #{time_ago_with_tooltip(last_deployment.created_at)} %td diff --git a/app/views/projects/environments/index.html.haml b/app/views/projects/environments/index.html.haml index 40d35ef38813c7be5eefbd98c1ef5b1036f9787c..2da8d068e9f52bb549efe1a91d565639b28b7186 100644 --- a/app/views/projects/environments/index.html.haml +++ b/app/views/projects/environments/index.html.haml @@ -3,16 +3,19 @@ = render "projects/pipelines/head" %div{ class: (container_class) } - .gray-content-block - Environments for this project + - if can?(current_user, :create_environment, @project) + .top-area + .nav-controls + = link_to new_namespace_project_environment_path(@project.namespace, @project), class: 'btn btn-create' do + New environment - %ul.content-list + %ul.content-list.environments - if @environments.blank? %li .nothing-here-block No environments to show - else .table-holder - %table.table.builds + %table.table %tbody %th Environment %th Last deployment diff --git a/app/views/projects/environments/new.html.haml b/app/views/projects/environments/new.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..5e8bc596f1e0008d649abb9500b9daf7fbcb953c --- /dev/null +++ b/app/views/projects/environments/new.html.haml @@ -0,0 +1,15 @@ +- page_title "New Environment" + +%h3.page-title + New Environment +%hr + += form_for @environment, url: namespace_project_environments_path(@project.namespace, @project), html: { id: "new-environment-form", class: "form-horizontal js-new-environment-form js-requires-input" } do |f| + = form_errors(@environment) + .form-group + = f.label :ref, 'Name', class: 'control-label' + .col-sm-10 + = f.text_field :name, required: true, tabindex: 2, class: 'form-control' + .form-actions + = f.submit 'Create', class: 'btn btn-create', tabindex: 3 + = link_to 'Cancel', namespace_project_environments_path(@project.namespace, @project), class: 'btn btn-cancel' diff --git a/app/views/projects/environments/show.html.haml b/app/views/projects/environments/show.html.haml index de5e686044f92b3704050c8f0310788bde03fb6c..dc07ad1a769e538424fcd99968d3f4a3355777c1 100644 --- a/app/views/projects/environments/show.html.haml +++ b/app/views/projects/environments/show.html.haml @@ -3,21 +3,26 @@ = render "projects/pipelines/head" %div{ class: (container_class) } - .gray-content-block - Latest deployments for - %strong= @environment.name + .top-area + .col-md-9 + %h3= @environment.name.titleize + + .col-md-3 + .nav-controls + = link_to 'Destroy', namespace_project_environment_path(@project.namespace, @project, @environment), data: { confirm: 'Are you sure?' }, class: 'btn btn-danger', method: :post %ul.content-list - if @deployments.blank? %li - .nothing-here-block No deployment for specific environment + .nothing-here-block No deployments for #{@environment.name} - else .table-holder %table.table.builds %thead %tr + %th ID %th Commit - %th Context + %th Build %th Date %th diff --git a/app/views/projects/pipelines/_head.html.haml b/app/views/projects/pipelines/_head.html.haml index 3562d91dfbdcde5012ae020e99bf42727cc03644..8374cb4223d965fc84c36f2160e86848f156fefa 100644 --- a/app/views/projects/pipelines/_head.html.haml +++ b/app/views/projects/pipelines/_head.html.haml @@ -19,3 +19,4 @@ = link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do %span Environments + %span.badge.count.environments_counter= number_with_delimiter(@project.environments.count) diff --git a/config/routes.rb b/config/routes.rb index 6b8402c40ddfbe90dbf905c6c3acd51f1a4f888a..d50e2535e75dfe06c51dfd463efe7fafa303942a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -704,7 +704,7 @@ Rails.application.routes.draw do end end - resources :environments, only: [:index, :show] + resources :environments, only: [:index, :show, :new, :create, :destroy] resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do collection do