FileCard.tsx 3.67 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
import * as React from 'react';
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
2
import { translate } from 'react-i18next';
Matija Obreza's avatar
Matija Obreza committed
3
4
5
6
7
8
9

// Models
import RepositoryFile from 'model/repository/RepositoryFile';

// UI
import Card, {CardHeader, CardContent} from 'ui/common/Card';
import {Properties, PropertiesItem} from 'ui/common/Properties';
Maxym Borodenko's avatar
Maxym Borodenko committed
10
11
import ActionButton from 'ui/common/buttons/ActionButton';
import Permissions from 'ui/common/permission/Permissions';
Matija Obreza's avatar
Matija Obreza committed
12
import PrettyDate from 'ui/common/time/PrettyDate';
Maxym Borodenko's avatar
Maxym Borodenko committed
13
import DownloadIcon from '@material-ui/icons/GetApp';
Matija Obreza's avatar
Matija Obreza committed
14
import withStyles from '@material-ui/core/styles/withStyles';
Maxym Borodenko's avatar
Maxym Borodenko committed
15
import Grid from '@material-ui/core/Grid';
Matija Obreza's avatar
Matija Obreza committed
16

Maxym Borodenko's avatar
Maxym Borodenko committed
17
/*tslint:disable*/
Matija Obreza's avatar
Matija Obreza committed
18
19
20
21
22
23
24
const style = (theme) => ({
  root: {
    height: '100%',
    flexDirection: 'column' as 'column',
    justifyContent: 'space-between',
    display: 'flex',
  },
Maxym Borodenko's avatar
Maxym Borodenko committed
25
26
27
28
29
30
31
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
  header: {
    [theme.breakpoints.down('sm')]: {
      display: 'flex',
      flexDirection: 'column' as 'column',
      alignItems: 'flex-start' as 'flex-start',
    },
    '& > div': {
      alignSelf: 'initial',
      margin: '0',
      [theme.breakpoints.down('sm')]: {
        width: '100%',
      },
    },
  },
  actions: {
    [theme.breakpoints.down('sm')]: {
      width: '100%',
      paddingTop: '8px',
      display: 'flex' as 'flex',
      justifyContent: 'space-between',
    },
    '& > div': {
      [theme.breakpoints.down('sm')]: {
        display: 'flex',
        width: '100%',
      },
      '& > span': {
        margin: '0 8px',
        [theme.breakpoints.down('sm')]: {
          flex: '1 0 auto',
          '& > button': {
            width: '100%',
            margin: 0,
          },
        },
      },
    },
    '& > span': {
      margin: '0 8px',
      [theme.breakpoints.down('sm')]: {
        flex: '1 0 auto',
        '& > button': {
          width: '100%',
          margin: 0,
        },
      },
    },
  },
Matija Obreza's avatar
Matija Obreza committed
73
});
Maxym Borodenko's avatar
Maxym Borodenko committed
74
75
/*tslint:enable*/

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
76
77
const FileCard = ({file, classes, compact = false, edit = false, deleteFile, editFile, t, ...other}:
  { file: RepositoryFile, classes?: any, compact?: boolean, edit?: boolean, deleteFile: (uuid: string) => any, editFile: (uuid: string) => any, t: any }) => {
Matija Obreza's avatar
Matija Obreza committed
78
79
80
81
82
83
84
85

  if (!file) {
    return null;
  }

  return compact ? (
    <Grid item xs={ 12 }>
      <Card className={ classes.root }>
Matija Obreza's avatar
Matija Obreza committed
86
        <CardHeader title={ <a href={ `/proxy/uploads/${file.uuid}` }>{ file.originalFilename }</a> } />
Matija Obreza's avatar
Matija Obreza committed
87
88
89
90
91
92
93
94
95
96
        <CardContent>
          { file.storageFolder }
        </CardContent>
      </Card>
    </Grid>
  )
  :
  (
    <Grid item xs={ 12 }>
      <Card className={ classes.root }>
Maxym Borodenko's avatar
Maxym Borodenko committed
97
98
99
100
        <CardHeader className={ classes.header }
          title={ <span><a href={ `/proxy/uploads/${file.uuid}` }><DownloadIcon /></a> <span>{ file.originalFilename }</span></span> }
          action={
            <div className={ classes.actions }>
Matija Obreza's avatar
Matija Obreza committed
101
102
              <span><ActionButton action={ () => editFile(file.uuid) } title={ t('common:action.edit') } /></span>
              <span><ActionButton action={ () => deleteFile(file.uuid) } title={ t('common:action.delete') } /></span>
Maxym Borodenko's avatar
Maxym Borodenko committed
103
104
105
106
              { file && file._permissions.manage && <Permissions clazz={ RepositoryFile.clazz } id={ file.id } /> }
            </div>
          }
        />
Matija Obreza's avatar
Matija Obreza committed
107
108
        <CardContent>
          <Properties>
Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
109
110
111
            <PropertiesItem title="repository.admin.c.fileCard.originalName">{ file.originalFilename }</PropertiesItem>
            <PropertiesItem title="repository.admin.c.common.registered"><PrettyDate value={ new Date(file.createdDate) }/></PropertiesItem>
            <PropertiesItem title="common:label.lastModified"><PrettyDate value={ new Date(file.lastModifiedDate) }/></PropertiesItem>
Matija Obreza's avatar
Matija Obreza committed
112
113
114
115
116
117
118
          </Properties>
        </CardContent>
      </Card>
    </Grid>
  );
};

Viacheslav Pavlov's avatar
i18n    
Viacheslav Pavlov committed
119
export default translate()(withStyles(style)(FileCard));