From 56e1ecbe675f7acc6f43f6e8c66638a014e61765 Mon Sep 17 00:00:00 2001 From: "v.pavlov" Date: Tue, 14 Aug 2018 14:05:59 +0300 Subject: [PATCH 1/2] Location and timing Added mcpdDate component --- src/actions/dataset.ts | 17 ++++++++++ src/model/dataset.model.ts | 2 ++ src/model/location.model.ts | 2 ++ src/ui/common/time/McpdDate.tsx | 31 +++++++++++++++++++ src/ui/pages/dataset/c/DatasetDisplay.tsx | 5 ++- .../steps/location/LocationForm.tsx | 16 ++++++++++ src/utilities/Validators.ts | 1 + 7 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/ui/common/time/McpdDate.tsx diff --git a/src/actions/dataset.ts b/src/actions/dataset.ts index d35b67e..9b8114e 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 d119d7b..bdf11b0 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 759c8d8..51efc7b 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 0000000..17f8357 --- /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 specified!); + } + + 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 5b56737..6bb8115 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 3d9922b..d80a15b 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 17bed58..72bc6c6 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'; } -- GitLab From b490ef6a554cefd71f8c3fd08be4ccd228d88d34 Mon Sep 17 00:00:00 2001 From: Maxym Borodenko Date: Wed, 15 Aug 2018 10:43:27 +0300 Subject: [PATCH 2/2] Rename labels --- src/ui/common/time/McpdDate.tsx | 2 +- src/ui/pages/dataset/c/DatasetDisplay.tsx | 4 ++-- .../dataset/dataset-stepper/steps/location/LocationForm.tsx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/common/time/McpdDate.tsx b/src/ui/common/time/McpdDate.tsx index 17f8357..ac83f6f 100644 --- a/src/ui/common/time/McpdDate.tsx +++ b/src/ui/common/time/McpdDate.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; export default function McpdDate({ value, locale = 'en-GB' }: { value: string, locale?: string }) { if (!value) { - return (Date not specified!); + return (Date not provided); } const year = value.substr(0, 4); diff --git a/src/ui/pages/dataset/c/DatasetDisplay.tsx b/src/ui/pages/dataset/c/DatasetDisplay.tsx index 6bb8115..47bf7f3 100644 --- a/src/ui/pages/dataset/c/DatasetDisplay.tsx +++ b/src/ui/pages/dataset/c/DatasetDisplay.tsx @@ -349,8 +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 d80a15b..767b5ad 100644 --- a/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx +++ b/src/ui/pages/dataset/dataset-stepper/steps/location/LocationForm.tsx @@ -153,14 +153,14 @@ class LocationForm extends React.Component { -- GitLab