Skip to content

Commit 4b86656

Browse files
committed
ui: allow docHelp override using config.json
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 f8ad3ad commit 4b86656

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

ui/public/config.json

Lines changed: 2 additions & 1 deletion
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-
"plugins": []
49+
"plugins": [],
50+
"docHelpMappings": {}
5051
}

ui/src/components/widgets/Breadcrumb.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<a
4646
v-if="item.meta.docHelp"
4747
style="margin-right: 12px"
48-
:href="$config.docBase + '/' + $route.meta.docHelp"
48+
:href="$config.docBase + '/' + docHelp"
4949
target="_blank">
5050
<a-icon type="question-circle-o"></a-icon>
5151
</a>
@@ -72,6 +72,7 @@ export default {
7272
data () {
7373
return {
7474
name: '',
75+
docHelp: '',
7576
breadList: []
7677
}
7778
},
@@ -86,6 +87,7 @@ export default {
8687
methods: {
8788
getBreadcrumb () {
8889
this.name = this.$route.name
90+
this.docHelp = this.$applyDocHelpMappings(this.$route.meta.docHelp)
8991
this.breadList = []
9092
this.$route.matched.forEach((item) => {
9193
if (item && item.parent && item.parent.name !== 'index' && !item.path.endsWith(':id')) {

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,22 @@ export const toLocaleDatePlugin = {
167167
}
168168
}
169169
}
170+
171+
export const configUtilPlugin = {
172+
install (Vue) {
173+
Vue.prototype.$applyDocHelpMappings = function (docHelp) {
174+
var helpDocMappings = this.$config.helpDocMappings
175+
if (docHelp !== null && docHelp !== undefined && docHelp !== '' &&
176+
helpDocMappings !== null && helpDocMappings !== undefined &&
177+
helpDocMappings.constructor === Object && Object.keys(helpDocMappings).length > 0) {
178+
for (var key in helpDocMappings) {
179+
if (docHelp.includes(key)) {
180+
docHelp = docHelp.replace(key, helpDocMappings[key])
181+
break
182+
}
183+
}
184+
}
185+
return docHelp
186+
}
187+
}
188+
}

ui/src/views/AutogenView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<a
104104
v-if="currentAction.docHelp || $route.meta.docHelp"
105105
style="margin-left: 5px"
106-
:href="$config.docBase + '/' + (currentAction.docHelp || $route.meta.docHelp)"
106+
:href="$config.docBase + '/' + this.$applyDocHelpMappings(currentAction.docHelp || $route.meta.docHelp)"
107107
target="_blank">
108108
<a-icon type="question-circle-o"></a-icon>
109109
</a>

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)