diff options
author | Raimund Schlüßler <raimund.schluessler@mailbox.org> | 2022-03-18 14:32:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-18 14:32:39 +0300 |
commit | d33d1faceaa3487fa6e813978d0b59f839a78b60 (patch) | |
tree | 592084f787c1f987b018dd75d872a0e7144d5645 /src | |
parent | 69f1824700bd9f79b0b38993b7c6c42190ebcb38 (diff) |
Load all calendars for trash bin (#1943)
Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/App.vue | 9 | ||||
-rw-r--r-- | src/components/AppNavigation/Trashbin.vue | 2 | ||||
-rw-r--r-- | src/store/calendars.js | 31 | ||||
-rw-r--r-- | src/store/collections.js | 2 | ||||
-rw-r--r-- | src/store/tasks.js | 15 | ||||
-rw-r--r-- | src/views/Dashboard.vue | 9 |
6 files changed, 40 insertions, 28 deletions
diff --git a/src/App.vue b/src/App.vue index 10221c9e..e3e3be6b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,7 +40,7 @@ import { translate as t } from '@nextcloud/l10n' import AppContent from '@nextcloud/vue/dist/Components/AppContent' import Content from '@nextcloud/vue/dist/Components/Content' -import { mapState } from 'vuex' +import { mapGetters } from 'vuex' export default { name: 'App', @@ -50,15 +50,16 @@ export default { Content, }, computed: { - ...mapState({ - calendars: state => state.calendars.calendars, + ...mapGetters({ + calendars: 'getTaskCalendars', }), }, async beforeMount() { // get calendars then get tasks await client.connect({ enableCalDAV: true }) await this.$store.dispatch('fetchCurrentUserPrincipal') - const { calendars } = await this.$store.dispatch('getCalendarsAndTrashBin') + let { calendars } = await this.$store.dispatch('getCalendarsAndTrashBin') + calendars = calendars.filter(calendar => calendar.supportsTasks) const owners = [] calendars.forEach((calendar) => { if (owners.indexOf(calendar.owner) === -1) { diff --git a/src/components/AppNavigation/Trashbin.vue b/src/components/AppNavigation/Trashbin.vue index 318eb0a9..ed5ad985 100644 --- a/src/components/AppNavigation/Trashbin.vue +++ b/src/components/AppNavigation/Trashbin.vue @@ -253,7 +253,7 @@ export default { const { calendars } = await this.$store.dispatch('getCalendarsAndTrashBin') // Load the tasks of the restored calendar const calendar = calendars.find(cal => cal.url === item.calendar.url) - if (calendar) { + if (calendar?.supportsTasks) { await this.$store.dispatch('getTasksFromCalendar', { calendar, completed: false, related: null }) } break diff --git a/src/store/calendars.js b/src/store/calendars.js index 72483e54..b392ba55 100644 --- a/src/store/calendars.js +++ b/src/store/calendars.js @@ -175,13 +175,26 @@ function getCalendarUriFromUrl(url) { const getters = { /** + * Returns all calendars supporting VTODOs + * + * @param {object} state The store data + * @return {Array<Calendar>} The calendars supporting tasks + */ + getTaskCalendars: state => { + return state.calendars.filter(calendar => { + return calendar.supportsTasks + }) + }, + + /** * Returns the calendars sorted alphabetically * * @param {object} state The store data + * @param {object} getters The store getters * @return {Array<Calendar>} Array of the calendars sorted alphabetically */ - getSortedCalendars: state => { - return state.calendars.sort(function(cal1, cal2) { + getSortedCalendars: (state, getters) => { + return getters.getTaskCalendars.sort(function(cal1, cal2) { const n1 = cal1.order const n2 = cal2.order return (n1 < n2) ? -1 : (n1 > n2) ? 1 : 0 @@ -192,10 +205,11 @@ const getters = { * Returns the calendars sorted alphabetically * * @param {object} state The store data + * @param {object} getters The store getters * @return {Array<Calendar>} Array of the calendars sorted alphabetically */ - getSortedWritableCalendars: state => { - return state.calendars.filter(calendar => { + getSortedWritableCalendars: (state, getters) => { + return getters.getTaskCalendars.filter(calendar => { return !calendar.readOnly }) .sort(function(cal1, cal2) { @@ -284,16 +298,17 @@ const getters = { * Returns if a calendar name is already used by an other calendar * * @param {object} state The store data + * @param {object} getters The store getters * @return {boolean} If a calendar name is already used */ - isCalendarNameUsed: state => + isCalendarNameUsed: (state, getters) => /** * @param {string} name The name to check * @param {string} id The id of the calendar to exclude * @return {boolean} If a calendar name is already used */ (name, id) => { - return state.calendars.some(calendar => { + return getters.getTaskCalendars.some(calendar => { return (calendar.displayName === name && calendar.id !== id) }) }, @@ -345,6 +360,7 @@ const getters = { * @return {Array} */ sortedDeletedCalendars(state) { + console.debug(state.deletedCalendars) return state.deletedCalendars .sort((a, b) => a.deletedAt - b.deletedAt) }, @@ -605,9 +621,6 @@ const actions = { return Calendar(calendar, getters.getCurrentUserPrincipal) }) - // Remove calendars which don't support tasks - calendars = calendars.filter(calendar => calendar.supportsTasks) - calendars.forEach(calendar => { commit('addCalendar', calendar) }) diff --git a/src/store/collections.js b/src/store/collections.js index 4df2b1bd..815bc349 100644 --- a/src/store/collections.js +++ b/src/store/collections.js @@ -56,7 +56,7 @@ const getters = { */ (collectionId) => { let count = 0 - rootState.calendars.calendars.forEach(calendar => { + getters.getTaskCalendars.forEach(calendar => { let tasks = Object.values(calendar.tasks).filter(task => { return isTaskInList(task, collectionId, false) }) diff --git a/src/store/tasks.js b/src/store/tasks.js index b2ba9933..94d58752 100644 --- a/src/store/tasks.js +++ b/src/store/tasks.js @@ -104,12 +104,11 @@ const getters = { * * @param {object} state The store data * @param {object} getters The store getters - * @param {object} rootState The store root state * @return {Array} All tasks in store */ - getAllTasks: (state, getters, rootState) => { + getAllTasks: (state, getters) => { let tasks = [] - rootState.calendars.calendars.forEach(calendar => { + getters.getTaskCalendars.forEach(calendar => { tasks = tasks.concat(Object.values(calendar.tasks)) }) return tasks @@ -143,10 +142,9 @@ const getters = { * * @param {object} state The store data * @param {object} getters The store getters - * @param {object} rootState The store root state * @return {Task} The task */ - getTaskByUri: (state, getters, rootState) => + getTaskByUri: (state, getters) => /** * @param {string} taskUri The Uri of the task in question * @return {Task} The task @@ -154,7 +152,7 @@ const getters = { (taskUri) => { // We have to search in all calendars let task - for (const calendar of rootState.calendars.calendars) { + for (const calendar of getters.getTaskCalendars) { task = Object.values(calendar.tasks).find(task => { return task.uri === taskUri }) @@ -168,10 +166,9 @@ const getters = { * * @param {object} state The store data * @param {object} getters The store getters - * @param {object} rootState The store root state * @return {Task} The task */ - getTaskByUid: (state, getters, rootState) => + getTaskByUid: (state, getters) => /** * @param {string} taskUid The Uid of the task in question * @return {Task} The task @@ -179,7 +176,7 @@ const getters = { (taskUid) => { // We have to search in all calendars let task - for (const calendar of rootState.calendars.calendars) { + for (const calendar of getters.getTaskCalendars) { task = Object.values(calendar.tasks).find(task => { return task.uid === taskUid }) diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 7f807136..b2b1884c 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -63,7 +63,7 @@ import { translate as t } from '@nextcloud/l10n' import { generateUrl } from '@nextcloud/router' import { DashboardWidget, DashboardWidgetItem } from '@nextcloud/vue-dashboard' -import { mapState, mapActions } from 'vuex' +import { mapGetters, mapActions } from 'vuex' export default { name: 'Dashboard', @@ -86,8 +86,8 @@ export default { } }, computed: { - ...mapState({ - calendars: state => state.calendars.calendars, + ...mapGetters({ + calendars: 'getTaskCalendars', }), hasTaskToday() { return this.filteredTasks.some(task => isTaskInList(task, 'today')) @@ -109,7 +109,8 @@ export default { async initializeEnvironment() { await client.connect({ enableCalDAV: true }) await this.$store.dispatch('fetchCurrentUserPrincipal') - const { calendars } = await this.$store.dispatch('getCalendarsAndTrashBin') + let { calendars } = await this.$store.dispatch('getCalendarsAndTrashBin') + calendars = calendars.filter(calendar => calendar.supportsTasks) const owners = [] calendars.forEach((calendar) => { if (owners.indexOf(calendar.owner) === -1) { |