-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undo event deletion #149
Undo event deletion #149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* | ||
*/ | ||
|
||
app.factory('FcEvent', function(SimpleEvent) { | ||
app.factory('FcEvent', function($timeout, SimpleEvent) { | ||
'use strict'; | ||
|
||
/** | ||
|
@@ -33,6 +33,7 @@ app.factory('FcEvent', function(SimpleEvent) { | |
function FcEvent(vevent, event, start, end) { | ||
const context = {vevent, event}; | ||
context.iCalEvent = new ICAL.Event(event); | ||
context.isDeleted = false; | ||
|
||
let id = context.vevent.uri; | ||
if (event.hasProperty('recurrence-id')) { | ||
|
@@ -192,17 +193,34 @@ app.factory('FcEvent', function(SimpleEvent) { | |
}; | ||
|
||
/** | ||
* lock fc event for editing | ||
* Show undo notification for deletion | ||
* @returns {Promise} | ||
*/ | ||
iface.lock = function() { | ||
context.lock = true; | ||
}; | ||
iface.delete = function() { | ||
return new Promise(function(resolve, reject) { | ||
context.isDeleted = true; | ||
|
||
/** | ||
* unlock fc event | ||
*/ | ||
iface.unlock = function() { | ||
context.lock = false; | ||
const timeout = $timeout(function() { | ||
if (context.isDeleted) { | ||
resolve(); | ||
} | ||
}, 7500); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 7.5 seconds is too high IMHO. The user has got plenty of time to switch to another app, resulting in the deletion action not executing (correct ?). I don't know if there's a way to execute queue actions when we're leaving the app. Leaving the browser could be handled though, right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems good. So undo actions should be in a queue that gets emptied on timeout or on the |
||
|
||
const msg = t('calendar', '<strong>{title}</strong> has been deleted. <strong>Undo?</strong>', { | ||
title: iface.title | ||
}); | ||
const html = $('<div/>').append($(msg)); | ||
|
||
const elm = OC.Notification.showTemporary(html, { | ||
isHTML: true | ||
}); | ||
angular.element(elm[0]).click(function() { | ||
context.isDeleted = false; | ||
OC.Notification.hide(elm); | ||
$timeout.cancel(timeout); | ||
reject('Deletion cancelled by user'); | ||
}); | ||
}); | ||
}; | ||
|
||
return iface; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rerendering undeleted events like this causes them to double render when another event is created. I know that is a confusing way to word it so I took a short video.
Fortunately, this is simply a rendering artifact and resolves itself on reload.
If you rerender the events like this:
fc.elm.fullCalendar('refetchEventSources', vevent.calendar.fcEventSource);
it does not appear to cause this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
I tried using refetchEventSources, but I think it's a bit problematic. The event takes at least one second to reappear, because the browser has to send a CalDAV request to the server.
It would be way better, if the event would reappear immediately.