Skip to content

Commit

Permalink
Merge pull request #51 from digital-land/newDatasets
Browse files Browse the repository at this point in the history
New datasets
  • Loading branch information
GeorgeGoodall authored Feb 2, 2024
2 parents 5ddc459 + b8edb5f commit 8a40b6b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
31 changes: 22 additions & 9 deletions src/controllers/datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ class DatasetController extends PageController {
// const dataset = req.sessionModel.get('data-subject')
// const options = datasetOptions[dataset]

const options = [dataSubjects['Article 4'].dataSets[0], dataSubjects['Conservation area'].dataSets[0]]

if (options) {
this.availableDatasets = options.filter(option => option.available)
req.form.options.datasetItems = options
super.get(req, res, next)
} else {
// skip to next step of form wizard
this.successHandler(req, res, next)
// the options should be all the datasets that are available

const availableDataSubjects = Object.values(dataSubjects).filter(dataSubject => dataSubject.available)
const dataSets = Object.values(availableDataSubjects).map(dataSubject => dataSubject.dataSets).flat()
const availableDatasets = dataSets.filter(dataSet => dataSet.available)

req.form.options.datasetItems = availableDatasets
super.get(req, res, next)
}

// we shouldn't need this here but as we dont currently set the datasubject, we need to do so here
post (req, res, next) {
const dataset = req.body.dataset
// set the data-subject based on the dataset selected
let dataSubject = ''
for (const [key, value] of Object.entries(dataSubjects)) {
if (value.dataSets.find(dataSet => dataSet.value === dataset)) {
dataSubject = key
break
}
}
req.body['data-subject'] = dataSubject
super.post(req, res, next)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/uploadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UploadController extends PageController {
originalname: req.file.originalname,
dataset: req.sessionModel.get('dataset'),
dataSubject: req.sessionModel.get('data-subject'),
organisation: 'local-authority-eng:CAT', // ToDo: this needs to be dynamic, not collected in the prototype, should it be?
// organisation: 'local-authority-eng:CAT', // ToDo: this needs to be dynamic, not collected in the prototype, should it be?
sessionId: await hash(req.sessionID),
ipAddress: await hash(req.ip)
})
Expand Down
2 changes: 1 addition & 1 deletion src/routes/form-wizard/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
'/dataset': {
...baseSettings,
controller: datasetController,
fields: ['dataset'],
fields: ['dataset', 'data-subject'],
next: 'upload',
backLink: './'
},
Expand Down
34 changes: 25 additions & 9 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const severityLevels = {
}

export const dataSubjects = {
'Article 4': {
'article-4-direction': {
available: true,
dataSets: [
{
Expand All @@ -15,13 +15,13 @@ export const dataSubjects = {
available: true
},
{
value: 'article-4-direction area',
value: 'article-4-direction-area',
text: 'Article 4 direction area dataset',
available: false
}
]
},
'Conservation area': {
'conservation-area': {
available: true,
dataSets: [
{
Expand All @@ -36,8 +36,8 @@ export const dataSubjects = {
}
]
},
'Tree preservation order': {
available: false,
'tree-preservation-order': {
available: true,
dataSets: [
{
value: 'tree-preservation-order',
Expand All @@ -47,7 +47,7 @@ export const dataSubjects = {
{
value: 'tree-preservation-zone',
text: 'Tree preservation zone dataset',
available: false
available: true
},
{
value: 'tree',
Expand All @@ -56,8 +56,24 @@ export const dataSubjects = {
}
]
},
'Listed building': {
available: false,
dataSets: []
'listed-building': {
available: true,
dataSets: [
{
value: 'listed-building',
text: 'Listed building',
available: false
},
{
value: 'listed-building-outline',
text: 'Listed building outline',
available: true
},
{
value: 'listed-building-grade',
text: 'Listed building grade',
available: false
}
]
}
}

0 comments on commit 8a40b6b

Please sign in to comment.