DatasetDisplay.tsx 16.4 KB
Newer Older
1
2
3
4

import * as React from 'react';
import { withStyles } from 'material-ui/styles';

Valeriy Panov's avatar
Valeriy Panov committed
5
6
import {log} from 'utilities/debug';

7
8
9
10
import { Dataset } from 'model/dataset.model';
import { Descriptor } from 'model/descriptor.model';
import { RepositoryFile } from 'model/repositoryFile.model';
import { Creator } from 'model/creator.model';
Valeriy Panov's avatar
Valeriy Panov committed
11
import { AVAILABLE_LICENSES } from 'model/license.model';
12
13
14
15

import confirm from 'utilities/confirmAlert';
import Authorize from 'ui/common/authorized/Authorize';
import Section from 'ui/common/layout/Section';
16
import Markdown from 'ui/catalog/markdown';
17
import PrettyDate from 'ui/common/time/PrettyDate';
Matija Obreza's avatar
Matija Obreza committed
18
import { DatasetLink, DescriptorLink, ExternalLink, PartnerLink } from 'ui/catalog/Links';
19
20
21

import LocationMap from './LocationMap';
import Button from 'material-ui/Button';
Maxim Babichev's avatar
Maxim Babichev committed
22
import { Properties, PropertiesItem } from 'ui/catalog/Properties';
23
24
import Grid from 'material-ui/Grid';
import Divider from 'material-ui/Divider';
Matija Obreza's avatar
Matija Obreza committed
25
import List, { ListItem, ListItemText } from 'material-ui/List';
26

27
import AccessionIdentifiersTable from 'ui/catalog/accession/IdentifiersTable';
28
import Permissions from 'ui/common/permission/Permissions';
Valeriy Panov's avatar
Valeriy Panov committed
29
import CropChips from 'ui/catalog/crop/CropChips';
30

31
import Card, {CardHeader, CardContent, CardActions } from 'ui/common/Card';
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

const styles = (theme) => ({
    root: {
        flexGrow: 1,
    },
    gray: {
        backgroundColor: '#f3f2ee',
    },
    title: {
        fontSize: '30px',
        fontWeight: 'bold',
        [theme.breakpoints.down('md')]: {
            fontSize: '24px',
        },
    },
    grayRowsEven: theme.table.grayRowsEven,
    grayRowsOdd: theme.table.grayRowsOdd,
    green: {
        color: '#88ba42',
    },
    grayTitleBig: {
        fontSize: '14px',
        fontWeight: 'bold',
        lineHeight: '22px',
        padding: '15px 14px',
        margin: '0 1px',
        [theme.breakpoints.down('md')]: {
            marginLeft: '0',
            marginRight: '0',
        },
    },
    grayTitleSmall: {
        fontSize: '14px',
        lineHeight: '22px',
        padding: '10px 14px',
        margin: '0 1px',
        minHeight: '100%',
        [theme.breakpoints.down('md')]: {
            marginLeft: '0',
            marginRight: '0',
        },
    },
    rightTextWrapper: {
        display: 'flex',
        justifyContent: 'space-between',
        margin: '0 1px',
        padding: '10px 20px',
        [theme.breakpoints.down('md')]: {
            marginLeft: '0',
            marginRight: '0',
            padding: '10px 14px',
        },
    },
    buttonGreen: theme.buttons.green,
    dataContainer: {
        flexWrap: 'nowrap',
        marginBottom: '2px',
        wordWrap: 'break-word',
        [theme.breakpoints.down('md')]: {
            flexWrap: 'wrap',
        },
    },
    dataName: {
        [theme.breakpoints.down('lg')]: {
            display: 'none',
        },
    },
    margin1: {
        margin: '0 1px',
        [theme.breakpoints.down('md')]: {
            margin: '0',
        },
    },
    grayTitleA: {
        display: 'block',
        padding: '10px 14px',
    },
    centerAlign : {
         [theme.breakpoints.down('lg')]: {
            justifyContent: 'center',
         },
     },
    pdTop0: {
        [theme.breakpoints.down('md')]: {
            paddingTop: '0',
            marginLeft: '0',
            marginRight: '0',
        },
    },
});

interface IDetailInfoProps extends React.ClassAttributes<any> {
    classes: any;
    dataset: Dataset;
    publishDataset?: (dataset: Dataset, publish?: boolean) => any;
    deleteDataset?: (dataset: Dataset) => any;
}

