Skip to content

Commit

Permalink
Merge pull request #55 from Marvell-Consulting/SW-139-implement-dimen…
Browse files Browse the repository at this point in the history
…sion-preview

This implements date period and point in time matching
  • Loading branch information
j-maynard authored Dec 10, 2024
2 parents 779f9de + 9b0d4d2 commit b714230
Show file tree
Hide file tree
Showing 26 changed files with 1,855 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/@types/express-session/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'express-session';
import { DimensionPatchDto } from '../../dtos/dimension-patch-dto';
import { ViewError } from '../../dtos/view-error';

declare module 'express-session' {
interface SessionData {
errors: ViewError[] | undefined;
dimensionPatch: DimensionPatchDto | undefined;
}
}
598 changes: 594 additions & 4 deletions src/controllers/publish.ts

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/dtos/dimension-patch-dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DimensionType } from '../enums/dimension-type';
import { YearType } from '../enums/year-type';

export interface DimensionPatchDto {
dimension_type: DimensionType;
dimension_title?: string;
lookup_join_column?: string;
reference_type?: string;
date_type?: YearType;
year_format?: string;
quarter_format?: string;
month_format?: string;
date_format?: string;
fifth_quarter?: boolean;
}
1 change: 1 addition & 0 deletions src/dtos/dimension-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { TaskStatus } from '../enums/task-status';
export interface DimensionState {
name: string;
status: TaskStatus;
type: string;
}
2 changes: 1 addition & 1 deletion src/dtos/task-list-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DimensionState } from './dimension-state';

