Skip to content

Commit

Permalink
fix: load tables/views from transferred context
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <[email protected]>
  • Loading branch information
enjeck committed Apr 2, 2024
1 parent 3cf2ca9 commit 72afabb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/pages/Context.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -175,6 +172,7 @@ export default {
}
}
}
this.loading = false
},
createColumn(isView, element) {
emit('tables:column:create', { isView, element })
Expand Down
49 changes: 49 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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 {
Expand Down

0 comments on commit 72afabb

Please sign in to comment.