Commit 4f00b93d authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add deployment views

parent 907c0e67
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
......
......@@ -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
......
%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"
&middot;
= 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
&nbsp;
#{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'
......@@ -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"
&middot;
= 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
- if last_deployment
%p
%i.fa.fa-calendar
&nbsp;
#{time_ago_with_tooltip(last_deployment.created_at)}
%td
......@@ -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
......
- 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'
......@@ -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
......
......@@ -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)
......@@ -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
......
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