Skip to content

Commit

Permalink
Create a new page for displaying SSA diagrams
Browse files Browse the repository at this point in the history
- Add a new stylesheet
- Add a new JS module
- Add mermaid as a dependency
- Add a loading message to be shown while mermaid intialises
- Add a link from the simple smart answer edition view to the diagram visualisation page.
  • Loading branch information
mtaylorgds authored and Ana Botto committed Jan 8, 2024
1 parent 6c04518 commit 4a99766
Show file tree
Hide file tree
Showing 7 changed files with 2,161 additions and 1,092 deletions.
25 changes: 25 additions & 0 deletions app/assets/javascripts/modules/smart_answer_flowchart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//= require mermaid/dist/mermaid

(function (Modules) {
'use strict'

Modules.SmartAnswerFlowchart = function () {
this.start = function (element) {
var diagram = element.find('.flowchart')
var flowchartLoading = element.find('.flowchart__loading')

// eslint-disable-next-line
mermaid.initialize(
{
startOnLoad: true,
flowchart: {
useMaxWidth: false
}
}
)

diagram.removeClass('flowchart--hidden')
flowchartLoading.addClass('flowchart__loading--hidden')
}
}
})(window.GOVUKAdmin.Modules)
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Pages
@import "downtime";
@import "smart_answer_builder";
@import "smart_answer_flowchart";

// GOVUK Design System
@import "govuk_publishing_components/all_components";
14 changes: 14 additions & 0 deletions app/assets/stylesheets/smart_answer_flowchart.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.smart-answer-flowchart {
.mermaid {
background-color: #ffffff;
}

.flowchart--hidden,
.flowchart__loading--hidden {
display: none;
}

pre {
word-break: normal;
}
}
7 changes: 7 additions & 0 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def process_unpublish
end
end

def diagram
# [MT] TODO: What's the best way to handle requests for a diagram for a non-simple smart answer?
if @resource.format != "SimpleSmartAnswer"
render plain: "404 Not Found", status: :not_found
end
end

protected

def permitted_params(subtype: nil)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get "tagging", to: "editions#linking"
get "related_external_links", to: "editions#linking"
get "unpublish"
get "diagram"
post "duplicate"
post "update_tagging"
post "process_unpublish"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"stylelint-config-gds": "^1.1.0"
},
"dependencies": {
"mermaid": "10.5.1",
"paste-html-to-govspeak": "^0.4.0"
},
"resolutions": {
Expand Down
Loading

0 comments on commit 4a99766

Please sign in to comment.