From 72afabb4b2462c74d9c9ca8d6cd884fd20fe48a2 Mon Sep 17 00:00:00 2001 From: Cleopatra Enjeck M Date: Tue, 26 Mar 2024 12:35:35 +0100 Subject: [PATCH] fix: load tables/views from transferred context Signed-off-by: Cleopatra Enjeck M --- src/pages/Context.vue | 10 ++++----- src/store/store.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/pages/Context.vue b/src/pages/Context.vue index 173882478..8b7819f0e 100644 --- a/src/pages/Context.vue +++ b/src/pages/Context.vue @@ -130,13 +130,10 @@ export default { methods: { async reload() { - this.loading = true - if (this.activeContextId) { - await this.loadContext() + if (!this.activeContextId) { + return } - this.loading = false - }, - async loadContext() { + this.loading = true this.icon = await this.getContextIcon(this.activeContext.iconName) this.contextResources = [] await this.$store.dispatch('loadContext', { id: this.activeContextId }) @@ -175,6 +172,7 @@ export default { } } } + this.loading = false }, createColumn(isView, element) { emit('tables:column:create', { isView, element }) diff --git a/src/store/store.js b/src/store/store.js index 520a9a9d4..02c6a72d5 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -377,6 +377,7 @@ export default new Vuex.Store({ try { const res = await axios.get(generateOcsUrl('/apps/tables/api/2/contexts')) commit('setContexts', res.data.ocs.data) + await this.dispatch('getContextsTablesAndViews') } catch (e) { displayError(e, t('tables', 'Could not load applications.')) showError(t('tables', 'Could not fetch applications')) @@ -395,6 +396,54 @@ export default new Vuex.Store({ } return true }, + async getContextsTablesAndViews({ state }) { + for (const context of state.contexts) { + for (const node of Object.values(context?.nodes)) { + if (parseInt(node.node_type) === NODE_TYPE_TABLE) { + await this.dispatch('loadContextTable', { id: node.node_id }) + } else if (parseInt(node.node_type) === NODE_TYPE_VIEW) { + await this.dispatch('loadContextView', { id: node.node_id }) + } + } + + } + }, + + async loadContextTable({ commit, state, getters }, { id }) { + const table = getters.getTable(id) + if (table) { + return true + } + let res + try { + res = await axios.get(generateOcsUrl('/apps/tables/api/2/tables/' + id)) + const tables = state.tables + tables.push(res.data.ocs.data) + commit('setTables', tables) + } catch (e) { + displayError(e, t('tables', 'Could not load table.')) + showError(t('tables', 'Could not fetch table')) + } + return res?.data.ocs.data + }, + + async loadContextView({ commit, state, getters }, { id }) { + const view = getters.getView(id) + if (view) { + return true + } + let res + try { + res = await axios.get(generateUrl('/apps/tables/view/' + id)) + const views = state.views + views.push(res.data) + commit('setViews', views) + } catch (e) { + displayError(e, t('tables', 'Could not load view')) + showError(t('tables', 'Could not fetch view')) + } + return res?.data + }, async transferContext({ state, commit, dispatch }, { id, data }) { try {