-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Spike "pseudo self serve" feature #2775
Draft
ChrisBAshton
wants to merge
6
commits into
main
Choose a base branch
from
spike-pseudo-selfserve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53f12f7
WIP: allow Design System on Specialist Publisher
ChrisBAshton ac4566a
WIP: add pseudo self serve
ChrisBAshton 454a678
WIP: split out into multiple forms
ChrisBAshton 33d6312
Add 'diff' for proposed schema change
ChrisBAshton 22540cb
WIP: implement rudimentary "pass this onto a dev" step
ChrisBAshton f57e2f2
fix linting
ChrisBAshton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//= link_directory ../javascripts .js | ||
//= link_tree ../builds | ||
//= link application.css | ||
//= link diff.css |
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,3 +1,5 @@ | ||
@import "govuk_publishing_components/all_components"; | ||
|
||
@import "select2"; | ||
@import "select2-bootstrap"; | ||
|
||
|
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,83 @@ | ||
// stylelint-disable max-nesting-depth | ||
|
||
// Diff of two editions | ||
|
||
$added-color: #ddffdd; | ||
$strong-added-color: #77f177; | ||
$removed-color: #ffdddd; | ||
$strong-removed-color: #ffaaaa; | ||
$gray-lighter: govuk-colour("light-grey"); | ||
$state-danger-text: govuk-colour("red"); | ||
$state-success-text: govuk-colour("green"); | ||
|
||
.diff { | ||
border: 1px solid $gray-lighter; | ||
border-left: 40px solid $gray-lighter; | ||
border-radius: 3px; | ||
padding: 15px; | ||
|
||
ul { | ||
padding-left: 0; | ||
|
||
li { | ||
min-height: 24px; | ||
margin: 0 -15px; | ||
padding: 0 15px; | ||
word-wrap: break-word; | ||
list-style: none; | ||
position: relative; | ||
|
||
del, | ||
ins { | ||
text-decoration: none; | ||
} | ||
} | ||
|
||
.del, | ||
.ins { | ||
padding-top: 2px; | ||
} | ||
|
||
.del { | ||
background-color: $removed-color; | ||
|
||
strong { | ||
font-weight: normal; | ||
background-color: $strong-removed-color; | ||
} | ||
} | ||
|
||
.ins { | ||
background-color: $added-color; | ||
|
||
strong { | ||
font-weight: normal; | ||
background-color: $strong-added-color; | ||
} | ||
} | ||
|
||
.del::before, | ||
.ins::before { | ||
position: absolute; | ||
font-weight: bold; | ||
margin-left: -55px; | ||
width: 40px; | ||
text-align: center; | ||
min-height: 24px; | ||
top: 0; | ||
bottom: 0; | ||
} | ||
|
||
.del::before { | ||
color: $state-danger-text; | ||
background-color: $removed-color; | ||
content: "-"; | ||
} | ||
|
||
.ins::before { | ||
color: $state-success-text; | ||
background-color: $added-color; | ||
content: "+"; | ||
} | ||
} | ||
} |
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,74 @@ | ||
class AdminController < ApplicationController | ||
layout "design_system" | ||
|
||
before_action :check_authorisation, if: :document_type_slug | ||
|
||
def index_of_admin_forms; end | ||
|
||
def edit_metadata; end | ||
|
||
def edit_facets; end | ||
|
||
def save_metadata | ||
@submitted_params = params.permit( | ||
:name, | ||
:description, | ||
:organisations, | ||
:editing_organisations, | ||
:related, | ||
:base_path, | ||
:content_id, | ||
"filter.format".to_sym, | ||
:format_name, | ||
:document_title, | ||
:document_noun, | ||
).to_unsafe_h | ||
%i[organisations editing_organisations related].each do |str_that_should_be_arr| | ||
@submitted_params[str_that_should_be_arr] = @submitted_params[str_that_should_be_arr].split("\r\n") | ||
if @submitted_params[str_that_should_be_arr].empty? | ||
@submitted_params.delete(str_that_should_be_arr) | ||
end | ||
end | ||
@submitted_params["filter"] = { "format": @submitted_params["filter.format".to_sym] } | ||
@submitted_params.delete("filter.format".to_sym) | ||
|
||
@original_schema = current_format.finder_schema.schema | ||
@proposed_schema = @original_schema.merge(@submitted_params) | ||
render :temporary_output | ||
end | ||
|
||
def save_facets | ||
@submitted_params = params.except(:authenticity_token, :action, :controller, :document_type_slug).to_unsafe_h | ||
# hashes come through as e.g. `facets: { "0": { "name": "Category"... }}`, | ||
# we need to convert to array e.g. `facets: [ { "name", "Category"... } ]` | ||
@submitted_params["facets"] = @submitted_params["facets"].keys.map(&:to_i).sort.map do |i| | ||
@submitted_params["facets"][i.to_s] | ||
end | ||
@submitted_params["facets"].each_with_index do |hash, i| | ||
hash.each do |key, value| | ||
# delete empty values | ||
if value == "" | ||
@submitted_params["facets"][i].delete(key) | ||
# cast booleans | ||
elsif %w[true false].include?(value) | ||
@submitted_params["facets"][i][key] = value == "true" | ||
end | ||
end | ||
end | ||
|
||
@original_schema = current_format.finder_schema.schema | ||
@proposed_schema = @original_schema.merge(@submitted_params) | ||
render :temporary_output | ||
end | ||
|
||
private | ||
|
||
def check_authorisation | ||
if current_format | ||
authorize current_format | ||
else | ||
flash[:danger] = "That format doesn't exist. If you feel you've reached this in error, please contact your main GDS contact." | ||
redirect_to root_path | ||
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
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,41 @@ | ||
<%= content_for :page_title, "Edit #{current_format.title} finder" %> | ||
|
||
<% content_for :back_link, render_back_link(href: "/admin/#{current_format.admin_slug}") %> | ||
|
||
<h1>Editing <%= current_format.title %> finder</h1> | ||
|
||
<div class="row"> | ||
<div class="col-md-8"> | ||
<p>The intention is for this to start off as "pseudo self serve". Departments would be able to make edits to this form, generate the JSON output, and then send the JSON to a developer to apply (the onus would be on the dev to 'git diff' the changes to make sure they make sense). In time, we may then swap out aspects of this for 'true' self-serve. It could also form the basis of a form be used for 'new' specialist finders, as opposed to just editing existing ones.</p> | ||
|
||
<%= form_tag do %> | ||
<h2>Facets</h2> | ||
<% current_format.finder_schema.schema["facets"].each_with_index do |facet, i| %> | ||
<h4><%= facet["name"] %></h4> | ||
<% %w[key name short_name type preposition display_as_result_metadata filterable].each do |property| %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: property, | ||
}, | ||
name: "facets[#{i}][#{property}]", | ||
value: facet[property].to_s, | ||
} # could add ` if facet[property]` to hide the empty inputs, but then there'd be no way of adding them | ||
%> | ||
<% end %> | ||
<%= render "govuk_publishing_components/components/textarea", { | ||
label: { | ||
text: "'allowed_values' (JSON hashes, each on a separate line)", | ||
}, | ||
name: "facets[#{i}][allowed_values]", | ||
rows: facet["allowed_values"] ? 10 : 3, # only show a large textarea if there is an existing value | ||
value: facet["allowed_values"]&.join("\n"), | ||
} %> | ||
<hr /> | ||
<% end %> | ||
|
||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Generate schema" | ||
} %> | ||
<% end %> | ||
</div> | ||
</div> |
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,62 @@ | ||
<%= content_for :page_title, "Edit #{current_format.title} finder" %> | ||
|
||
<% content_for :back_link, render_back_link(href: "/admin/#{current_format.admin_slug}") %> | ||
|
||
<h1>Editing <%= current_format.title %> finder</h1> | ||
|
||
<div class="row"> | ||
<div class="col-md-8"> | ||
<%= form_tag do %> | ||
<h2>Finder metadata</h2> | ||
<p>How the finder displays to users</p> | ||
<% %w[name description].each do |input| %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: input, | ||
}, | ||
name: input, | ||
value: current_format.finder_schema.schema[input], | ||
} %> | ||
<% end %> | ||
|
||
<% # special case for arrays %> | ||
<% %w[organisations editing_organisations related].each do |input| %> | ||
<%= render "govuk_publishing_components/components/textarea", { | ||
label: { | ||
text: "#{input} (content IDs, each on a separate line)", | ||
}, | ||
name: input, | ||
rows: 3, | ||
value: current_format.finder_schema.schema[input]&.join(","), | ||
} %> | ||
<% end %> | ||
|
||
<% # special case for 'nested' structure `filter.format` %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: "filter.format", | ||
}, | ||
name: "filter.format", | ||
value: current_format.finder_schema.schema["filter"]["format"], | ||
readonly: true, | ||
} %> | ||
|
||
<h2>Publisher configuration</h2> | ||
<p>How the finder and its documents are referred to in Specialist Publisher.</p> | ||
|
||
<% %w[format_name document_noun document_title].each do |input| %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { | ||
text: input, | ||
}, | ||
name: input, | ||
value: current_format.finder_schema.schema[input], | ||
} %> | ||
<% end %> | ||
|
||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Generate schema" | ||
} %> | ||
<% end %> | ||
</div> | ||
</div> |
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 @@ | ||
<%= content_for :page_title, "Edit #{current_format.title} finder" %> | ||
|
||
<% content_for :back_link, render_back_link(href: documents_path(current_format.admin_slug)) %> | ||
|
||
<h1>Editing <%= current_format.title %> finder</h1> | ||
|
||
<div class="row"> | ||
<div class="col-md-8"> | ||
<ul> | ||
<li><%= link_to "Edit metadata", "/admin/metadata/#{current_format.admin_slug}" %></li> | ||
<li><%= link_to "Edit facets", "/admin/facets/#{current_format.admin_slug}" %></li> | ||
</ul> | ||
</div> | ||
</div> |
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,30 @@ | ||
<%= content_for :page_title, "Edit #{current_format.title} finder" %> | ||
|
||
<% content_for :back_link, render_back_link(href: "/admin/#{current_format.admin_slug}") %> | ||
|
||
<h1>Submit request for changes to <%= current_format.title %> finder</h1> | ||
|
||
<div class="row"> | ||
<div class="col-md-8"> | ||
<p>Please visit <a href="https://support.publishing.service.gov.uk/changes_to_publishing_apps_request/new">Changes to publishing applications or technical advice</a> and copy and paste the "Proposed JSON" code for a developer to action. Ignore the other outputs below it, which are for debugging only.</p> | ||
<p>Longer term, we will eliminate this step and automatically raise a Zendesk ticket on your behalf.</p> | ||
|
||
<h2>Proposed JSON</h2> | ||
<pre><%= JSON.pretty_generate(@proposed_schema) %></pre> | ||
|
||
<hr /> | ||
|
||
<h2>Diff</h2> | ||
<%= Diffy::Diff.new( | ||
JSON.pretty_generate(@original_schema).to_s, | ||
JSON.pretty_generate(@proposed_schema).to_s, | ||
allow_empty_diff: false, | ||
).to_s(:html).html_safe %> | ||
|
||
<h2>Submitted params</h2> | ||
<pre><%= JSON.pretty_generate(@submitted_params) %></pre> | ||
|
||
<h2>Original JSON</h2> | ||
<pre><%= JSON.pretty_generate(@original_schema) %></pre> | ||
</div> | ||
</div> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Brakeman
Unescaped parameter value. Note