Skip to content

Commit

Permalink
Set Values on the System or Session Page (PanJiaChen#2319)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsiosanchez authored Jun 4, 2024
1 parent 3e6a1b3 commit 6c0cd48
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 55 deletions.
Binary file removed public/img/icons/favicon-16x16.png
Binary file not shown.
Binary file removed public/img/icons/favicon-32x32.png
Binary file not shown.
20 changes: 0 additions & 20 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@ export default {
return 'ADempiere'
}
},
watch: {
getResourceName(value) {
this.loadImage()
}
},
async mounted() {
const link = document.createElement('link')
link.rel = 'shortcut icon'
link.type = 'image/x-icon'
link.href = this.defaultImageLogo
document.title = this.nameSystem
document.head.appendChild(link)
this.$nextTick(() => {
window.addEventListener('resize', this.getWindowWidth)
window.addEventListener('resize', this.getWindowHeight)
Expand All @@ -64,14 +52,6 @@ export default {
window.removeEventListener('resize', this.getWindowHeight)
},
methods: {
async loadImage() {
const link = document.createElement('link')
link.rel = 'shortcut icon'
link.type = 'image/x-icon'
link.href = this.defaultImageLogo
document.title = this.nameSystem
document.head.appendChild(link)
},
getWindowWidth(event) {
this.$store.dispatch('setWidth', document.documentElement.clientWidth)
},
Expand Down
15 changes: 9 additions & 6 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title'
import getPageFavicon from '@/utils/get-page-favicon'
import { setSystemValues, setSessionValues } from '@/utils/set-value-page.js'
import { isEmptyValue } from '@/utils/ADempiere'

NProgress.configure({ showSpinner: false }) // NProgress Configuration
Expand All @@ -15,15 +14,15 @@ const whiteList = ['/login', '/userEnrollment', '/createPassword', '/forgotPassw
router.beforeEach(async(to, from, next) => {
// start progress bar
NProgress.start()
const link = getPageFavicon()
document.head.appendChild(link)
// set page title
document.title = getPageTitle(to.meta.title)

// determine whether the user has logged in
const hasToken = getToken()

if (hasToken) {
// Set Page Title and Favicon
setSessionValues({
routeName: to.meta.title
})
if (to.path === '/login') {
// if is logged in, redirect to the home page
next({ path: '/' })
Expand Down Expand Up @@ -66,6 +65,10 @@ router.beforeEach(async(to, from, next) => {
}
}
} else {
// Set Page Title and Favicon
setSystemValues({
routeName: to.meta.title
})
/* has no token*/
if (whiteList.includes(to.path)) {
// in the free login whitelist, go directly
Expand Down
13 changes: 0 additions & 13 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,19 +727,6 @@ const actions = {
...info,
name: systemName
})
// tab browser title
window.document.title = response.name

// tab browser favicon
if (!isEmptyValue(info.logoUrl)) {
let link = document.querySelector("link[rel~='icon']")
if (!link) {
link = document.createElement('link')
link.rel = 'icon'
document.head.appendChild(link)
}
link.href = info.logoUrl
}

resolve(info)
})
Expand Down
12 changes: 0 additions & 12 deletions src/utils/get-page-favicon.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/utils/get-page-title.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import defaultSettings from '@/settings'
import i18n from '@/lang'
import store from '@/store'

export default function getPageTitle(key) {
const { name } = store.getters['user/getSystem']
const title = name || defaultSettings.title
export default function getPageTitle({
key,
nameSystem
}) {
const title = nameSystem || defaultSettings.title
const hasKey = i18n.te(`route.${key}`)
if (hasKey) {
const pageName = i18n.t(`route.${key}`)
Expand Down
76 changes: 76 additions & 0 deletions src/utils/set-value-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import store from '@/store'
// Constants
import { config } from '@/utils/ADempiere/config'
// Utils and Helper Methods
import getPageTitle from '@/utils/get-page-title'
import { getResourcePath } from '@/utils/ADempiere/resource'
import { isEmptyValue } from '@/utils/ADempiere'

function getPageFavicon({
logo
}) {
let link = document.querySelector("link[rel~='icon']")
if (!link) {
link = document.createElement('link')
link.rel = 'icon'
}
link.href = logo
document.head.appendChild(link)
return link
}

// function getFaviconClient() {}
/**
* Get System Information (System Logo and System Name)
*/
export function setSystemValues({
routeName
}) {
store.dispatch('user/system')
.then(response => {
const {
name,
logoUrl
} = response
// Set Page Title and Favicon
document.title = getPageTitle({
key: routeName,
nameSystem: name
})
const link = getPageFavicon({ logo: logoUrl })
document.head.appendChild(link)
})
}

/**
* Get Session Information (Session Logo, User Logo and Session Name)
*/
export function setSessionValues({
routeName
}) {
const {
client
} = store.getters['user/getRole']
const nameSystem = client ? client.name : ''
// Set Page Title
document.title = getPageTitle({
key: routeName,
nameSystem
})

if (isEmptyValue(client)) return
getResourcePath({
clientId: client.id,
containerId: '109',
containerType: 'resource',
columnName: 'Logo_ID',
recordId: client.id,
tableName: 'AD_ClientInfo'
})
.then(response => {
if (isEmptyValue(response)) return
// Set Page Favicon
const link = getPageFavicon({ logo: config.adempiere.resource.url + response })
document.head.appendChild(link)
})
}

0 comments on commit 6c0cd48

Please sign in to comment.