mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
Merge pull request #2396 from internetee/2391-domain-pdf
Admin: download pdf with domain data on show
This commit is contained in:
commit
c488085cb3
7 changed files with 276 additions and 3 deletions
|
@ -2,7 +2,7 @@ module Admin
|
|||
class DomainsController < BaseController
|
||||
DEFAULT_VERSIONS_PER_PAGE = 10
|
||||
|
||||
before_action :set_domain, only: %i[show edit update keep]
|
||||
before_action :set_domain, only: %i[show edit update download keep]
|
||||
authorize_resource
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
|
@ -65,6 +65,11 @@ module Admin
|
|||
.per(DEFAULT_VERSIONS_PER_PAGE)
|
||||
end
|
||||
|
||||
def download
|
||||
filename = "#{@domain.name}.pdf"
|
||||
send_data @domain.as_pdf, filename: filename
|
||||
end
|
||||
|
||||
def keep
|
||||
@domain.keep
|
||||
redirect_to edit_admin_domain_url(@domain), notice: t('.kept')
|
||||
|
|
|
@ -743,6 +743,12 @@ class Domain < ApplicationRecord
|
|||
]
|
||||
end
|
||||
|
||||
def as_pdf
|
||||
domain_html = ApplicationController.render(template: 'domain/pdf', assigns: { domain: self })
|
||||
generator = PDFKit.new(domain_html)
|
||||
generator.to_pdf
|
||||
end
|
||||
|
||||
def registrant_name
|
||||
return registrant.name if registrant
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
|
||||
<div class="page-header">
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
<div class="col-sm-7">
|
||||
<h1><%= domain.name_with_status %></h1>
|
||||
</div>
|
||||
|
||||
<div class="col-sm-4 text-right">
|
||||
<div class="col-sm-5 text-right">
|
||||
<%= link_to t('.download_btn'), download_admin_domain_path(@domain), class: 'btn btn-primary' %>
|
||||
<%= link_to t('.edit_btn'), edit_admin_domain_path(@domain), class: 'btn btn-primary' %>
|
||||
<%= link_to t('.history_btn'), admin_domain_domain_versions_path(@domain),
|
||||
class: 'btn btn-primary' %>
|
||||
|
|
241
app/views/domain/pdf.haml
Normal file
241
app/views/domain/pdf.haml
Normal file
|
@ -0,0 +1,241 @@
|
|||
%html{lang: 'et'}
|
||||
%head
|
||||
%meta{charset: "utf-8"}
|
||||
:css
|
||||
.container {
|
||||
margin: auto;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.col-md-12 {
|
||||
|
||||
}
|
||||
|
||||
.col-xs-4 {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
.left {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.left {
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.right {
|
||||
float: right;
|
||||
}
|
||||
|
||||
dt {
|
||||
float: left;
|
||||
width: 100px;
|
||||
clear: left;
|
||||
text-align: right;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
line-height: 1.42857;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin-left: 120px;
|
||||
line-height: 1.42857;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: left;
|
||||
border: 0px;
|
||||
border-top: 1px solid #DDD;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
thead th {
|
||||
border-bottom: 2px solid #DDD;
|
||||
border-top: 0px;
|
||||
}
|
||||
|
||||
td {
|
||||
border-top: 1px solid #DDD;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
color: #DDD;
|
||||
background-color: #DDD;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.pull-down {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
#header {
|
||||
position: relative;
|
||||
min-height: 100px;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 106px;
|
||||
height: 102px;
|
||||
}
|
||||
|
||||
#header-content {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
width: 99%;
|
||||
}
|
||||
|
||||
.blue {
|
||||
color: #0098da;
|
||||
}
|
||||
|
||||
%body
|
||||
.container
|
||||
#header.row
|
||||
.col-sm-6.left
|
||||
#header-content
|
||||
%h1= "#{@domain.name} (#{Time.zone.now.to_date.strftime("%d/%m/%Y")})"
|
||||
.col-sm-6.right
|
||||
%img{src: "#{Rails.root}/public/eis-logo-black-et.png"}
|
||||
.clear
|
||||
%hr
|
||||
.row
|
||||
.col-sm-8.left
|
||||
%h3 Üldine
|
||||
%hr
|
||||
%dl.dl-horizontal
|
||||
%dt Nimi
|
||||
%dd= @domain.name
|
||||
%dt Registreeritud
|
||||
%dd= @domain.registered_at.to_date.strftime("%d/%m/%Y")
|
||||
%dt Aegub
|
||||
%dd= @domain.valid_to.to_date.strftime("%d/%m/%Y")
|
||||
%dt Registripidaja
|
||||
%dd= "#{@domain.registrar} #{@domain.registrar.website}"
|
||||
|
||||
.col-sm-4.right
|
||||
%h3 Registreerija
|
||||
%hr
|
||||
%dl.dl-horizontal
|
||||
%dt.left_25 Nimi
|
||||
%dd.left_25= @domain.registrant
|
||||
|
||||
%dt.left_25 Isikukood
|
||||
%dd.left_25= @domain.registrant.ident_human_description
|
||||
|
||||
%dt.left_25 E-mail
|
||||
%dd.left_25= @domain.registrant.email
|
||||
|
||||
%dt.left_25 Telefon
|
||||
%dd.left_25= @domain.registrant.phone
|
||||
|
||||
.clear
|
||||
.row.pull-down
|
||||
.col-md-12
|
||||
%h3 Halduskontaktid
|
||||
%hr
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-3'} Nimi
|
||||
%th{class: 'col-xs-3'} Isikukood
|
||||
%th{class: 'col-xs-3'} E-mail
|
||||
%th{class: 'col-xs-3'} Telefon
|
||||
%tbody
|
||||
- @domain.admin_contacts.each do |ac|
|
||||
%tr
|
||||
%td= ac.name
|
||||
%td= ac.ident_human_description
|
||||
%td= ac.email
|
||||
%td= ac.phone
|
||||
|
||||
.clear
|
||||
.row.pull-down
|
||||
.col-md-12
|
||||
%h3 Tehnilised kontaktid
|
||||
%hr
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-3'} Nimi
|
||||
%th{class: 'col-xs-3'} Isikukood
|
||||
%th{class: 'col-xs-3'} E-mail
|
||||
%th{class: 'col-xs-3'} Telefon
|
||||
%tbody
|
||||
- @domain.tech_contacts.each do |tc|
|
||||
%tr
|
||||
%td= tc.name
|
||||
%td= tc.ident_human_description
|
||||
%td= tc.email
|
||||
%td= tc.phone
|
||||
|
||||
.clear
|
||||
.row.pull-down
|
||||
.col-md-12
|
||||
%h3 Nimeserverid
|
||||
%hr
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-4'} Hostinimi
|
||||
%th{class: 'col-xs-4'}= t(:ipv4)
|
||||
%th{class: 'col-xs-4'}= t(:ipv6)
|
||||
%tbody
|
||||
- @domain.nameservers.each do |x|
|
||||
%tr
|
||||
%td= x
|
||||
%td= x.ipv4
|
||||
%td= x.ipv6
|
||||
.clear
|
||||
.row.pull-down
|
||||
.col-md-12
|
||||
%h3= t(:dnskeys)
|
||||
%hr
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-1'} Lipp
|
||||
%th{class: 'col-xs-1'} Protokolli
|
||||
%th{class: 'col-xs-1'} Algoritm
|
||||
%th{class: 'col-xs-9'} Avalik võti
|
||||
%tbody
|
||||
- @domain.dnskeys.each do |x|
|
||||
%tr
|
||||
%td= x.flags
|
||||
%td= x.protocol
|
||||
%td= x.alg
|
||||
%td= x.public_key
|
||||
#footer
|
||||
%hr
|
||||
%p{class: 'blue'} Eesti Interneti SA
|
||||
%p Paldiski mnt 80, 10617 Tallinn, Estonia T +372 727 1000 E info@internet.ee www.internet.ee
|
||||
%p Reg. nr 90010019 KMKR EE101286464
|
|
@ -6,6 +6,7 @@ en:
|
|||
registrant: Registrant
|
||||
|
||||
show:
|
||||
download_btn: Download PDF
|
||||
edit_btn: Edit statuses
|
||||
history_btn: History
|
||||
|
||||
|
|
|
@ -343,6 +343,7 @@ Rails.application.routes.draw do
|
|||
resource :registry_lock, controller: 'domains/registry_lock', only: :destroy
|
||||
|
||||
member do
|
||||
get :download
|
||||
patch :keep
|
||||
end
|
||||
end
|
||||
|
|
18
test/integration/admin_area/domain_show_test.rb
Normal file
18
test/integration/admin_area/domain_show_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainShowTest < ApplicationIntegrationTest
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
sign_in users(:admin)
|
||||
end
|
||||
|
||||
def test_downloads_domain
|
||||
filename = "#{@domain.name}.pdf"
|
||||
get download_admin_domain_path(@domain)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 'application/pdf', response.headers['Content-Type']
|
||||
assert_equal "attachment; filename=\"#{filename}\"; filename*=UTF-8''#{filename}", response.headers['Content-Disposition']
|
||||
assert_not_empty response.body
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue