DatasetDisplay.tsx 20.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
import * as React from 'react';
import { translate } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';

import { log } from 'utilities/debug';
import { fixDate } from 'utilities';

import Dataset from 'model/catalog/Dataset';
import Descriptor from 'model/catalog/Descriptor';
import RepositoryFile from 'model/repository/RepositoryFile';
import DatasetCreator from 'model/catalog/DatasetCreator';
import { AVAILABLE_LICENSES } from 'model/License';
import { PublishState } from 'model/common.model';
14
15
import Page from 'model/Page';
import { AccessionRef } from 'model/accession/AccessionRef';
Oleksii Savran's avatar
Oleksii Savran committed
16
import MapLayer from 'model/genesys/MapTileLayer';
17
18
19
20

import confirm from 'utilities/confirmAlert';
import Authorize from 'ui/common/authorized/Authorize';
import Section from 'ui/common/layout/Section';
Matija Obreza's avatar
Matija Obreza committed
21
import Markdown from 'ui/common/markdown';
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import PrettyDate from 'ui/common/time/PrettyDate';
import { DescriptorLink, ExternalLink, PartnerLink } from 'ui/catalog/Links';

import LocationMap from './LocationMap';
import Button from '@material-ui/core/Button';
import { Properties, PropertiesItem } from 'ui/common/Properties';
import Grid from '@material-ui/core/Grid';
import Divider from '@material-ui/core/Divider';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';

import Permissions from 'ui/common/permission/Permissions';
import CropChips from 'crop/ui/c/CropChips';

import Card, { CardHeader, CardContent, CardActions } from 'ui/common/Card';
import McpdDate from 'ui/common/time/McpdDate';
39
import PagedLoader from 'ui/common/PagedLoader';
Matija Obreza's avatar
Matija Obreza committed
40
import AccessionRefCard from 'accessions/ui/c/AccessionRefCard';
Matija Obreza's avatar
Matija Obreza committed
41
import Number from 'ui/common/Number';
42
import DownloadDialog from 'ui/common/download-dialog';
43
import {DatasetLink} from 'ui/genesys/Links';
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

const styles = (theme) => ({
  root: {
    flexGrow: 1,
  },
  gray: {
    backgroundColor: '#f3f2ee',
  },
  title: {
    fontSize: '30px',
    fontWeight: 'bold',
    [theme.breakpoints.down('sm')]: {
      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('sm')]: {
      marginLeft: '0',
      marginRight: '0',
    },
  },
  grayTitleSmall: {
    fontSize: '14px',
    lineHeight: '22px',
    padding: '10px 14px',
    margin: '0 1px',
    minHeight: '100%',
    [theme.breakpoints.down('sm')]: {
      marginLeft: '0',
      marginRight: '0',
    },
  },
  rightTextWrapper: {
    display: 'flex',
    justifyContent: 'space-between',
    margin: '0 1px',
    padding: '10px 20px',
    [theme.breakpoints.down('sm')]: {
      marginLeft: '0',
      marginRight: '0',
      padding: '10px 14px',
    },
  },
  buttonGreen: theme.buttons.green,
  dataContainer: {
    flexWrap: 'nowrap',
    marginBottom: '2px',
    wordWrap: 'break-word',
    [theme.breakpoints.down('sm')]: {
      flexWrap: 'wrap',
    },
  },
  dataName: {
    [theme.breakpoints.down('md')]: {
      display: 'none',
    },
  },
  margin1: {
    margin: '0 1px',
    [theme.breakpoints.down('sm')]: {
      margin: '0',
    },
  },
  grayTitleA: {
    display: 'block',
    padding: '10px 14px',
  },
  centerAlign: {
    [theme.breakpoints.down('md')]: {
      justifyContent: 'center',
    },
  },
  pdTop0: {
    [theme.breakpoints.down('sm')]: {
      paddingTop: '0',
      marginLeft: '0',
      marginRight: '0',
    },
  },
133
134
135
  hasNewVersion: {
    backgroundColor: '#ffe2e2 !important',
  },
136
137
138
});

interface IDetailInfoProps extends React.ClassAttributes<any> {
139
140
  t: any;
  classes: any;
141
142
143
144
145
  dataset: Dataset;
  publishDataset?: (dataset: Dataset, needToRedirect?: boolean) => void;
  approveDataset?: (dataset: Dataset) => void;
  rejectDataset?: (dataset: Dataset, needToRedirect?: boolean) => void;
  deleteDataset?: (dataset: Dataset) => any;
146
  loadAccessions: (page: Page<AccessionRef>) => any;
147
  rematchDatasetAccessions: (dataset: Dataset) => void;
148
  accessionRefs: Page<AccessionRef>;
Oleksii Savran's avatar
Oleksii Savran committed
149
  mapLayers: MapLayer[];
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
}

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

    if (!publishDataset) {
      return;
    }

    confirm(<span>{ t('common:action.publish') } <b>{ dataset.title }</b>?</span>, {
      description: t(`datasets.public.c.datasetDisplay.confirmDescription.onPublish`),
      confirmLabel: t('common:action.publish'),
      abortLabel: t('common:action.cancel'),
    }).then(() => {
      log('Publishing dataset', dataset);
      publishDataset(dataset);
    }).catch(() => {
      // don't
    });
  }

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

    if (!rejectDataset) {
      return;
    }

    confirm(<span>{ t('common:action.unpublish') } <b>{ dataset.title }</b>?</span>, {
      // description: `Deleting the descriptor is only possible when there is no associated data.`,
      confirmLabel: t('common:action.unpublish'),
      abortLabel: t('common:action.cancel'),
    }).then(() => {
      log('Unpublishing dataset', dataset);
      rejectDataset(dataset, false);
    }).catch(() => {
      // don't
    });
  }

  private onApprove = (e) => {
    const { dataset, approveDataset, t } = this.props;

    if (!approveDataset) {
      return;
    }

    confirm(<span>{ t('common:action.approve') } <b>{ dataset.title }</b>?</span>, {
      description: t(`datasets.public.c.datasetDisplay.confirmDescription.approve`),
      confirmLabel: t('common:action.approve'),
      abortLabel: t('common:action.cancel'),
    }).then(() => {
      log('Approving dataset', dataset);
      approveDataset(dataset);
    }).catch(() => {
      // don't
    });
  }

  private onReject = (e) => {
    const { dataset, rejectDataset } = this.props;

    if (!rejectDataset) {
      return;
    }

    log('Rejecting dataset', dataset);
    rejectDataset(dataset, true);
  }

