diff --git a/resources/views/forms/components/json-input.blade.php b/resources/views/forms/components/json-input.blade.php index 7a86e6e..76158f2 100644 --- a/resources/views/forms/components/json-input.blade.php +++ b/resources/views/forms/components/json-input.blade.php @@ -11,7 +11,7 @@
diff --git a/resources/views/infolists/components/json-entry.blade.php b/resources/views/infolists/components/json-entry.blade.php index 8542c4f..ffcd05e 100644 --- a/resources/views/infolists/components/json-entry.blade.php +++ b/resources/views/infolists/components/json-entry.blade.php @@ -6,28 +6,62 @@
{ + var count = undefined; + + // Get open / close token + var startToken = '{', endToken = '}'; + var prevLine = codeMirrorEditor.getLine(from.line); + if (prevLine.lastIndexOf('[') > prevLine.lastIndexOf('{')) { + startToken = '[', endToken = ']'; + } + + // Get json content + var internal = codeMirrorEditor.getRange(from, to); + var toParse = startToken + internal + endToken; + + // Get key count + try { + var parsed = JSON.parse(toParse); + count = Object.keys(parsed).length; + } catch(e) { } + + return count ? `\u21A4${count}\u21A6` : '\u2194'; + } + } }); - codeMirrorEditor.setSize(null, '100%'); - codeMirrorEditor.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}'); + {{ str_replace('.', '', $getId()) }}.setSize(null, '100%'); + {{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}'); setTimeout(function() { - codeMirrorEditor.refresh(); + {{ str_replace('.', '', $getId()) }}.refresh(); }, 1); " >