MNT-20500 - Admin console breaks with serialised objects (#291)

* Added macro convertToJSON to recursively parse hashes and enumerables
* Added attempt/recover in macros to handle errors and not break the page
* Changed the output of serialized objects to JSON format
This commit is contained in:
evasques
2021-04-05 17:52:15 +01:00
committed by GitHub
parent 34f360211f
commit ce62fb1da3

View File

@@ -4,31 +4,71 @@
<#macro dateFormat date>${date?string("dd MMM yyyy HH:mm:ss 'GMT'Z '('zzz')'")}</#macro> <#macro dateFormat date>${date?string("dd MMM yyyy HH:mm:ss 'GMT'Z '('zzz')'")}</#macro>
<#macro propValue p> <#macro propValue p>
<#if p.value??> <#attempt>
<#if p.value?is_date> <#if p.value??>
<@dateFormat p.value /> <#if p.value?is_date>
<#elseif p.value?is_boolean> <@dateFormat p.value />
${p.value?string} <#elseif p.value?is_boolean>
<#elseif p.value?is_number> ${p.value?string}
${p.value?c} <#elseif p.value?is_number>
<#elseif p.value?is_string> ${p.value?c}
${p.value?html} <#elseif p.value?is_string>
<#elseif p.value?is_hash> ${p.value?html}
<#assign result = "{"/> <#elseif p.value?is_hash || p.value?is_enumerable>
<#assign first = true /> <@convertToJSON p.value />
<#list p.value?keys as key> </#if>
<#if first = false> <#else>
<#assign result = result + ", "/> ${null}
</#if>
<#recover>
<span style="color:red">${.error}</span>
</#attempt>
</#macro>
<#macro convertToJSON v>
<#attempt>
<#if v??>
<#if v?is_date>
<@dateFormat v />
<#elseif v?is_boolean>
${v?string}
<#elseif v?is_number>
${v?c}
<#elseif v?is_string>
"${v?string}"
<#elseif v?is_hash>
<@compress single_line=true>
{
<#assign first = true />
<#list v?keys as key>
<#if first = false>,</#if>
"${key}":
<#if v[key]??>
<@convertToJSON v[key] />
<#else>
${null}
</#if>
<#assign first = false/>
</#list>
}
</@compress>
<#elseif v?is_enumerable>
<#assign first = true />
<@compress single_line=true>
[
<#list v as item>
<#if first = false>,</#if>
<@convertToJSON item />
<#assign first = false/>
</#list>
]
</@compress>
</#if> </#if>
<#assign result = result + "${key}=${p.value[key]?html}" /> <#else>
<#assign first = false/> ${null}
</#list> </#if>
<#assign result = result + "}"/> <#recover>
${result} <span style="color:red">${.error}</span>
</#if> </#attempt>
<#else>
${null}
</#if>
</#macro> </#macro>
<#macro contentUrl nodeRef prop> <#macro contentUrl nodeRef prop>
${url.serviceContext}/api/node/${nodeRef?replace("://","/")}/content;${prop?url} ${url.serviceContext}/api/node/${nodeRef?replace("://","/")}/content;${prop?url}