1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| {% import ( "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/util" ) %}
{% func JSONModal(key string, title string, item any, indent int) %}{% stripspace %} <div id="modal-{%s key %}" class="modal" style="display: none;"> <a class="backdrop" href="#"></a> <div class="modal-content"> <div class="modal-header"> <a href="#" class="modal-close">×</a> <h2>{%s title %}</h2> </div> <div class="modal-body"> <div id="modal-{%s key %}-data" hidden="hidden" style="display:none;">{%s util.ToJSON(item) %}</div> <button onclick="clip('{%s key %}');">Copy to clipboard</button> <div class="mt">{%= JSON(item) %}</div> </div> </div> </div> <script> function clip(k) { if (!navigator.clipboard) { return; } const el = document.getElementById("modal-" + k + "-data"); navigator.clipboard.writeText(el.innerText); } </script> {% endstripspace %}{% endfunc %}
{% func JSON(v any) %}{% stripspace %} {% code b, ok := v.([]byte) if ok { _ = util.FromJSON(b, &v) } %} {% code json := util.ToJSONBytes(v, true) %} {% if len(json) > (1024 * 256) %} <div><em>This JSON is too large (<strong>{%s util.ByteSizeSI(int64(len(json))) %}</strong>), highlighting is disabled</em></div> <div class="overflow full-width"> <pre>{%s string(json) %}</pre> </div> {% else %} {% code out, err := cutil.FormatLang(string(json), util.KeyJSON) %} {% if err == nil %} <div class="overflow full-width">{%s= out %}</div> {% else %} <div class="error">{%s err.Error() %}</div> {% endif %} {% endif %} {% endstripspace %}{% endfunc %}
|