diff --git a/src/actions/dataset.ts b/src/actions/dataset.ts index d35b67ea2d08e5980b06ae7b23248fc76a93de4f..9b8114e6e0917548c7dd416aa7eea59928685ff0 100644 --- a/src/actions/dataset.ts +++ b/src/actions/dataset.ts @@ -390,6 +390,7 @@ function updateLocationRequest(datasetUUID: string, location: Location) { return LocationService.saveLocation(token, datasetUUID, location) .then((saved) => { dispatch(receiveLocation(saved)); + dispatch(receiveDataset(refreshStartEndDates(getState().datasets.currentDataset))); }).catch((error) => { log('Save error', error); }); @@ -413,10 +414,26 @@ function deleteLocationRequest(datasetUUID: string, location: Location) { return LocationService.deleteLocation(token, datasetUUID, location) .then((saved) => { dispatch(deleteLocation(datasetUUID, saved)); + dispatch(receiveDataset(refreshStartEndDates(getState().datasets.currentDataset))); }).catch((error) => { log('Delete error', error); }); }; } +function refreshStartEndDates(dataset) { + const res = {...dataset}; + res.startDate = null; + res.endDate = null; + res.locations.forEach((location) => { + if (!res.startDate || (location.startDate && res.startDate.localeCompare(location.startDate) > 0)) { + res.startDate = location.startDate; + } + if (!res.endDate || (location.endDate && res.endDate.localeCompare(location.endDate) < 0)) { + res.endDate = location.endDate; + } + }); + return res; +} + export { createLocationRequest, updateLocationRequest, deleteLocationRequest, receiveLocation }; diff --git a/src/model/dataset.model.ts b/src/model/dataset.model.ts index d119d7bd985348dadf2af24bc09fb7b0eafb01fc..bdf11b05fe133e04414526fbdd1c69b783dc7ab4 100644 --- a/src/model/dataset.model.ts +++ b/src/model/dataset.model.ts @@ -31,6 +31,8 @@ export class Dataset extends UuidModel implements IUserPermissions { public created: string; public rights: string; public language: string; + public startDate: string; + public endDate: string; public source: string; public creators: Creator[]; public owner: string | Partner | any; diff --git a/src/model/location.model.ts b/src/model/location.model.ts index 759c8d8d01e528474c1ac9431a7f67f82bf6e959..51efc7ba889448fe28a28e64fbae83290bd40ed1 100644 --- a/src/model/location.model.ts +++ b/src/model/location.model.ts @@ -7,6 +7,8 @@ class Location extends UuidModel { public verbatimLocality: string; public decimalLatitude: number; public decimalLongitude: number; + public startDate: string; + public endDate: string; public constructor(obj?) { super(obj); diff --git a/src/ui/common/time/McpdDate.tsx b/src/ui/common/time/McpdDate.tsx new file mode 100644 index 0000000000000000000000000000000000000000..ac83f6fb52b184f546fc0622efea626576357530 --- /dev/null +++ b/src/ui/common/time/McpdDate.tsx @@ -0,0 +1,31 @@ +import * as React from 'react'; + + +export default function McpdDate({ value, locale = 'en-GB' }: { value: string, locale?: string }) { + + if (!value) { + return (Date not provided); + } + + const year = value.substr(0, 4); + const month = value.substr(4, 2); + const day = value.substr(6, 2); + let mcpdDate; + + if (!month || month === '--' || month === '00') { + mcpdDate = year; + } else { + if (!day || day === '--' || day === '00') { + const options = {year: 'numeric', month: 'long'}; + mcpdDate = new Date(parseInt(year, 10), parseInt(month, 10) - 1, 1).toLocaleDateString(locale, options); + } else { + const options = {year: 'numeric', month: 'long', day: 'numeric'}; + mcpdDate = new Date(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10)).toLocaleDateString(locale, options); + } + } + return ( + + { mcpdDate } + + ); +} diff --git a/src/ui/pages/dataset/c/DatasetDisplay.tsx b/src/ui/pages/dataset/c/DatasetDisplay.tsx index 5b5673714828b317f5b09959b21591bd5e80d5be..47bf7f3ca1a54eb0d5753da7e4456d2d6e0ff586 100644 --- a/src/ui/pages/dataset/c/DatasetDisplay.tsx +++ b/src/ui/pages/dataset/c/DatasetDisplay.tsx @@ -4,7 +4,7 @@ import { translate } from 'react-i18next'; import { withStyles } from '@material-ui/core/styles'; import {log} from 'utilities/debug'; -import { fixDate } from 'utilities'; +import {fixDate} from 'utilities'; import { Dataset } from 'model/dataset.model'; import { Descriptor } from 'model/descriptor.model'; @@ -33,6 +33,7 @@ import Permissions from 'ui/common/permission/Permissions'; import CropChips from 'ui/catalog/crop/CropChips'; import Card, {CardHeader, CardContent, CardActions } from 'ui/common/Card'; +import McpdDate from 'ui/common/time/McpdDate'; const styles = (theme) => ({ root: { @@ -348,6 +349,8 @@ class DetailInfo extends React.Component { { dataset.created } + + { dataset.source } { dataset.createdDate && } diff --git a/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx b/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx index 3d9922b8d8d8314934c3063c50bdd25637d3f013..767b5adc5a52abb3690f80d6d7d1393176df94fe 100644 --- a/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx +++ b/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx @@ -112,6 +112,8 @@ class LocationForm extends React.Component { `${location}.mapCountry`, `${location}.decimalLatitude`, `${location}.decimalLongitude`, + `${location}.startDate`, + `${location}.endDate`, ] } checkGeonames={ this.checkGeonames } component={ FormMap } @@ -148,6 +150,20 @@ class LocationForm extends React.Component { onBlur={ this.updateCountryInfo(fields, index)('decimalLongitude') } validate={ [ Validators.decimalNumber ] } /> + + )) }
diff --git a/src/utilities/Validators.ts b/src/utilities/Validators.ts index 17bed5849ea5b10ebc03a9d4e3d0566f749e81ae..72bc6c6c083c4cf7bdfc91015d49b777ffd7b0a5 100644 --- a/src/utilities/Validators.ts +++ b/src/utilities/Validators.ts @@ -11,4 +11,5 @@ export default class Validators { public static emailAddress = (value) => !value || value.match(/^[\w\d\-\+\._]+@[\w\d\-_]+(\.[\w\d\-_]+)*$/g) ? undefined : 'Invalid email address'; public static phoneNumber = (value) => !value || value.match(/^\+[\d\-\. ]+( ext\. \d+)?$/gi) ? undefined : 'Invalid number format: only digits and + . - allowed'; public static url = (value) => !value || value.match(/^(\w+:)\/\//g) ? undefined : 'Invalid URL'; + public static mcpdDate = (value) => !value || value.match('^(?:(?:[1-9]\\d{3})|(?:----)|(?:0000))(?:--|(?:0[0-9])|(?:1[0-2]))(?:--|(?:0[0-9])|(?:[1-2][0-9])|(?:3[0-1]))$') ? undefined : 'Invalid date'; }