github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/views/components/JSON.html.go (about) 1 // Code generated by qtc from "JSON.html". DO NOT EDIT. 2 // See https://github.com/valyala/quicktemplate for details. 3 4 // <!-- Content managed by Project Forge, see [projectforge.md] for details. --> 5 6 //line views/components/JSON.html:2 7 package components 8 9 //line views/components/JSON.html:2 10 import ( 11 "github.com/kyleu/dbaudit/app/controller/cutil" 12 "github.com/kyleu/dbaudit/app/util" 13 ) 14 15 //line views/components/JSON.html:7 16 import ( 17 qtio422016 "io" 18 19 qt422016 "github.com/valyala/quicktemplate" 20 ) 21 22 //line views/components/JSON.html:7 23 var ( 24 _ = qtio422016.Copy 25 _ = qt422016.AcquireByteBuffer 26 ) 27 28 //line views/components/JSON.html:7 29 func StreamJSONModal(qw422016 *qt422016.Writer, key string, title string, item any, indent int) { 30 //line views/components/JSON.html:7 31 qw422016.N().S(`<div id="modal-`) 32 //line views/components/JSON.html:8 33 qw422016.E().S(key) 34 //line views/components/JSON.html:8 35 qw422016.N().S(`" 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>`) 36 //line views/components/JSON.html:13 37 qw422016.E().S(title) 38 //line views/components/JSON.html:13 39 qw422016.N().S(`</h2></div><div class="modal-body"><div id="modal-`) 40 //line views/components/JSON.html:16 41 qw422016.E().S(key) 42 //line views/components/JSON.html:16 43 qw422016.N().S(`-data" hidden="hidden" style="display:none;">`) 44 //line views/components/JSON.html:16 45 qw422016.E().S(util.ToJSON(item)) 46 //line views/components/JSON.html:16 47 qw422016.N().S(`</div><button onclick="clip('`) 48 //line views/components/JSON.html:17 49 qw422016.E().S(key) 50 //line views/components/JSON.html:17 51 qw422016.N().S(`');">Copy to clipboard</button>`) 52 //line views/components/JSON.html:18 53 StreamJSON(qw422016, item) 54 //line views/components/JSON.html:18 55 qw422016.N().S(`</div></div></div><script>function clip(k) {if (!navigator.clipboard) {return;}const el = document.getElementById("modal-" + k + "-data");navigator.clipboard.writeText(el.innerText);}</script>`) 56 //line views/components/JSON.html:31 57 } 58 59 //line views/components/JSON.html:31 60 func WriteJSONModal(qq422016 qtio422016.Writer, key string, title string, item any, indent int) { 61 //line views/components/JSON.html:31 62 qw422016 := qt422016.AcquireWriter(qq422016) 63 //line views/components/JSON.html:31 64 StreamJSONModal(qw422016, key, title, item, indent) 65 //line views/components/JSON.html:31 66 qt422016.ReleaseWriter(qw422016) 67 //line views/components/JSON.html:31 68 } 69 70 //line views/components/JSON.html:31 71 func JSONModal(key string, title string, item any, indent int) string { 72 //line views/components/JSON.html:31 73 qb422016 := qt422016.AcquireByteBuffer() 74 //line views/components/JSON.html:31 75 WriteJSONModal(qb422016, key, title, item, indent) 76 //line views/components/JSON.html:31 77 qs422016 := string(qb422016.B) 78 //line views/components/JSON.html:31 79 qt422016.ReleaseByteBuffer(qb422016) 80 //line views/components/JSON.html:31 81 return qs422016 82 //line views/components/JSON.html:31 83 } 84 85 //line views/components/JSON.html:33 86 func StreamJSON(qw422016 *qt422016.Writer, v any) { 87 //line views/components/JSON.html:35 88 b, ok := v.([]byte) 89 if ok { 90 _ = util.FromJSON(b, &v) 91 } 92 93 //line views/components/JSON.html:40 94 json := util.ToJSONBytes(v, true) 95 96 //line views/components/JSON.html:41 97 if len(json) > (1024 * 256) { 98 //line views/components/JSON.html:41 99 qw422016.N().S(`<div class="mt"><em>This JSON is too large (<strong>`) 100 //line views/components/JSON.html:42 101 qw422016.E().S(util.ByteSizeSI(int64(len(json)))) 102 //line views/components/JSON.html:42 103 qw422016.N().S(`</strong>), highlighting is disabled</em></div><div class="mt overflow full-width"><pre>`) 104 //line views/components/JSON.html:44 105 qw422016.E().S(string(json)) 106 //line views/components/JSON.html:44 107 qw422016.N().S(`</pre></div>`) 108 //line views/components/JSON.html:46 109 } else { 110 //line views/components/JSON.html:47 111 out, err := cutil.FormatLang(string(json), "json") 112 113 //line views/components/JSON.html:48 114 if err == nil { 115 //line views/components/JSON.html:48 116 qw422016.N().S(`<div class="mt overflow full-width">`) 117 //line views/components/JSON.html:49 118 qw422016.N().S(out) 119 //line views/components/JSON.html:49 120 qw422016.N().S(`</div>`) 121 //line views/components/JSON.html:50 122 } else { 123 //line views/components/JSON.html:50 124 qw422016.N().S(`<div class="mt error">`) 125 //line views/components/JSON.html:51 126 qw422016.E().S(err.Error()) 127 //line views/components/JSON.html:51 128 qw422016.N().S(`</div>`) 129 //line views/components/JSON.html:52 130 } 131 //line views/components/JSON.html:53 132 } 133 //line views/components/JSON.html:54 134 } 135 136 //line views/components/JSON.html:54 137 func WriteJSON(qq422016 qtio422016.Writer, v any) { 138 //line views/components/JSON.html:54 139 qw422016 := qt422016.AcquireWriter(qq422016) 140 //line views/components/JSON.html:54 141 StreamJSON(qw422016, v) 142 //line views/components/JSON.html:54 143 qt422016.ReleaseWriter(qw422016) 144 //line views/components/JSON.html:54 145 } 146 147 //line views/components/JSON.html:54 148 func JSON(v any) string { 149 //line views/components/JSON.html:54 150 qb422016 := qt422016.AcquireByteBuffer() 151 //line views/components/JSON.html:54 152 WriteJSON(qb422016, v) 153 //line views/components/JSON.html:54 154 qs422016 := string(qb422016.B) 155 //line views/components/JSON.html:54 156 qt422016.ReleaseByteBuffer(qb422016) 157 //line views/components/JSON.html:54 158 return qs422016 159 //line views/components/JSON.html:54 160 }