export interface TaskListState {
datatable: TaskStatus;

measure?: DimensionState;
dimensions: DimensionState[];

metadata: {
Expand Down
1 change: 1 addition & 0 deletions src/dtos/view-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ViewErrDTO {
}

export interface ViewDTO {
status: number;
dataset: DatasetDTO;
fact_table: FactTableDto;
current_page: number;
Expand Down
8 changes: 8 additions & 0 deletions src/enums/year-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum YearType {
Financial = 'financial',
Tax = 'tax',
Academic = 'academic',
Calendar = 'calendar',
Meteorological = 'meteorological',
PointInTime = 'pointInTime'
}
4 changes: 3 additions & 1 deletion src/exceptions/api.exception.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export class ApiException extends Error {
constructor(
public message: string,
public status?: number
public status?: number,
public body?: string | FormData
) {
super(message);
this.name = 'ApiException';
this.status = status;
this.body = body;
}
}
135 changes: 133 additions & 2 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"continue": "Continue",
"back": "Back",
"cancel": "Cancel",
"upload_csv": "Upload CSV File"
"upload_csv": "Upload CSV File",
"preview": "Preview (opens in new tab)"
},
"pagination": {
"previous": "Previous",
Expand Down Expand Up @@ -68,6 +69,122 @@
"lookup_table": "lookup tables for all relevant dimensions - using either common tables within this service or uploading them yourself",
"metadata": "details about this dataset including description, quality and how the data was collected"
},
"dimension_name": {
"heading": "What should this dimension be called on the StatsWales website?",
"hint": "This should be:",
"concise": "concise and clearly explain what the dimension contains",
"language": "entered in the language in which you're viewing this service"
},
"dimension_type_chooser": {
"heading": "Add reference data",
"subheading": "Dimension",
"question": "What kind of data does this dimension contain?",
"chooser": {
"age": "Age",
"ethnicity": "Ethnicity",
"geography": "Geography",
"religion": "Religion",
"sex_gender": "Sex and gender",
"lookup": "Something else"
}
},
"time_dimension_chooser": {
"heading": "Set up dimension containing time",
"subheading": "Dates",
"showing": "A sample of {{rows}} of {{total}} rows.",
"question": "What kind of dates does the dimension contain?",
"chooser": {
"period": "Periods of time",
"period-hint": "For example, months or years for which data values apply to",
"point": "Specific points in time",
"point-hint": "For example, specific dates when data values were collected"
}
},
"time_dimension_review": {
"heading": "Confirm the dates are correct",
"showing": "Showing a sample of {{rows}} of {{total}} rows.",
"confirm": "By continuing, you confirm the dates are correct.",
"go_back": "Change date format",
"column_headers": {
"date_code": "Date code",
"description": "Description",
"start_date": "Start",
"end_date": "End",
"date_type": "Date type"
},
"year_type": {
"calendar_year": "Calendar Year",
"calendar_quarter": "Calendar Quarter",
"calendar_month": "Calendar Month",
"financial_year": "Financial Year",
"financial_quarter": "Financial Quarter",
"financial_month": "Financial Month",
"academic_year": "Academic Year",
"academic_quarter": "Academic Quarter",
"academic_month": "Academic Month",
"tax_year": "Tax Year",
"tax_quarter": "Tax Quarter",
"tax_month": "Tax Month",
"meteorological_year": "Meteorological Year",
"meteorological_quarter": "Meteorological Quarter",
"meteorological_month": "Meteorological Month"
}
},
"period-type-chooser": {
"heading": "What are the periods of time?",
"subheading": "Dates",
"chooser": {
"years": "Years",
"quarters": "Quarters",
"months": "Months"
}
},
"year_type": {
"heading": "What type of year does this dimension represent?",
"chooser": {
"calendar": "Calendar",
"calendar-hint": "1st January - 31st December",
"financial" : "Financial",
"financial-hint": "1st April - 31st March",
"tax": "Tax",
"tax-hint": "6th April - 5th April",
"academic": "Academic",
"academic-hint": "1st September - 31st August",
"meteorological": "Meteorological",
"meteorological-hint": "1st March - 28th/29th February"
}
},
"year_format": {
"heading": "What format is used to represent years?",
"example": "For example, {{example}}"
},
"quarter_format": {
"heading": "What format is used to represent quarters?",
"heading-alt": "What format is used for quarterly totals?",
"example": "For example, {{example}}",
"fifth_quarter": "Year totals are represented as a 5th quarter",
"no_quarterly_totals": "There are no quarterly totals"
},
"month_format": {
"heading": "What format is used to represent months?",
"example": "For example, {{example}}"
},
"period_match_failure": {
"heading": "Date formatting cannot be matched to the fact table",
"information": "{{failureCount}} of the dates in the fact table do not match the date formatting you have indicated. You should check:",
"formatting": "the date formatting in the fact table is correct",
"choices": "you indicated the correct date formats",
"supplied_format":"Indicated date format:",
"year_format": "Years: {{format}}",
"quarter_format": "Quarters: {{format}}",
"month_format": "Months: {{format}}",
"date_format": "Date: {{format}}",
"subheading": "Date formats that cannot be matched",
"upload_different_file": "Upload corrected or different data table",
"upload_different_file_warning": "(This will remove reference data from all dimensions)",
"try_different_format": "Indicate different date formatting",
"no_matches": "None of the dates matched the format supplied"
},
"title": {
"heading": "What is the title of this dataset?",
"appear": "This title will appear on the StatsWales website",
Expand Down Expand Up @@ -400,6 +517,10 @@
"label": "Change what each column in the data table contains",
"description": "This will remove reference data and notes for any columns you change that contain dimensions"
}
},
"point_in_time": {
"heading": "What date format is used?",
"example": "For example: {{example}}"
}
},
"view": {
Expand Down Expand Up @@ -470,6 +591,15 @@
"try_later": "Please try later",
"name_missing": "Dataset Name Missing",
"dataset_missing": "No dataset found with this ID",
"dimension": {
"name_to_short": "The Dimension name is to short or missing",
"name_to_long": "Dimension name is limited to 1024 characters",
"naming_failed": "Something went wrong trying to set the name. Please try again"
},
"title": {
"missing": "Either a title was not entered or there is a problem.",
"duplicate": "Title already exists"
},
"description": {
"missing": "You need to provide a summary of this dataset"
},
Expand Down Expand Up @@ -511,7 +641,8 @@
"no_csv_data": "No CSV data available"
},
"not_found": "Page not found",
"server_error": "An unknown error occcured, please try again later"
"server_error": "An unknown error occcured, please try again later",
"dimension_reset": "Something went wrong trying to reset the dimension"
},
"routes": {
"healthcheck": "healthcheck",
Expand Down
4 changes: 4 additions & 0 deletions src/middleware/services.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextFunction, Request, Response } from 'express';
import { format, parseISO } from 'date-fns';

