Commit 10102453 authored by Matija Obreza's avatar Matija Obreza

Merge branch '172-accession-display-display-audit-log-data' into 'master'

Added referencedEntity handling to AuditInfo

Closes #172

See merge request genesys-pgr/genesys-ui!220
parents a4846fee 3f52c87a
......@@ -62,6 +62,7 @@
"dateSearch": "Date search",
"fromIncluding": "At least (min)",
"toIncluding": "At most (max)",
"createdDate": "Created on",
"lastModifiedDate": "Last modified date",
"textSearch": "Text search",
"keyword": "Keyword search"
......
......@@ -485,6 +485,11 @@
"acceNumb": "Accession number",
"countryOfOrigin": "Country of origin",
"instituteCode": "Institute code",
"institute": {
"country": {
"iso3": "Country of holding institute"
}
},
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
......
......@@ -142,6 +142,11 @@
"acceNumb": "Accession number",
"countryOfOrigin": "Country of origin",
"instituteCode": "Institute code",
"institute": {
"country": {
"iso3": "Country of holding institute"
}
},
"taxonomy": "Taxonomy",
"genus": "Genus",
"species": "Species",
......
......@@ -190,7 +190,12 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
}
>
<Properties>
{ accession.doi && <PropertiesItem title={ t('accessions.public.p.display.DOI') }><DOI noPrefix value={ accession.doi } /></PropertiesItem> }
{ accession.doi &&
<PropertiesItem title={ t('accessions.public.p.display.DOI') }>
<DOI noPrefix value={ accession.doi } />
<AuditedInfo info={ auditAccession.doi }/>
</PropertiesItem>
}
<PropertiesItem title={ t('accessions.common.acceNumb') } >
{ accession.accessionNumber }
<AuditedInfo info={ auditAccession.accessionNumber }/>
......@@ -217,25 +222,31 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
<McpdDate value={ accession.acquisitionDate } />
<AuditedInfo info={ auditAccession.acquisitionDate }/>
</PropertiesItem>
{ accession.countryOfOrigin && <PropertiesItem title={ t('accessions.common.countryOfOrigin') }>{ <CountryLink country={ accession.countryOfOrigin }/> }<AuditedInfo info={ auditAccession.countryOfOrigin }/></PropertiesItem> }
{ accession.countryOfOrigin &&
<PropertiesItem title={ t('accessions.common.countryOfOrigin') }>
<CountryLink country={ accession.countryOfOrigin }/>
<AuditedInfo info={ auditAccession.countryOfOrigin }/>
</PropertiesItem>
}
{ accession.sampStat &&
<PropertiesItem title={ t('accessions.common.sampStat') }>
{ t(`accessions.common.sampleStatus.${accession.sampStat}`) }
<AuditedInfo info={ auditAccession.sampStat }/>
<AuditedInfo info={ auditAccession.sampStat } tPrefix="accessions.common.sampleStatus"/>
</PropertiesItem>
}
{ accession.storage && accession.storage.length > 0 && <PropertiesItem title={ t('accessions.common.storageType') }>
{ accession.storage.map((storage, i) => (
<div key={ storage } style={ {width: '100%', paddingTop: '.25rem'} }>{ t(`accessions.common.storage.${storage}`) }</div>
)) }
<AuditedInfo info={ auditAccession.storage } tPrefix="accessions.common.storage"/>
</PropertiesItem> }
<PropertiesItem title={ t('accessions.public.p.display.availability') } keepEmpty>
{ t(`accessions.common.available.${accession.available}`) }
<AuditedInfo info={ auditAccession.available }/>
<AuditedInfo info={ auditAccession.available } tPrefix="accessions.common.available"/>
</PropertiesItem>
<PropertiesItem title={ t('accessions.public.p.display.ITPGRFAMLS') } keepEmpty>
{ t(`accessions.common.mlsStatus.${accession.mlsStatus}`) }
<AuditedInfo info={ auditAccession.mlsStatus }/>
<AuditedInfo info={ auditAccession.mlsStatus } tPrefix="accessions.common.mlsStatus"/>
</PropertiesItem>
{ accession.donorCode &&
<PropertiesItem title={ t('accessions.public.p.display.donorInstitute') }>
......@@ -253,9 +264,15 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
{ accession.duplSite.map((duplSite, i) => (
<div key={ duplSite } style={ {width: '100%', paddingTop: '.25rem'} }>{ duplSite }</div>
)) }
<AuditedInfo info={ auditAccession.duplSite }/>
</PropertiesItem> }
{ accession.acceUrl && <PropertiesItem title={ t('accessions.public.p.display.accessionURL') }><ExternalLink link={ accession.acceUrl } /></PropertiesItem> }
{ accession.acceUrl &&
<PropertiesItem title={ t('accessions.public.p.display.accessionURL') }>
<ExternalLink link={ accession.acceUrl } />
<AuditedInfo info={ auditAccession.acceUrl }/>
</PropertiesItem>
}
</Properties>
</MainSection>
......@@ -267,23 +284,36 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
<Properties>
<PropertiesItem title={ t('accessions.common.genus') }>
{ accession.taxonomy.genus }
<AuditedInfo info={ auditAccession.genus }/>
<AuditedInfo info={ auditAccession.taxonomy } property="genus"/>
</PropertiesItem>
<PropertiesItem title={ t('accessions.common.species') }>
{ accession.taxonomy.species }
{ '' }
<a onClick={ this.applyFilterForInstituteSpecies }>View <i>{ `${accession.taxonomy.genus} ${accession.taxonomy.species}` }</i> at { accession.institute.code }</a>
<AuditedInfo info={ auditAccession.taxonomy } property="species"/>
</PropertiesItem>
<PropertiesItem title={ t('accessions.public.p.display.scientificName') }>
<SciName taxa={ accession.taxonomy.taxonNameHtml } />
<AuditedInfo info={ auditAccession.taxonomy }/>
</PropertiesItem>
<PropertiesItem title={ t('accessions.public.p.display.scientificName') }><SciName taxa={ accession.taxonomy.taxonNameHtml } /></PropertiesItem>
{ accession.crop && <PropertiesItem title={ t('accessions.public.p.display.cropName') }><CropChips crops={ accession.crop.shortName } /></PropertiesItem> }
<PropertiesItem title={ t('accessions.public.p.display.providedCropName') }>{ accession.cropName }</PropertiesItem>
<PropertiesItem title={ t('accessions.public.p.display.providedCropName') }>
{ accession.cropName }
<AuditedInfo info={ auditAccession.cropName }/>
</PropertiesItem>
</Properties>
</PageSection>
{ (accession.donorCode || (accession.aliases && accession.aliases.length > 0)) &&
<PageSection title={ t('accessions.public.p.display.accessionNames') }>
<Properties>
{ accession.donorCode && <PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>{ accession.donorNumb } <em>{ accession.donorCode }</em></PropertiesItem> }
{ accession.donorCode &&
<PropertiesItem title={ t('accessions.common.alias.DONORNUMB') }>
{ accession.donorNumb } <em>{ accession.donorCode }</em>
<AuditedInfo info={ auditAccession.donorNumb }/>
<AuditedInfo info={ auditAccession.donorCode }/>
</PropertiesItem>
}
{ accession.aliases && accession.aliases.map((alias) => (
<PropertiesItem key={ alias.id } title={ t(`accessions.common.alias.${alias.aliasType}`) }>{ alias.name } <em>{ alias.usedBy }</em></PropertiesItem>
)) }
......@@ -309,7 +339,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
{ accession.coll.collSrc &&
<PropertiesItem key="collSrc" title={ t(`accessions.common.coll.collSrc`) }>
{ t(`accessions.common.collectingSource.${accession.coll.collSrc}`) }
<AuditedInfo info={ auditAccessionCollect.collSrc }/>
<AuditedInfo info={ auditAccessionCollect.collSrc } tPrefix="accessions.common.collectingSource"/>
</PropertiesItem>
}
{ accession.coll &&
......
......@@ -23,10 +23,12 @@ const AccessionFilters = ({handleSubmit, initialValues, initialize, t, ...other}
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title={ t('common:f.textSearch') }>
<StringArrFilter name="holder.code" label={ t('accessions.common.instituteCode') } placeholder="NGA039"/>
<StringArrFilter name="holder.country.iso3" label={ t('accessions.model.institute.country.iso3') } placeholder="NGA"/>
<StringFilter name="acceNumb" searchType="contains" label={ t('accessions.common.acceNumb') } placeholder="IRGC"/>
<NumberFilter name="seqNo" label={ t('accessions.public.f.seqNumber') } />
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title={ t('common:f.dateSearch') }>
<DateFilter name="createdDate" label={ t('common:f.createdDate') }/>
<DateFilter name="lastModifiedDate" label={ t('common:f.lastModifiedDate') }/>
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title={ t('accessions.public.f.crop') }>
......
......@@ -4,8 +4,10 @@ class AuditLog {
public entityId: number;
public id: number;
public logDate: Date;
public newEntity: any;
public newState: string;
public previousState: string;
public previousEntity: any;
public propertyName: string;
public referencedEntity: any;
}
......
......@@ -21,6 +21,7 @@ class Taxonomy2 {
public version: number;
public taxonNameHtml: string;
public static clazz = 'org.genesys2.server.model.genesys.Taxonomy2';
}
export default Taxonomy2;
......@@ -18,6 +18,8 @@ class Country {
public region: GeoRegion;
public replacedBy: Country;
public wikiLink: string;
public static clazz = 'org.genesys2.server.model.impl.Country';
}
export default Country;
......@@ -2,10 +2,19 @@ import * as React from 'react';
import { translate } from 'react-i18next';
// model
import AuditLog from 'model/AuditLog';
import Country from 'model/geo/Country';
import FaoInstitute from 'model/genesys/FaoInstitute';
import Taxonomy2 from 'model/genesys/Taxonomy2';
// utility
import Validators from 'utilities/Validators';
// ui
import PrettyDate from 'ui/common/time/PrettyDate';
import McpdDate from 'ui/common/time/McpdDate';
import {CountryLink, InstituteLink} from 'ui/genesys/Links';
import SciName from 'ui/genesys/SciName';
import withStyles from '@material-ui/core/styles/withStyles';
const styles = (theme) => ({
root: {
display: 'flex' as 'flex',
......@@ -28,22 +37,68 @@ const styles = (theme) => ({
interface IAuditedInfo extends React.ClassAttributes<any> {
info: AuditLog[];
property?: string;
tPrefix?: string;
t?: any;
classes?: any;
}
const AuditedInfoDisplay = ({property, clazz, state, referencedEntity, tPrefix, classes, t}) => {
let value = referencedEntity ? (state && property ? state[property] : state) : state;
if (!value) {
return <span className={ classes.noValue }>{ t('common:label.noValue') }</span>;
}
if (clazz === FaoInstitute.clazz) {
return <InstituteLink to={ value }/>;
}
if (clazz === Country.clazz) {
return <CountryLink noflag country={ value }/>;
}
if (clazz === Taxonomy2.clazz) {
return property ? <i>{ value }</i> : <SciName taxa={ state.taxonNameHtml } />;
}
value = tPrefix ? (t(`${tPrefix}.${value}`) !== `${tPrefix}.${value}` ? t(`${tPrefix}.${value}`) : value) : value;
if (Validators.mcpdDate(value) !== 'Invalid date') {
return <McpdDate value={ value }/>;
}
return <span>{ value }</span>;
};
class AuditedInfo extends React.Component<IAuditedInfo> {
public render() {
const { info, t, classes } = this.props;
const { info, property, tPrefix, t, classes } = this.props;
return info ? (
<div>
{ info.map((auditLog) => (
{ [...info].map((auditLog) => (
<div className={ classes.root } key={ auditLog.id }>
<code>
<span>{ auditLog.previousState || <span className={ classes.noValue }>{ t('common:label.noValue') }</span> }</span>
<AuditedInfoDisplay
property={ property }
clazz={ auditLog.referencedEntity && auditLog.referencedEntity.classname }
state={ auditLog.referencedEntity ? auditLog.previousEntity : auditLog.previousState }
referencedEntity={ auditLog.referencedEntity }
tPrefix={ tPrefix }
classes={ classes }
t={ t }
/>
<span className={ classes.arrow }>&#10230;</span>
<span>{ auditLog.newState || <span className={ classes.noValue }>{ t('common:label.noValue') }</span> }</span>
<AuditedInfoDisplay
property={ property }
clazz={ auditLog.referencedEntity && auditLog.referencedEntity.classname }
state={ auditLog.referencedEntity ? auditLog.newEntity : auditLog.newState }
referencedEntity={ auditLog.referencedEntity }
tPrefix={ tPrefix }
classes={ classes }
t={ t }
/>
</code>
<PrettyDate value={ auditLog.logDate } t={ t }/>
</div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment