Show dialog for closed popups

#30
This commit is contained in:
casperlamboo 2018-01-17 15:53:03 +01:00
parent 222a27d5b5
commit 1f4ca15442
2 changed files with 48 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import createSceneData from 'doodle3d-core/d3/createSceneData.js';
import { generateExportMesh } from 'doodle3d-core/utils/exportUtils.js';
import { Matrix4 } from 'three/src/math/Matrix4.js';
import muiThemeable from 'material-ui/styles/muiThemeable';
import Dialog from 'material-ui/Dialog';
const MAX_FULLSCREEN_WIDTH = 720;
@ -121,6 +122,10 @@ class Interface extends React.Component {
popover: {
element: null,
open: false
},
openUrlDialog: {
open: true,
url: ''
}
};
}
@ -222,8 +227,12 @@ class Interface extends React.Component {
const updateProgres = progress => this.setState({ progress: { ...this.state.progress, ...progress } });
await slice(target, name, exportMesh, settings, updateProgres);
} catch (error) {
this.setState({ error: error.message });
throw error;
if (error.code === 3) {
this.setState({ openUrlDialog: { open: true, url: error.url } });
} else {
this.setState({ error: error.message });
throw error;
}
} finally {
this.setState({ isSlicing: false });
}
@ -288,7 +297,7 @@ class Interface extends React.Component {
render() {
const { classes, onCancel } = this.props;
const { isSlicing, isLoading, progress, showFullScreen, error, objectDimensions } = this.state;
const { isSlicing, isLoading, progress, showFullScreen, error, objectDimensions, openUrlDialog } = this.state;
const disableUI = isSlicing || isLoading;
const style = { ...(showFullScreen ? {} : { maxWidth: 'inherit', width: '100%', height: '100%' }) };
@ -352,6 +361,32 @@ class Interface extends React.Component {
</div>
);
const closeDialog = () => this.setState({ openUrlDialog: { open: false, url: '' } });
const dialog = (
<Dialog
open={openUrlDialog.open}
title="Open with Doodle3D Connect"
contentStyle={{ maxWidth: '400px' }}
actions={[
<FlatButton
label="Cancel"
onTouchTap={closeDialog}
/>,
<FlatButton
label="Open"
primary
onTouchTap={() => {
window.open(openUrlDialog.url, '_blank');
closeDialog();
}}
/>
]}
>
<p>Click 'Open' to continue to Doodle3D Connect</p>
</Dialog>
)
if (showFullScreen) {
return (
<div className={classes.container}>
@ -359,6 +394,7 @@ class Interface extends React.Component {
<h1 className={classes.title}>Doodle3D Slicer</h1>
{d3Panel}
{settingsPanel}
{dialog}
</div>
);
} else {
@ -379,6 +415,7 @@ class Interface extends React.Component {
{d3Panel}
</Tab>
</Tabs>
{dialog}
</div>
);
}

View File

@ -118,7 +118,7 @@ const GCODE_SERVER_URL = 'https://gcodeserver.doodle3d.com';
const CONNECT_URL = 'http://connect.doodle3d.com/';
export async function slice(target, name, mesh, settings, updateProgress) {
if (!settings) throw new Error('please select a printer first');
if (!settings) throw { message: 'please select a printer first', code: 0 };
let steps;
let currentStep = 0;
@ -130,7 +130,7 @@ export async function slice(target, name, mesh, settings, updateProgress) {
steps = 2;
break;
default:
throw new Error('unknown target');
throw { message: 'unknown target', code: 1 };
break;
}
@ -144,6 +144,8 @@ export async function slice(target, name, mesh, settings, updateProgress) {
action: progress.action,
percentage: currentStep / steps + progress.done / progress.total / steps
});
}).catch(error => {
throw { message: `error during slicing: ${error.message}`, code: 2 };
});
currentStep ++;
@ -182,13 +184,14 @@ export async function slice(target, name, mesh, settings, updateProgress) {
});
currentStep ++;
const popup = window.open(`${CONNECT_URL}?uuid=${id}`, '_blank');
if (!popup) throw new Error('popup was blocked by browser');
const url = `${CONNECT_URL}?uuid=${id}`;
const popup = window.open(url, '_blank');
if (!popup) throw { message: 'popup was blocked by browser', code: 3, url };
break;
}
default:
throw new Error('unknown target');
throw { message: 'unknown target', code: 1 };
break;
}
}