-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fed27ab
commit 82c30cd
Showing
8 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/views/decidim/anonymous_codes/admin/export/_token_tr.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<tr> | ||
<td><%= token[:token] %></td> | ||
<td><a href="<%= token[:resource_url] %>"><%= token[:resource_url] %></a></td> | ||
<td><%= t("booleans.#{token[:available]}") %></td> | ||
<td><%= t("booleans.#{token[:used]}") %></td> | ||
<td><%= token[:usage_count] %></td> | ||
</tr> |
25 changes: 25 additions & 0 deletions
25
app/views/decidim/anonymous_codes/admin/export/tokens_pdf.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="tokens"> | ||
<div class="header"> | ||
<h1><%= t(".tokens_for", group: translated_attribute(code_group.title)) %></h1> | ||
<% if collection.count > 1 %> | ||
<h2><%= t(".totals", total: collection.count) %></h2> | ||
<h2><%= t(".expires", expires: t("booleans.#{code_group.expires?}")) %></h2> | ||
<%= content_tag "h3", t(".expires_at", expires_at: l(code_group.expires_at, format: :decidim_short)) if code_group.expires? %> | ||
<% end %> | ||
</div> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th class='token'><%= t("token", scope: "decidim.anonymous_codes.tokens_serializer") %></th> | ||
<th><%= t("resource_url", scope: "decidim.anonymous_codes.tokens_serializer") %></th> | ||
<th><%= t("available", scope: "decidim.anonymous_codes.tokens_serializer") %></th> | ||
<th><%= t("used", scope: "decidim.anonymous_codes.tokens_serializer") %></th> | ||
<th><%= t("usage_count", scope: "decidim.anonymous_codes.tokens_serializer") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render partial: "decidim/anonymous_codes/admin/export/token_tr", collection: collection, locals: { code_group: code_group }, as: :token %> | ||
</tbody> | ||
</table> | ||
</div> |
29 changes: 29 additions & 0 deletions
29
app/views/layouts/decidim/anonymous_codes/admin/export/pdf.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="<%= I18n.locale %>" class="no-js"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title><%= @title %></title> | ||
<style type="text/css"> | ||
.tokens .header h1 { | ||
margin: 0; | ||
padding: 25px; | ||
background: rgb(59, 69, 87); | ||
color: white; | ||
border-radius: 4px 4px 0 0; | ||
} | ||
.tokens table th,tokens table td { | ||
text-align: left; | ||
} | ||
.tokens table a { | ||
font-size: 0.9em; | ||
} | ||
.tokens table .token { | ||
font-weight: bold; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "wicked_pdf" | ||
|
||
module Decidim | ||
module Exporters | ||
# Inherits from abstract PDF exporter. This class is used to set | ||
# the parameters used to create a PDF when exporting Survey Answers. | ||
# | ||
class AnonymousTokensPDF < PDF | ||
def controller | ||
@controller ||= AnonymousTokensPDFControllerHelper.new | ||
end | ||
|
||
def template | ||
"decidim/anonymous_codes/admin/export/tokens_pdf" | ||
end | ||
|
||
def layout | ||
"decidim/anonymous_codes/admin/export/pdf" | ||
end | ||
|
||
def locals | ||
{ | ||
code_group: collection&.first&.group, | ||
collection: collection.map { |token| Decidim::AnonymousCodes::TokenSerializer.new(token).serialize } | ||
} | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/decidim/exporters/anonymous_tokens_pdf_controller_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Exporters | ||
# rubocop: disable Rails/ApplicationController | ||
# A dummy controller to render views while exporting questionnaires | ||
class AnonymousTokensPDFControllerHelper < ActionController::Base | ||
# rubocop: enable Rails/ApplicationController | ||
helper Decidim::TranslationsHelper | ||
end | ||
end | ||
end |