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

List extra Descriptor information on display page

parent 88ca7678
......@@ -3,7 +3,7 @@ import {SubmissionError} from 'redux-form';
import {dereferenceReferences} from 'utilities';
import {DescriptorService} from 'service/DescriptorService';
import {CREATE_DESCRIPTOR, RECEIVE_DESCRIPTOR, RECEIVE_DESCRIPTOR_PAGE, GET_DESCRIPTOR, LIST_DESCRIPTORS} from 'constants/descriptors';
import {CREATE_DESCRIPTOR, RECEIVE_DESCRIPTOR, RECEIVE_DESCRIPTOR_EXTRA, RECEIVE_DESCRIPTOR_PAGE, GET_DESCRIPTOR, LIST_DESCRIPTORS} from 'constants/descriptors';
import {Descriptor, IDescriptorFilter} from 'model/descriptor.model';
import {Partner} from 'model/partner.model';
import {Page} from 'model/common.model';
......@@ -14,6 +14,11 @@ const receiveDescriptor = (descriptor: Descriptor) => ({
payload: descriptor,
});
const receiveDescriptorExtra = (descriptor: Descriptor, extra: any) => ({
type: RECEIVE_DESCRIPTOR_EXTRA,
payload: { descriptor, extra },
});
const receiveDescriptorPage = (paged: Page<Descriptor>, page, results, sortBy, filter: IDescriptorFilter, order) => ({
type: RECEIVE_DESCRIPTOR_PAGE,
payload: { paged, query: { page, results, sortBy, filter, order } },
......@@ -48,7 +53,11 @@ export function loadDescriptor(uuid: string, success?: (d) => any, fail?: (error
if (success) {
return success(loaded);
}
dispatch(receiveDescriptor(loaded));
return DescriptorService.loadDescriptorExtra(token, uuid)
.then((extra) => {
dispatch(receiveDescriptorExtra(loaded, extra));
return { loaded, extra };
});
}).catch((error) => {
log(`No descriptor with uuid ${uuid}`, error);
if (fail) {
......
......@@ -3,6 +3,7 @@ export const CREATE_DESCRIPTOR = 'App/Descriptor/CREATE_DESCRIPTOR';
export const PUBLISH_DESCRIPTOR = 'App/PUBLISH_DESCRIPTOR';
export const RECEIVE_DESCRIPTOR_LIST_PAGE = 'App/RECEIVE_DESCRIPTOR_LIST_PAGE';
export const RECEIVE_DESCRIPTOR = 'App/RECEIVE_DESCRIPTOR';
export const RECEIVE_DESCRIPTOR_EXTRA = 'App/Descriptor/RECEIVE_DESCRIPTOR_EXTRA';
export const DESCRIPTOR_FORM = 'Form/DESCRIPTOR_FORM';
export const RECEIVE_DESCRIPTOR_PAGE = 'App/RECEIVE_DESCRIPTOR_PAGE';
export const GET_DESCRIPTOR = 'App/GET_DESCRIPTOR';
......
......@@ -6,16 +6,18 @@ import {IReducerAction, Page} from 'model/common.model';
import {Descriptor} from 'model/descriptor.model';
import {
CREATE_DESCRIPTOR, RECEIVE_DESCRIPTOR, RECEIVE_DESCRIPTOR_PAGE, GET_DESCRIPTOR, LIST_DESCRIPTORS,
CREATE_DESCRIPTOR, RECEIVE_DESCRIPTOR, RECEIVE_DESCRIPTOR_EXTRA, RECEIVE_DESCRIPTOR_PAGE, GET_DESCRIPTOR, LIST_DESCRIPTORS,
} from 'constants/descriptors';
const INITIAL_STATE: {
currentDescriptor: Descriptor;
currentDescriptorExtra: any;
paged: Page<Descriptor>;
pagedQuery: any;
loading: boolean;
} = {
currentDescriptor: null,
currentDescriptorExtra: null,
paged: null,
pagedQuery: null,
loading: null,
......@@ -40,6 +42,7 @@ function descriptors(state = INITIAL_STATE, action: IReducerAction) {
case CREATE_DESCRIPTOR: {
return update(state, {
currentDescriptor: {$set: new Descriptor()},
currentDescriptorExtra: {$set: null},
});
}
......@@ -47,6 +50,16 @@ function descriptors(state = INITIAL_STATE, action: IReducerAction) {
log(RECEIVE_DESCRIPTOR, action);
return update(state, {
currentDescriptor: {$set: action.payload},
currentDescriptorExtra: {$set: null},
loading: {$set: null},
});
}
case RECEIVE_DESCRIPTOR_EXTRA: {
log(RECEIVE_DESCRIPTOR, action);
return update(state, {
currentDescriptor: {$set: action.payload.descriptor},
currentDescriptorExtra: {$set: action.payload.extra},
loading: {$set: null},
});
}
......
......@@ -126,6 +126,16 @@ export class DescriptorService {
});
}
public static loadDescriptorExtra(token: string, uuid: string): Promise<Descriptor> {
log('Load descriptor extra by UUID ', uuid);
return authenticatedRequest(token, {
url: `${GET_DESCRIPTOR_URL}/extra/${uuid}`,
method: 'GET',
})
.then(({ data }) => data);
}
public static publishDescriptor(token: string, descriptor: Descriptor, published: boolean): Promise<Descriptor> {
log('Publish descriptor', descriptor);
......
......@@ -16,7 +16,7 @@ import Section from 'ui/common/layout/Section';
import Markdown from 'ui/catalog/markdown';
import ContentHeaderWithButton from 'ui/common/heading/ContentHeaderWithButton';
import PrettyDate from 'ui/common/time/PrettyDate';
import { PartnerLink, DescriptorLink, CropLink } from 'ui/catalog/Links';
import { PartnerLink, DescriptorLink, CropLink, DescriptorListLink, DatasetLink } from 'ui/catalog/Links';
import { Table, TableRow, TableCell } from 'ui/common/tables';
import { Properties, PropertiesItem } from 'ui/catalog/Properties';
import VocabularyCard from 'ui/pages/vocabulary/c/VocabularyCard';
......@@ -26,6 +26,7 @@ import BackButton from 'ui/common/buttons/BackButton';
import Grid from 'material-ui/Grid';
import Card, { CardHeader, CardContent, CardActions } from 'ui/common/Card';
import Button from 'material-ui/Button';
import List, { ListItem, ListItemText } from 'material-ui/List';
interface IDisplayPageProps extends React.ClassAttributes<any> {
......@@ -36,6 +37,7 @@ interface IDisplayPageProps extends React.ClassAttributes<any> {
publishDescriptor: (descriptor: Descriptor, published?: boolean) => void;
deleteDescriptor: (descriptor: Descriptor) => void;
descriptor: Descriptor;
descriptorExtra: any;
}
class DisplayPage extends React.Component<IDisplayPageProps, any> {
......@@ -96,7 +98,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
}
public render() {
const {uuid, descriptor} = this.props;
const {uuid, descriptor, descriptorExtra} = this.props;
const stillLoading: boolean = (! descriptor || (uuid && (descriptor.uuid !== uuid)));
......@@ -198,6 +200,38 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
</Grid>
) }
{ (descriptorExtra.datasets && descriptorExtra.datasets.length > 0) && (
<Grid item xs={ 12 }>
<Section title="Datasets">
<List>
{ descriptorExtra.datasets.map((dataset) => (
<ListItem button key={ dataset.uuid }>
<ListItemText primary={ <DatasetLink to={ dataset }><Markdown basic source={ dataset.title } /></DatasetLink> }
secondary={ `${dataset.versionTag}` }
/>
</ListItem>
)) }
</List>
</Section>
</Grid>
) }
{ (descriptorExtra.descriptorLists && descriptorExtra.descriptorLists.length > 0) && (
<Grid item xs={ 12 }>
<Section title="Crop descriptors">
<List>
{ descriptorExtra.descriptorLists.map((descriptorList) => (
<ListItem button key={ descriptorList.uuid }>
<ListItemText primary={ <DescriptorListLink to={ descriptorList }><Markdown basic source={ descriptorList.title } /></DescriptorListLink> }
secondary={ `${descriptorList.versionTag}` }
/>
</ListItem>
)) }
</List>
</Section>
</Grid>
) }
<Grid item xs={ 12 }>
<Section title="Record metadata" className="p-20">
<Properties>
......@@ -217,6 +251,7 @@ class DisplayPage extends React.Component<IDisplayPageProps, any> {
const mapStateToProps = (state, ownProps) => ({
uuid: ownProps.params.uuid,
descriptor: state.descriptors.currentDescriptor,
descriptorExtra: state.descriptors.currentDescriptorExtra,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
......
Supports Markdown
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