Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions client/src/actions/sftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,25 @@ export const sftp_chmod = (fm, cwd, name, mode, recursive) => {
fm.showAlert('Error: ' + error.message);
}
});
}
};

export const sftp_quota = (fm, cwd, ms) => {
fm.setState({
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to load silently because not all targets have a quota / support quota checking

loading: true
})
axios.post("/exec_blocking", {
// load silently as much as possible
// because not all machines support quota checking
axios.post('/exec_blocking', {
session_id: fm.session_id,
cmd: "quota -s | tail -n 1"
cmd: 'quota -s | tail -n 1'
}).then(res => {
fm.loadDir(cwd)
const mem = res.data.match(/[0-9]+[a-zA-Z]+/g)
const mem = res.data.match(/[0-9]+[a-zA-Z]+/g);
ms.setState({
memQuota: parseInt(mem[1]),
memUnit: mem[0].replace(/[0-9]+/,''),
memUsed: parseInt(mem[0])
})
used: parseInt(mem[0]),
usedUnit: mem[0].replace(/[0-9]+/, ''),
quota: parseInt(mem[1]),
quotaUnit: mem[1].replace(/[0-9]+/, ''),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse the quota unit as well: the number is usually in 'human readable size' format so the 'quota' unit might not always be the same as the 'used' unit

});
}).catch(error => {
fm.loadDir(cwd)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to handle this silently because not all targets have a quota / support quota checking

if (error.response) {
fm.showAlert(htmlResponseToReason(error.response.data));
} else {
// Something happened in setting up the request that triggered an Error
fm.showAlert('Error: ' + error.message);
}
// handle this silently because not all machines support quota checking
ms.setState({quota: null});
});
}
};

6 changes: 3 additions & 3 deletions client/src/actions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export const htmlResponseToReason = (response) => {
html.innerHTML = response;
const reasonHTML = html.children[1];
try {
const reasonTitle = reasonHTML.children[0].innerText
const reasonContent = reasonHTML.children[1].innerText
const reasonTitle = reasonHTML.children[0].innerText;
const reasonContent = reasonHTML.children[1].innerText;
return `${reasonTitle} - ${reasonContent}`;
} catch (_) {
return reasonHTML.innerText
return reasonHTML.innerText;
}

};
56 changes: 34 additions & 22 deletions client/src/interface/components/MemoryUsage/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import React from 'react';
import { sftp_quota } from '../../../actions/sftp';
import {
Box,
LinearProgress,
Typography
} from '@material-ui/core'
import {sftp_quota} from '../../../actions/sftp';
import {Box, LinearProgress, Skeleton, Typography} from '@material-ui/core';

function LinearProgressWithLabel(props) {
return (
<Box sx={{display: 'flex', alignItems: 'center'}}>
<Box sx={{width: '100%', mr: 1}}>
<LinearProgress variant="determinate" {...props} />
<Box flexGrow={1}>
<LinearProgress
variant={props.loading ? 'indeterminate' : 'determinate'}
value={props.value}
/>
</Box>
<Box sx={{minWidth: 35}}>
<Typography variant="body2" color="text.secondary">{`${Math.round(
props.value,
)}%`}</Typography>
<Box sx={{marginLeft: 1.5}}>
<Typography display={'flex'} variant="body2" color="text.secondary">
{props.loading ? <Skeleton width={15}/> : `${Math.round(props.value)}`}%
</Typography>
</Box>
</Box>
);
Expand All @@ -26,26 +25,39 @@ export default class MemoryUsage extends React.Component {
constructor(props) {
super(props);
this.state = {
memQuota: 0,
memUnit: '',
memUsed: 0
}
used: 0,
usedUnit: '',
quota: 0,
quotaUnit: ''
};
}

componentDidMount() {
sftp_quota(
this.props.fm,
this.props.fm.state.cwd,
this
)
);
}

render() {
return (<div>
<LinearProgressWithLabel variant="determinate" value={this.state.memUsed / this.state.memQuota * 100}/>
<Typography variant="caption" display="block">
{this.state.memUsed} {this.state.memUnit} of {this.state.memQuota} {this.state.memUnit} Used
</Typography>
const {
used,
usedUnit,
quota,
quotaUnit
} = this.state;
const loading = (quota === 0);
const loadFailed = (quota === null);
return (<div style={{width: '100%', visibility: loadFailed ? 'hidden' : 'visible'}}>
<LinearProgressWithLabel loading={loading}
value={used / quota * 100}/>
<Typography variant="caption" display={'flex'}>
{loading ? <Skeleton width={44}/> : `${used}${usedUnit}`}
{' / '}
{loading ? <Skeleton width={44}/> : `${quota}${quotaUnit}`}
{' Used'}
</Typography>
</div>
);
}
Expand Down
27 changes: 13 additions & 14 deletions client/src/interface/pages/FileManager/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {
Alert, Box,
Alert,
Divider,
Drawer,
duration,
Expand All @@ -12,7 +12,8 @@ import {
Menu,
MenuItem,
Paper,
Snackbar, Typography
Snackbar,
Typography
} from '@material-ui/core';
import {DataGrid} from '@material-ui/data-grid';

Expand Down Expand Up @@ -70,7 +71,7 @@ export default class FileManager extends React.Component {
filesDisplaying: [],
loading: true,
newMenuAnchorEl: null,
newFolderDialogOpen:false,
newFolderDialogOpen: false,
uploadWindowCollapsed: false,
uploadProgress: []
};
Expand Down Expand Up @@ -217,14 +218,14 @@ export default class FileManager extends React.Component {
});
};

handleNewFolderDialogOpen= (_) => {
this.handleNewMenuClose()
handleNewFolderDialogOpen = (_) => {
this.handleNewMenuClose();
this.setState({newFolderDialogOpen: true});
};
handleNewFolderDialogClose = () =>{
handleNewFolderDialogClose = () => {
this.setState({newFolderDialogOpen: false});
this.loadDir(this.state.cwd)
}
this.loadDir(this.state.cwd);
};

handleNewMenuOpen = (_) => {
this.setState({newMenuAnchorEl: document.getElementById('new-button')});
Expand Down Expand Up @@ -298,17 +299,15 @@ export default class FileManager extends React.Component {
primary={item[1]}/>
</ListItem>
))}
</List>
<Divider/>
<List style={{width: drawerWidth}}>
<Divider/>
<ListItem>
<ListItemIcon>
<FilterDrama/>
</ListItemIcon>
<ListItemText primary="Storage" />
<ListItemText primary="Storage"/>
</ListItem>
<ListItem>
<MemoryUsage fm={this}></MemoryUsage>
<MemoryUsage fm={this}/>
</ListItem>
</List>
</Drawer>
Expand Down Expand Up @@ -381,7 +380,7 @@ export default class FileManager extends React.Component {
transitionDuration={100}
>
<MenuItem key={'new-menu-folder'} style={{width: drawerWidth - 32}}
onClick={this.handleNewFolderDialogOpen}>
onClick={this.handleNewFolderDialogOpen}>
<ListItemIcon>
<CreateNewFolder/>
</ListItemIcon>
Expand Down