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'
vkovtun
committed
import InfoPanel from "@src/js/components/database/data-browser/InfoPanel.jsx";
const HTTP_SERVER_URI = "/data-store-server";
boundary: {
padding: theme.spacing(1),
borderColor: theme.palette.border.secondary,
backgroundColor: theme.palette.background.paper,
height: '100%'
},
icon: {
fontSize: '4rem',
},
'&>*': {
flex: '0 0 auto',
padding: theme.spacing(1),
borderWidth: '1px',
borderStyle: 'solid',
borderColor: theme.palette.border.secondary,
backgroundColor: theme.palette.background.paper
},
},
container: {
flexGrow: '1',
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)
this.datastoreServer = new DataStoreServer('http://localhost:8085', HTTP_SERVER_URI);
const owner = "demo-sample"
const source = ""
this.datastoreServer.login("admin", "changeit", this.login);
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
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')
multiselectedFiles: new Set([]),
showInfo: false
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
login(token) {
if (!token) {
alert("Could not perform login.");
return;
}
console.log("Token: " + token)
this.datastoreServer.list("demo-sample", "", "true", this.displayReturnedFiles)
}
displayReturnedFiles(data) {
if (data.error) {
console.error(data.error);
alert("Could not list files.");
return;
}
const results = data.result[1];
// Restrict the display to 50 samples
// results = results.splice(0, 50);
// generateTable(results);
console.log("Received data: " + results)
}
vkovtun
committed
handleViewTypeChange(viewType) {
this.setState({ viewType })
}
handleClick(file) {
// TODO: implement
}
this.setState({selectedFile: selectedRow && 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)
}
handleShowInfoChange() {
this.setState({showInfo: !this.state.showInfo})
}
render() {
const { classes } = this.props
const { viewType, files, selectedFile, multiselectedFiles, showInfo } = this.state
<Paper className={classes.boundary}>
<Toolbar
viewType={viewType}
onViewTypeChange={this.handleViewTypeChange}
onShowInfoChange={this.handleShowInfoChange}
showInfo={showInfo}
<div className={[classes.flexContainer, classes.boundary].join(' ')}>
{viewType === 'list' && (
<Grid
// id={id}
// settingsId={id}
filterModes={[GridFilterOptions.COLUMN_FILTERS]}
header='Files'
vkovtun
committed
classes={{ container: classes.container }}
columns={[
{
name: 'name',
label: 'Name',
sortable: true,
getValue: ({ row }) => row.name,
renderValue: ({ row }) => <><ItemIcon file={row} classes={{ icon: classes.icon }} configuration={configuration} /> {row.name}</>,
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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}
/>
)}
{showInfo && selectedFile && <InfoPanel file={selectedFile} configuration={configuration} />}
</Paper>