Skip to content

Commit cd05768

Browse files
upload image kinds
1 parent ad57f8f commit cd05768

6 files changed

Lines changed: 97 additions & 4 deletions

File tree

app/components/admin/edition_images/uploaded_images_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if edition.configurable_document_type.present? %>
1+
<% if edition.configurable_document_type.present? && @edition.type_instance.form("images").present? %>
22
<%= render "govuk_publishing_components/components/heading", {
33
text: "Select a lead image",
44
font_size: "l",

app/models/standard_edition.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ def is_in_valid_state_for_type_conversion?
9999
%w[draft submitted rejected].include?(state)
100100
end
101101

102+
def permitted_image_kinds
103+
return super unless type_instance.settings["images"]["permitted_image_kinds"]
104+
105+
Whitehall.image_kinds.values.select { _1.permitted_uses.intersect?(type_instance.settings["images"]["permitted_image_kinds"].map { |image| image["kind"] }) }
106+
end
107+
102108
private
103109

104110
def string_for_slug

app/views/admin/edition_images/_image_upload.html.erb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
<%
2+
image_kind ||= Whitehall.image_kinds.fetch("default")
3+
text = image_kind.permitted_uses.include?("govspeak_embed") ? "Upload an image" : "Upload an #{image_kind.display_name} image"
4+
%>
5+
16
<%= form_tag(
27
admin_edition_images_path(@edition),
38
multipart: true,
49
) do %>
510
<%= render "govuk_publishing_components/components/file_upload", {
611
label: {
7-
text: "Upload an image",
12+
text:,
813
},
914
heading_level: 2,
1015
heading_size: "l",
@@ -17,7 +22,7 @@
1722
accept: "image/png, image/jpeg, image/gif, image/svg+xml",
1823
} %>
1924

20-
<% if @edition.permitted_image_kinds.size == 1 %>
25+
<% if image_kind.present? %>
2126
<%= hidden_field_tag("image[image_data][image_kind]", @edition.permitted_image_kinds.first.name) %>
2227
<% else %>
2328
<%= render "govuk_publishing_components/components/radio", {

app/views/admin/edition_images/index.html.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
items: secondary_navigation_tabs_items(@edition, request.path),
1111
} %>
1212

13-
<%= render "image_upload", edition: @edition %>
13+
<% if @edition.is_a?(StandardEdition) %>
14+
<% @edition.permitted_image_kinds.each do |image_kind| %>
15+
<%= render "image_upload", edition: @edition, image_kind: %>
16+
<% end %>
17+
<% else %>
18+
<%= render "image_upload", edition: @edition %>
19+
<% end %>
20+
1421
<%= render Admin::EditionImages::UploadedImagesComponent.new(edition: @edition) %>
1522
</div>
1623
</div>

config/image_kinds.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,23 @@ hero_desktop:
105105
width: 1200
106106
height: 400
107107
from_version: hero_desktop_2x
108+
topical_event_header:
109+
display_name: "Header"
110+
valid_width: 800
111+
valid_height: 800
112+
permitted_uses:
113+
- header
114+
versions:
115+
- name: hero_desktop_2x
116+
width: 800
117+
height: 800
118+
topical_event_logo:
119+
display_name: "Logo"
120+
valid_width: 800
121+
valid_height: 800
122+
permitted_uses:
123+
- logo
124+
versions:
125+
- name: hero_desktop_2x
126+
width: 800
127+
height: 800
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Feature: Images tab on edit standard edition
2+
3+
Background:
4+
Given I am a writer
5+
6+
Scenario: Images are listed on the images tab
7+
And a draft standard edition with images exists
8+
When I visit the images tab of the document with images
9+
Then I should see a list with 2 images
10+
11+
Scenario: Images can be deleted from the images tab
12+
And a draft standard edition with images exists
13+
When I visit the images tab of the document with images
14+
Then I should see a list with 2 images
15+
When I click to delete an image
16+
And I confirm the deletion
17+
Then I should see a successfully deleted banner
18+
And I should see a list with 1 image
19+
20+
Scenario: Images details can be updated from the images tab
21+
And a draft standard edition with images exists
22+
When I visit the images tab of the document with images
23+
And I click to edit the details of an image
24+
And I update the image details and save
25+
Then I should see a updated banner
26+
Then I should see the updated image details
27+
28+
Scenario: Lead image setting can be updated from the images tab
29+
And an organisation with a default news image exists
30+
And the organisation has a draft case study with images
31+
When I visit the images tab of the standard edition with images
32+
Then I should see the organisations default news image
33+
When I click to hide the lead image
34+
Then I should see a button to select a custom lead image
35+
And I should see a button to choose to use the default image
36+
37+
Scenario: User selects a new lead image
38+
And a draft standard edition with images with the captions "First image uploaded" and "Second image uploaded" exists
39+
When I visit the images tab of the document with images
40+
And I make the image with caption "First image uploaded" the lead image
41+
Then I can see that the image with caption "First image uploaded" is the lead image
42+
And I make the image with caption "Second image uploaded" the lead image
43+
Then I can see that the image with caption "Second image uploaded" is the lead image
44+
45+
Scenario: Image uploaded with no cropping required
46+
And I start drafting a new standard edition "Standard Beard Lengths"
47+
When I visit the images tab of the document "Standard Beard Lengths"
48+
And I upload a 960x640 image
49+
Then I should see a list with 1 image
50+
51+
Scenario: No file uploaded
52+
And I start drafting a new standard edition "Standard Beard Lengths"
53+
When I visit the images tab of the document "Standard Beard Lengths"
54+
And I click upload without attaching a file
55+
Then I should get the error message "No images selected. Choose a valid JPEG, PNG, SVG or GIF."

0 commit comments

Comments
 (0)