Skip to content

Commit 7aed223

Browse files
committed
Fix test connection page
The image replace functionality broke and early-outed the whole ajax handling CMK-28892 Change-Id: I45087d55884f7099bbc5241ff9ef881a32d5f38d
1 parent 523ebb8 commit 7aed223

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cmk/gui/htmllib/html.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ def render_static_icon(
13011301
component_name="cmk-static-icon",
13021302
data=asdict_strip_none(StaticIconAppProps(icon=icon.icon, title=title, size=size)),
13031303
class_=css_classes,
1304+
id_=id_,
13041305
)
13051306

13061307
def static_icon(

packages/cmk-frontend/src/js/modules/host_diagnose.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ export function getFirstElementByNameAsInput(name: string): HTMLInputElement {
1010
return document.getElementsByName(name)[0] as HTMLInputElement
1111
}
1212

13+
function replaceIcon(img: HTMLImageElement, new_icon: string) {
14+
const imgData = img.getAttribute('data')
15+
if (imgData) {
16+
img.setAttribute('data', imgData.replace(/(.*"icon": ").*(".*)/, `$1${new_icon}$2`))
17+
}
18+
}
19+
1320
export function start_test(ident: string, hostname: string, transid: string) {
1421
const log = document.getElementById(ident + '_log') as HTMLImageElement
1522
const img = document.getElementById(ident + '_img') as HTMLImageElement
@@ -84,7 +91,7 @@ export function start_test(ident: string, hostname: string, transid: string) {
8491
'&snmp_retries=' +
8592
encodeURIComponent(getFirstElementByNameAsInput('vs_rules_p_snmp_retries').value)
8693

87-
img.src = img.src.replace(/(.*\/icon_).*(\.svg$)/i, '$1reload$2')
94+
replaceIcon(img, 'reload')
8895
add_class(img, 'reloading')
8996

9097
log.innerHTML = '...'
@@ -124,10 +131,10 @@ function handle_host_diag_result(data: { hostname: string; ident: string }, resp
124131
text = response.result.output
125132
}
126133

127-
img.src = img.src.replace(/(.*\/icon_).*(\.svg$)/i, '$1' + new_icon + '$2')
134+
replaceIcon(img, new_icon)
128135
log.innerText = text
129136

130-
retry.src = retry.src.replace(/(.*\/icon_).*(\.svg$)/i, '$1reload$2')
137+
replaceIcon(retry, 'reload')
131138
retry.style.display = 'inline'
132139
;(retry.parentNode as HTMLAnchorElement).href =
133140
`javascript:cmk.host_diagnose.start_test(${data.ident}, ${data.hostname}, ${response.result.next_transid});`

0 commit comments

Comments
 (0)