221
222
223
224
225
226
227
228
  private onRematch = (e) => {
    e.preventDefault();

    const {rematchDatasetAccessions, dataset} = this.props;
    log('Rematching Accessions for dataset', dataset);
    rematchDatasetAccessions(dataset);
  }

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  private onDelete = (e) => {
    const { dataset, deleteDataset, t } = this.props;

    if (!deleteDataset) {
      return;
    }

    confirm(<span>{ t('common:action.delete') } <b>{ dataset.title }</b>?</span>, {
      description: t(`datasets.common.delete`),
      confirmLabel: t('common:action.delete'),
      abortLabel: t('common:action.cancel'),
    }).then(() => {
      deleteDataset(dataset);
    }).catch(() => {
      // don't
    });
  }

  public render() {
Oleksii Savran's avatar
Oleksii Savran committed
248
    const { classes, dataset, publishDataset, deleteDataset, t, accessionRefs, mapLayers } = this.props;
249
250
251
252
253
254

    if (!dataset) {
      log('Waiting for dataset.');
      return null;
    }

255
    const renderAccession = (accessionRef: AccessionRef, index: number) => (
Matija Obreza's avatar
Matija Obreza committed
256
257
      <Grid key={ `aref-${index}` } item xs={ 12 } className="pt-5 pb-5 pr-10 pl-10">
        <AccessionRefCard index={ index } accessionRef={ accessionRef }/>
258
259
260
      </Grid>
    );

Matija Obreza's avatar
Matija Obreza committed
261
    console.log(`AccessionRefs`, accessionRefs);
262
263
264
265
266
267
268
269
270
    const license = dataset.rights && AVAILABLE_LICENSES.find((e) => e.code === dataset.rights);
    const oneDay = 24 * 60 * 60 * 1000;
    const oneDayPassed = dataset && (fixDate(dataset.lastModifiedDate).getTime() <= (new Date()).getTime() - oneDay);

    return (
      <div className={ classes.root }>
        <Grid container spacing={ 0 }>
          <Grid item xs={ 12 } className="p-10" id="dataset-top">
            <Card className={ classes.card } square>
271
              <CardHeader className={ dataset.currentVersion && classes.hasNewVersion }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
272
                          title={ t('datasets.public.p.display.title') }
273
274
275
276
277
278
279
280
281
                          subheader={ <small>{ dataset.versionTag }</small> }/>
              <CardContent className={ classes.cardContent }>
                { dataset.description && <Markdown className="mb-20" source={ dataset.description }/> }

                <Properties>
                  <PropertiesItem title={ t('partners.common.modelName') }>
                    <PartnerLink to={ dataset.owner }/>
                  </PropertiesItem>
                  { dataset.crops && dataset.crops.length > 0 &&
282
                  <PropertiesItem title={ `${t('crop.common.modelName')} ${t('common:label.name').toLowerCase()}` }>
283
284
285
286
                    <CropChips crops={ dataset.crops }/>
                  </PropertiesItem>
                  }
                  <PropertiesItem title={ t('datasets.public.common.accessionsNumber') }>
Matija Obreza's avatar
Matija Obreza committed
287
                    <Number value={ dataset.accessionCount } />
288
289
                  </PropertiesItem>
                  <PropertiesItem title={ t('datasets.public.common.traitsNumber') }>
Matija Obreza's avatar
Matija Obreza committed
290
                    <Number value={ dataset.descriptorCount } />
291
292
293
294
295
296
297
                  </PropertiesItem>
                  <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.evaluationStart') }>
                    <McpdDate value={ dataset.startDate }/>
                  </PropertiesItem>
                  <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.evaluationEnd') }>
                    <McpdDate value={ dataset.endDate }/>
                  </PropertiesItem>
298
299
300
301
302
303
304
                  { dataset.currentVersion &&
                  <PropertiesItem classes={ {propertiesRow: classes.hasNewVersion} } title={ t('datasets.public.c.card.version') }>
                    <span>
                      <DatasetLink uuid={ dataset.currentVersion }>{ t('datasets.public.c.card.newVersionLink') }</DatasetLink>
                    </span>
                  </PropertiesItem>
                  }
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
                </Properties>
              </CardContent>
              { publishDataset && (dataset._permissions.write || dataset._permissions.delete) && (
                <CardActions>
                  { dataset.state === PublishState.PUBLISHED ?
                    (dataset._permissions.manage && !oneDayPassed) ?
                      <Button onClick={ this.onUnpublish } type="button">
                        { t('common:action.un-publish') }
                      </Button>
                      :
                      <Authorize role="ROLE_ADMINISTRATOR">
                        <Button onClick={ this.onUnpublish } type="button">
                          { t('common:action.un-publish') }
                        </Button>
                      </Authorize>
                    : null
                  }
                  { dataset.state === PublishState.DRAFT && dataset._permissions.write &&
Maxym Borodenko's avatar
Maxym Borodenko committed
323
                    <Button onClick={ this.onPublish } type="button">{ t('common:action.publish') }</Button>
324
325
                  }
                  { dataset.state !== PublishState.PUBLISHED && dataset._permissions.write &&
Maxym Borodenko's avatar
Maxym Borodenko committed
326
                    <Button onClick={ this.onReject } type="button">{ t('common:action.edit') }</Button>
327
328
                  }
                  { dataset.state === PublishState.REVIEWING &&
Maxym Borodenko's avatar
Maxym Borodenko committed
329
330
331
                    <Authorize role="ROLE_ADMINISTRATOR">
                      <Button onClick={ this.onApprove } type="button">{ t('common:action.approve') }</Button>
                    </Authorize>
332
333
                  }
                  { dataset.state !== PublishState.PUBLISHED && deleteDataset && dataset._permissions.delete &&
Maxym Borodenko's avatar
Maxym Borodenko committed
334
                    <Button onClick={ this.onDelete } type="button">{ t('common:action.delete') }</Button>
335
336
                  }
                  { dataset._permissions.manage && <Permissions clazz={ Dataset.clazz } id={ dataset.id }/> }
337
338
339
340
341
                  <Authorize role="ROLE_ADMINISTRATOR">
                    <Button onClick={ this.onRematch } type="button">
                      { t('datasets.public.c.datasetDisplay.rematch') }
                    </Button>
                  </Authorize>
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
                </CardActions>
              ) }
            </Card>
          </Grid>
        </Grid>

        <Grid container spacing={ 0 }>
          <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-metadata">
            <Section title={ t('datasets.public.c.datasetDisplay.datasetMetadata') }>
              { dataset.creators && dataset.creators.length > 0 &&
              <div>
                <div className="pt-15 pb-15 pl-20 pr-20">
                  <h4 className="font-bold m-0">{ t('datasets.public.c.datasetDisplay.creators') }</h4>
                </div>
                <Divider/>
                <Grid container spacing={ 0 } className="p-20">
                  <Grid item xs={ 12 }>
                    <Properties>
                      { dataset.creators && dataset.creators.map((e: DatasetCreator, i) => (
                        <PropertiesItem title={ t(`datasets.common.creator.role.${e.role}`) } key={ e.id }>
Maxym Borodenko's avatar
Maxym Borodenko committed
362
363
364
365
                          <span>
                            <b>{ e.fullName }</b>
                            { e.institutionalAffiliation && <span> { e.institutionalAffiliation }</span> }
                          </span>
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
                          { /* { e.email && <div><a href={ `mailto:${e.email}` }>{ e.email }</a></div> } */ }
                        </PropertiesItem>
                      )) }
                    </Properties>
                  </Grid>
                </Grid>
                <Divider/>
              </div>
              }

              <div className="pt-15 pb-15 pl-20 pr-20">
                <h4 className="font-bold m-0">{ t('datasets.public.c.datasetDisplay.useAndLicensing') }</h4>
              </div>
              <Divider/>
              { license &&
              <Grid container spacing={ 0 } className="p-20">
                <Properties>
                  <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.licensed') }><b>{ license.code }</b> { license.title }</PropertiesItem>
                  { license.url &&
                  <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.moreInformation') }>
                    <ExternalLink link={ license.url }>{ license.url }</ExternalLink>
                  </PropertiesItem>
                  }
                </Properties>
              </Grid>
              }

              <Divider/>
              <div className="pt-15 pb-15 pl-20 pr-20">
                <h4 className="font-bold m-0">
                  { t('datasets.public.c.datasetDisplay.dataAndResources') }
                </h4>
              </div>
              <Divider/>
              <Grid container spacing={ 0 } className="p-20">
                <Grid item xs={ 12 }>
                  <Properties>
                    {
                      dataset.repositoryFiles && dataset.repositoryFiles.map((e: RepositoryFile) => (
                        <PropertiesItem key={ e.uuid } title={
406
                          <a href={ `/proxy/api/v1/repository/download/${e.uuid}` }>
407
                            <Button variant="contained" component="span" className={ `${classes.buttonGreen} ${classes.button}` }>
408
409
410
411
                              { t('common:action.download') }
                            </Button>
                          </a>
                        }>
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
412
                          <p>{ e.title || t('datasets.public.c.datasetDisplay.datasetFile') }</p>
413
414
415
416
                          <p>{ e.originalFilename }</p>
                        </PropertiesItem>
                      ))
                    }
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

                    <Authorize role="ROLE_USER">
                      <PropertiesItem key={ dataset.uuid } title={
                        <DownloadDialog downloadUrl={ `/proxy/api/v1/dataset/${dataset.uuid}/download` }
                          slug="download-authenticated"
                          postParams={ { mcpd: 'mcpd' } }
                          buttonTitle={ `${t('common:action.download')}` }
                          variant="contained"
                          btnClasses={ `${classes.buttonGreen} ${classes.button}` }
                        />
                      }>
                        <p>{ t(`datasets.public.c.datasetDisplay.datasetMcpdPasportData`) }</p>
                        <p>{ `MCPD - ${dataset.uuid}.xlsx` }</p>
                      </PropertiesItem>
                    </Authorize>

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
                  </Properties>
                </Grid>
              </Grid>
              <Divider/>
              <div className="pt-15 pb-15 pl-20 pr-20">
                <h4 className="font-bold m-0">
                  { t('datasets.public.c.datasetDisplay.contact') }
                </h4>
              </div>
              <Divider/>
              <Grid container spacing={ 0 } className="p-20">
                <Grid item xs={ 12 }>
                  <Grid container spacing={ 0 }>
                    <Properties>
                      { dataset.owner.email &&
                      <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.email') }>
                        <div><a href={ `mailto:${dataset.owner.email}` }>{ dataset.owner.email }</a></div>
                      </PropertiesItem> }
                      { dataset.owner.phone && <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.phone') }>{ dataset.owner.phone }</PropertiesItem> }
                      { dataset.owner.address && <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.address') }>{ dataset.owner.address }</PropertiesItem> }
                    </Properties>
                  </Grid>
                </Grid>
              </Grid>
              <Divider/>
              <div className="pt-15 pb-15 pl-20 pr-20">
                <h4 className="font-bold m-0">
                  { t('datasets.public.c.datasetDisplay.otherMetadata') }
                </h4>
              </div>
              <Divider/>
              <Grid container spacing={ 0 } className="p-20">
                <Grid item xs={ 12 }>
                  <Grid container spacing={ 0 }>
                    <Properties>
                      <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.datasetDate') }><McpdDate value={ dataset.created }/></PropertiesItem>
                      <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.relatedResources') }>
                        <Markdown source={ dataset.source }/>
                      </PropertiesItem>
                      <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.metadataCreateDate') }>
                        { dataset.createdDate && <PrettyDate value={ dataset.createdDate }/> }
                      </PropertiesItem>
                      <PropertiesItem title={ t('datasets.public.c.datasetDisplay.properties.metadataUpdatedDate') }>
                        { dataset.lastModifiedDate && <PrettyDate value={ dataset.lastModifiedDate }/> }
                      </PropertiesItem>
                    </Properties>
                  </Grid>
                </Grid>
              </Grid>
            </Section>
          </Grid>
        </Grid>

        <Grid container spacing={ 0 }>
          { dataset.locations && dataset.locations.length > 0 && (
            <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-locations">
              <Section title={ t('datasets.public.c.datasetDisplay.locations') }>
                <div className="p-20">
Oleksii Savran's avatar
Oleksii Savran committed
491
                  <LocationMap locations={ dataset.locations } mapLayers={ mapLayers } classes={ {} } />
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
                </div>
              </Section>
            </Grid>
          ) }

          { dataset.descriptors && dataset.descriptors.length > 0 && (
            <Grid item xs={ 12 } md={ 12 } lg={ 12 } className="p-10" id="dataset-traits">
              <Section title={ t('datasets.public.c.datasetDisplay.traitsObserved') }>
                <List>
                  { dataset.descriptors.map((descriptor: Descriptor) => (
                    <ListItem key={ descriptor.uuid } className="">
                      <ListItemText primary={ <DescriptorLink to={ descriptor }><Markdown source={ descriptor.title }/></DescriptorLink> }
                                    secondary={ descriptor.description && <Markdown source={ descriptor.description }/> }/>
                    </ListItem>
                  )) }
                </List>
              </Section>
            </Grid>
          ) }

512
513
514
515
516
517
518
          { accessionRefs && accessionRefs.content && accessionRefs.content.length > 0 && (
            <PagedLoader
              paged={ accessionRefs }
              loadMore={ this.props.loadAccessions }
              roughItemHeight={ 80 }
              itemRenderer={ renderAccession }
            />
519
520
521
522
523
524
525
526
527
          ) }
        </Grid>
      </div>
    );
  }

}

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