Add deployment views

This commit is contained in:
Kamil Trzcinski 2016-06-11 00:15:53 +02:00
parent 907c0e6796
commit 4f00b93ddd
9 changed files with 74 additions and 33 deletions

View file

@ -1,17 +1,44 @@
class Projects::EnvironmentsController < Projects::ApplicationController class Projects::EnvironmentsController < Projects::ApplicationController
layout 'project' layout 'project'
before_action :authorize_read_environment! before_action :authorize_read_environment!
before_action :environment, only: [:show] before_action :environment, only: [:show, :destroy]
def index def index
@environments = project.environments @environments = project.environments
end end
def show 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 end
private private
def create_params
params.require(:environment).permit(:name)
end
def environment def environment
@environment ||= project.environments.find(params[:id].to_s) @environment ||= project.environments.find(params[:id].to_s)
@environment || render_404 @environment || render_404

View file

@ -2,7 +2,8 @@ require_relative 'base_service'
class CreateDeploymentService < BaseService class CreateDeploymentService < BaseService
def execute(deployable) 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) deployment = create_deployment(environment, deployable)
if deployment.persisted? if deployment.persisted?
@ -14,14 +15,6 @@ class CreateDeploymentService < BaseService
private 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) def find_environment(environment)
project.environments.find_by(name: environment) project.environments.find_by(name: environment)
end end

View file

@ -1,11 +1,11 @@
%tr.deployment %tr.deployment
%td %td
%strong= "##{environment.id}" %strong= "##{deployment.iid}"
%td %td
%div.branch-commit %div.branch-commit
- if deployment.ref - 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; &middot;
= link_to deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-id monospace" = link_to deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, deployment.sha), class: "commit-id monospace"
@ -18,15 +18,13 @@
%td %td
- if deployment.deployable - 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})" = "#{deployment.deployable.name} (##{deployment.deployable.id})"
%td %td
%p
%i.fa.fa-calendar
&nbsp;
#{time_ago_with_tooltip(deployment.created_at)} #{time_ago_with_tooltip(deployment.created_at)}
%td %td
- if can?(current_user, :update_deployment, @project) && deployment.deployable - 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'

View file

@ -9,7 +9,7 @@
- if last_deployment - if last_deployment
%div.branch-commit %div.branch-commit
- if last_deployment.ref - 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; &middot;
= link_to last_deployment.short_sha, namespace_project_commit_path(@project.namespace, @project, last_deployment.sha), class: "commit-id 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 No deployments yet
%td %td
- if last_deployment
%p %p
%i.fa.fa-calendar
&nbsp;
#{time_ago_with_tooltip(last_deployment.created_at)} #{time_ago_with_tooltip(last_deployment.created_at)}
%td %td

View file

@ -3,16 +3,19 @@
= render "projects/pipelines/head" = render "projects/pipelines/head"
%div{ class: (container_class) } %div{ class: (container_class) }
.gray-content-block - if can?(current_user, :create_environment, @project)
Environments for this 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? - if @environments.blank?
%li %li
.nothing-here-block No environments to show .nothing-here-block No environments to show
- else - else
.table-holder .table-holder
%table.table.builds %table.table
%tbody %tbody
%th Environment %th Environment
%th Last deployment %th Last deployment

View file

@ -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'

View file

@ -3,21 +3,26 @@
= render "projects/pipelines/head" = render "projects/pipelines/head"
%div{ class: (container_class) } %div{ class: (container_class) }
.gray-content-block .top-area
Latest deployments for .col-md-9
%strong= @environment.name %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 %ul.content-list
- if @deployments.blank? - if @deployments.blank?
%li %li
.nothing-here-block No deployment for specific environment .nothing-here-block No deployments for #{@environment.name}
- else - else
.table-holder .table-holder
%table.table.builds %table.table.builds
%thead %thead
%tr %tr
%th ID
%th Commit %th Commit
%th Context %th Build
%th Date %th Date
%th %th

View file

@ -19,3 +19,4 @@
= link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do = link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do
%span %span
Environments Environments
%span.badge.count.environments_counter= number_with_delimiter(@project.environments.count)

View file

@ -704,7 +704,7 @@ Rails.application.routes.draw do
end end
end end
resources :environments, only: [:index, :show] resources :environments, only: [:index, :show, :new, :create, :destroy]
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do collection do