class DetailInfo extends React.Component<IDetailInfoProps, any> {
    private onPublish = (e) => {
      const {dataset, publishDataset} = this.props;

      if (! publishDataset) {
        return;
      }

      confirm(<span>Publish <b>{ dataset.title }</b>?</span>, {
        description: `After publishing the dataset no changes are permitted, a new version must be created.`,
        confirmLabel: 'Publish',
        abortLabel: 'Cancel',
      }).then(() => {
Valeriy Panov's avatar
Valeriy Panov committed
143
        log('Publishing dataset', dataset);
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
        publishDataset(dataset);
      }).catch(() => {
          // don't
      });
    }

    private onUnpublish = (e) => {
      const {dataset, publishDataset} = this.props;

      if (! publishDataset) {
        return;
      }

      confirm(<span>Unpublish <b>{ dataset.title }</b>?</span>, {
          // description: `Deleting the descriptor is only possible when there is no associated data.`,
          confirmLabel: 'Unpublish',
          abortLabel: 'Cancel',
      }).then(() => {
Valeriy Panov's avatar
Valeriy Panov committed
162
        log('Publishing dataset', dataset);
163
164
165
166
167
168
169
170
171
172
173
174
175
176
        publishDataset(dataset, false);
      }).catch(() => {
          // don't
      });
    }

    private onDelete = (e) => {
      const {dataset, deleteDataset} = this.props;

      if (! deleteDataset) {
        return;
      }

      confirm(<span>Delete <b>{ dataset.title }</b>?</span>, {
Maxym Borodenko's avatar
Maxym Borodenko committed
177
          description: `Deleting the dataset will remove all related data.`,
178
179
180
181
182
183
184
185
186
187
188
189
190
          confirmLabel: 'Delete',
          abortLabel: 'Cancel',
      }).then(() => {
          deleteDataset(dataset);
      }).catch(() => {
          // don't
      });
    }

