Implement Event copying.

Fixes #51.
master
Ramzan 4 years ago committed by Tom Hacohen
parent 205d7a3e1b
commit 2b43463fb0

@ -55,6 +55,7 @@ export const routeResolver = new RouteResolver({
_id: { _id: {
_base: ':itemUid', _base: ':itemUid',
edit: 'edit', edit: 'edit',
copy: 'copy',
log: 'log', log: 'log',
}, },
new: 'new', new: 'new',

@ -5,6 +5,7 @@ import * as React from 'react';
import { Route, Switch } from 'react-router'; import { Route, Switch } from 'react-router';
import Button from '@material-ui/core/Button'; import Button from '@material-ui/core/Button';
import IconEdit from '@material-ui/icons/Edit'; import IconEdit from '@material-ui/icons/Edit';
import IconCopy from '@material-ui/icons/FileCopy';
import IconChangeHistory from '@material-ui/icons/ChangeHistory'; import IconChangeHistory from '@material-ui/icons/ChangeHistory';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
@ -189,6 +190,34 @@ const CollectionRoutes = withStyles(styles)(withRouter(
); );
}} }}
/> />
{props.routePrefix === 'pim.events' &&
<Route
path={routeResolver.getRoute(props.routePrefix + '._id.copy')}
exact
render={({ match }) => {
const itemUid = decodeURIComponent(match.params.itemUid);
if (this.itemUndefined(itemUid)) {
return PageNotFound();
}
return (
<Container style={{ maxWidth: '30rem' }}>
{(itemUid in props.items) &&
<ComponentEdit
initialCollection={(props.items[itemUid] as any).journalUid}
item={props.items[itemUid]}
collections={props.collections}
onSave={props.onItemSave}
onDelete={props.onItemDelete}
onCancel={props.onItemCancel}
history={props.history}
copy
/>
}
</Container>
);
}}
/>
}
<Route <Route
path={routeResolver.getRoute(props.routePrefix + '._id.log')} path={routeResolver.getRoute(props.routePrefix + '._id.log')}
exact exact
@ -246,6 +275,24 @@ const CollectionRoutes = withStyles(styles)(withRouter(
<IconEdit className={classes.leftIcon} /> <IconEdit className={classes.leftIcon} />
Edit Edit
</Button> </Button>
{props.routePrefix === 'pim.events' &&
<Button
color="secondary"
variant="contained"
disabled={!props.componentEdit}
className={classes.button}
style={{ marginLeft: 15 }}
onClick={() =>
history.push(routeResolver.getRoute(
props.routePrefix + '._id.copy',
{ itemUid: match.params.itemUid }))
}
>
<IconCopy className={classes.leftIcon} />
Copy
</Button>
}
</div> </div>
<ComponentView item={props.items[decodeURIComponent(match.params.itemUid)]} /> <ComponentView item={props.items[decodeURIComponent(match.params.itemUid)]} />
</Container> </Container>

@ -50,6 +50,7 @@ interface PropsType {
onCancel: () => void; onCancel: () => void;
location: Location; location: Location;
history: History; history: History;
copy: boolean;
} }
class EventEdit extends React.PureComponent<PropsType> { class EventEdit extends React.PureComponent<PropsType> {
@ -105,8 +106,12 @@ class EventEdit extends React.PureComponent<PropsType> {
endDate.adjust(-1, 0, 0, 0); endDate.adjust(-1, 0, 0, 0);
} }
this.state.uid = event.uid; if (this.props.copy) {
this.state.title = event.title ? event.title : ''; this.state.title = event.title ? `Copy of ${event.title}` : '';
} else {
this.state.uid = event.uid;
this.state.title = event.title ? event.title : '';
}
this.state.allDay = allDay; this.state.allDay = allDay;
this.state.start = event.startDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate(); this.state.start = event.startDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate();
this.state.end = endDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate(); this.state.end = endDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate();
@ -120,7 +125,8 @@ class EventEdit extends React.PureComponent<PropsType> {
this.state.rrule.until = rruleProp.until; this.state.rrule.until = rruleProp.until;
} }
} }
} else { }
if (this.props.copy || this.props.item === undefined) {
this.state.uid = uuid.v4(); this.state.uid = uuid.v4();
} }
@ -222,7 +228,7 @@ class EventEdit extends React.PureComponent<PropsType> {
return; return;
} }
const event = (this.props.item) ? const event = (this.props.item && !this.props.copy) ?
this.props.item.clone() this.props.item.clone()
: :
new EventType() new EventType()
@ -281,7 +287,7 @@ class EventEdit extends React.PureComponent<PropsType> {
return ( return (
<> <>
<h2> <h2>
{this.props.item ? 'Edit Event' : 'New Event'} {(this.props.item && !this.props.copy) ? 'Edit Event' : 'New Event'}
</h2> </h2>
{recurring && ( {recurring && (
<div> <div>

Loading…
Cancel
Save