-
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.
- Loading branch information
Showing
20 changed files
with
29,835 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SEARCH_API_BASE=https://search.dev.trade-tariff.service.gov.uk | ||
SEARCH_API_SECRET_KEY= |
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,12 @@ | ||
# Node.js ignores | ||
node_modules/ | ||
|
||
# Prototype ignores - per-user | ||
.tmp/ | ||
.env | ||
migrate.log | ||
usage-data-config.json | ||
|
||
# General ignores | ||
.DS_Store | ||
.idea |
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,21 @@ | ||
The MIT License | ||
|
||
Copyright (C) 2014 Crown Copyright (Government Digital Service) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,8 @@ | ||
// | ||
// For guidance on how to add JavaScript see: | ||
// https://prototype-kit.service.gov.uk/docs/adding-css-javascript-and-images | ||
// | ||
|
||
window.GOVUKPrototypeKit.documentReady(() => { | ||
// Add JavaScript here | ||
}) |
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,6 @@ | ||
// | ||
// For guidance on how to add CSS and SCSS see: | ||
// https://prototype-kit.service.gov.uk/docs/adding-css-javascript-and-images | ||
// | ||
|
||
// Add extra styles here |
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,3 @@ | ||
{ | ||
"serviceName": "Commodi-tea ☕" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
const { parse } = require('csv-parse/sync'); | ||
const fs = require('fs'); | ||
|
||
const rawCommodities = parse(fs.readFileSync(__dirname + `/commodities.csv`), { | ||
columns: true, | ||
skip_empty_lines: true | ||
}) | ||
"SID","Commodity code","Product line suffix","Start date","End date","Indentation","End line","Description","Class","ItemIDPlusPLS","Hierarchy" | ||
const commodities = {} | ||
|
||
for(rawCode of rawCommodities) { | ||
const newCode = { | ||
code: rawCode["Commodity code"], | ||
suffix: rawCode["Product line suffix"], | ||
description: rawCode["Description"], | ||
hierarchy: rawCode["Hierarchy"].split(',').map(ancestor => { | ||
const [ancestor_code, ancestor_suffix] = ancestor.split('_'); | ||
return { code: ancestor_code, suffix: ancestor_suffix } | ||
}) | ||
} | ||
|
||
if(commodities[rawCode["Commodity code"]]) { | ||
commodities[rawCode["Commodity code"]].push(newCode); | ||
} else { | ||
commodities[rawCode["Commodity code"]] = [newCode]; | ||
} | ||
} | ||
|
||
const findSubheading = (code, suffix) => { | ||
return findCommodity(`${code}`.padEnd(10, '0'), suffix); | ||
} | ||
|
||
const findCommodity = (code, suffix) => { | ||
const commodity = commodities[code]; | ||
|
||
if(suffix) { | ||
console.log(code, suffix, commodity.find(c => c.suffix == suffix)) | ||
return commodity.find(c => c.suffix == suffix) | ||
} | ||
|
||
if(commodity && commodity.length > 0) { | ||
return commodity[0] | ||
} | ||
|
||
return null; | ||
} | ||
|
||
const expandHierarchy = (commodity) => { | ||
|
||
if(!commodity?.hierarchy) | ||
return [] | ||
|
||
return commodity.hierarchy | ||
.map(ancestor => findCommodity(ancestor.code, ancestor.suffix)) | ||
.filter(ancestor => !!ancestor) | ||
} | ||
|
||
module.exports = { | ||
findSubheading, | ||
findCommodity, | ||
expandHierarchy, | ||
} |
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,5 @@ | ||
module.exports = { | ||
|
||
// Insert values here | ||
|
||
} |
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,10 @@ | ||
// | ||
// For guidance on how to create filters see: | ||
// https://prototype-kit.service.gov.uk/docs/filters | ||
// | ||
|
||
const govukPrototypeKit = require('govuk-prototype-kit') | ||
const addFilter = govukPrototypeKit.views.addFilter | ||
|
||
// Add your filters here | ||
|
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,75 @@ | ||
// | ||
// For guidance on how to create routes see: | ||
// https://prototype-kit.service.gov.uk/docs/create-routes | ||
// | ||
require('dotenv').config(); | ||
|
||
const fs = require('fs'); | ||
const govukPrototypeKit = require('govuk-prototype-kit') | ||
const commodities = require('./data/commodities/commodities'); | ||
const { default: axios } = require('axios'); | ||
|
||
const router = govukPrototypeKit.requests.setupRouter() | ||
|
||
const descriptions = fs.readFileSync(`${__dirname}/../descriptions.txt`).toString().split("\n"); | ||
|
||
const searchApiBase = process.env["SEARCH_API_BASE"] || "http://127.0.0.1:5000"; | ||
const searchApiSecretKey = process.env["SEARCH_API_SECRET_KEY"] | ||
|
||
// Add your routes here | ||
router.get('/new-product', async (request, response) => { | ||
request.session.data.description = descriptions[Math.floor(Math.random() * descriptions.length)]; | ||
|
||
const result = await axios.post(`${searchApiBase}/fpo-code-search`, { | ||
description: request.session.data.description, | ||
digits: 8 | ||
}, { | ||
headers: { | ||
'X-Api-Key': searchApiSecretKey, | ||
} | ||
} | ||
) | ||
|
||
const searchResults = await result.data; | ||
|
||
if(searchResults["results"].length > 0) { | ||
const searchResult = searchResults["results"][0]; | ||
|
||
const commodity = commodities.findSubheading(searchResult.code); | ||
|
||
request.session.data.searchResult = { | ||
code: searchResult.code, | ||
score: searchResult.score.toFixed(1), | ||
commodity: commodity, | ||
hierarchy: commodities.expandHierarchy(commodity).filter(c => c.description.toLowerCase() != 'other').reverse(), | ||
} | ||
|
||
console.log(request.session.data.searchResult) | ||
} else { | ||
request.session.data.searchResult = null; | ||
} | ||
|
||
const result6 = await axios.post(`${searchApiBase}/fpo-code-search`, { | ||
description: request.session.data.description, | ||
digits: 8 | ||
}, { | ||
headers: { | ||
'X-Api-Key': searchApiSecretKey, | ||
} | ||
} | ||
) | ||
|
||
response.redirect('product') | ||
}) | ||
|
||
router.post('/product-answer', async (request, response) => { | ||
const isCodeCorrect = request.session.data.isCodeCorrect; | ||
|
||
if(isCodeCorrect == 'yes') { | ||
response.redirect('/answer-yes'); | ||
} else if(isCodeCorrect == 'maybe') { | ||
response.redirect('/answer-maybe'); | ||
} else if(isCodeCorrect == 'no') { | ||
response.redirect('/answer-no'); | ||
} | ||
}); |
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,72 @@ | ||
{% extends "layouts/main.html" %} | ||
|
||
{% block pageTitle %} | ||
Question page template – {{ serviceName }} – GOV.UK Prototype Kit | ||
{% endblock %} | ||
|
||
{% block beforeContent %} | ||
{{ govukBackLink({ | ||
text: "Back", | ||
href: "javascript:window.history.back()" | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
|
||
<form class="form" action="/path/of/next/page" method="post"> | ||
<span class="govuk-caption-l">"{{ data['description'] }}"</span> | ||
|
||
{{ govukCheckboxes({ | ||
name: "whereDoYouLive", | ||
fieldset: { | ||
legend: { | ||
text: "What extra information would you need to classify this to 8 digits?", | ||
isPageHeading: true, | ||
classes: "govuk-fieldset__legend--l" | ||
} | ||
}, | ||
items: [ | ||
{ | ||
value: "item-type", | ||
text: "Type of item" | ||
}, | ||
{ | ||
value: "material", | ||
text: "Material" | ||
}, | ||
{ | ||
value: "purpose", | ||
text: "The purpose of the item" | ||
}, | ||
{ | ||
value: "state", | ||
text: "What state the item is in" | ||
}, | ||
{ | ||
value: "alcohol-volume", | ||
text: "Alcohol volume" | ||
}, | ||
{ | ||
value: "gender", | ||
text: "Gender (e.g. for clothing)" | ||
}, | ||
{ | ||
value: "container-size", | ||
text: "Container size" | ||
} | ||
] | ||
}) }} | ||
|
||
{{ govukButton({ | ||
text: "Continue" | ||
}) }} | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
|
||
{% endblock %} |
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,58 @@ | ||
{% extends "layouts/main.html" %} | ||
|
||
{% block pageTitle %} | ||
Question page template – {{ serviceName }} – GOV.UK Prototype Kit | ||
{% endblock %} | ||
|
||
{% block beforeContent %} | ||
{{ govukBackLink({ | ||
text: "Back", | ||
href: "javascript:window.history.back()" | ||
}) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<span class="govuk-caption-l">"{{ data['description'] }}"</span> | ||
|
||
<form class="form" action="thanks" method="get"> | ||
|
||
{{ govukRadios({ | ||
name: "whereDoYouLive", | ||
fieldset: { | ||
legend: { | ||
text: "Did you have to refer anywhere else (e.g. web search) to identify it?", | ||
isPageHeading: true, | ||
classes: "govuk-fieldset__legend--l" | ||
} | ||
}, | ||
items: [ | ||
{ | ||
value: "yes", | ||
text: "Yes", | ||
hint: { | ||
text: "I had to refer elsewhere, like a web search for the product" | ||
} | ||
}, | ||
{ | ||
value: "no", | ||
text: "No", | ||
hint: { | ||
text: "All of the information and context I needed was in the description" | ||
} | ||
} | ||
] | ||
}) }} | ||
|
||
{{ govukButton({ | ||
text: "Continue" | ||
}) }} | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
|
||
{% endblock %} |
Oops, something went wrong.