Skip to content

Commit f566055

Browse files
Merge pull request #5 from junhaoliao/ictrl_review
hide quota check in the FM if the target doesn't support that
2 parents 51a0386 + d14f7a7 commit f566055

4 files changed

Lines changed: 64 additions & 59 deletions

File tree

client/src/actions/sftp.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,31 +143,25 @@ export const sftp_chmod = (fm, cwd, name, mode, recursive) => {
143143
fm.showAlert('Error: ' + error.message);
144144
}
145145
});
146-
}
146+
};
147147

148148
export const sftp_quota = (fm, cwd, ms) => {
149-
fm.setState({
150-
loading: true
151-
})
152-
axios.post("/exec_blocking", {
149+
// load silently as much as possible
150+
// because not all machines support quota checking
151+
axios.post('/exec_blocking', {
153152
session_id: fm.session_id,
154-
cmd: "quota -s | tail -n 1"
153+
cmd: 'quota -s | tail -n 1'
155154
}).then(res => {
156-
fm.loadDir(cwd)
157-
const mem = res.data.match(/[0-9]+[a-zA-Z]+/g)
155+
const mem = res.data.match(/[0-9]+[a-zA-Z]+/g);
158156
ms.setState({
159-
memQuota: parseInt(mem[1]),
160-
memUnit: mem[0].replace(/[0-9]+/,''),
161-
memUsed: parseInt(mem[0])
162-
})
157+
used: parseInt(mem[0]),
158+
usedUnit: mem[0].replace(/[0-9]+/, ''),
159+
quota: parseInt(mem[1]),
160+
quotaUnit: mem[1].replace(/[0-9]+/, ''),
161+
});
163162
}).catch(error => {
164-
fm.loadDir(cwd)
165-
if (error.response) {
166-
fm.showAlert(htmlResponseToReason(error.response.data));
167-
} else {
168-
// Something happened in setting up the request that triggered an Error
169-
fm.showAlert('Error: ' + error.message);
170-
}
163+
// handle this silently because not all machines support quota checking
164+
ms.setState({quota: null});
171165
});
172-
}
166+
};
173167

client/src/actions/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ export const htmlResponseToReason = (response) => {
33
html.innerHTML = response;
44
const reasonHTML = html.children[1];
55
try {
6-
const reasonTitle = reasonHTML.children[0].innerText
7-
const reasonContent = reasonHTML.children[1].innerText
6+
const reasonTitle = reasonHTML.children[0].innerText;
7+
const reasonContent = reasonHTML.children[1].innerText;
88
return `${reasonTitle} - ${reasonContent}`;
99
} catch (_) {
10-
return reasonHTML.innerText
10+
return reasonHTML.innerText;
1111
}
1212

1313
};

client/src/interface/components/MemoryUsage/index.js

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import React from 'react';
2-
import { sftp_quota } from '../../../actions/sftp';
3-
import {
4-
Box,
5-
LinearProgress,
6-
Typography
7-
} from '@material-ui/core'
2+
import {sftp_quota} from '../../../actions/sftp';
3+
import {Box, LinearProgress, Skeleton, Typography} from '@material-ui/core';
84

95
function LinearProgressWithLabel(props) {
106
return (
117
<Box sx={{display: 'flex', alignItems: 'center'}}>
12-
<Box sx={{width: '100%', mr: 1}}>
13-
<LinearProgress variant="determinate" {...props} />
8+
<Box flexGrow={1}>
9+
<LinearProgress
10+
variant={props.loading ? 'indeterminate' : 'determinate'}
11+
value={props.value}
12+
/>
1413
</Box>
15-
<Box sx={{minWidth: 35}}>
16-
<Typography variant="body2" color="text.secondary">{`${Math.round(
17-
props.value,
18-
)}%`}</Typography>
14+
<Box sx={{marginLeft: 1.5}}>
15+
<Typography display={'flex'} variant="body2" color="text.secondary">
16+
{props.loading ? <Skeleton width={15}/> : `${Math.round(props.value)}`}%
17+
</Typography>
1918
</Box>
2019
</Box>
2120
);
@@ -26,26 +25,39 @@ export default class MemoryUsage extends React.Component {
2625
constructor(props) {
2726
super(props);
2827
this.state = {
29-
memQuota: 0,
30-
memUnit: '',
31-
memUsed: 0
32-
}
28+
used: 0,
29+
usedUnit: '',
30+
quota: 0,
31+
quotaUnit: ''
32+
};
3333
}
3434

3535
componentDidMount() {
3636
sftp_quota(
3737
this.props.fm,
3838
this.props.fm.state.cwd,
3939
this
40-
)
40+
);
4141
}
4242