import { Locale } from '../enums/locale';
import { StatsWalesApi } from '../services/stats-wales-api';
Expand All @@ -14,6 +15,9 @@ export const initServices = (req: Request, res: Response, next: NextFunction): v
req.buildUrl = localeUrl; // for controllers
res.locals.buildUrl = localeUrl; // for templates
res.locals.url = req.originalUrl; // Allows the passing through of the URL
res.locals.referrer = req.get('Referrer');
res.locals.parseISO = parseISO;
res.locals.dateFormat = format;
}
next();
};
39 changes: 38 additions & 1 deletion src/routes/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ import {
provideDesignation,
provideTopics,
providePublishDate,
provideOrganisation
provideOrganisation,
fetchDimensionPreview,
fetchTimeDimensionPreview,
pointInTimeChooser,
periodOfTimeChooser,
yearFormat,
quarterChooser,
monthChooser,
yearTypeChooser,
periodType,
periodReview,
dimensionName
} from '../controllers/publish';

export const publish = Router();
Expand Down Expand Up @@ -48,6 +59,32 @@ publish.post('/:datasetId/sources', fetchDataset, upload.none(), sources);

publish.get('/:datasetId/tasklist', fetchDataset, taskList);

/* Dimension creation routes */
publish.get('/:datasetId/dimension-data-chooser/:dimensionId', fetchDataset, fetchDimensionPreview);
publish.post('/:datasetId/dimension-data-chooser/:dimensionId', fetchDataset, fetchDimensionPreview);

publish.get('/:datasetId/time-period/:dimensionId', fetchDataset, fetchTimeDimensionPreview);
publish.post('/:datasetId/time-period/:dimensionId', fetchDataset, fetchTimeDimensionPreview);
publish.get('/:datasetId/time-period/:dimensionId/point-in-time', fetchDataset, pointInTimeChooser);
publish.post('/:datasetId/time-period/:dimensionId/point-in-time', fetchDataset, pointInTimeChooser);

// Period of time flow)
publish.get('/:datasetId/time-period/:dimensionId/period-of-time', fetchDataset, yearTypeChooser);
publish.post('/:datasetId/time-period/:dimensionId/period-of-time', fetchDataset, yearTypeChooser);
publish.get('/:datasetId/time-period/:dimensionId/period-of-time/year-format', fetchDataset, yearFormat);
publish.post('/:datasetId/time-period/:dimensionId/period-of-time/year-format', fetchDataset, yearFormat);
publish.get('/:datasetId/time-period/:dimensionId/period-of-time/period-type', fetchDataset, periodType);
publish.post('/:datasetId/time-period/:dimensionId/period-of-time/period-type', fetchDataset, periodType);
publish.get('/:datasetId/time-period/:dimensionId/period-of-time/quarters', fetchDataset, quarterChooser);
publish.post('/:datasetId/time-period/:dimensionId/period-of-time/quarters', fetchDataset, quarterChooser);
publish.get('/:datasetId/time-period/:dimensionId/period-of-time/months', fetchDataset, monthChooser);
publish.post('/:datasetId/time-period/:dimensionId/period-of-time/months', fetchDataset, monthChooser);
publish.get('/:datasetId/time-period/:dimensionId/review', fetchDataset, periodReview);
publish.post('/:datasetId/time-period/:dimensionId/review', fetchDataset, periodReview);
publish.get('/:datasetId/dimension/:dimensionId/name', upload.none(), fetchDataset, dimensionName);
publish.post('/:datasetId/dimension/:dimensionId/name', upload.none(), fetchDataset, dimensionName);

/* Meta Data related Routes */
publish.get('/:datasetId/change', fetchDataset, changeData);
publish.post('/:datasetId/change', fetchDataset, upload.none(), changeData);

Expand Down
Loading

0 comments on commit b714230

Please sign in to comment.