Redefine API to provider access. (#199)
* Migrate login, get session, change role, logout. * Convert menu.pull/3759/head
parent
206539251b
commit
79698ad562
|
@ -13,59 +13,25 @@ function Instance() {
|
||||||
|
|
||||||
// Make login by UserName and password, this function can return user data for show
|
// Make login by UserName and password, this function can return user data for show
|
||||||
export function login(loginValues) {
|
export function login(loginValues) {
|
||||||
if (loginValues.role !== undefined && loginValues.role.trim() !== '') {
|
if (loginValues.role && loginValues.role.trim() !== '') {
|
||||||
return Instance.call(this).requestLogin(
|
return Instance.call(this).requestLogin({
|
||||||
loginValues.userName,
|
userName: loginValues.userName,
|
||||||
loginValues.password,
|
userPass: loginValues.password,
|
||||||
loginValues.role,
|
role: loginValues.role,
|
||||||
null,
|
language: getLanguage() || 'en_US'
|
||||||
loginValues.language
|
})
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return Instance.call(this).requestLoginDefault(
|
return Instance.call(this).requestLoginDefault({
|
||||||
loginValues.userName,
|
userName: loginValues.userName,
|
||||||
loginValues.password,
|
userPass: loginValues.password,
|
||||||
loginValues.language
|
language: getLanguage() || 'en_US'
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get User Info from session Uuid or token
|
// Get User Info from session Uuid or token
|
||||||
export function getInfo(token) {
|
export function getInfo(token) {
|
||||||
return Instance.call(this).requestUserInfoFromSession(token)
|
return Instance.call(this).requestUserInfoFromSession(token)
|
||||||
.then(session => {
|
|
||||||
var roles = []
|
|
||||||
var rolesList = session.getRolesList().map(itemRol => {
|
|
||||||
roles.push(itemRol.getName())
|
|
||||||
return {
|
|
||||||
id: itemRol.getId(),
|
|
||||||
uuid: itemRol.getUuid(),
|
|
||||||
name: itemRol.getName(),
|
|
||||||
description: itemRol.getDescription(),
|
|
||||||
clientId: itemRol.getClientid(),
|
|
||||||
clientName: itemRol.getClientname(),
|
|
||||||
organizationList: itemRol.getOrganizationsList()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// TODO: Add user.id, user.level in request
|
|
||||||
const user = session.getUserinfo()
|
|
||||||
|
|
||||||
const response = {
|
|
||||||
id: user.getId(),
|
|
||||||
uuid: user.getUuid(),
|
|
||||||
name: user.getName(),
|
|
||||||
comments: user.getComments(),
|
|
||||||
description: user.getDescription(),
|
|
||||||
// TODO: Add from ADempiere
|
|
||||||
avatar: 'https://avatars1.githubusercontent.com/u/1263359?s=200&v=4',
|
|
||||||
roles: roles, // rol list names, used from app (src/permission.js, src/utils/permission.js)
|
|
||||||
rolesList: rolesList,
|
|
||||||
responseGrpc: session
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
}).catch(error => {
|
|
||||||
console.log(error)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +44,7 @@ export function getSessionInfo(sessionUuid) {
|
||||||
|
|
||||||
// Logout from server
|
// Logout from server
|
||||||
export function logout(sessionUuid) {
|
export function logout(sessionUuid) {
|
||||||
return Instance.call(this).requestLogout(sessionUuid)
|
return Instance.call(this).requestLogOut(sessionUuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get User menu from server
|
// Get User menu from server
|
||||||
|
|
|
@ -1,112 +1,121 @@
|
||||||
import { getMenu } from '@/api/user'
|
import { getMenu } from '@/api/user'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
|
import { convertAction } from '@/utils/ADempiere/dictionaryUtils'
|
||||||
|
|
||||||
/* Layout */
|
/* Layout */
|
||||||
import Layout from '@/layout'
|
import Layout from '@/layout'
|
||||||
|
|
||||||
|
const staticRoutes = [
|
||||||
|
{
|
||||||
|
path: '*',
|
||||||
|
redirect: '/404',
|
||||||
|
hidden: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/ProcessActivity',
|
||||||
|
component: Layout,
|
||||||
|
meta: {
|
||||||
|
title: 'ProcessActivity',
|
||||||
|
icon: 'tree-table',
|
||||||
|
noCache: true,
|
||||||
|
breadcrumb: false
|
||||||
|
},
|
||||||
|
redirect: '/ProcessActivity/index',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'index',
|
||||||
|
component: () => import('@/views/ADempiere/ProcessActivity'),
|
||||||
|
name: 'ProcessActivity',
|
||||||
|
meta: {
|
||||||
|
title: 'ProcessActivity',
|
||||||
|
icon: 'tree-table',
|
||||||
|
noCache: true,
|
||||||
|
isIndex: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/report-viewer',
|
||||||
|
component: Layout,
|
||||||
|
hidden: true,
|
||||||
|
redirect: 'report-viewer/:processId/:instanceUuid/:fileName',
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: ':processId/:instanceUuid/:fileName',
|
||||||
|
component: () => import('@/views/ADempiere/ReportViewer'),
|
||||||
|
name: 'Report Viewer',
|
||||||
|
meta: {
|
||||||
|
title: 'ReportViewer'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
// Get Menu from server
|
// Get Menu from server
|
||||||
export function loadMainMenu() {
|
export function loadMainMenu() {
|
||||||
return getMenu(getToken()).then(menu => {
|
return getMenu(getToken()).then(menu => {
|
||||||
const asyncRouterMap = [
|
const asyncRoutesMap = []
|
||||||
{
|
menu.childsList.forEach(menu => {
|
||||||
path: '*',
|
|
||||||
redirect: '/404',
|
|
||||||
hidden: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/ProcessActivity',
|
|
||||||
component: Layout,
|
|
||||||
meta: { title: 'ProcessActivity', icon: 'tree-table', noCache: true, breadcrumb: false },
|
|
||||||
redirect: '/ProcessActivity/index',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: 'index',
|
|
||||||
component: () => import('@/views/ADempiere/ProcessActivity'),
|
|
||||||
name: 'ProcessActivity',
|
|
||||||
meta: { title: 'ProcessActivity', icon: 'tree-table', noCache: true, isIndex: true }
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/report-viewer',
|
|
||||||
component: Layout,
|
|
||||||
hidden: true,
|
|
||||||
redirect: 'report-viewer/:processId/:instanceUuid/:fileName',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: ':processId/:instanceUuid/:fileName',
|
|
||||||
component: () => import('@/views/ADempiere/ReportViewer'),
|
|
||||||
name: 'Report Viewer',
|
|
||||||
meta: {
|
|
||||||
title: 'ReportViewer'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
menu.getChildsList().forEach(menu => {
|
|
||||||
const optionMenu = getRouteFromMenuItem(menu)
|
const optionMenu = getRouteFromMenuItem(menu)
|
||||||
if (menu.getIssummary()) {
|
if (menu.isSummary) {
|
||||||
menu.getChildsList().forEach((menu, index) => {
|
menu.childsList.forEach(menu => {
|
||||||
optionMenu.children.push(getChildFromAction(menu, index = 0))
|
const childsSumaryConverted = getChildFromAction(menu, 0)
|
||||||
optionMenu.children[0].meta.childs.push(getChildFromAction(menu, index = 0))
|
|
||||||
optionMenu.meta.childs.push(getChildFromAction(menu, index = 0))
|
optionMenu.children.push(childsSumaryConverted)
|
||||||
|
optionMenu.children[0].meta.childs.push(childsSumaryConverted)
|
||||||
|
optionMenu.meta.childs.push(childsSumaryConverted)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
optionMenu.children.push(getChildFromAction(menu))
|
const childsConverted = getChildFromAction(menu)
|
||||||
optionMenu.meta.childs.push(getChildFromAction(menu))
|
|
||||||
|
optionMenu.children.push(childsConverted)
|
||||||
|
optionMenu.meta.childs.push(childsConverted)
|
||||||
}
|
}
|
||||||
asyncRouterMap.push(optionMenu)
|
asyncRoutesMap.push(optionMenu)
|
||||||
})
|
})
|
||||||
return asyncRouterMap
|
return staticRoutes.concat(asyncRoutesMap)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log('Error with Login: ' + error)
|
console.warn(`Error getting menu: ${error.message}. Code: ${error.code}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Only Child
|
// Get Only Child
|
||||||
function getChildFromAction(menu, index) {
|
function getChildFromAction(menu, index) {
|
||||||
const action = menu.getAction()
|
const action = menu.action
|
||||||
var actionAttributes = convertAction(action)
|
const actionAttributes = convertAction(action)
|
||||||
var routeIdentifier = actionAttributes.name + '/' + menu.getId()
|
let routeIdentifier = actionAttributes.name + '/' + menu.id
|
||||||
let selectedComponent
|
if (menu.isSummary) {
|
||||||
if (action === 'W') {
|
routeIdentifier = '/' + menu.id
|
||||||
selectedComponent = () => import('@/views/ADempiere/Window')
|
|
||||||
routeIdentifier = actionAttributes.name + '/' + menu.getId()
|
|
||||||
} else if (action === 'S') {
|
|
||||||
selectedComponent = () => import('@/views/ADempiere/Browser')
|
|
||||||
} else if (action === 'P' || action === 'R') {
|
|
||||||
selectedComponent = () => import('@/views/ADempiere/Process')
|
|
||||||
} else if (action === 'B' || action === 'F' || action === 'T' || action === 'X') {
|
|
||||||
selectedComponent = () => import('@/views/ADempiere/Unsupported')
|
|
||||||
} else {
|
|
||||||
selectedComponent = () => import('@/views/ADempiere/Summary')
|
|
||||||
routeIdentifier = '/' + menu.getId()
|
|
||||||
}
|
}
|
||||||
var option = {
|
|
||||||
|
const option = {
|
||||||
path: routeIdentifier,
|
path: routeIdentifier,
|
||||||
component: selectedComponent,
|
component: actionAttributes.component,
|
||||||
name: menu.getUuid(),
|
name: menu.uuid,
|
||||||
hidden: index > 0,
|
hidden: index > 0,
|
||||||
meta: {
|
meta: {
|
||||||
isIndex: actionAttributes.isIndex,
|
isIndex: actionAttributes.isIndex,
|
||||||
title: menu.getName(),
|
title: menu.name,
|
||||||
description: menu.getDescription(),
|
description: menu.description,
|
||||||
uuid: menu.getReferenceuuid(),
|
uuid: menu.referenceUuid,
|
||||||
tabUuid: '',
|
tabUuid: '',
|
||||||
type: actionAttributes.name,
|
type: actionAttributes.name,
|
||||||
parentUuid: menu.getParentuuid(),
|
parentUuid: menu.parentUuid,
|
||||||
icon: actionAttributes.icon,
|
icon: actionAttributes.icon,
|
||||||
alwaysShow: true,
|
alwaysShow: true,
|
||||||
noCache: false,
|
noCache: false,
|
||||||
childs: []
|
childs: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (option.meta.type === 'summary') {
|
|
||||||
|
if (actionAttributes.isIndex || actionAttributes.name === 'summary') {
|
||||||
option['children'] = []
|
option['children'] = []
|
||||||
menu.getChildsList().forEach((child, index) => {
|
menu.childsList.forEach(child => {
|
||||||
option.children.push(getChildFromAction(child, index = 1))
|
const menuConverted = getChildFromAction(child, 1)
|
||||||
option.meta.childs.push(getChildFromAction(child, index = 1))
|
option.children.push(menuConverted)
|
||||||
|
option.meta.childs.push(menuConverted)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return option
|
return option
|
||||||
|
@ -114,93 +123,38 @@ function getChildFromAction(menu, index) {
|
||||||
|
|
||||||
// Convert menu item from server to Route
|
// Convert menu item from server to Route
|
||||||
function getRouteFromMenuItem(menu) {
|
function getRouteFromMenuItem(menu) {
|
||||||
const action = menu.getAction()
|
const action = menu.action
|
||||||
var actionAttributes = convertAction(action)
|
const actionAttributes = convertAction(action)
|
||||||
var optionMenu = []
|
const optionMenu = {
|
||||||
optionMenu = {
|
path: '/' + menu.id,
|
||||||
path: '/' + menu.getId(),
|
redirect: '/' + menu.id + '/index',
|
||||||
redirect: '/' + menu.getId() + '/index',
|
|
||||||
component: Layout,
|
component: Layout,
|
||||||
name: menu.getUuid(),
|
name: menu.uuid,
|
||||||
meta: {
|
meta: {
|
||||||
title: menu.getName(),
|
title: menu.name,
|
||||||
description: menu.getDescription(),
|
description: menu.description,
|
||||||
type: actionAttributes.name,
|
type: actionAttributes.name,
|
||||||
icon: actionAttributes.icon,
|
icon: actionAttributes.icon,
|
||||||
noCache: true,
|
noCache: true,
|
||||||
childs: []
|
childs: []
|
||||||
},
|
},
|
||||||
children: [
|
children: [{
|
||||||
{
|
path: 'index',
|
||||||
path: 'index',
|
component: actionAttributes.component,
|
||||||
component: () => import('@/views/ADempiere/Summary'),
|
name: menu.uuid + '-index',
|
||||||
name: menu.getUuid() + '-index',
|
hidden: true,
|
||||||
hidden: true,
|
meta: {
|
||||||
meta: {
|
isIndex: actionAttributes.isIndex,
|
||||||
isIndex: actionAttributes.isIndex,
|
parentUuid: menu.uuid,
|
||||||
parentUuid: menu.getUuid(),
|
title: menu.name,
|
||||||
title: menu.getName(),
|
description: menu.description,
|
||||||
description: menu.getDescription(),
|
type: actionAttributes.name,
|
||||||
type: actionAttributes.name,
|
icon: actionAttributes.icon,
|
||||||
icon: actionAttributes.icon,
|
noCache: true,
|
||||||
noCache: true,
|
breadcrumb: false,
|
||||||
breadcrumb: false,
|
childs: []
|
||||||
childs: []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
}
|
}
|
||||||
return optionMenu
|
return optionMenu
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert action to action name for route
|
|
||||||
function convertAction(action) {
|
|
||||||
var actionAttributes = {
|
|
||||||
name: '',
|
|
||||||
icon: '',
|
|
||||||
hidden: false,
|
|
||||||
isIndex: false
|
|
||||||
}
|
|
||||||
switch (action) {
|
|
||||||
case 'B':
|
|
||||||
actionAttributes.name = 'workbech'
|
|
||||||
actionAttributes.icon = 'peoples'
|
|
||||||
break
|
|
||||||
case 'F':
|
|
||||||
actionAttributes.name = 'workflow'
|
|
||||||
actionAttributes.icon = 'example'
|
|
||||||
break
|
|
||||||
case 'P':
|
|
||||||
actionAttributes.name = 'process'
|
|
||||||
actionAttributes.icon = 'component'
|
|
||||||
break
|
|
||||||
case 'R':
|
|
||||||
actionAttributes.name = 'report'
|
|
||||||
actionAttributes.icon = 'skill'
|
|
||||||
break
|
|
||||||
case 'S':
|
|
||||||
actionAttributes.name = 'browser'
|
|
||||||
actionAttributes.icon = 'search'
|
|
||||||
break
|
|
||||||
case 'T':
|
|
||||||
actionAttributes.name = 'task'
|
|
||||||
actionAttributes.icon = 'size'
|
|
||||||
break
|
|
||||||
case 'W':
|
|
||||||
actionAttributes.name = 'window'
|
|
||||||
actionAttributes.icon = 'tab'
|
|
||||||
break
|
|
||||||
case 'X':
|
|
||||||
actionAttributes.name = 'form'
|
|
||||||
actionAttributes.icon = 'form'
|
|
||||||
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
actionAttributes.name = 'summary'
|
|
||||||
actionAttributes.icon = 'nested'
|
|
||||||
// actionAttributes.hidden = true
|
|
||||||
actionAttributes.isIndex = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
return actionAttributes
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,6 +7,13 @@ const context = {
|
||||||
context: {}
|
context: {}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
/**
|
||||||
|
* Set context in state
|
||||||
|
* @param {string} payload.parentUuid
|
||||||
|
* @param {string} payload.containerUuid
|
||||||
|
* @param {string} payload.columnName
|
||||||
|
* @param {mixed} payload.value
|
||||||
|
*/
|
||||||
setContext(state, payload) {
|
setContext(state, payload) {
|
||||||
var key = ''
|
var key = ''
|
||||||
if (payload.parentUuid && !isEmptyValue(payload.value)) {
|
if (payload.parentUuid && !isEmptyValue(payload.value)) {
|
||||||
|
@ -41,6 +48,25 @@ const context = {
|
||||||
commit('setContext', itemToSetter)
|
commit('setContext', itemToSetter)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
setMultipleContextObject: ({ commit }, valuesToSetter) => {
|
||||||
|
Object.keys(valuesToSetter).forEach(key => {
|
||||||
|
commit('setContext', {
|
||||||
|
columnName: key,
|
||||||
|
value: valuesToSetter[key]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setMultipleContextMap: ({ commit }, valuesToSetter) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
valuesToSetter.forEach((value, key) => {
|
||||||
|
commit('setContext', {
|
||||||
|
columnName: key,
|
||||||
|
value: value
|
||||||
|
})
|
||||||
|
})
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
},
|
||||||
setInitialContext: ({ commit }, otherContext = {}) => {
|
setInitialContext: ({ commit }, otherContext = {}) => {
|
||||||
commit('setInitialContext', otherContext)
|
commit('setInitialContext', otherContext)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { login, logout, getInfo, getSessionInfo, changeRole } from '@/api/user'
|
import { login, logout, getInfo, getSessionInfo, changeRole } from '@/api/user'
|
||||||
import { convertRoleFromGRPC } from '@/utils/ADempiere'
|
|
||||||
import { getToken, setToken, removeToken, getCurrentRole, setCurrentRole, removeCurrentRole } from '@/utils/auth'
|
import { getToken, setToken, removeToken, getCurrentRole, setCurrentRole, removeCurrentRole } from '@/utils/auth'
|
||||||
import router, { resetRouter } from '@/router'
|
import router, { resetRouter } from '@/router'
|
||||||
import { showMessage, convertMapToArrayPairs } from '@/utils/ADempiere'
|
import { showMessage } from '@/utils/ADempiere/notification'
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
|
@ -56,22 +55,18 @@ const actions = {
|
||||||
const { userName, password } = userInfo
|
const { userName, password } = userInfo
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login({ userName: userName.trim(), password: password })
|
login({ userName: userName.trim(), password: password })
|
||||||
.then(response => {
|
.then(logInResponse => {
|
||||||
var data = {
|
const { uuid: token } = logInResponse
|
||||||
id: response.getId(),
|
|
||||||
token: response.getUuid(),
|
|
||||||
name: response.getUserinfo().getName(),
|
|
||||||
avatar: 'https://avatars1.githubusercontent.com/u/1263359?s=200&v=4',
|
|
||||||
currentRole: convertRoleFromGRPC(response.getRole()),
|
|
||||||
isProcessed: response.getProcessed()
|
|
||||||
}
|
|
||||||
|
|
||||||
commit('SET_TOKEN', data.token)
|
logInResponse.avatar = 'https://avatars1.githubusercontent.com/u/1263359?s=200&v=4'
|
||||||
commit('SET_ROL', data.currentRole)
|
logInResponse.name = logInResponse.userInfo.name
|
||||||
|
|
||||||
setToken(data.token)
|
commit('SET_TOKEN', token)
|
||||||
setCurrentRole(data.currentRole.uuid)
|
commit('SET_ROL', logInResponse.role)
|
||||||
resolve(data)
|
|
||||||
|
setToken(token)
|
||||||
|
setCurrentRole(logInResponse.role.uuid)
|
||||||
|
resolve(logInResponse)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
|
@ -83,45 +78,36 @@ const actions = {
|
||||||
sessionUuid = getToken()
|
sessionUuid = getToken()
|
||||||
}
|
}
|
||||||
return getSessionInfo(sessionUuid)
|
return getSessionInfo(sessionUuid)
|
||||||
.then(response => {
|
.then(responseGetInfo => {
|
||||||
commit('setIsSession', true)
|
commit('setIsSession', true)
|
||||||
commit('setSessionInfo', {
|
commit('setSessionInfo', {
|
||||||
id: response.getId(),
|
id: responseGetInfo.id,
|
||||||
uuid: response.getUuid(),
|
uuid: responseGetInfo.uuid,
|
||||||
name: response.getName(),
|
name: responseGetInfo.name,
|
||||||
isProcessed: response.getProcessed()
|
processed: responseGetInfo.processed
|
||||||
})
|
})
|
||||||
|
|
||||||
const userInfo = response.getUserinfo()
|
const userInfo = responseGetInfo.userInfo
|
||||||
commit('SET_NAME', userInfo.getName())
|
commit('SET_NAME', responseGetInfo.name)
|
||||||
commit('SET_INTRODUCTION', userInfo.getDescription())
|
commit('SET_INTRODUCTION', userInfo.description)
|
||||||
commit('SET_USER_UUID', userInfo.getUuid())
|
commit('SET_USER_UUID', responseGetInfo.uuid)
|
||||||
|
|
||||||
var defaultContext = convertMapToArrayPairs({
|
// TODO: return 'Y' or 'N' string values as data type Booelan (4)
|
||||||
toConvert: response.getDefaultcontextMap()
|
// TODO: return #Date as long data type Date (5)
|
||||||
})
|
responseGetInfo.defaultContextMap.set('#Date', new Date())
|
||||||
// TODO: return request #Date as long data type Date (5)
|
|
||||||
// join column names without duplicating it
|
|
||||||
defaultContext = Array.from(new Set([
|
|
||||||
...defaultContext,
|
|
||||||
...[{
|
|
||||||
columnName: '#Date',
|
|
||||||
value: new Date()
|
|
||||||
}]
|
|
||||||
]))
|
|
||||||
// set multiple context
|
// set multiple context
|
||||||
dispatch('setMultipleContext', defaultContext, {
|
dispatch('setMultipleContextMap', responseGetInfo.defaultContextMap, {
|
||||||
root: true
|
root: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const sessionResponse = {
|
const sessionResponse = {
|
||||||
name: response.getName(),
|
name: responseGetInfo.name,
|
||||||
defaultContext: defaultContext
|
defaultContext: responseGetInfo.defaultContextMap
|
||||||
}
|
}
|
||||||
return sessionResponse
|
return sessionResponse
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.warn('Error gettin context', error.message)
|
console.warn(`Error getting context session ${error.message}`)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
dispatch('getUserInfoValue', sessionUuid)
|
dispatch('getUserInfoValue', sessionUuid)
|
||||||
|
@ -133,25 +119,37 @@ const actions = {
|
||||||
sessionUuid = getToken()
|
sessionUuid = getToken()
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
getInfo(sessionUuid).then(response => {
|
getInfo(sessionUuid).then(responseGetInfo => {
|
||||||
if (!response) {
|
if (!responseGetInfo) {
|
||||||
reject('Verification failed, please Login again.')
|
reject('Verification failed, please Login again.')
|
||||||
}
|
}
|
||||||
// roles must be a non-empty array
|
// roles must be a non-empty array
|
||||||
if (!response.rolesList || response.rolesList.length <= 0) {
|
if (!responseGetInfo.rolesList || responseGetInfo.rolesList.length <= 0) {
|
||||||
reject('getInfo: roles must be a non-null array!')
|
reject('getInfo: roles must be a non-null array!')
|
||||||
}
|
}
|
||||||
|
|
||||||
var rol = response.rolesList.find(itemRol => {
|
const rol = responseGetInfo.rolesList.find(itemRol => {
|
||||||
return itemRol.uuid === getCurrentRole()
|
return itemRol.uuid === getCurrentRole()
|
||||||
})
|
})
|
||||||
|
const rolesName = responseGetInfo.rolesList.map(rolItem => {
|
||||||
|
return rolItem.name
|
||||||
|
})
|
||||||
|
|
||||||
commit('SET_ROLES_LIST', response.rolesList)
|
commit('SET_ROLES_LIST', responseGetInfo.rolesList)
|
||||||
commit('SET_ROLES', response.roles)
|
commit('SET_ROLES', rolesName)
|
||||||
commit('SET_ROL', rol)
|
commit('SET_ROL', rol)
|
||||||
commit('SET_AVATAR', response.avatar)
|
|
||||||
resolve(response)
|
// TODO: Add support from ADempiere
|
||||||
|
const avatar = 'https://avatars1.githubusercontent.com/u/1263359?s=200&v=4'
|
||||||
|
commit('SET_AVATAR', avatar)
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
...responseGetInfo,
|
||||||
|
avatar: avatar,
|
||||||
|
roles: rolesName
|
||||||
|
})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
console.warn(`Error getting user info value ${error.message}`)
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -170,7 +168,7 @@ const actions = {
|
||||||
root: true
|
root: true
|
||||||
})
|
})
|
||||||
|
|
||||||
// dispatch('tagsView/delAllViews', null, {root:true})
|
// dispatch('tagsView/delAllViews', null, { root:true })
|
||||||
removeToken()
|
removeToken()
|
||||||
removeCurrentRole()
|
removeCurrentRole()
|
||||||
resetRouter()
|
resetRouter()
|
||||||
|
@ -190,31 +188,25 @@ const actions = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// dynamically modify permissions
|
// dynamically modify permissions
|
||||||
changeRoles({ commit, state, dispatch }, roleUuid) {
|
changeRoles({ commit, dispatch }, roleUuid) {
|
||||||
/**
|
|
||||||
* @param {string} attributes.sessionUuid
|
|
||||||
* @param {string} attributes.roleUuid
|
|
||||||
* @param {string} attributes.organizationUuid
|
|
||||||
* @param {string} attributes.warehouseUuid
|
|
||||||
*/
|
|
||||||
return changeRole({
|
return changeRole({
|
||||||
sessionUuid: getToken(),
|
sessionUuid: getToken(),
|
||||||
roleUuid: roleUuid,
|
roleUuid: roleUuid,
|
||||||
organizationUuid: null,
|
organizationUuid: null,
|
||||||
warehouseUuid: null
|
warehouseUuid: null
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(changeRoleResponse => {
|
||||||
var rol = convertRoleFromGRPC(response.getRole())
|
const { role } = changeRoleResponse
|
||||||
commit('SET_ROL', rol)
|
commit('SET_ROL', role)
|
||||||
setCurrentRole(rol.uuid)
|
setCurrentRole(role.uuid)
|
||||||
commit('SET_TOKEN', response.getUuid())
|
commit('SET_TOKEN', changeRoleResponse.uuid)
|
||||||
setToken(response.getUuid())
|
setToken(changeRoleResponse.uuid)
|
||||||
|
|
||||||
// Update user info and context associated with session
|
// Update user info and context associated with session
|
||||||
dispatch('getInfo', response.getUuid())
|
dispatch('getInfo', changeRoleResponse.uuid)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
var route = router.app._route
|
const route = router.app._route
|
||||||
var selectedTag = {
|
const selectedTag = {
|
||||||
fullPath: route.fullPath,
|
fullPath: route.fullPath,
|
||||||
hash: route.hash,
|
hash: route.hash,
|
||||||
matched: route.matched,
|
matched: route.matched,
|
||||||
|
@ -235,8 +227,8 @@ const actions = {
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...rol,
|
...role,
|
||||||
sessionUuid: response.getUuid()
|
sessionUuid: changeRoleResponse.uuid
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -244,7 +236,7 @@ const actions = {
|
||||||
message: error.message,
|
message: error.message,
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
console.warn('Error change role:' + error.message + '. Code: ' + error.code)
|
console.warn(`Error change role: ${error.message}. Code: ${error.code}`)
|
||||||
})
|
})
|
||||||
// return new Promise(async resolve => {
|
// return new Promise(async resolve => {
|
||||||
// const token = role
|
// const token = role
|
||||||
|
|
|
@ -443,51 +443,59 @@ export function fieldIsDisplayed(field) {
|
||||||
return field.isActive && isDisplayedView
|
return field.isActive && isDisplayedView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert action to action name for route
|
||||||
export function convertAction(action) {
|
export function convertAction(action) {
|
||||||
var actionAttributes = {
|
const actionAttributes = {
|
||||||
name: '',
|
name: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
isIndex: false
|
isIndex: false,
|
||||||
|
component: () => import('@/views/ADempiere/Unsupported')
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'B':
|
case 'B':
|
||||||
actionAttributes.name = 'Workbench'
|
actionAttributes.name = 'workbech'
|
||||||
actionAttributes.icon = 'peoples'
|
actionAttributes.icon = 'peoples'
|
||||||
break
|
break
|
||||||
case 'F':
|
case 'F':
|
||||||
actionAttributes.name = 'Workflow'
|
actionAttributes.name = 'workflow'
|
||||||
actionAttributes.icon = 'example'
|
actionAttributes.icon = 'example'
|
||||||
break
|
break
|
||||||
case 'P':
|
case 'P':
|
||||||
actionAttributes.name = 'Process'
|
actionAttributes.name = 'process'
|
||||||
actionAttributes.icon = 'component'
|
actionAttributes.icon = 'component'
|
||||||
|
actionAttributes.component = () => import('@/views/ADempiere/Process')
|
||||||
break
|
break
|
||||||
case 'R':
|
case 'R':
|
||||||
actionAttributes.name = 'Report'
|
actionAttributes.name = 'report'
|
||||||
actionAttributes.icon = 'skill'
|
actionAttributes.icon = 'skill'
|
||||||
|
actionAttributes.component = () => import('@/views/ADempiere/Process')
|
||||||
break
|
break
|
||||||
case 'S':
|
case 'S':
|
||||||
actionAttributes.name = 'SmartBrowser'
|
actionAttributes.name = 'browser'
|
||||||
actionAttributes.icon = 'search'
|
actionAttributes.icon = 'search'
|
||||||
|
actionAttributes.component = () => import('@/views/ADempiere/Browser')
|
||||||
break
|
break
|
||||||
case 'T':
|
case 'T':
|
||||||
actionAttributes.name = 'Task'
|
actionAttributes.name = 'task'
|
||||||
actionAttributes.icon = 'size'
|
actionAttributes.icon = 'size'
|
||||||
break
|
break
|
||||||
case 'W':
|
case 'W':
|
||||||
actionAttributes.name = 'Window'
|
actionAttributes.name = 'window'
|
||||||
actionAttributes.icon = 'tab'
|
actionAttributes.icon = 'tab'
|
||||||
|
actionAttributes.component = () => import('@/views/ADempiere/Window')
|
||||||
break
|
break
|
||||||
case 'X':
|
case 'X':
|
||||||
actionAttributes.name = 'Form'
|
actionAttributes.name = 'form'
|
||||||
actionAttributes.icon = 'form'
|
actionAttributes.icon = 'form'
|
||||||
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
actionAttributes.name = 'summary'
|
actionAttributes.name = 'summary'
|
||||||
actionAttributes.icon = 'nested'
|
actionAttributes.icon = 'nested'
|
||||||
|
// actionAttributes.hidden = true
|
||||||
actionAttributes.isIndex = true
|
actionAttributes.isIndex = true
|
||||||
|
actionAttributes.component = () => import('@/views/ADempiere/Summary')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return actionAttributes
|
return actionAttributes
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
export function convertRoleFromGRPC(roleGRPC) {
|
|
||||||
return {
|
|
||||||
id: roleGRPC.getId(),
|
|
||||||
uuid: roleGRPC.getUuid(),
|
|
||||||
name: roleGRPC.getName(),
|
|
||||||
desctiption: roleGRPC.getDescription(),
|
|
||||||
clientId: roleGRPC.getClientid(),
|
|
||||||
clientName: roleGRPC.getClientname(),
|
|
||||||
organizationsList: roleGRPC.getOrganizationsList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { default } from '@/utils/ADempiere/evaluator.js'
|
export { default } from '@/utils/ADempiere/evaluator.js'
|
||||||
export * from '@/utils/ADempiere/auth.js'
|
export * from '@/utils/ADempiere/auth.js'
|
||||||
|
export * from '@/utils/ADempiere/auth.js'
|
||||||
export * from '@/utils/ADempiere/notification.js'
|
export * from '@/utils/ADempiere/notification.js'
|
||||||
export * from '@/utils/ADempiere/valueUtils.js'
|
export * from '@/utils/ADempiere/valueUtils.js'
|
||||||
export * from '@/utils/ADempiere/contextUtils.js'
|
export * from '@/utils/ADempiere/contextUtils.js'
|
||||||
|
|
|
@ -22,6 +22,8 @@ export function isEmptyValue(value) {
|
||||||
return Boolean(!value.trim().length)
|
return Boolean(!value.trim().length)
|
||||||
} else if (typeof value === 'function' || typeof value === 'number' || typeof value === 'boolean' || Object.prototype.toString.call(value) === '[object Date]') {
|
} else if (typeof value === 'function' || typeof value === 'number' || typeof value === 'boolean' || Object.prototype.toString.call(value) === '[object Date]') {
|
||||||
return false
|
return false
|
||||||
|
} else if (Object.prototype.toString.call(value) === '[object Map]' && value.size === 0) {
|
||||||
|
return true
|
||||||
} else if (Array.isArray(value)) {
|
} else if (Array.isArray(value)) {
|
||||||
return Boolean(!value.length)
|
return Boolean(!value.length)
|
||||||
} else if (typeof value === 'object') {
|
} else if (typeof value === 'object') {
|
||||||
|
|
|
@ -182,7 +182,6 @@ export default {
|
||||||
this.$store.dispatch('user/login', this.loginForm)
|
this.$store.dispatch('user/login', this.loginForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$router.push({ path: this.redirect || '/' })
|
this.$router.push({ path: this.redirect || '/' })
|
||||||
// this.loading = false
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if (error.code === 13) {
|
if (error.code === 13) {
|
||||||
|
@ -190,6 +189,8 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(this.$t('login.unexpectedError'))
|
this.$message.error(this.$t('login.unexpectedError'))
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue