Newer
Older
import React from 'react'
import { withStyles } from '@material-ui/core/styles'
vkovtun
committed
import autoBind from 'auto-bind'
import Toolbar from '@src/js/components/database/data-browser/Toolbar.jsx'
import GridView from '@src/js/components/database/data-browser/GridView.jsx'
import DescriptionIcon from '@material-ui/icons/DescriptionOutlined'
import AudioIcon from '@material-ui/icons/MusicNoteOutlined'
import VideoIcon from '@material-ui/icons/LocalMovies'
import ImageIcon from '@material-ui/icons/Image'
import Paper from '@material-ui/core/Paper'
import Grid from '@src/js/components/common/grid/Grid.jsx'
import GridFilterOptions from '@src/js/components/common/grid/GridFilterOptions.js'
import AppController from '@src/js/components/AppController.js'
import ItemIcon from '@src/js/components/database/data-browser/ItemIcon.jsx'
import { InfoPanel } from "@src/js/components/database/data-browser/InfoPanel.jsx";
boundary: {
padding: theme.spacing(1),
borderWidth: '2px',
borderStyle: 'solid',
borderColor: theme.palette.border.secondary,
backgroundColor: theme.palette.background.paper
},
icon: {
fontSize: '4rem',
},
flex: {
display: 'flex',
flexWrap: 'wrap',
}
const configuration =
[
{
icon: AudioIcon,
extensions: ['wav', 'mp3', 'acc', 'ogg']
},
{
icon: DescriptionIcon,
extensions: ['txt', 'rtf', 'doc', 'pdf']
},
{
icon: VideoIcon,
extensions: ['mp4', 'mkv', 'avi']
},
{
icon: ImageIcon,
extensions: ['tif', 'gif', 'jpg', 'jpeg', 'png']
}
]
class DataBrowser extends React.Component {
constructor(props, context) {
super(props, context)
vkovtun
committed
autoBind(this)
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
viewType: props.viewType,
files: [
{
name: 'Processed',
folder: true,
size: 0,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2022-02-24 04:35:21.486930'),
lastAccessTime: new Date('2023-05-25 14:55:31.902857')
},
{
name: 'Text.txt',
folder: false,
size: 21432,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2022-02-24 04:35:21.486930'),
lastAccessTime: new Date('2023-05-25 14:55:31.902857')
},
{
name: 'Movie.mp4',
folder: false,
size: 2143243443537,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2022-02-24 04:35:21.486930'),
lastAccessTime: new Date('2023-05-25 14:55:31.902857')
},
{
name: 'Music.mp3',
folder: false,
size: 21432443,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2022-02-24 04:35:21.486930'),
lastAccessTime: new Date('2023-05-25 14:55:31.902857')
},
{
name: 'Image.png',
folder: false,
size: 214323234,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2022-02-24 04:35:21.486930'),
lastAccessTime: new Date('2023-05-25 14:55:31.902857')
},
{
name: 'lock',
folder: false,
size: 0,
creationTime: new Date('2020-08-13 14:45:54.034563'),
lastModifiedTime: new Date('2023-05-30 15:33:14.048038'),
lastAccessTime: new Date('2023-05-30 15:33:14.048038')
],
selectedFile: null,
multiselectedFiles: new Set([])
vkovtun
committed
handleViewTypeChange(viewType) {
this.setState({ viewType })
}
handleClick(file) {
// TODO: implement
}
handleSelect(selectedRow) {
this.setState({selectedFile: selectedRow.data});
}
handleMultiselect(file) {
// TODO: implement
}
async load(params) {
return await this.state.files.map((file) => ({id: file.name, ...file}));
}
async onError(error) {
await AppController.getInstance().errorChange(error)
}
const { viewType, files, selectedFile, multiselectedFiles } = this.state
const { classes } = this.props
return (
<Paper className={classes.boundary}>
<Toolbar
viewType={viewType}
onViewTypeChange={this.handleViewTypeChange}
/>
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
<div className={classes.flex}>
{viewType === 'list' && (
<Grid
// id={id}
// settingsId={id}
filterModes={[GridFilterOptions.COLUMN_FILTERS]}
header='Files'
columns={[
{
name: 'name',
label: 'Name',
sortable: true,
getValue: ({ row }) => row,
renderValue: ({ value }) => <><ItemIcon file={value} classes={classes} configuration={configuration} /> {value.name}</>,
renderFilter: null
},
{
name: 'size',
label: 'Size',
sortable: true,
getValue: ({ row }) => row.size
},
{
name: 'modified',
label: 'Modified',
sortable: false,
getValue: ({ row }) => row.lastModifiedTime.toLocaleString()
},
]}
loadRows={this.load}
sort='registrationDate'
sortDirection='desc'
exportable={false}
selectable={true}
multiselectable={true}
loadSettings={null}
onSettingsChange={null}
onError={this.onError}
onSelectedRowChange={this.handleSelect}
exportXLS={null}
/>
)}
{viewType === 'grid' && (
<GridView
clickable={true}
selectable={true}
multiselectable={true}
onClick={this.handleClick}
onSelect={this.handleSelect}
onMultiselect={this.handleMultiselect}
configuration={configuration}
files={files}
selectedFile = {selectedFile}
multiselectedFiles = {multiselectedFiles}
/>
)}
<InfoPanel file={selectedFile} />
</div>
</Paper>