Skip to content

Commit 2513683

Browse files
authored
ui: allow docHelp override using config.json (#4745)
config.json can have a property named 'docHelpMappings' which can be used to override docHelp suffixes. In config.json admin can add mappings as follows: "docHelpMappings": { "virtual_machine.html": "some.html", "some_string": "override_string" } UI will use these mappings and will make appropriate replacements in the documentation links for different sections and forms. Addresses #4731 Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent dc5b9ec commit 2513683

6 files changed

Lines changed: 31 additions & 6 deletions

File tree

ui/public/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"jp": "label.japanese.keyboard",
4747
"sc": "label.simplified.chinese.keyboard"
4848
},
49+
"docHelpMappings": {},
4950
"plugins": []
5051
}

ui/src/components/view/ActionButton.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export default {
134134
methods: {
135135
execAction (action) {
136136
action.resource = this.resource
137+
if (action.docHelp) {
138+
action.docHelp = this.$applyDocHelpMappings(action.docHelp)
139+
}
137140
this.$emit('exec-action', action)
138141
},
139142
handleShowBadge () {

ui/src/config/router.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function generateRouterMap (section) {
4242
name: section.name,
4343
path: '/' + section.name,
4444
hidden: section.hidden,
45-
meta: { title: section.title, icon: section.icon, docHelp: section.docHelp, searchFilters: section.searchFilters },
45+
meta: { title: section.title, icon: section.icon, docHelp: Vue.prototype.$applyDocHelpMappings(section.docHelp), searchFilters: section.searchFilters },
4646
component: RouteView
4747
}
4848

@@ -63,7 +63,7 @@ function generateRouterMap (section) {
6363
title: child.title,
6464
name: child.name,
6565
icon: child.icon,
66-
docHelp: child.docHelp,
66+
docHelp: Vue.prototype.$applyDocHelpMappings(child.docHelp),
6767
permission: child.permission,
6868
resourceType: child.resourceType,
6969
filters: child.filters,
@@ -85,7 +85,7 @@ function generateRouterMap (section) {
8585
title: child.title,
8686
name: child.name,
8787
icon: child.icon,
88-
docHelp: child.docHelp,
88+
docHelp: Vue.prototype.$applyDocHelpMappings(child.docHelp),
8989
permission: child.permission,
9090
resourceType: child.resourceType,
9191
params: child.params ? child.params : {},
@@ -140,7 +140,7 @@ function generateRouterMap (section) {
140140
title: section.title,
141141
name: section.name,
142142
icon: section.icon,
143-
docHelp: section.docHelp,
143+
docHelp: Vue.prototype.$applyDocHelpMappings(section.docHelp),
144144
hidden: section.hidden,
145145
permission: section.permission,
146146
resourceType: section.resourceType,

ui/src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import './core/lazy_use'
2626
import './core/ext'
2727
import './permission' // permission control
2828
import './utils/filter' // global filter
29-
import { pollJobPlugin, notifierPlugin, toLocaleDatePlugin } from './utils/plugins'
29+
import { pollJobPlugin, notifierPlugin, toLocaleDatePlugin, configUtilPlugin } from './utils/plugins'
3030
import { VueAxios } from './utils/request'
3131

3232
Vue.config.productionTip = false
@@ -49,3 +49,5 @@ fetch('config.json').then(response => response.json()).then(config => {
4949
}).$mount('#app')
5050
})
5151
})
52+
53+
Vue.use(configUtilPlugin)

ui/src/utils/plugins.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,21 @@ export const toLocaleDatePlugin = {
167167
}
168168
}
169169
}
170+
171+
export const configUtilPlugin = {
172+
install (Vue) {
173+
Vue.prototype.$applyDocHelpMappings = function (docHelp) {
174+
var docHelpMappings = this.$config.docHelpMappings
175+
if (docHelp && docHelpMappings &&
176+
docHelpMappings.constructor === Object && Object.keys(docHelpMappings).length > 0) {
177+
for (var key in docHelpMappings) {
178+
if (docHelp.includes(key)) {
179+
docHelp = docHelp.replace(key, docHelpMappings[key])
180+
break
181+
}
182+
}
183+
}
184+
return docHelp
185+
}
186+
}
187+
}

ui/tests/common/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import mockRouter from '../mock/mockRouter'
2121

2222
import localVue from '../setup'
2323
import { mount } from '@vue/test-utils'
24-
import { pollJobPlugin, notifierPlugin } from '@/utils/plugins'
24+
import { pollJobPlugin, notifierPlugin, configUtilPlugin } from '@/utils/plugins'
2525

2626
localVue.use(pollJobPlugin)
2727
localVue.use(notifierPlugin)
28+
localVue.use(configUtilPlugin)
2829

2930
function createMockRouter (newRoutes = []) {
3031
let routes = []

0 commit comments

Comments
 (0)