Commit 7cb9a1ed authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Adopted GUI to lasted refactorings. This completes #80 and #88.

parent 1733a634
Pipeline #41878 failed with stages
in 17 minutes and 22 seconds
......@@ -43,7 +43,7 @@ const handleResponseErrors = (response) => {
class Upload {
constructor(json) {
this.uploading = 0
this._assignFromJson(json)
Object.assign(this, json)
}
uploadFile(file) {
......@@ -78,17 +78,6 @@ class Upload {
.then(() => this)
}
_assignFromJson(uploadJson) {
Object.assign(this, uploadJson)
if (this.calcs) {
this.calcs.results.forEach(calc => {
const archiveId = calc.archive_id.split('/')
calc.upload_hash = archiveId[0]
calc.calc_hash = archiveId[1]
})
}
}
get(page, perPage, orderBy, order) {
if (this.uploading !== null && this.uploading !== 100) {
return new Promise(resolve => resolve(this))
......@@ -105,7 +94,7 @@ class Upload {
.then(handleResponseErrors)
.then(response => response.body)
.then(uploadJson => {
this._assignFromJson(uploadJson)
Object.assign(this, uploadJson)
return this
})
} else {
......@@ -137,23 +126,23 @@ async function getUploads() {
}))
}
async function archive(uploadHash, calcHash) {
async function archive(uploadId, calcId) {
const client = await swaggerPromise
return client.apis.archive.get_archive_calc({
upload_hash: uploadHash,
calc_hash: calcHash
upload_id: uploadId,
calc_id: calcId
})
.catch(networkError)
.then(handleResponseErrors)
.then(response => response.body)
}
async function calcProcLog(uploadHash, calcHash) {
async function calcProcLog(uploadId, calcId) {
const client = await swaggerPromise
console.log(uploadHash + calcHash)
console.log(uploadId + calcId)
return client.apis.archive.get_archive_logs({
upload_hash: uploadHash,
calc_hash: calcHash
upload_id: uploadId,
calc_id: calcId
})
.catch(networkError)
.then(response => {
......@@ -169,11 +158,11 @@ async function calcProcLog(uploadHash, calcHash) {
})
}
async function repo(uploadHash, calcHash) {
async function repo(uploadId, calcId) {
const client = await swaggerPromise
return client.apis.repo.get_repo_calc({
upload_hash: uploadHash,
calc_hash: calcHash
upload_id: uploadId,
calc_id: calcId
})
.catch(networkError)
.then(handleResponseErrors)
......
......@@ -19,10 +19,10 @@ function App() {
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/repo" component={Repo} />
<Route path="/repo/:uploadHash/:calcHash" component={RepoCalc} />
<Route path="/repo/:uploadId/:calcId" component={RepoCalc} />
<Route path="/upload" component={Uploads} />
<Route exact path="/archive" render={() => <div>Archive</div>} />
<Route path="/archive/:uploadHash/:calcHash" component={ArchiveCalc} />
<Route path="/archive/:uploadId/:calcId" component={ArchiveCalc} />
<Route path="/enc" render={() => <div>{'In the future, you\'ll see charts\'n\'stuff for your calculations and materials.'}</div>} />
<Route path="/analytics" render={() => <div>{'In the future, you\'ll see analytics notebooks here.'}</div>} />
<Route path="/profile" render={() => <div>Profile</div>} />
......
......@@ -65,8 +65,8 @@ class ArchiveCalc extends React.Component {
}
componentDidMount() {
const {uploadHash, calcHash} = this.props.match.params
api.archive(uploadHash, calcHash).then(data => {
const {uploadId, calcId} = this.props.match.params
api.archive(uploadId, calcId).then(data => {
this.setState({data: data})
}).catch(error => {
this.setState({data: null})
......@@ -92,7 +92,7 @@ class ArchiveCalc extends React.Component {
const { classes } = this.props
const { data, showMetaInfo, metaInfo } = this.state
const metaInfoData = metaInfo ? metaInfo[showMetaInfo] : null
const { uploadHash, calcHash } = this.props.match.params
const { uploadId, calcId } = this.props.match.params
return (
<div className={classes.root} ref={this.logPopperAnchor}>
<Markdown>{`
......@@ -123,8 +123,8 @@ class ArchiveCalc extends React.Component {
</Paper>
<CalcProcLogPopper
open={this.state.showLogs}
uploadHash={uploadHash}
calcHash={calcHash}
uploadId={uploadId}
calcId={calcId}
onClose={() => this.setState({showLogs: false})}
anchorEl={this.logPopperAnchor.current}
raiseError={this.props.raiseError}
......
......@@ -10,8 +10,8 @@ import Link from 'react-router-dom/Link'
class CalcLink extends React.Component {
static propTypes = {
classes: PropTypes.object.isRequired,
uploadHash: PropTypes.string,
calcHash: PropTypes.string,
uploadId: PropTypes.string,
calcId: PropTypes.string,
disabled: PropTypes.bool
}
......@@ -23,18 +23,18 @@ class CalcLink extends React.Component {
});
render() {
const { uploadHash, calcHash, classes, disabled } = this.props
const { uploadId, calcId, classes, disabled } = this.props
return (
<div className={classes.root}>
<MuiThemeProvider theme={repoTheme}>
<IconButton color="primary" component={Link} to={`/repo/${uploadHash}/${calcHash}`} disabled={disabled}><RepoIcon /></IconButton>
<IconButton color="primary" component={Link} to={`/repo/${uploadId}/${calcId}`} disabled={disabled}><RepoIcon /></IconButton>
</MuiThemeProvider>
<MuiThemeProvider theme={archiveTheme}>
<IconButton color="primary" component={Link} to={`/archive/${uploadHash}/${calcHash}`} disabled={disabled}><ArchiveIcon /></IconButton>
<IconButton color="primary" component={Link} to={`/archive/${uploadId}/${calcId}`} disabled={disabled}><ArchiveIcon /></IconButton>
</MuiThemeProvider>
<MuiThemeProvider theme={encTheme}>
<IconButton color="primary" component={Link} to={`/enc/${uploadHash}/${calcHash}`} disabled={disabled}><EncIcon /></IconButton>
<IconButton color="primary" component={Link} to={`/enc/${uploadId}/${calcId}`} disabled={disabled}><EncIcon /></IconButton>
</MuiThemeProvider>
</div>
)
......
......@@ -11,8 +11,8 @@ class CalcProcLogPopper extends React.Component {
static propTypes = {
classes: PropTypes.object.isRequired,
raiseError: PropTypes.func.isRequired,
uploadHash: PropTypes.string.isRequired,
calcHash: PropTypes.string.isRequired,
uploadId: PropTypes.string.isRequired,
calcId: PropTypes.string.isRequired,
open: PropTypes.bool,
onClose: PropTypes.func,
anchorEl: PropTypes.any
......@@ -29,8 +29,8 @@ class CalcProcLogPopper extends React.Component {
}
componentDidMount() {
const {uploadHash, calcHash} = this.props
api.calcProcLog(uploadHash, calcHash).then(logs => {
const {uploadId, calcId} = this.props
api.calcProcLog(uploadId, calcId).then(logs => {
if (logs && logs !== '') {
this.setState({logs: logs})
}
......
......@@ -166,7 +166,7 @@ class Repo extends React.Component {
<TableCell padding="dense" key={rowIndex}>{calc[key]}</TableCell>
))}
<TableCell padding="dense">
<CalcLinks uploadHash={calc.upload_hash} calcHash={calc.calc_hash} />
<CalcLinks uploadId={calc.upload_id} calcId={calc.calc_id} />
</TableCell>
</TableRow>
))}
......
......@@ -29,8 +29,8 @@ class RepoCalc extends React.Component {
}
componentDidMount() {
const {uploadHash, calcHash} = this.props.match.params
api.repo(uploadHash, calcHash).then(data => {
const {uploadId, calcId} = this.props.match.params
api.repo(uploadId, calcId).then(data => {
this.setState({data: data})
}).catch(error => {
this.setState({data: null})
......
......@@ -80,7 +80,7 @@ class Upload extends React.Component {
orderBy: 'status',
order: 'asc'
},
archiveLogs: null, // { uploadHash, calcHash } ids of archive to show logs for
archiveLogs: null, // { uploadId, calcId } ids of archive to show logs for
loading: true, // its loading data from the server and the user should know about it
updating: true // it is still not complete and continieusly looking for updates
}
......@@ -292,7 +292,7 @@ class Upload extends React.Component {
}
const renderRow = (calc, index) => {
const { mainfile, calc_hash, upload_hash, parser, tasks, current_task, status, errors } = calc
const { mainfile, calc_id, upload_id, parser, tasks, current_task, status, errors } = calc
const color = status === 'FAILURE' ? 'error' : 'default'
const row = (
<TableRow key={index}>
......@@ -301,7 +301,7 @@ class Upload extends React.Component {
{mainfile}
</Typography>
<Typography variant="caption" color={color}>
{upload_hash}/{calc_hash}
{upload_id}/{calc_id}
</Typography>
</TableCell>
<TableCell>
......@@ -324,7 +324,7 @@ class Upload extends React.Component {
<Typography color={color}>
{(status === 'SUCCESS' || status === 'FAILURE')
?
<a className={classes.logLink} href="#logs" onClick={() => this.setState({archiveLogs: { uploadHash: upload_hash, calcHash: calc_hash }})}>
<a className={classes.logLink} href="#logs" onClick={() => this.setState({archiveLogs: { uploadId: upload_id, calcId: calc_id }})}>
{status.toLowerCase()}
</a>
: status.toLowerCase()
......@@ -332,14 +332,14 @@ class Upload extends React.Component {
</Typography>
</TableCell>
<TableCell>
<CalcLinks uploadHash={upload_hash} calcHash={calc_hash} disabled={status !== 'SUCCESS'} />
<CalcLinks uploadId={upload_id} calcId={calc_id} disabled={status !== 'SUCCESS'} />
</TableCell>
</TableRow>
)
if (status === 'FAILURE') {
return (
<Tooltip key={calc_hash} title={errors.map((error, index) => (<p key={`${calc_hash}-${index}`}>{error}</p>))}>
<Tooltip key={calc_id} title={errors.map((error, index) => (<p key={`${calc_id}-${index}`}>{error}</p>))}>
{row}
</Tooltip>
)
......@@ -415,8 +415,8 @@ class Upload extends React.Component {
onClose={() => this.setState({archiveLogs: null})}
anchorEl={window.parent.document.documentElement.firstElementChild}
raiseError={this.props.raiseError}
uploadHash={this.state.archiveLogs.uploadHash}
calcHash={this.state.archiveLogs.calcHash}
uploadId={this.state.archiveLogs.uploadId}
calcId={this.state.archiveLogs.calcId}
/>
)
} else {
......
......@@ -58,7 +58,7 @@ class ArchiveCalcLogResource(Resource):
try:
return send_file(
upload_files.archive_log_file(calc_id, 'rt'),
upload_files.archive_log_file(calc_id, 'rb'),
mimetype='text/plain',
as_attachment=True,
attachment_filename='%s.log' % archive_id)
......@@ -91,7 +91,7 @@ class ArchiveCalcResource(Resource):
try:
return send_file(
upload_file.archive_file(calc_id, 'rt'),
upload_file.archive_file(calc_id, 'rb'),
mimetype='application/json',
as_attachment=True,
attachment_filename='%s.json' % archive_id)
......
......@@ -79,7 +79,7 @@ class RepoCalcsResource(Resource):
This is currently not implemented!
"""
return [], 200
return dict(pagination=dict(total=0, page=1, per_page=10), results=[]), 200
# page = int(request.args.get('page', 1))
# per_page = int(request.args.get('per_page', 10))
# owner = request.args.get('owner', 'all')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment