-
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.
* add controller * add back button * Update config/locales/en.yml * Update app/views/decidim/anonymous_codes/admin/codes/index.html.erb * add new method to codes_controller * add command createtokens and destroy method * fix merge * table headers * fix index page * add warning when inactive gorup * fix index empty status * add system token_codes_spec * relocate exporters * resolve review comments * use custom find_exporter * add create_tokens_spec * add tokens_form_spec * add codes_controller_spec * add checks to controller spec * fix codes_controller_spec get index check * allow to create tokens from the group creation * fix controller spec * add test case for GET #new controller method * add destroy method spec check * add create controller method spec * add create_tokens_job spec * resolve PR specs review comments --------- Co-authored-by: elviabth <[email protected]>
- Loading branch information
1 parent
9bc4469
commit f8119d9
Showing
32 changed files
with
668 additions
and
140 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
26 changes: 26 additions & 0 deletions
26
app/commands/decidim/anonymous_codes/admin/create_tokens.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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
module Admin | ||
class CreateTokens < Decidim::Command | ||
def initialize(form, code_group) | ||
@form = form | ||
@code_group = code_group | ||
end | ||
|
||
def call | ||
return broadcast(:invalid) if form.invalid? | ||
|
||
CreateTokensJob.perform_later(code_group, form.num_tokens) | ||
|
||
broadcast(:ok) | ||
end | ||
|
||
private | ||
|
||
attr_reader :form, :code_group | ||
end | ||
end | ||
end | ||
end |
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
33 changes: 33 additions & 0 deletions
33
app/exporters/decidim/anonymous_codes/exporters/anonymous_tokens_pdf.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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "wicked_pdf" | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
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 < Decidim::Exporters::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 | ||
end |
14 changes: 14 additions & 0 deletions
14
app/exporters/decidim/anonymous_codes/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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
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 | ||
end |
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
module Admin | ||
class TokensForm < Decidim::Form | ||
attribute :num_tokens, Integer, default: 1 | ||
|
||
validates :num_tokens, presence: true, numericality: { only_integer: true, greater_than: 0 } | ||
end | ||
end | ||
end | ||
end |
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 | ||
|
||
module Decidim | ||
module AnonymousCodes | ||
class CreateTokensJob < ApplicationJob | ||
def perform(code_group, num_tokens) | ||
@code_group = code_group | ||
num_tokens.times do | ||
create_token! | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :code_group | ||
|
||
def create_token! | ||
token = new_token while token.blank? | ||
token.save! | ||
end | ||
|
||
def new_token | ||
token = Decidim::AnonymousCodes::Token.new( | ||
token: Decidim::AnonymousCodes.token_generator, | ||
group: code_group | ||
) | ||
token if token.valid? | ||
end | ||
end | ||
end | ||
end |
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
36 changes: 14 additions & 22 deletions
36
app/views/decidim/anonymous_codes/admin/code_groups/_form.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 |
---|---|---|
@@ -1,27 +1,19 @@ | ||
<div class="card"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"><%= title %></h2> | ||
</div> | ||
|
||
<div class="card-section"> | ||
<div class="row column"> | ||
<%= form.translated :text_field, :title, label: t(".title") %> | ||
</div> | ||
<div class="row column"> | ||
<%= form.translated :text_field, :title, label: t(".title") %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<%= form.datetime_field :expires_at, label: t(".expires_at") %> | ||
</div> | ||
<div class="row column"> | ||
<%= form.datetime_field :expires_at, label: t(".expires_at") %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<%= form.check_box :active, label: t(".active") %> | ||
</div> | ||
<div class="row column"> | ||
<%= form.check_box :active, label: t(".active") %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<%= form.number_field :max_reuses, label: t(".max_reuses") %> | ||
</div> | ||
<div class="row column"> | ||
<%= form.number_field :max_reuses, label: t(".max_reuses") %> | ||
</div> | ||
|
||
<div class="row column"> | ||
<%= form.select :resource_id, surveys, include_blank: true, label: t(".resource") %> | ||
</div> | ||
</div> | ||
<div class="row column"> | ||
<%= form.select :resource_id, surveys, include_blank: true, label: t(".resource") %> | ||
</div> |
12 changes: 11 additions & 1 deletion
12
app/views/decidim/anonymous_codes/admin/code_groups/edit.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
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
16 changes: 15 additions & 1 deletion
16
app/views/decidim/anonymous_codes/admin/code_groups/new.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
14 changes: 14 additions & 0 deletions
14
app/views/decidim/anonymous_codes/admin/codes/_form.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,14 @@ | ||
<div class="card"> | ||
<div class="card-divider"> | ||
<h2 class="card-title"><%= title %> | ||
|
||
<a class="button tiny button--title hollow" href="<%= code_group_codes_path(code_group) %>"><%= t("codes.index.back_to_codes", scope: "decidim.anonymous_codes.admin") %></a> | ||
</h2> | ||
</div> | ||
|
||
<div class="card-section"> | ||
<div class="row column"> | ||
<%= form.number_field :num_tokens, label: t(".number_of_tokens_to_generate") %> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.