    public render() {
        const { classes, dataset, publishDataset, deleteDataset } = this.props;

        if (! dataset) {
Valeriy Panov's avatar
Valeriy Panov committed
191
          log('Waiting for dataset.');
192
193
194
          return null;
        }

Valeriy Panov's avatar
Valeriy Panov committed
195
196
        const license = dataset.rights && AVAILABLE_LICENSES.find((e) => e.code === dataset.rights);

197
198
199
        return (
            <div className={ classes.root }>
              <Grid container spacing={ 0 }>
Maxym Borodenko's avatar
Maxym Borodenko committed
200
                <Grid item xs={ 12 } className="p-10" id="dataset-top">
201
                    <Card className={ classes.card } square>
Maxym Borodenko's avatar
Maxym Borodenko committed
202
203
204
205
                        <CardHeader className={ classes.cardHeader }
                                    title={ <Markdown basic source={ dataset.title } /> }
                                    subheader={ <small>{ dataset.versionTag }</small> } />
                        <CardContent className={ classes.cardContent }>
Matija Obreza's avatar
Matija Obreza committed
206
                          { dataset.description && <Markdown className="mb-20" source={ dataset.description } /> }
207
208

                          <Properties>
Matija Obreza's avatar
Matija Obreza committed
209
210
211
212
213
214
215
                            <PropertiesItem title="Data provider:"><PartnerLink to={ dataset.owner } /></PropertiesItem>
                            { dataset.crops && dataset.crops.length > 0 &&
                              <PropertiesItem title="Crop:"><CropChips crops={ dataset.crops } /></PropertiesItem>
                            }
                            <PropertiesItem title="Number of accessions:">{ dataset.accessionCount }</PropertiesItem>
                            <PropertiesItem title="Number of traits:">{ dataset.descriptorCount }</PropertiesItem>
                            <PropertiesItem title="Upload date:"><PrettyDate value={ dataset.createdDate } /></PropertiesItem>
216
                          </Properties>
217
218
219
220
221
222
223
224
225
226
227
228
                      </CardContent>
                      { publishDataset && (dataset._permissions.write || dataset._permissions.delete) && (
                        <CardActions>
                          { dataset.published ?
                            <Authorize role="ROLE_ADMINISTRATOR">
                              <Button onClick={ this.onUnpublish } type="button">Un-publish</Button>
                            </Authorize>
                            :
                            <Button onClick={ this.onPublish } type="button">Publish</Button>
                          }
                          { ! dataset.published && dataset._permissions.write && <DatasetLink edit to={ dataset }><Button>Edit</Button></DatasetLink> }
                          { ! dataset.published && deleteDataset && dataset._permissions.delete && <Button onClick={ this.onDelete } type="button">Delete</Button> }
229
                          { dataset._permissions.manage && <Permissions clazz={ dataset.clazz } id={ dataset.id } /> }
230
231
232
233
234
235
236
                        </CardActions>
                      ) }
                  </Card>
                </Grid>
              </Grid>

              <Grid container spacing={ 0 }>
Matija Obreza's avatar
Matija Obreza committed
237
                <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-metadata">
238
                  <Section title="Dataset metadata">
Matija Obreza's avatar
Matija Obreza committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
                    { dataset.creators && dataset.creators.length > 0 &&
                      <div>
                        <div className="pt-15 pb-15 pl-20 pr-20">
                            <h4 className="font-bold m-0">Creators</h4>
                        </div>
                        <Divider/>
                        <Grid container spacing={ 0 } className="p-20">
                            <Grid item xs={ 12 }>
                              <Properties>
                                { dataset.creators && dataset.creators.map((e: Creator, i) => (
                                  <PropertiesItem title={ e.role } key={ e.id }>
                                      <p><b>{ e.fullName }</b></p>
                                      { e.institutionalAffiliation && <p>{ e.institutionalAffiliation }</p> }
                                      { e.email && <div><a href={ `mailto:${e.email}` }>{ e.email }</a></div> }
                                  </PropertiesItem>
                                )) }
                              </Properties>
                            </Grid>
                        </Grid>
                        <Divider/>
259
                      </div>
Matija Obreza's avatar
Matija Obreza committed
260
261
                    }

Matija Obreza's avatar
Matija Obreza committed
262
263
264
265
266
267
268
269
270
271
                      <div className="pt-15 pb-15 pl-20 pr-20">
                          <h4 className="font-bold m-0">Dataset use and licensing</h4>
                      </div>
                      <Divider/>
                      { license &&
                        <Grid container spacing={ 0 } className="p-20">
                            <Properties>
                                <PropertiesItem title="Licensed under:"><b>{ license.code }</b> { license.title }</PropertiesItem>
                                { license.url &&
                                  <PropertiesItem title="More information:">
Matija Obreza's avatar
Matija Obreza committed
272
                                    <ExternalLink link={ license.url }>{ license.url }</ExternalLink>
Matija Obreza's avatar
Matija Obreza committed
273
274
275
276
277
                                  </PropertiesItem>
                                }
                            </Properties>
                        </Grid>
                      }
Matija Obreza's avatar
Matija Obreza committed
278

Matija Obreza's avatar
Matija Obreza committed
279
                      <Divider/>
Maxim Babichev's avatar
Maxim Babichev committed
280
281
                      <div className="pt-15 pb-15 pl-20 pr-20">
                          <h4 className="font-bold m-0">
Matija Obreza's avatar
Matija Obreza committed
282
                              Data and resources
Maxim Babichev's avatar
Maxim Babichev committed
283
                          </h4>
284
285
286
287
                      </div>
                      <Divider/>
                      <Grid container spacing={ 0 } className="p-20">
                          <Grid item xs={ 12 }>
Matija Obreza's avatar
Matija Obreza committed
288
                            <Properties>
289
                              {
Matija Obreza's avatar
Matija Obreza committed
290
291
292
293
294
295
296
297
298
299
300
                                  dataset.repositoryFiles && dataset.repositoryFiles.map((e: RepositoryFile) => (
                                      <PropertiesItem key={ e.uuid } title={
                                        <a href={ `/proxy/api/v0/repository/download/${e.uuid}` }>
                                          <Button raised component="span" className={ `${classes.buttonGreen} ${classes.button}` }>
                                            Download
                                          </Button>
                                        </a>
                                       }>
                                          <p>{ e.title || 'Dataset file' }</p>
                                          <p>{ e.originalFilename }</p>
                                      </PropertiesItem>
301
302
                                  ))
                              }
Matija Obreza's avatar
Matija Obreza committed
303
                            </Properties>
304
305
306
                          </Grid>
                      </Grid>
                      <Divider/>
Maxym Borodenko's avatar
Maxym Borodenko committed
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
                      <div className="pt-15 pb-15 pl-20 pr-20">
                          <h4 className="font-bold m-0">
                              Partner contact information
                          </h4>
                      </div>
                      <Divider/>
                      <Grid container spacing={ 0 } className="p-20">
                          <Grid item xs={ 12 }>
                              <Grid container spacing={ 0 }>
                                  <Properties>
                                      { dataset.owner.email &&
                                          <PropertiesItem title="Email:">
                                              <div><a href={ `mailto:${dataset.owner.email}` }>{ dataset.owner.email }</a></div>
                                          </PropertiesItem> }
                                      { dataset.owner.phone && <PropertiesItem title="Phone number:">{ dataset.owner.phone }</PropertiesItem> }
                                      { dataset.owner.address && <PropertiesItem title="Address:">{ dataset.owner.address }</PropertiesItem> }
                                  </Properties>
                              </Grid>
                          </Grid>
                      </Grid>
                      <Divider/>
Maxim Babichev's avatar
Maxim Babichev committed
328
329
                      <div className="pt-15 pb-15 pl-20 pr-20">
                          <h4 className="font-bold m-0">
330
                              Other Metadata
Maxim Babichev's avatar
Maxim Babichev committed
331
                          </h4>
332
333
334
335
                      </div>
                      <Divider/>
                      <Grid container spacing={ 0 } className="p-20">
                          <Grid item xs={ 12 }>
Maxim Babichev's avatar
Maxim Babichev committed
336
337
                              <Grid container spacing={ 0 }>
                                  <Properties>
Matija Obreza's avatar
Matija Obreza committed
338
                                      <PropertiesItem title="Date of dataset:">{ dataset.created }</PropertiesItem>
Maxim Babichev's avatar
Maxim Babichev committed
339
                                      <PropertiesItem title="Related resources:">{ dataset.source }</PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
340
341
342
343
344
345
                                      <PropertiesItem title="Metadata create date:">
                                          { dataset.createdDate && <PrettyDate value={ dataset.createdDate } /> }
                                      </PropertiesItem>
                                      <PropertiesItem title="Metadata updated date:">
                                          { dataset.lastModifiedDate && <PrettyDate value={ dataset.lastModifiedDate } /> }
                                      </PropertiesItem>
Maxim Babichev's avatar
Maxim Babichev committed
346
                                  </Properties>
347
348
349
350
351
352
353
354
                              </Grid>
                          </Grid>
                      </Grid>
                  </Section>
                </Grid>
              </Grid>

              <Grid container spacing={ 0 }>
355
                  { dataset.locations && dataset.locations.length > 0 && (
Maxym Borodenko's avatar
Maxym Borodenko committed
356
                      <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-locations">
Valeriy Panov's avatar
Valeriy Panov committed
357
358
359
360
361
362
363
364
                          <Section title="Locations">
                              <div className="p-20">
                                  <LocationMap locations={ dataset.locations } classes={ {} }/>
                              </div>
                          </Section>
                      </Grid>
                  ) }

Matija Obreza's avatar
Matija Obreza committed
365
                  { dataset.descriptors && dataset.descriptors.length > 0 && (
Maxym Borodenko's avatar
Maxym Borodenko committed
366
                    <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-traits">
367
                      <Section title="Traits observed">
Matija Obreza's avatar
Matija Obreza committed
368
                        <List>
369
                        { dataset.descriptors.map((descriptor: Descriptor) => (
Matija Obreza's avatar
Matija Obreza committed
370
371
372
373
                          <ListItem key={ descriptor.uuid } className="">
                            <ListItemText primary={ <DescriptorLink to={ descriptor } /> }
                              secondary={ descriptor.description && <Markdown source={ descriptor.description } /> } />
                          </ListItem>
374
                        )) }
Matija Obreza's avatar
Matija Obreza committed
375
                        </List>
376
377
378
379
                      </Section>
                    </Grid>
                  ) }

Matija Obreza's avatar
Matija Obreza committed
380
                  { dataset.accessionIdentifiers && dataset.accessionIdentifiers.length > 0 && (
Maxym Borodenko's avatar
Maxym Borodenko committed
381
                    <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-accessions">
382
383
                      <Section title="Accessions evaluated">
                          <div className="p-20">
384
                              <AccessionIdentifiersTable accessionIdentifiers={ dataset.accessionIdentifiers } />
385
386
387
388
389
390
391
392
393
394
395
396
                          </div>
                      </Section>
                    </Grid>
                  ) }
              </Grid>
            </div>
        );
    }

}

export default ((withStyles as any)(styles)(DetailInfo));