|
53 | 53 | </div> |
54 | 54 | </template> |
55 | 55 |
|
56 | | -<script lang="ts"> |
| 56 | +<script lang="ts" setup> |
57 | 57 | import AppTemplate from '../components/AppTemplate.vue' |
58 | 58 | import SpacesList from '../components/Spaces/SpacesList.vue' |
59 | 59 | import ContextActions from '../components/Spaces/ContextActions.vue' |
@@ -83,207 +83,172 @@ import { |
83 | 83 | CreateSpace |
84 | 84 | } from '@ownclouders/web-pkg' |
85 | 85 | import { call, SpaceResource } from '@ownclouders/web-client' |
86 | | -import { computed, defineComponent, onBeforeUnmount, onMounted, ref, unref } from 'vue' |
| 86 | +import { computed, provide, onBeforeUnmount, onMounted, ref, unref } from 'vue' |
87 | 87 | import { useTask } from 'vue-concurrency' |
88 | 88 | import { useGettext } from 'vue3-gettext' |
89 | 89 |
|
90 | 90 | import { useSpaceSettingsStore } from '../composables' |
91 | 91 | import { storeToRefs } from 'pinia' |
92 | 92 | import { Quota } from '@ownclouders/web-client/graph/generated' |
93 | 93 |
|
94 | | -export default defineComponent({ |
95 | | - name: 'SpacesView', |
96 | | - components: { |
97 | | - CreateSpace, |
98 | | - AppLoadingSpinner, |
99 | | - SpacesList, |
100 | | - AppTemplate, |
101 | | - NoContentMessage, |
102 | | - ContextActions, |
103 | | - SpaceInfo |
104 | | - }, |
105 | | - provide() { |
106 | | - return { |
107 | | - resource: computed(() => this.selectedSpaces[0]) |
108 | | - } |
109 | | - }, |
110 | | - setup() { |
111 | | - const clientService = useClientService() |
112 | | - const { $gettext } = useGettext() |
113 | | - const { isSideBarOpen, sideBarActivePanel } = useSideBar() |
114 | | - const sharesStore = useSharesStore() |
115 | | - const { can } = useAbility() |
116 | | -
|
117 | | - const loadResourcesEventToken = ref(null) |
118 | | - let updateQuotaForSpaceEventToken: string |
119 | | - const template = ref(null) |
120 | | - const spaceSettingsStore = useSpaceSettingsStore() |
121 | | - const { spaces, selectedSpaces } = storeToRefs(spaceSettingsStore) |
122 | | -
|
123 | | - const currentPageQuery = useRouteQuery('page', '1') |
124 | | - const currentPage = computed(() => { |
125 | | - return parseInt(queryItemAsString(unref(currentPageQuery))) |
126 | | - }) |
127 | | -
|
128 | | - const itemsPerPageQuery = useRouteQuery('items-per-page', '1') |
129 | | - const itemsPerPage = computed(() => { |
130 | | - return parseInt(queryItemAsString(unref(itemsPerPageQuery))) |
131 | | - }) |
132 | | -
|
133 | | - const hasCreatePermission = computed(() => can('create-all', 'Drive')) |
134 | | -
|
135 | | - const loadResourcesTask = useTask(function* (signal) { |
136 | | - const drives = yield* call( |
137 | | - clientService.graphAuthenticated.drives.listAllDrives( |
138 | | - sharesStore.graphRoles, |
139 | | - { |
140 | | - orderBy: 'name asc', |
141 | | - filter: 'driveType eq project' |
142 | | - }, |
143 | | - { signal } |
144 | | - ) |
145 | | - ) |
146 | | - spaceSettingsStore.setSpaces(drives) |
147 | | - }) |
148 | | -
|
149 | | - const isLoading = computed(() => { |
150 | | - return loadResourcesTask.isRunning || !loadResourcesTask.last |
151 | | - }) |
152 | | -
|
153 | | - const breadcrumbs = computed(() => [ |
154 | | - { text: $gettext('Administration Settings'), to: { path: '/admin-settings' } }, |
155 | | - { |
156 | | - text: $gettext('Spaces'), |
157 | | - onClick: () => { |
158 | | - spaceSettingsStore.setSelectedSpaces([]) |
159 | | - loadResourcesTask.perform() |
160 | | - } |
161 | | - } |
162 | | - ]) |
| 94 | +const clientService = useClientService() |
| 95 | +const { $gettext } = useGettext() |
| 96 | +const { isSideBarOpen, sideBarActivePanel } = useSideBar() |
| 97 | +const sharesStore = useSharesStore() |
| 98 | +const { can } = useAbility() |
| 99 | +
|
| 100 | +const loadResourcesEventToken = ref(null) |
| 101 | +let updateQuotaForSpaceEventToken: string |
| 102 | +const template = ref(null) |
| 103 | +const spaceSettingsStore = useSpaceSettingsStore() |
| 104 | +const { spaces, selectedSpaces } = storeToRefs(spaceSettingsStore) |
| 105 | +
|
| 106 | +provide( |
| 107 | + 'resource', |
| 108 | + computed(() => selectedSpaces.value[0]) |
| 109 | +) |
| 110 | +
|
| 111 | +const currentPageQuery = useRouteQuery('page', '1') |
| 112 | +const currentPage = computed(() => { |
| 113 | + return parseInt(queryItemAsString(unref(currentPageQuery))) |
| 114 | +}) |
163 | 115 |
|
164 | | - const { actions: deleteActions } = useSpaceActionsDelete() |
165 | | - const { actions: disableActions } = useSpaceActionsDisable() |
166 | | - const { actions: editQuotaActions } = useSpaceActionsEditQuota() |
167 | | - const { actions: restoreActions } = useSpaceActionsRestore() |
| 116 | +const itemsPerPageQuery = useRouteQuery('items-per-page', '1') |
| 117 | +const itemsPerPage = computed(() => { |
| 118 | + return parseInt(queryItemAsString(unref(itemsPerPageQuery))) |
| 119 | +}) |
168 | 120 |
|
169 | | - const batchActions = computed((): SpaceAction[] => { |
170 | | - return [ |
171 | | - ...unref(editQuotaActions), |
172 | | - ...unref(restoreActions), |
173 | | - ...unref(deleteActions), |
174 | | - ...unref(disableActions) |
175 | | - ].filter((item) => item.isVisible({ resources: unref(selectedSpaces) })) |
176 | | - }) |
| 121 | +const hasCreatePermission = computed(() => can('create-all', 'Drive')) |
177 | 122 |
|
178 | | - const sideBarPanelContext = computed<SideBarPanelContext<unknown, unknown, SpaceResource>>( |
179 | | - () => { |
180 | | - return { |
181 | | - parent: null, |
182 | | - items: unref(selectedSpaces) |
183 | | - } |
184 | | - } |
185 | | - ) |
186 | | - const sideBarAvailablePanels = [ |
187 | | - { |
188 | | - name: 'SpaceNoSelection', |
189 | | - icon: 'layout-grid', |
190 | | - title: () => $gettext('Details'), |
191 | | - component: SpaceNoSelection, |
192 | | - isRoot: () => true, |
193 | | - isVisible: ({ items }) => items.length === 0 |
194 | | - }, |
195 | | - { |
196 | | - name: 'SpaceDetails', |
197 | | - icon: 'layout-grid', |
198 | | - title: () => $gettext('Details'), |
199 | | - component: SpaceDetails, |
200 | | - componentAttrs: () => ({ |
201 | | - showSpaceImage: false, |
202 | | - showShareIndicators: false |
203 | | - }), |
204 | | - isRoot: () => true, |
205 | | - isVisible: ({ items }) => items.length === 1 |
206 | | - }, |
207 | | - { |
208 | | - name: 'SpaceDetailsMultiple', |
209 | | - icon: 'layout-grid', |
210 | | - title: () => $gettext('Details'), |
211 | | - component: SpaceDetailsMultiple, |
212 | | - componentAttrs: ({ items }) => ({ |
213 | | - selectedSpaces: items |
214 | | - }), |
215 | | - isRoot: () => true, |
216 | | - isVisible: ({ items }) => items.length > 1 |
217 | | - }, |
| 123 | +const loadResourcesTask = useTask(function* (signal) { |
| 124 | + const drives = yield* call( |
| 125 | + clientService.graphAuthenticated.drives.listAllDrives( |
| 126 | + sharesStore.graphRoles, |
218 | 127 | { |
219 | | - name: 'SpaceActions', |
220 | | - icon: 'play-circle', |
221 | | - iconFillType: 'line', |
222 | | - title: () => $gettext('Actions'), |
223 | | - component: ActionsPanel, |
224 | | - isVisible: ({ items }) => items.length === 1 |
| 128 | + orderBy: 'name asc', |
| 129 | + filter: 'driveType eq project' |
225 | 130 | }, |
226 | | - { |
227 | | - name: 'SpaceMembers', |
228 | | - icon: 'group', |
229 | | - title: () => $gettext('Members'), |
230 | | - component: MembersPanel, |
231 | | - isVisible: ({ items }) => items.length === 1 |
232 | | - } |
233 | | - ] satisfies SideBarPanel<unknown, unknown, SpaceResource>[] |
| 131 | + { signal } |
| 132 | + ) |
| 133 | + ) |
| 134 | + spaceSettingsStore.setSpaces(drives) |
| 135 | +}) |
234 | 136 |
|
235 | | - onMounted(async () => { |
236 | | - await loadResourcesTask.perform() |
| 137 | +const isLoading = computed(() => { |
| 138 | + return loadResourcesTask.isRunning || !loadResourcesTask.last |
| 139 | +}) |
237 | 140 |
|
238 | | - loadResourcesEventToken.value = eventBus.subscribe( |
239 | | - 'app.admin-settings.list.load', |
240 | | - async () => { |
241 | | - await loadResourcesTask.perform() |
242 | | - selectedSpaces.value = [] |
| 141 | +const breadcrumbs = computed(() => [ |
| 142 | + { text: $gettext('Administration Settings'), to: { path: '/admin-settings' } }, |
| 143 | + { |
| 144 | + text: $gettext('Spaces'), |
| 145 | + onClick: () => { |
| 146 | + spaceSettingsStore.setSelectedSpaces([]) |
| 147 | + loadResourcesTask.perform() |
| 148 | + } |
| 149 | + } |
| 150 | +]) |
| 151 | +
|
| 152 | +const { actions: deleteActions } = useSpaceActionsDelete() |
| 153 | +const { actions: disableActions } = useSpaceActionsDisable() |
| 154 | +const { actions: editQuotaActions } = useSpaceActionsEditQuota() |
| 155 | +const { actions: restoreActions } = useSpaceActionsRestore() |
| 156 | +
|
| 157 | +const batchActions = computed((): SpaceAction[] => { |
| 158 | + return [ |
| 159 | + ...unref(editQuotaActions), |
| 160 | + ...unref(restoreActions), |
| 161 | + ...unref(deleteActions), |
| 162 | + ...unref(disableActions) |
| 163 | + ].filter((item) => item.isVisible({ resources: unref(selectedSpaces) })) |
| 164 | +}) |
243 | 165 |
|
244 | | - const pageCount = Math.ceil(unref(spaces).length / unref(itemsPerPage)) |
245 | | - if (unref(currentPage) > 1 && unref(currentPage) > pageCount) { |
246 | | - // reset pagination to avoid empty lists (happens when deleting all items on the last page) |
247 | | - currentPageQuery.value = pageCount.toString() |
248 | | - } |
249 | | - } |
250 | | - ) |
| 166 | +const sideBarPanelContext = computed<SideBarPanelContext<unknown, unknown, SpaceResource>>(() => { |
| 167 | + return { |
| 168 | + parent: null, |
| 169 | + items: unref(selectedSpaces) |
| 170 | + } |
| 171 | +}) |
| 172 | +const sideBarAvailablePanels = [ |
| 173 | + { |
| 174 | + name: 'SpaceNoSelection', |
| 175 | + icon: 'layout-grid', |
| 176 | + title: () => $gettext('Details'), |
| 177 | + component: SpaceNoSelection, |
| 178 | + isRoot: () => true, |
| 179 | + isVisible: ({ items }) => items.length === 0 |
| 180 | + }, |
| 181 | + { |
| 182 | + name: 'SpaceDetails', |
| 183 | + icon: 'layout-grid', |
| 184 | + title: () => $gettext('Details'), |
| 185 | + component: SpaceDetails, |
| 186 | + componentAttrs: () => ({ |
| 187 | + showSpaceImage: false, |
| 188 | + showShareIndicators: false |
| 189 | + }), |
| 190 | + isRoot: () => true, |
| 191 | + isVisible: ({ items }) => items.length === 1 |
| 192 | + }, |
| 193 | + { |
| 194 | + name: 'SpaceDetailsMultiple', |
| 195 | + icon: 'layout-grid', |
| 196 | + title: () => $gettext('Details'), |
| 197 | + component: SpaceDetailsMultiple, |
| 198 | + componentAttrs: ({ items }) => ({ |
| 199 | + selectedSpaces: items |
| 200 | + }), |
| 201 | + isRoot: () => true, |
| 202 | + isVisible: ({ items }) => items.length > 1 |
| 203 | + }, |
| 204 | + { |
| 205 | + name: 'SpaceActions', |
| 206 | + icon: 'play-circle', |
| 207 | + iconFillType: 'line', |
| 208 | + title: () => $gettext('Actions'), |
| 209 | + component: ActionsPanel, |
| 210 | + isVisible: ({ items }) => items.length === 1 |
| 211 | + }, |
| 212 | + { |
| 213 | + name: 'SpaceMembers', |
| 214 | + icon: 'group', |
| 215 | + title: () => $gettext('Members'), |
| 216 | + component: MembersPanel, |
| 217 | + isVisible: ({ items }) => items.length === 1 |
| 218 | + } |
| 219 | +] satisfies SideBarPanel<unknown, unknown, SpaceResource>[] |
251 | 220 |
|
252 | | - updateQuotaForSpaceEventToken = eventBus.subscribe( |
253 | | - 'app.admin-settings.spaces.space.quota.updated', |
254 | | - ({ spaceId, quota }: { spaceId: string; quota: Quota }) => { |
255 | | - const space = unref(spaces).find((s) => s.id === spaceId) |
256 | | - if (space) { |
257 | | - space.spaceQuota = quota |
258 | | - } |
259 | | - } |
260 | | - ) |
261 | | - }) |
| 221 | +onMounted(async () => { |
| 222 | + await loadResourcesTask.perform() |
262 | 223 |
|
263 | | - onBeforeUnmount(() => { |
264 | | - spaceSettingsStore.reset() |
265 | | - eventBus.unsubscribe('app.admin-settings.list.load', unref(loadResourcesEventToken)) |
266 | | - eventBus.unsubscribe( |
267 | | - 'app.admin-settings.spaces.space.quota.updated', |
268 | | - updateQuotaForSpaceEventToken |
269 | | - ) |
270 | | - }) |
| 224 | + loadResourcesEventToken.value = eventBus.subscribe('app.admin-settings.list.load', async () => { |
| 225 | + await loadResourcesTask.perform() |
| 226 | + selectedSpaces.value = [] |
271 | 227 |
|
272 | | - return { |
273 | | - isSideBarOpen, |
274 | | - sideBarActivePanel, |
275 | | - spaces, |
276 | | - loadResourcesTask, |
277 | | - breadcrumbs, |
278 | | - batchActions, |
279 | | - selectedSpaces, |
280 | | - sideBarAvailablePanels, |
281 | | - sideBarPanelContext, |
282 | | - isLoading, |
283 | | - template, |
284 | | - hasCreatePermission, |
285 | | - spaceSettingsStore |
| 228 | + const pageCount = Math.ceil(unref(spaces).length / unref(itemsPerPage)) |
| 229 | + if (unref(currentPage) > 1 && unref(currentPage) > pageCount) { |
| 230 | + // reset pagination to avoid empty lists (happens when deleting all items on the last page) |
| 231 | + currentPageQuery.value = pageCount.toString() |
286 | 232 | } |
287 | | - } |
| 233 | + }) |
| 234 | +
|
| 235 | + updateQuotaForSpaceEventToken = eventBus.subscribe( |
| 236 | + 'app.admin-settings.spaces.space.quota.updated', |
| 237 | + ({ spaceId, quota }: { spaceId: string; quota: Quota }) => { |
| 238 | + const space = unref(spaces).find((s) => s.id === spaceId) |
| 239 | + if (space) { |
| 240 | + space.spaceQuota = quota |
| 241 | + } |
| 242 | + } |
| 243 | + ) |
| 244 | +}) |
| 245 | +
|
| 246 | +onBeforeUnmount(() => { |
| 247 | + spaceSettingsStore.reset() |
| 248 | + eventBus.unsubscribe('app.admin-settings.list.load', unref(loadResourcesEventToken)) |
| 249 | + eventBus.unsubscribe( |
| 250 | + 'app.admin-settings.spaces.space.quota.updated', |
| 251 | + updateQuotaForSpaceEventToken |
| 252 | + ) |
288 | 253 | }) |
289 | 254 | </script> |
0 commit comments