mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
duplicate widget via context menu, closes #184
This commit is contained in:
parent
86b1b2d5a5
commit
797300b2bc
2 changed files with 21 additions and 0 deletions
|
@ -268,6 +268,19 @@ class Dashboard extends Component {
|
|||
this.setState({ editModal: true, modalData: widget, modalIndex: index });
|
||||
};
|
||||
|
||||
duplicateWidget(widget) {
|
||||
let widgetCopy = JSON.parse(JSON.stringify(widget));
|
||||
delete widgetCopy.id;
|
||||
widgetCopy.x = widgetCopy.x + 50;
|
||||
widgetCopy.y = widgetCopy.y + 50;
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'widgets/start-add',
|
||||
token: this.state.sessionToken,
|
||||
data: widgetCopy
|
||||
});
|
||||
};
|
||||
|
||||
startEditFiles() {
|
||||
let tempFiles = [];
|
||||
this.state.files.forEach(file => {
|
||||
|
@ -505,6 +518,7 @@ class Dashboard extends Component {
|
|||
index={parseInt(widgetKey, 10)}
|
||||
widget={this.state.widgets[widgetKey]}
|
||||
onEdit={this.editWidget.bind(this)}
|
||||
onDuplicate={this.duplicateWidget.bind(this)}
|
||||
onDelete={this.deleteWidget.bind(this)}
|
||||
onChange={this.widgetChange.bind(this)}
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@ class WidgetContextMenu extends React.Component {
|
|||
}
|
||||
};
|
||||
|
||||
duplicateWidget = event => {
|
||||
if (this.props.onDuplicate != null) {
|
||||
this.props.onDuplicate(this.props.widget);
|
||||
}
|
||||
};
|
||||
|
||||
deleteWidget = event => {
|
||||
if (this.props.onDelete != null) {
|
||||
this.props.onDelete(this.props.widget, this.props.index);
|
||||
|
@ -92,6 +98,7 @@ class WidgetContextMenu extends React.Component {
|
|||
const ContextMenu = () => (
|
||||
<Menu id={'widgetMenu'+ this.props.index} style={{zIndex: 1000, display: 'inline-block'}}>
|
||||
<Item disabled={isLocked} onClick={this.editWidget}>Edit</Item>
|
||||
<Item disabled={isLocked} onClick={this.duplicateWidget}>Duplicate</Item>
|
||||
<Item disabled={isLocked} onClick={this.deleteWidget}>Delete</Item>
|
||||
|
||||
<Separator />
|
||||
|
|
Loading…
Add table
Reference in a new issue