mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
443 lines
14 KiB
443 lines
14 KiB
3 years ago
|
import Vue from 'vue'
|
||
4 years ago
|
|
||
|
export const state = () => ({
|
||
|
list: [],
|
||
|
activeTab: 0,
|
||
3 years ago
|
activeTabCtx: {},
|
||
|
tabsState: {}
|
||
3 years ago
|
})
|
||
4 years ago
|
|
||
|
export const mutations = {
|
||
3 years ago
|
add(state, tab) {
|
||
4 years ago
|
if (state.list.length >= 8) {
|
||
3 years ago
|
state.list.shift()
|
||
4 years ago
|
}
|
||
3 years ago
|
state.list = [...state.list, tab]
|
||
4 years ago
|
},
|
||
3 years ago
|
remove(state, index) {
|
||
3 years ago
|
state.list.splice(index, 1)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeTableOrViewTabs(state) {
|
||
3 years ago
|
state.list = state.list.filter(t => !['table', 'view'].includes(t.type))
|
||
3 years ago
|
},
|
||
3 years ago
|
clear(state, index) {
|
||
3 years ago
|
state.list = []
|
||
4 years ago
|
},
|
||
3 years ago
|
active(state, index) {
|
||
4 years ago
|
if (state.list[index]) {
|
||
3 years ago
|
state.activeTabCtx = { ...state.list[index] }
|
||
|
state.activeTab = index
|
||
4 years ago
|
this.$router.push({
|
||
|
query: {
|
||
|
name: state.list[index].name || '',
|
||
|
dbalias: (state.list[index]._nodes && state.list[index]._nodes.dbAlias) || '',
|
||
3 years ago
|
type: (state.list[index]._nodes && state.list[index]._nodes.type) || ''
|
||
4 years ago
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
3 years ago
|
list(state, list) {
|
||
3 years ago
|
Vue.set(state, 'list', list)
|
||
4 years ago
|
},
|
||
3 years ago
|
activeTabCtx(state, activeTabCtx) {
|
||
3 years ago
|
let list = [...state.list]
|
||
4 years ago
|
|
||
3 years ago
|
list = list.map((el) => {
|
||
4 years ago
|
if (el.name === state.activeTabCtx.name) {
|
||
3 years ago
|
return { ...el, name: activeTabCtx.name } // add props can be updated every rest keep it as it is
|
||
4 years ago
|
}
|
||
3 years ago
|
return el
|
||
|
})
|
||
4 years ago
|
|
||
3 years ago
|
state.activeTabCtx = activeTabCtx
|
||
4 years ago
|
|
||
3 years ago
|
Vue.set(state, 'list', list)
|
||
4 years ago
|
|
||
|
// state.list = list;
|
||
3 years ago
|
},
|
||
|
MutSetTabState(state, { id, key, val }) {
|
||
|
const tabState = { ...(state.tabsState[id] || {}) }
|
||
|
Vue.set(tabState, key, val)
|
||
|
Vue.set(state.tabsState, id, tabState)
|
||
|
},
|
||
|
MutClearTabState(state, key) {
|
||
|
if (key) {
|
||
|
const newState = { ...state.tabsState }
|
||
|
delete newState[key]
|
||
|
state.tabsState = newState
|
||
|
} else {
|
||
|
state.tabsState = {}
|
||
|
}
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
export const getters = {
|
||
3 years ago
|
list(state) {
|
||
3 years ago
|
return state.list
|
||
4 years ago
|
},
|
||
3 years ago
|
activeTab(state) {
|
||
3 years ago
|
return state.activeTab
|
||
4 years ago
|
},
|
||
3 years ago
|
activeTabCtx(state) {
|
||
3 years ago
|
return state.activeTabCtx
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
export const actions = {
|
||
3 years ago
|
async changeActiveTab({ commit, state }, index) {
|
||
3 years ago
|
commit('active', index)
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadDefaultTabs({ commit, state, rootGetters, dispatch, rootState }, load) {
|
||
3 years ago
|
const tabs = []
|
||
4 years ago
|
|
||
3 years ago
|
if ('name' in this.$router.currentRoute.query &&
|
||
|
'type' in this.$router.currentRoute.query &&
|
||
|
'dbalias' in this.$router.currentRoute.query
|
||
4 years ago
|
) {
|
||
|
if (!load) {
|
||
3 years ago
|
return commit('list', tabs)
|
||
4 years ago
|
}
|
||
|
const {
|
||
|
name,
|
||
|
type,
|
||
|
dbalias
|
||
3 years ago
|
} = this.$router.currentRoute.query
|
||
4 years ago
|
try {
|
||
3 years ago
|
let tabNode
|
||
3 years ago
|
|
||
|
await dispatch('project/_loadTables', {
|
||
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.tables',
|
||
|
_nodes: {
|
||
|
dbAlias: 'db',
|
||
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
|
type: 'tableDir'
|
||
|
}
|
||
|
}, { root: true })
|
||
3 years ago
|
/* await dispatch('project/_loadViews', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.views',
|
||
|
_nodes: {
|
||
|
dbAlias: 'db',
|
||
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
|
type: 'viewDir'
|
||
|
}
|
||
3 years ago
|
}, { root: true }) */
|
||
3 years ago
|
|
||
4 years ago
|
switch (type) {
|
||
3 years ago
|
case 'table':
|
||
3 years ago
|
/* await dispatch('project/_loadTables', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.tables',
|
||
4 years ago
|
_nodes: {
|
||
|
dbAlias: dbalias,
|
||
3 years ago
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
3 years ago
|
type: 'tableDir'
|
||
4 years ago
|
}
|
||
3 years ago
|
}, { root: true }) */
|
||
4 years ago
|
tabNode = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
3 years ago
|
.children.find(n => n.type === 'tableDir') // parent node
|
||
|
.children.find(t => t.name === name)
|
||
4 years ago
|
|
||
3 years ago
|
break
|
||
|
case 'view':
|
||
3 years ago
|
/* await dispatch('project/_loadViews', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.views',
|
||
4 years ago
|
_nodes: {
|
||
|
dbAlias: dbalias,
|
||
3 years ago
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
3 years ago
|
type: 'viewDir'
|
||
4 years ago
|
}
|
||
3 years ago
|
}, { root: true }) */
|
||
4 years ago
|
tabNode = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
3 years ago
|
// .children.find(n => n.type === 'viewDir') // parent node
|
||
3 years ago
|
.children.find(n => n.type === 'tableDir') // parent node
|
||
3 years ago
|
.children.find(t => t.name === name)
|
||
4 years ago
|
|
||
3 years ago
|
break
|
||
|
case 'function':
|
||
4 years ago
|
await dispatch('project/_loadFunctions', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.functions',
|
||
4 years ago
|
_nodes: {
|
||
|
dbAlias: dbalias,
|
||
3 years ago
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
3 years ago
|
type: 'functionDir'
|
||
4 years ago
|
}
|
||
3 years ago
|
}, { root: true })
|
||
4 years ago
|
tabNode = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
3 years ago
|
.children.find((n) => {
|
||
|
return n.type === 'functionDir'
|
||
4 years ago
|
}) // parent node
|
||
3 years ago
|
.children.find((t) => {
|
||
4 years ago
|
return t.name === name
|
||
3 years ago
|
})
|
||
|
|
||
|
break
|
||
|
case 'procedure':
|
||
4 years ago
|
await dispatch('project/_loadProcedures', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.procedures',
|
||
4 years ago
|
_nodes: {
|
||
|
dbAlias: dbalias,
|
||
3 years ago
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
3 years ago
|
type: 'procedureDir'
|
||
4 years ago
|
}
|
||
3 years ago
|
}, { root: true })
|
||
4 years ago
|
tabNode = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
3 years ago
|
.children.find(n => n.type === 'procedureDir') // parent node
|
||
|
.children.find(t => t.name === name)
|
||
|
break
|
||
|
case 'sequence':
|
||
4 years ago
|
await dispatch('project/_loadFunctions', {
|
||
3 years ago
|
dbKey: '0.projectJson.envs._noco.db.0',
|
||
|
key: '0.projectJson.envs._noco.db.0.sequences',
|
||
4 years ago
|
_nodes: {
|
||
|
dbAlias: dbalias,
|
||
3 years ago
|
// dbKey: "0.projectJson.envs._noco.db.0",
|
||
|
env: '_noco',
|
||
|
// key: "0.projectJson.envs._noco.db.0.tables",
|
||
3 years ago
|
type: 'sequenceDir'
|
||
4 years ago
|
}
|
||
3 years ago
|
}, { root: true })
|
||
4 years ago
|
tabNode = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
3 years ago
|
.children.find((n) => {
|
||
|
return n.type === 'sequenceDir'
|
||
4 years ago
|
}) // parent node
|
||
3 years ago
|
.children.find((t) => {
|
||
4 years ago
|
return t.name === name
|
||
3 years ago
|
})
|
||
4 years ago
|
|
||
3 years ago
|
break
|
||
4 years ago
|
}
|
||
|
if (tabNode) {
|
||
3 years ago
|
tabs.push(tabNode)
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
4 years ago
|
}
|
||
|
} else {
|
||
|
if (rootGetters['project/GtrProjectIsGrpc']) {
|
||
|
const item = {
|
||
3 years ago
|
name: 'gRPC Client',
|
||
|
key: 'grpcClient',
|
||
|
_nodes: {
|
||
3 years ago
|
env: '_noco',
|
||
4 years ago
|
type: 'grpcClient'
|
||
|
}
|
||
3 years ago
|
}
|
||
|
tabs.push(item)
|
||
4 years ago
|
} else if (rootGetters['project/GtrProjectIsGraphql']) {
|
||
|
const item = {
|
||
3 years ago
|
name: 'Graphql Client',
|
||
|
key: 'graphqlClientDir',
|
||
|
_nodes: {
|
||
3 years ago
|
env: '_noco',
|
||
4 years ago
|
type: 'graphqlClientDir'
|
||
|
}
|
||
3 years ago
|
}
|
||
|
tabs.push(item)
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
if (rootGetters['users/GtrIsAdmin']) {
|
||
|
tabs.unshift({
|
||
|
name: 'Team & Auth ',
|
||
|
key: 'roles',
|
||
|
_nodes: {
|
||
|
env: '_noco',
|
||
|
type: 'roles'
|
||
|
}
|
||
|
})
|
||
3 years ago
|
} else {
|
||
|
const nodes = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
|
.children.find(n => n.type === 'tableDir') // parent node
|
||
|
.children
|
||
3 years ago
|
if (nodes && nodes[0]) {
|
||
|
tabs.push(nodes[0])
|
||
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
}
|
||
3 years ago
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadFirstTableTab({ commit, state, rootGetters, dispatch, rootState }, load) {
|
||
|
const tabs = []
|
||
|
|
||
|
const nodes = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
|
.children.find(n => n.type === 'tableDir') // parent node
|
||
|
.children
|
||
|
if (nodes && nodes[0]) {
|
||
|
tabs.push(nodes[0])
|
||
|
}
|
||
|
if (tabs.length) { commit('list', tabs) }
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
removeTableTab({ commit, state }, nodes) {
|
||
3 years ago
|
const tabs = JSON.parse(JSON.stringify(state.list))
|
||
4 years ago
|
const tabIndex = state.list.findIndex(
|
||
|
el =>
|
||
|
el._nodes.env === nodes.env &&
|
||
|
el._nodes.dbAlias === nodes.dbAlias &&
|
||
3 years ago
|
el._nodes.table_name === nodes.table_name
|
||
3 years ago
|
)
|
||
|
tabs.splice(tabIndex, 1)
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeViewTab({ commit, state }, nodes) {
|
||
3 years ago
|
const tabs = JSON.parse(JSON.stringify(state.list))
|
||
4 years ago
|
const tabIndex = state.list.findIndex(
|
||
|
el =>
|
||
|
el._nodes.env === nodes.env &&
|
||
|
el._nodes.dbAlias === nodes.dbAlias &&
|
||
|
el._nodes.view_name === nodes.view_name
|
||
3 years ago
|
)
|
||
|
tabs.splice(tabIndex, 1)
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeFunctionTab({ commit, state }, nodes) {
|
||
3 years ago
|
const tabs = JSON.parse(JSON.stringify(state.list))
|
||
4 years ago
|
const tabIndex = state.list.findIndex(
|
||
|
el =>
|
||
|
el._nodes.env === nodes.env &&
|
||
|
el._nodes.dbAlias === nodes.dbAlias &&
|
||
|
el._nodes.function_name === nodes.function_name
|
||
3 years ago
|
)
|
||
|
tabs.splice(tabIndex, 1)
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeProcedureTab({ commit, state }, nodes) {
|
||
3 years ago
|
const tabs = JSON.parse(JSON.stringify(state.list))
|
||
4 years ago
|
const tabIndex = state.list.findIndex(
|
||
|
el =>
|
||
|
el._nodes.env === nodes.env &&
|
||
|
el._nodes.dbAlias === nodes.dbAlias &&
|
||
|
el._nodes.procedure_name === nodes.procedure_name
|
||
3 years ago
|
)
|
||
|
tabs.splice(tabIndex, 1)
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeSequenceTab({ commit, state }, nodes) {
|
||
3 years ago
|
const tabs = JSON.parse(JSON.stringify(state.list))
|
||
4 years ago
|
const tabIndex = state.list.findIndex(
|
||
|
el =>
|
||
|
el._nodes.env === nodes.env &&
|
||
|
el._nodes.dbAlias === nodes.dbAlias &&
|
||
|
el._nodes.sequence_name === nodes.sequence_name
|
||
3 years ago
|
)
|
||
|
tabs.splice(tabIndex, 1)
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
3 years ago
|
removeTabsByName({ commit, state }, item) {
|
||
3 years ago
|
let tabs = JSON.parse(JSON.stringify(state.list))
|
||
|
tabs = tabs.filter((el) => {
|
||
4 years ago
|
if (
|
||
|
el._nodes.env === item._nodes.env &&
|
||
|
el._nodes.dbAlias === item._nodes.dbAlias &&
|
||
|
el.name === item.name
|
||
|
) {
|
||
3 years ago
|
return false
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
return true
|
||
|
})
|
||
|
commit('list', tabs)
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async ActAddTab({ commit, state, rootState }, item) {
|
||
3 years ago
|
// if (rootState.users.ui_ability.rules.maxTabs <= state.list.length) {
|
||
|
// this.commit('snackbar/setSnack', `Free plan limits to ${rootState.users.ui_ability.rules.maxTabs} tabs. Please <a href="https://nocodb.com/pricing" style="color: white;font-weight: bold;">upgrade</a> your plan for unlimited tabs.`)
|
||
|
// return
|
||
|
// }
|
||
3 years ago
|
commit('add', item)
|
||
3 years ago
|
await Vue.nextTick()
|
||
3 years ago
|
const index = state.list.length - 1
|
||
4 years ago
|
if (state.activeTab !== 0 && state.activeTab === index) {
|
||
3 years ago
|
commit('active', index - 1)
|
||
|
setTimeout(() => commit('active', index))
|
||
4 years ago
|
} else {
|
||
|
commit('active', index)
|
||
|
}
|
||
|
// this.$nextTick(() => {
|
||
|
// this.$router.push({
|
||
|
// query: {
|
||
|
// name: item.name || '',
|
||
|
// dbalias: (item._nodes || item._nodes.dbAlias) || '',
|
||
|
// type: (item._nodes || item._nodes.type) || ''
|
||
|
// }
|
||
|
// })
|
||
|
// });
|
||
3 years ago
|
},
|
||
|
async loadFirstCreatedTableTab({ commit, state, rootGetters, dispatch, rootState }, data) {
|
||
|
const tabs = state.list || []
|
||
|
const item = rootState.project
|
||
|
.list[0] // project
|
||
|
.children[0] // environment
|
||
|
.children[0] // db
|
||
|
.children.find(n => n.type === 'tableDir') // parent node
|
||
|
.children.find(n => n.title === data.title) // look for the target table
|
||
|
if (item) {
|
||
|
tabs.push(item)
|
||
|
}
|
||
|
if (tabs.length) {
|
||
|
commit('list', tabs)
|
||
|
}
|
||
|
return item
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
3 years ago
|
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
|
||
4 years ago
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|