-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from digital-land/staging
LPA dashboard increment
- Loading branch information
Showing
29 changed files
with
719 additions
and
44 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
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,74 @@ | ||
import performanceDbApi from '../services/performanceDbApi.js' // Assume you have an API service module | ||
import logger from '../utils/logger.js' | ||
import { dataSubjects } from '../utils/utils.js' | ||
|
||
// get a list of available datasets | ||
const availableDatasets = Object.values(dataSubjects) | ||
.flatMap(dataSubject => | ||
dataSubject.dataSets | ||
.filter(dataset => dataset.available) | ||
.map(dataset => dataset.value) | ||
) | ||
|
||
const LpaOverviewController = { | ||
/** | ||
* Get LPA overview data and render the overview page | ||
* @param {Request} req - Express request object | ||
* @param {Response} res - Express response object | ||
* @param {NextFunction} next - Express next function | ||
* @returns {Promise<void>} - Returns a promise that resolves when the overview page is rendered | ||
*/ | ||
async getOverview (req, res, next) { | ||
try { | ||
const lpa = req.params.lpa | ||
|
||
// Make API request | ||
const lpaOverview = await performanceDbApi.getLpaOverview(lpa) | ||
|
||
// restructure datasets to usable format | ||
const datasets = Object.entries(lpaOverview.datasets).map(([key, value]) => { | ||
return { | ||
slug: key, | ||
...value | ||
} | ||
}) | ||
|
||
// add in any of the missing key 8 datasets | ||
const keys = Object.keys(lpaOverview.datasets) | ||
availableDatasets.forEach(dataset => { | ||
if (!keys.includes(dataset)) { | ||
datasets.push({ | ||
slug: dataset, | ||
endpoint: null | ||
}) | ||
} | ||
}) | ||
|
||
const totalDatasets = datasets.length | ||
const [datasetsWithEndpoints, datasetsWithIssues, datasetsWithErrors] = datasets.reduce((accumulator, dataset) => { | ||
if (dataset.endpoint !== null) accumulator[0]++ | ||
if (dataset.issue) accumulator[1]++ | ||
if (dataset.error) accumulator[2]++ | ||
return accumulator | ||
}, [0, 0, 0]) | ||
|
||
const params = { | ||
organisation: { | ||
name: lpaOverview.name | ||
}, | ||
datasets, | ||
totalDatasets, | ||
datasetsWithEndpoints, | ||
datasetsWithIssues, | ||
datasetsWithErrors | ||
} | ||
|
||
res.render('manage/lpa-overview.html', params) | ||
} catch (error) { | ||
logger.error(error) | ||
next(error) | ||
} | ||
} | ||
} | ||
|
||
export default LpaOverviewController |
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
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
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,43 @@ | ||
import logger from '../utils/logger.js' | ||
|
||
/** | ||
* Creates a filter function that takes a dataset slug as input and returns its corresponding readable name. | ||
* The filter function uses a provided dataset name mapping to look up the readable name. | ||
* | ||
* @param {Map<string, string>} datasetNameMapping - A map of dataset slugs to their corresponding readable names. | ||
* @returns {(slug: string) => string} - A filter function that takes a dataset slug as input and returns its corresponding readable name. | ||
*/ | ||
export const makeDatasetSlugToReadableNameFilter = (datasetNameMapping) => { | ||
/** | ||
* A filter function that takes a dataset slug as input and returns its corresponding readable name. | ||
* | ||
* @param {string} slug - The dataset slug to look up. | ||
* @returns {string} - The readable name corresponding to the provided slug. | ||
* @throws {Error} - If the provided slug is not found in the dataset name mapping. | ||
*/ | ||
return (slug) => { | ||
const name = datasetNameMapping.get(slug) | ||
if (!name) { | ||
// throw new Error(`Can't find a name for ${slug}`) | ||
// ToDo: work out what to do here? potentially update it with data from datasette | ||
logger.warning(`can't find a name for ${slug}`) | ||
return slug | ||
} | ||
return name | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {*} dataSubjects | ||
* @returns {Map<string,string>} | ||
*/ | ||
export const createDatasetMapping = (dataSubjects) => { | ||
const mapping = new Map() | ||
for (const data of Object.values(dataSubjects)) { | ||
for (const dataset of data.dataSets) { | ||
mapping.set(dataset.value, dataset.text) | ||
} | ||
} | ||
return mapping | ||
} |
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,8 @@ | ||
import express from 'express' | ||
import LpaOverviewController from '../controllers/LpaOverviewController.js' | ||
|
||
const router = express.Router() | ||
|
||
router.get('/:lpa/overview', LpaOverviewController.getOverview) | ||
|
||
export default router |
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
File renamed without changes.
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,19 @@ | ||
import axios from 'axios' | ||
import logger from '../utils/logger.js' | ||
|
||
const datasetteUrl = 'https://datasette.planning.data.gov.uk' | ||
const database = 'digital-land' | ||
|
||
export default { | ||
runQuery: async (query) => { | ||
const encodedQuery = encodeURIComponent(query) | ||
const url = `${datasetteUrl}/${database}.json?sql=${encodedQuery}` | ||
try { | ||
const response = await axios.get(url) | ||
return response.data | ||
} catch (error) { | ||
logger.warn(error) | ||
throw error | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.