Skip to content

Commit

Permalink
Merge pull request alphagov#896 from alphagov/add-columns-to-petition…
Browse files Browse the repository at this point in the history
…s-list

Update columns on moderation petitions index page
  • Loading branch information
pixeltrix authored Feb 2, 2024
2 parents eaf8917 + 92769d1 commit aa9ba03
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/petitions/admin/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
padding-right: $gutter;
}

.creator {
.creator, .rejection {
text-align: left;
}

.petition-id, .state, .tags {
.petition-id, .state, .notes, .tags {
text-align: center;
}

Expand Down
12 changes: 12 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ def back_link
end
end

def show_closing_column?(scope)
scope.in?(%i[open closed])
end

def show_rejection_column?(scope)
scope.in?(%i[rejected hidden])
end

def short_rejection_reason(rejection)
t(rejection.code, scope: :"rejection.reasons.short", default: rejection.code.titleize)
end

private

def admin_petition_facets
Expand Down
16 changes: 0 additions & 16 deletions app/helpers/tags_helper.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
module TagsHelper
SHOW_TAGS_COLUMN = %i[
collecting_sponsors
flagged
dormant
in_moderation
recently_in_moderation
nearly_overdue_in_moderation
overdue_in_moderation
tagged_in_moderation
untagged_in_moderation
]

def show_tags_column?(scope)
scope.in?(SHOW_TAGS_COLUMN)
end

def tag_names(tags)
tags.each_with_object([]) do |tag, names|
if name = tag_mapping[tag]
Expand Down
18 changes: 12 additions & 6 deletions app/views/admin/petitions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@
<th class="creator">Creator</th>
<th class="petition-id">ID</th>
<th class="state">State</th>
<% if show_tags_column?(@petitions.scope) %>
<th class="tags">Tags</th>
<% else %>
<th class="notes">Notes</th>
<th class="tags">Tags</th>
<% if show_closing_column?(@petitions.scope) %>
<th class="date">Closing</th>
<% end %>
<% if show_rejection_column?(@petitions.scope) %>
<th class="rejection">Reason</th>
<% end %>
<th class="numeric last">Signatures</th>
</tr>
</thead>
Expand All @@ -103,11 +106,14 @@
</td>
<td class="petition-id"><%= petition.id %></td>
<td class="state"><%= petition.state.humanize %></td>
<% if show_tags_column?(@petitions.scope) %>
<td class="tags"><%= tag_names(petition.tags) %></td>
<% else %>
<td class="notes"><%= petition.notes? ? "Yes" : " " %></td>
<td class="tags"><%= tag_names(petition.tags) %></td>
<% if show_closing_column?(@petitions.scope) %>
<td class="date"><%= date_format(petition.closing) || "–" %></td>
<% end %>
<% if show_rejection_column?(@petitions.scope) %>
<td class="rejection"><%= short_rejection_reason(petition.rejection) %></td>
<% end %>
<td class="numeric last"><%= number_with_delimiter(petition.signature_count) %></td>
</tr>
<% end -%>
Expand Down
22 changes: 22 additions & 0 deletions config/locales/rejections.en-GB.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
en-GB:
rejection:
reasons:
short:
duplicate: "Duplicate"
irrelevant: "Irrelevant"
no-action: "No Action"
honours: "Honours"
fake-name: "Fake Name"
foi: "FOI"
libellous: "Libellous"
offensive: "Offensive"
advert: "Advert"
removed: "Removed"
already-happening: "Already Happening"
no-reply: "No Reply"
individual: "Individual"
personal: "Personal"
fraudulent: "Fraudulent"
operational: "Operational"
local: "Local"
joke: "Joke"
12 changes: 12 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,18 @@

factory :hidden_petition, :parent => :petition do
state { Petition::HIDDEN_STATE }

transient do
rejection_code { "libellous" }
rejection_details { nil }
end

after(:create) do |petition, evaluator|
petition.create_rejection! do |r|
r.code = evaluator.rejection_code
r.details = evaluator.rejection_details
end
end
end

factory :awaiting_petition, :parent => :open_petition do
Expand Down

0 comments on commit aa9ba03

Please sign in to comment.