Skip to content
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

Check for updates and update public calendars #2917

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

azul
Copy link
Contributor

@azul azul commented Feb 25, 2021

Description

Fetch calendars every 20 seconds
and check if new ones have been added
or known ones have changed since they were loaded.

If a calendar changed remove all it's data from the store
and thereby effectively trigger a reload.

This is a fairly brute force approach as it drops all known data
rather than fetching only the data that changed via the caldav sync API.

However Caldav sync is yet to be implemented. (nextcloud/cdav-library#9)
So this serves as a workaround for the time being.

Fixes #31.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update ( I'm unsure 🤷🏼 )

How to test / use your changes?

Please provide instructions how to test your changes

  1. Check out the branch, compile the js an load it in a browser
  2. Share a calendar in a different browser
  3. Open the shared calendar and change the original
  4. Wait for the shared calendar display to update. (at most 20 seconds)

UI Changes

update-calendar.mp4

Checklist:

  • My code follows the style guidelines of this project
  • I signed off my changes (git commit -sm "Your commit message")
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Todolist:

  • Keep the order of calendars in the sidebar. (We now respect calendar.dav.order when adding it back.)
  • Add a server wide setting for the polling time defaulting to 1 Minute
  • Also reload calendars on the dashboard (The dashboard data structure is quite different from the calendar view. Won't handle it as part of this Pull Request.)

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Patch coverage: 13.46% and project coverage change: +6.81% 🎉

Comparison is base (4d3172f) 22.61% compared to head (56fc034) 29.43%.
Report is 2 commits behind head on main.

❗ Current head 56fc034 differs from pull request most recent head 7150df4. Consider uploading reports for the commit 7150df4 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2917      +/-   ##
============================================
+ Coverage     22.61%   29.43%   +6.81%     
+ Complexity      395      116     -279     
============================================
  Files           241      154      -87     
  Lines         11848     5535    -6313     
  Branches       2306      817    -1489     
============================================
- Hits           2679     1629    -1050     
+ Misses         9169     3906    -5263     
Flag Coverage Δ
javascript 24.03% <6.25%> (+10.21%) ⬆️
php 94.35% <100.00%> (+30.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/store/calendars.js 0.00% <0.00%> (ø)
src/store/fetchedTimeRanges.js 0.00% <ø> (ø)
src/views/Calendar.vue 0.00% <0.00%> (ø)
lib/Controller/PublicViewController.php 100.00% <100.00%> (ø)
lib/Controller/ViewController.php 100.00% <100.00%> (ø)
src/store/settings.js 100.00% <100.00%> (+12.17%) ⬆️

... and 227 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheOneWithTheBraid
Copy link

I did not read the full code changes yet but is it working in the embedded calendar view as well @azul?

@azul
Copy link
Contributor Author

azul commented Feb 26, 2021

@TheOneWithTheBraid I added the hooks to the main Calendar.vue which is also used for embedded calendars as far as i can tell. So I would expect it to work. Have not tested it though.

src/views/Calendar.vue Outdated Show resolved Hide resolved
src/views/Calendar.vue Outdated Show resolved Hide resolved
Fetch the open calendars every 20 seconds
and check if they have changed since they were loaded.

If a calendar changed remove all it's data from the store
and thereby effectively trigger a reload.

This is a fairly brute force approach as it drops all known data
rather than fetching only the data that changed via the caldav sync API.

However Caldav sync is yet to be implemented. (nextcloud/cdav-library#9)
So this serves as a workaround for the time being.

See #31.

Signed-off-by: Azul <[email protected]>
* Add new calendars to the list as they show up.
* Reload non-public calendars if they are updated on the server.

Fixes #31.

This works but it is not an optimal solution:
* If a calendar changes it reloads the current view
  no matter wether anyting in the view changed or not.
* If a calendar changes it drops all cached events
  even if they did not change.
* If an event is added to the calendar or moved
  this calendar will also be reloaded because the new event
  changed the syncToken on the server.
* If a calendar changed
  it will be added to the bottom of the list of calendars.

I would be fine with most of these but the last one needs to be fixed.

Signed-off-by: Azul <[email protected]>
When reloading updated calendars we effectively re-add them.
Put them in the list of calendars in the place they belong to
according to the `order` given by the dav response.

Signed-off-by: Azul <[email protected]>
@azul azul force-pushed the ux/reloadCalendars branch 10 times, most recently from e4a5b6f to f1afd6f Compare February 28, 2021 11:06
@@ -120,6 +120,7 @@ private function publicIndex(string $token,
$defaultSkipPopover = $this->config->getAppValue($this->appName, 'skipPopover', 'yes');
$defaultTimezone = $this->config->getAppValue($this->appName, 'timezone', 'automatic');
$defaultSlotDuration = $this->config->getAppValue($this->appName, 'slotDuration', '00:30:00');
$defaultSyncTimeout = $this->config->getAppValue($this->appName, 'syncTimeout', '00:02:00');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format is kinda ugly and prone to issues. The ISO 8601 duration format is probably better here (we already use if for the refresh rate of subscriptions for instance). On the front-end you can use momentjs to parse it.

Copy link
Contributor Author

@azul azul Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using ISO 8601 in the tests and defaults now and parse the value with moment.duration - so in the end both formats will work.

I'm not entirely sure what more it will take to have a properly working setting. I will open another PR to https://github.com/nextcloud/documentation/blob/master/admin_manual/groupware/calendar.rst to document the setting.

Edit: Removed resolved issue with loading sync_timeout - i was missing a call to loadState.

@azul azul force-pushed the ux/reloadCalendars branch 3 times, most recently from 9bf8ae9 to 6734bc3 Compare February 28, 2021 14:09
The setting is a string that can be formatted as anything that
[moment.duration](https://momentjs.com/docs/#/durations/creating/)
can parse:
* 'hh:mm:ss'
* 'PT1M' (ISO 8601)

Any invalid setting or setting to less than a second
will lead to the calendar updates being disabled.

The setting is not exposed in the UI.
It's meant to be configured by server admins
to be able to adjust the timeout and prevent an overly high load.

Signed-off-by: Azul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-refresh
5 participants