Commit 57367762 authored by Matija Obreza's avatar Matija Obreza
Browse files

PGRFA Networks: Code refactored and updated

- Models renamed
- Delete PGRFA network
- Added missing translations changes
parent b3439a26
......@@ -54,6 +54,7 @@
},
"holder": {
"code": "Holder",
"networks": "Network",
"owner": {
"uuid": "Data provider"
},
......@@ -1751,6 +1752,32 @@
"menu": "My List"
}
},
"networks": {
"public": {
"c": {
"card": {
"title": "Title",
"slug": "Short name",
"createdDate": "Date of creation"
}
},
"p": {
"display": {
"actions": "Browse or download data",
"title": "Network details",
"browseAccessions": "Browse accessions",
"overview": "Accession overview",
"deleteNetwork": "Delete network {{slug}}?"
},
"networkBrowse": {
"title": "Browse networks"
}
}
},
"common": {
"locations": "Members locations"
}
},
"partners": {
"admin": {
"c": {
......
......@@ -20,7 +20,7 @@ const ArticleFilters = ({ handleSubmit, initialValues, initialize, t, ...other }
<StringFilter name="title" label={ t('cms.admin.f.title') } searchType="contains"/>
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title={ t('cms.admin.f.meta') }>
<StringArrFilter name="slug" label="cms.admin.f.slug" placeholder="blurp"/>
<StringArrFilter name="slug" label="cms.admin.f.slug" placeholder="blurb"/>
<StringArrFilter name="lang" label="cms.admin.f.lang" placeholder="en"/>
</CollapsibleComponentSearch>
</FiltersBlock>
......
/*
* Defined in Swagger as '#/definitions/OrganizationBlurbJson'
*/
class OrganizationBlurbJson {
public blurp: string;
public locale: string;
public summary: string;
}
export default OrganizationBlurbJson;
import { Permissions, IUserPermissions } from 'model/acl/ACL';
/*
* Defined in Swagger as '#/definitions/Organization'
* Defined in Swagger as '#/definitions/PGRFANetwork'
*/
class Organization {
class PGRFANetwork implements IUserPermissions {
public static clazz: string = 'org.genesys2.server.model.impl.PGRFANetwork';
public _permissions: Permissions;
public active: boolean;
public createdBy: number;
public createdDate: Date;
......@@ -13,7 +17,6 @@ class Organization {
public title: string;
public version: number;
}
export default Organization;
export default PGRFANetwork;
import Article from 'model/cms/Article';
import Organization from 'model/network/Organization';
import PGRFANetwork from 'model/network/PGRFANetwork';
import Page from 'model/Page';
import FaoInstitute from 'model/genesys/FaoInstitute';
/*
* Defined in Swagger as '#/definitions/OrganizationDetails'
* Defined in Swagger as '#/definitions/PGRFANetworkDetails'
*/
class OrganizationDetails {
class PGRFANetworkDetails {
public blurb: Article;
public institutes: Page<FaoInstitute>;
public organization: Organization;
public network: PGRFANetwork;
}
export default OrganizationDetails;
export default PGRFANetworkDetails;
// actions
// constants
// service
import NetworkService from 'service/genesys/NetworkService';
import PGRFANetwork from 'model/network/PGRFANetwork';
export const deleteNetwork = (network: PGRFANetwork) => (dispatch, getState) => {
return NetworkService.deleteNetwork(network.slug, network.version);
};
......@@ -3,14 +3,14 @@ import update from 'immutability-helper';
import { IReducerAction } from 'model/common.model';
import Page from 'model/Page';
import ApiCall from 'model/ApiCall';
import Organization from 'model/network/Organization';
import OrganizationDetails from 'model/network/OrganizationDetails';
import PGRFANetwork from 'model/network/PGRFANetwork';
import PGRFANetworkDetails from 'model/network/PGRFANetworkDetails';
// constants
import {APPEND_NETWORK_PAGE, RECEIVE_NETWORK_DETAILS, RECEIVE_NETWORK_INSTITUTES} from 'networks/constants';
const INITIAL_STATE: {
networks: ApiCall<Organization[]>,
network: ApiCall<OrganizationDetails>,
networks: ApiCall<PGRFANetwork[]>,
network: ApiCall<PGRFANetworkDetails>,
} = {
networks: null,
network: null,
......
......@@ -8,8 +8,12 @@
}
},
"p": {
"display":{
"title": "Network details"
"display": {
"actions": "Browse or download data",
"title": "Network details",
"browseAccessions": "Browse accessions",
"overview": "Accession overview",
"deleteNetwork": "Delete network {{slug}}?"
},
"networkBrowse": {
"title": "Browse networks"
......
......@@ -6,7 +6,7 @@ import { translate } from 'react-i18next';
import {listNetworks} from 'networks/actions/public';
// model
import ApiCall from 'model/ApiCall';
import Organization from 'model/network/Organization';
import PGRFANetwork from 'model/network/PGRFANetwork';
// ui
import PageLayout, {PageContents} from 'ui/layout/PageLayout';
import ContentHeader from 'ui/common/heading/ContentHeader';
......@@ -16,7 +16,7 @@ import NetworkCard from 'networks/ui/c/NetworkCard';
interface IBrowsePageProps extends React.ClassAttributes<any> {
apiCall: ApiCall<Organization[]>;
apiCall: ApiCall<PGRFANetwork[]>;
listNetworks: () => void;
t: any;
}
......@@ -46,7 +46,7 @@ class BrowsePage extends React.Component<IBrowsePageProps> {
{ loading ? <Loading /> :
<div className="full-width container-spacing-horizontal">
{
networks && networks.sort((a, b) => a.title.localeCompare(b.title)).map((network: Organization) => (
networks && networks.sort((a, b) => a.title.localeCompare(b.title)).map((network: PGRFANetwork) => (
<NetworkCard compact key={ network.slug } network={ network }/>
))
}
......
......@@ -5,16 +5,19 @@ import {translate} from 'react-i18next';
// actions
import {loadMoreNetworkInstitutes, loadNetwork} from 'networks/actions/public';
import { deleteNetwork } from 'networks/actions/admin';
import { applyFilters, applyOverviewFilters } from 'accessions/actions/public';
import { navigateTo } from 'actions/navigation';
// model
import ApiCall from 'model/ApiCall';
import MapLayer from 'model/genesys/MapTileLayer';
import Page from 'model/Page';
import FaoInstitute from 'model/genesys/FaoInstitute';
import OrganizationDetails from 'model/network/OrganizationDetails';
import PGRFANetwork from 'model/network/PGRFANetwork';
import PGRFANetworkDetails from 'model/network/PGRFANetworkDetails';
// ui
import NetworkCard from 'networks/ui/c/NetworkCard';
import InstituteCard from 'institutes/ui/с/InstituteCard';
import PageLayout, {PageContents, PageSection} from 'ui/layout/PageLayout';
import PageLayout, {PageContents, PageSection, MainSection} from 'ui/layout/PageLayout';
import Loading from 'ui/common/Loading';
import {ScrollToTopOnMount} from 'ui/common/page/scrollers';
import ContentHeader from 'ui/common/heading/ContentHeader';
......@@ -22,13 +25,25 @@ import PageTitle from 'ui/common/PageTitle';
import LocationMap from 'ui/common/LocationMap';
import PagedLoader from 'ui/common/PagedLoader';
import {InstituteLink} from 'ui/genesys/Links';
import { PropertiesItem, Properties } from 'ui/common/Properties';
import BlurbText from 'cms/ui/c/BlurbText';
import PrettyDate from 'ui/common/time/PrettyDate';
import { CardActions } from 'ui/common/Card';
import ButtonBar from 'ui/common/buttons/ButtonBar';
import { Button } from '@material-ui/core';
import confirmAlert from 'utilities/confirmAlert';
import Authorize from 'ui/common/authorized/Authorize';
interface IDisplayPageProps extends React.ClassAttributes<any> {
apiCall: ApiCall<OrganizationDetails>;
networkCall: ApiCall<PGRFANetworkDetails>;
mapLayers: MapLayer[];
shortName: string;
loadNetwork: (shortName: string, lang: string) => void;
loadMoreNetworkInstitutes: (shortName: string, page: number) => void;
applyFilters: any;
applyOverviewFilters: any;
deleteNetwork: (network: PGRFANetwork) => any;
navigateTo: any;
t: any;
i18n: any;
}
......@@ -40,17 +55,17 @@ class DisplayPage extends React.Component<IDisplayPageProps> {
];
public componentWillMount(): void {
const {apiCall, shortName, loadNetwork, i18n} = this.props;
if (!apiCall) {
const {networkCall, shortName, loadNetwork, i18n} = this.props;
if (!networkCall) {
return loadNetwork(shortName, i18n.language);
}
const {loading, data: network} = apiCall;
const {loading, data: network} = networkCall;
if (!loading && (!network || !network.organization)) {
if (!loading && (!network || !network.network)) {
return loadNetwork(shortName, i18n.language);
}
if (network.organization.slug !== shortName) {
if (network.network.slug !== shortName) {
return loadNetwork(shortName, i18n.language);
}
......@@ -65,10 +80,34 @@ class DisplayPage extends React.Component<IDisplayPageProps> {
return <InstituteCard key={ s.code } index={ index } institute={ s }/>;
}
private applyNetworkFilter = () => {
const { networkCall: { data: networkDetails }, applyFilters} = this.props;
const filter = {holder: {networks: [ networkDetails.network.slug ]}};
applyFilters(filter);
}
private applyNetworkOverviewFilter = () => {
const { networkCall: { data: networkDetails }, applyOverviewFilters} = this.props;
const filter = {holder: {networks: [ networkDetails.network.slug ]}};
applyOverviewFilters(filter);
}
private onDelete = () => {
const { networkCall: { data: networkDetails }, deleteNetwork, navigateTo, t } = this.props;
confirmAlert(t('networks.public.p.display.deleteNetwork', { slug: networkDetails.network.slug }))
.then(() => {
deleteNetwork(networkDetails.network).then(() => {
navigateTo('/network');
});
}).catch((error) => {
console.log(`Couldn't delete network`, error);
});
}
public render(): React.ReactNode {
const {apiCall, mapLayers, t} = this.props;
const {data: networkDetails, loading, error} = apiCall || {data: undefined, loading: true, error: undefined};
const {organization: network, blurb, institutes } = networkDetails || {organization: undefined, blurb: undefined, institutes: undefined};
const {networkCall, mapLayers, t} = this.props;
const {data: networkDetails, loading, error} = networkCall || {data: undefined, loading: true, error: undefined};
const {network, blurb, institutes } = networkDetails || {network: undefined, blurb: undefined, institutes: undefined};
return (
<PageLayout withFooter>
......@@ -80,12 +119,32 @@ class DisplayPage extends React.Component<IDisplayPageProps> {
{ error && <div>{ JSON.stringify(error) }</div> }
{ network &&
<PageContents className="pt-1rem">
<NetworkCard key={ network.slug } network={ network } blurbBody={ blurb.body }/>
<MainSection title={ t('networks.public.p.display.title') }>
{ blurb &&
<div className="mb-20">
<BlurbText body={ blurb.body } />
</div>
}
<Properties>
<PropertiesItem title={ t('networks.public.c.card.title') }>{ network.title }</PropertiesItem>
<PropertiesItem title={ t('networks.public.c.card.slug') }>{ network.slug }</PropertiesItem>
<PropertiesItem title={ t('networks.public.c.card.createdDate') }><PrettyDate value={ network.createdDate }/></PropertiesItem>
</Properties>
<CardActions className="container-spacing-vertical mt-15">
<ButtonBar barLabelText={ t('networks.public.p.display.actions') }>
<Button onClick={ this.applyNetworkFilter }>{ t('networks.public.p.display.browseAccessions') }</Button>
<Button onClick={ this.applyNetworkOverviewFilter }>{ t('networks.public.p.display.overview') }</Button>
<Authorize role="ROLE_ADMINISTRATOR">
<Button onClick={ this.onDelete }>{ t('common:action.delete') }</Button>
</Authorize>
</ButtonBar>
</CardActions>
</MainSection>
{ institutes && institutes.content && institutes.content.length > 0 &&
<PageSection title={ t('networks.common.locations') }>
<LocationMap
locations={ institutes.content.map(
(institute) => ({id: institute.id, lat: institute.latitude, lng: institute.longitude, popup: <InstituteLink to={ institute }>{ institute.fullName }</InstituteLink>}))
(institute) => ({id: institute.id, lat: institute.latitude, lng: institute.longitude, popup: <InstituteLink key={ institute.code } to={ institute }>{ institute.fullName }</InstituteLink>}))
}
mapLayers={ mapLayers }
/>
......@@ -103,7 +162,7 @@ class DisplayPage extends React.Component<IDisplayPageProps> {
}
const mapStateToProps = (state, ownProps) => ({
apiCall: state.networks.public.network,
networkCall: state.networks.public.network,
memberCodes: state.networks.public.memberCodes,
blurb: state.networks.public.blurb,
members: state.networks.public.members,
......@@ -114,6 +173,10 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadNetwork,
loadMoreNetworkInstitutes,
deleteNetwork,
applyOverviewFilters,
applyFilters,
navigateTo,
}, dispatch);
export default translate()((connect(mapStateToProps, mapDispatchToProps)(DisplayPage)));
import * as React from 'react';
import {translate} from 'react-i18next';
import {withStyles} from '@material-ui/core/styles';
import { translate } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';
// model
import Organization from 'model/network/Organization';
import PGRFANetwork from 'model/network/PGRFANetwork';
// ui
import PrettyDate from 'ui/common/time/PrettyDate';
import {Properties, PropertiesItem} from 'ui/common/Properties';
import Card, {CardHeader} from 'ui/common/Card';
import {NetworkLink} from 'ui/catalog/Links';
import {MainSection} from 'ui/layout/PageLayout';
import BlurbText from 'cms/ui/c/BlurbText';
import Card, { CardHeader } from 'ui/common/Card';
import { NetworkLink } from 'ui/catalog/Links';
// import { Properties, PropertiesItem } from 'ui/catalog/Properties';
interface INetworkCardProps extends React.ClassAttributes<any> {
network: Organization;
blurbBody: string;
compact: boolean;
network: PGRFANetwork;
classes: any;
t: any;
}
......@@ -64,13 +59,13 @@ const styles = (theme) => ({
class NetworkCard extends React.Component<INetworkCardProps, any> {
public render() {
const {network, blurbBody, compact = false, classes, t} = this.props;
const {network, classes, t} = this.props;
if (!network) {
return null;
}
return compact ? (
return (
<Card square>
<CardHeader
classes={ {
......@@ -81,19 +76,6 @@ class NetworkCard extends React.Component<INetworkCardProps, any> {
subheader={ network.createdDate && <span>{ t('common:label.registered') } <PrettyDate value={ network.createdDate }/></span> }
/>
</Card>
) : (
<MainSection title={ t('networks.public.p.display.title') }>
{ blurbBody &&
<div className="mb-20">
<BlurbText body={ blurbBody } />
</div>
}
<Properties>
<PropertiesItem title={ t('networks.public.c.card.title') }>{ network.title }</PropertiesItem>
<PropertiesItem title={ t('networks.public.c.card.slug') }>{ network.slug }</PropertiesItem>
<PropertiesItem title={ t('networks.public.c.card.createdDate') }><PrettyDate value={ network.createdDate }/></PropertiesItem>
</Properties>
</MainSection>
);
}
......
......@@ -5,9 +5,8 @@ import { axiosBackend } from 'utilities/requestUtils';
import Article from 'model/cms/Article';
import FaoInstitute from 'model/genesys/FaoInstitute';
import Organization from 'model/network/Organization';
import OrganizationBlurbJson from 'model/network/OrganizationBlurbJson';
import OrganizationDetails from 'model/network/OrganizationDetails';
import PGRFANetwork from 'model/network/PGRFANetwork';
import PGRFANetworkDetails from 'model/network/PGRFANetworkDetails';
import Page from 'model/Page';
const URL_LIST_NETWORKS = `/api/v1/network`;
......@@ -33,7 +32,7 @@ class NetworkService {
* @param page page
* @param xhrConfig additional xhr config
*/
public static listNetworks(page?: number, xhrConfig?: any): Promise<Organization[]> {
public static listNetworks(page?: number, xhrConfig?: any): Promise<PGRFANetwork[]> {
const qs = QueryString.stringify({
page: page || undefined,
......@@ -47,7 +46,7 @@ class NetworkService {
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as Organization[]);
}).then(({ data }) => data as PGRFANetwork[]);
}
/**
......@@ -56,7 +55,7 @@ class NetworkService {
* @param organizationJson organizationJson
* @param xhrConfig additional xhr config
*/
public static updateNetwork(organizationJson: Organization, xhrConfig?: any): Promise<Organization> {
public static updateNetwork(organizationJson: PGRFANetwork, xhrConfig?: any): Promise<PGRFANetwork> {
const apiUrl = URL_UPDATE_NETWORK;
// console.log(`Fetching from ${apiUrl}`);
......@@ -67,7 +66,7 @@ class NetworkService {
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as Organization);
}).then(({ data }) => data as PGRFANetwork);
}
/**
......@@ -76,7 +75,7 @@ class NetworkService {
* @param shortName shortName
* @param xhrConfig additional xhr config
*/
public static getNetwork(shortName: string, xhrConfig?: any): Promise<Organization> {
public static getNetwork(shortName: string, xhrConfig?: any): Promise<PGRFANetwork> {
const apiUrl = URL_GET_NETWORK.expand({ shortName });
// console.log(`Fetching from ${apiUrl}`);
......@@ -87,7 +86,7 @@ class NetworkService {
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as Organization);
}).then(({ data }) => data as PGRFANetwork);
}
/**
......@@ -96,7 +95,7 @@ class NetworkService {
* @param shortName shortName
* @param xhrConfig additional xhr config
*/
public static deleteNetwork(shortName: string, xhrConfig?: any): Promise<Organization> {
public static deleteNetwork(shortName: string, xhrConfig?: any): Promise<PGRFANetwork> {
const apiUrl = URL_DELETE_NETWORK.expand({ shortName });
// console.log(`Fetching from ${apiUrl}`);
......@@ -107,7 +106,7 @@ class NetworkService {
url: apiUrl,
method: 'DELETE',
...content,
}).then(({ data }) => data as Organization);
}).then(({ data }) => data as PGRFANetwork);
}
/**
......@@ -117,7 +116,7 @@ class NetworkService {
* @param blurb blurb
* @param xhrConfig additional xhr config
*/
public static updateBlurb(shortName: string, blurb: OrganizationBlurbJson, xhrConfig?: any): Promise<Article> {
public static updateBlurb(shortName: string, blurb: Article, xhrConfig?: any): Promise<Article> {
const apiUrl = URL_UPDATE_BLURB.expand({ shortName });
// console.log(`Fetching from ${apiUrl}`);
......@@ -159,7 +158,7 @@ class NetworkService {
* @param language language
* @param xhrConfig additional xhr config
*/
public static getNetworkDetails(shortName: string, language?: string, xhrConfig?: any): Promise<OrganizationDetails> {
public static getNetworkDetails(shortName: string, language?: string, xhrConfig?: any): Promise<PGRFANetworkDetails> {
const qs = QueryString.stringify({
language: language || undefined,
......@@ -173,7 +172,7 @@ class NetworkService {
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as OrganizationDetails);
}).then(({ data }) => data as PGRFANetworkDetails);
}
/**
......@@ -227,7 +226,7 @@ class NetworkService {
* @param instituteList instituteList
* @param xhrConfig additional xhr config
*/
public static addNetworkInstitutes(slug: string, instituteList: string[], xhrConfig?: any): Promise<Organization> {
public static addNetworkInstitutes(slug: string, instituteList: string[], xhrConfig?: any): Promise<PGRFANetwork> {
const apiUrl = URL_ADD_NETWORK_INSTITUTES.expand({ slug });
// console.log(`Fetching from ${apiUrl}`);
......@@ -238,7 +237,7 @@ class NetworkService {
url: apiUrl,
method: 'PUT',
...content,
}).then(({ data }) => data as Organization);
}).then(({ data }) => data as PGRFANetwork);
}
/**
......@@ -248,7 +247,7 @@ class NetworkService {
* @param instituteList instituteList
* @param xhrConfig additional xhr config
*/
public static setNetworkInstitutes(slug: string, instituteList: string[], xhrConfig?: any): Promise<Organization> {
public static setNetworkInstitutes(slug: string, instituteList: string[], xhrConfig?: any): Promise<PGRFANetwork> {
const apiUrl = URL_SET_NETWORK_INSTITUTES.expand({ slug });
// console.log(`Fetching from ${apiUrl}`);
......@@ -259,7 +258,7 @@ class NetworkService {
url: apiUrl,
method: 'PUT',
...content,
}).then(({ data }) => data as Organization);
}).then(({ data }) => data as PGRFANetwork);
}
......
......@@ -54,6 +54,7 @@
},
"holder": {
"code": "Holder",
"networks": "Network",
"owner": {
"uuid": "Data provider"
},
......
......@@ -6,7 +6,7 @@ import Descriptor from 'model/catalog/Descriptor';
import DescriptorList from 'model/catalog/DescriptorList';
import Partner from 'model/genesys/Partner';
import Organization from 'model/network/Organization';
import PGRFANetwork from 'model/network/PGRFANetwork';
import Vocabulary from 'model/vocabulary/Vocabulary';
......@@ -138,7 +138,7 @@ const PartnerLink = ({ to: partner, edit = false, children }: { to: Partner, edi
}
};
const NetworkLink = ({to: network, children}: { to: Organization, children?: any } & any) => {
const NetworkLink = ({to: network, children}: { to: PGRFANetwork, children?: any } & any) => {
return (
<Link to={ `/network/${network.slug}` }>{ children || network.title }</Link>
);
......
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