4343
render() {
44-
return (<div>
45-
<LinearProgressWithLabel variant="determinate" value={this.state.memUsed / this.state.memQuota * 100}/>
46-
<Typography variant="caption" display="block">
47-
{this.state.memUsed} {this.state.memUnit} of {this.state.memQuota} {this.state.memUnit} Used
48-
</Typography>
44+
const {
45+
used,
46+
usedUnit,
47+
quota,
48+
quotaUnit
49+
} = this.state;
50+
const loading = (quota === 0);
51+
const loadFailed = (quota === null);
52+
return (<div style={{width: '100%', visibility: loadFailed ? 'hidden' : 'visible'}}>
53+
<LinearProgressWithLabel loading={loading}
54+
value={used / quota * 100}/>
55+
<Typography variant="caption" display={'flex'}>
56+
{loading ? <Skeleton width={44}/> : `${used}${usedUnit}`}
57+
{' / '}
58+
{loading ? <Skeleton width={44}/> : `${quota}${quotaUnit}`}
59+
{' Used'}
60+
</Typography>
4961
</div>
5062
);
5163
}

client/src/interface/pages/FileManager/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
import {
4-
Alert, Box,
4+
Alert,
55
Divider,
66
Drawer,
77
duration,
@@ -12,7 +12,8 @@ import {
1212
Menu,
1313
MenuItem,
1414
Paper,
15-
Snackbar, Typography
15+
Snackbar,
16+
Typography
1617
} from '@material-ui/core';
1718
import {DataGrid} from '@material-ui/data-grid';
1819

@@ -70,7 +71,7 @@ export default class FileManager extends React.Component {
7071
filesDisplaying: [],
7172
loading: true,
7273
newMenuAnchorEl: null,
73-
newFolderDialogOpen:false,
74+
newFolderDialogOpen: false,
7475
uploadWindowCollapsed: false,
7576
uploadProgress: []
7677
};
@@ -217,14 +218,14 @@ export default class FileManager extends React.Component {
217218
});
218219
};
219220

220-
handleNewFolderDialogOpen= (_) => {
221-
this.handleNewMenuClose()
221+
handleNewFolderDialogOpen = (_) => {
222+
this.handleNewMenuClose();
222223
this.setState({newFolderDialogOpen: true});
223224
};
224-
handleNewFolderDialogClose = () =>{
225+
handleNewFolderDialogClose = () => {
225226
this.setState({newFolderDialogOpen: false});
226-
this.loadDir(this.state.cwd)
227-
}
227+
this.loadDir(this.state.cwd);
228+
};
228229

229230
handleNewMenuOpen = (_) => {
230231
this.setState({newMenuAnchorEl: document.getElementById('new-button')});
@@ -298,17 +299,15 @@ export default class FileManager extends React.Component {
298299
primary={item[1]}/>
299300
</ListItem>
300301
))}
301-
</List>
302-
<Divider/>
303-
<List style={{width: drawerWidth}}>
302+
<Divider/>
304303
<ListItem>
305304
<ListItemIcon>
306305
<FilterDrama/>
307306
</ListItemIcon>
308-
<ListItemText primary="Storage" />
307+
<ListItemText primary="Storage"/>
309308
</ListItem>
310309
<ListItem>
311-
<MemoryUsage fm={this}></MemoryUsage>
310+
<MemoryUsage fm={this}/>
312311
</ListItem>
313312
</List>
314313
</Drawer>
@@ -381,7 +380,7 @@ export default class FileManager extends React.Component {
381380
transitionDuration={100}
382381
>
383382
<MenuItem key={'new-menu-folder'} style={{width: drawerWidth - 32}}
384-
onClick={this.handleNewFolderDialogOpen}>
383+
onClick={this.handleNewFolderDialogOpen}>
385384
<ListItemIcon>
386385
<CreateNewFolder/>
387386
</ListItemIcon>

0 commit comments

Comments
 (0)