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 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'
import DataBrowserController from '@src/js/components/database/data-browser/DataBrowserController.js'
import NavigationBar from '@src/js/components/database/data-browser/NavigationBar.jsx'
import messages from '@src/js/common/messages.js'
const HTTP_SERVER_URI = '/data-store-server'
columnFlexContainer: {
flexDirection: 'column',
display: 'flex',
height: 'calc(100vh - ' + theme.spacing(12) + 'px)'
boundary: {
padding: theme.spacing(1),
borderColor: theme.palette.border.secondary,
backgroundColor: theme.palette.background.paper
fontSize: '2rem',
paddingRight: '0.5rem'
'&>*': {
flex: '0 0 auto',
padding: theme.spacing(1),
borderWidth: '1px',
borderStyle: 'solid',
borderColor: theme.palette.border.secondary,
backgroundColor: theme.palette.background.paper
},
},
overflowY: 'auto',
paddingTop: 0,
paddingBottom: 0
},
content: {
flex: '1 1 100%',
},
nameCell: {
display: 'flex',
alignItems: 'center',
'&>span': {
flex: 1,
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis'
}
},
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)
const { sessionToken, controller } = this.props
this.controller = controller || new DataBrowserController()
this.datastoreServer = new DataStoreServer(
'http://localhost:8085',
HTTP_SERVER_URI
)
this.controller.setSessionToken(sessionToken)
this.state = {
viewType: props.viewType,
multiselectedFiles: new Set([]),
showInfo: false,
path: '/'
vkovtun
committed
handleViewTypeChange(viewType) {
this.setState({ viewType })
}
handleClick(file) {
// TODO: implement
}
const { directory, path } = row.data
if (directory) {
}
}
this.setState({ selectedFile: selectedRow && selectedRow.data })
handleMultiselect(selectedRow) {
this.setState({
multiselectedFiles: new Set(Object.values(selectedRow)
.map(value => value.data))
})
async onError(error) {
await AppController.getInstance().errorChange(error)
}
this.setState({ showInfo: !this.state.showInfo })
handleGridControllerRef(gridController) {
this.controller.gridController = gridController
}
async handlePathChange(path) {
await this.setPath(path)
}
if (this.state.path !== path + '/') {
this.setState({ path: path + '/' })
this.controller.setPath(path + '/')
await this.controller.gridController.load()
}
timeToString(time) {
return new Date(time).toLocaleString()
}
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
sizeToString(bytes) {
if (!bytes) {
return null
}
if (typeof bytes == "string") {
bytes = parseInt(bytes)
}
let size
let unit
const kbytes = bytes / 1024.0
const mbytes = kbytes / 1024.0
const gbytes = mbytes / 1024.0
if (gbytes > 1.0) {
size = gbytes
unit = "Gb"
} else if (mbytes > 1.0) {
size = mbytes
unit = "Mb"
} else if (kbytes > 1.0) {
size = kbytes
unit = "kb"
} else {
size = bytes
unit = "bytes"
}
return size.toFixed(1) + " " + unit;
}
const { classes, sessionToken } = this.props
const {
viewType,
files,
selectedFile,
multiselectedFiles,
showInfo,
path
} = this.state
<div className={[classes.boundary, classes.columnFlexContainer].join(' ')}>
viewType={viewType}
onViewTypeChange={this.handleViewTypeChange}
onShowInfoChange={this.handleShowInfoChange}
showInfo={showInfo}
selectedFile={selectedFile}
datastoreServer={this.datastoreServer}
sessionToken={sessionToken}
path={path}
<NavigationBar
path={path}
onPathChange={this.handlePathChange}
/>
<div className={[classes.flexContainer, classes.boundary, classes.content].join(' ')}>
controllerRef={this.handleGridControllerRef}
filterModes={[GridFilterOptions.COLUMN_FILTERS]}
header='Files'
classes={{ container: classes.grid }}
label: messages.get(messages.NAME),
<div className={classes.nameCell}>
<ItemIcon
file={row}
classes={{ icon: classes.icon }}
configuration={configuration}
/>
<span>{row.name}</span>
</div>
name: 'type',
label: messages.get(messages.TYPE),
sortable: true,
getValue: ({ row }) => row.directory ? 'Directory' : 'File'
},
label: messages.get(messages.SIZE),
getValue: ({ row }) => this.sizeToString(row.size)
{
name: 'created',
label: messages.get(messages.CREATED),
sortable: true,
getValue: ({ row }) => row.creationTime,
renderValue: ({ row }) => this.timeToString(row.creationTime)
},
label: messages.get(messages.MODIFIED),
sortable: true,
getValue: ({ row }) => row.lastModifiedTime,
renderValue: ({ row }) => this.timeToString(row.lastModifiedTime)
},
{
name: 'accessed',
label: messages.get(messages.ACCESSED),
sortable: true,
getValue: ({ row }) => row.lastAccessTime,
renderValue: ({ row }) => this.timeToString(row.lastAccessTime)
exportable={false}
selectable={true}
multiselectable={true}
loadSettings={null}
showHeaders={true}
onSettingsChange={null}
onError={this.onError}
onSelectedRowChange={this.handleSelect}
onMultiselectedRowsChange={this.handleMultiselect}
onRowDoubleClick={this.handleRowDoubleClick}
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 selectedFile={selectedFile} configuration={configuration} />