Skip to content

Commit

Permalink
change query schema editor to monaco-editor (#12458)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzx86 authored Sep 22, 2022
1 parent b70de62 commit 5c3ceaf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@await DisplayAsync(Model.Editor.Content)
}

@if (Model.Editor.Content != null)
@if (Model.Editor.Actions != null)
{
<div class="mb-3">
@await DisplayAsync(Model.Editor.Actions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@await DisplayAsync(Model.Editor.Content)
}

@if (Model.Editor.Content != null)
@if (Model.Editor.Actions != null)
{
<div class="mb-3">
@await DisplayAsync(Model.Editor.Actions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<script asp-name="codemirror" depends-on="admin" at="Foot"></script>
<script asp-name="codemirror-mode-javascript" at="Foot"></script>
<script asp-name="codemirror-mode-sql" at="Foot"></script>
<script asp-name="monaco" depends-on="admin" at="Foot"></script>

<zone Name="Title"><h1>@RenderTitleSegments(T["SQL Query"])</h1></zone>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@

<div class="mb-3">
<label asp-for="Schema">@T["Schema"]</label>
<textarea asp-for="Schema" rows="12" class="form-control" style="text-align:left"></textarea>
<textarea asp-for="Schema" hidden></textarea>
<div id="@Html.IdFor(x => x.Schema)_editor" style="min-height: 300px;" class="form-control"></div>
<span class="hint">@T["The schema the GraphQL API will use to return results."] <a class="seedoc" href="@(OrchardCore.Admin.Constants.DocsUrl)reference/modules/Queries/#graphql" target="_blank">@T["See documentation"]</a></span>
</div>
<script asp-name="monaco" depends-on="admin" at="Foot"></script>

<script at="Foot" depends-on="monaco">
$(document).ready(function () {
require(['vs/editor/editor.main'], function () {
var html = document.getElementsByTagName("html")[0];
const mutationObserver = new MutationObserver(setTheme);
mutationObserver.observe(html, { attributes: true });
function setTheme() {
var theme = html.dataset.theme;
if (theme === "darkmode") {
monaco.editor.setTheme('vs-dark')
} else {
monaco.editor.setTheme('vs')
}
}
setTheme();
var editor = monaco.editor.create(document.getElementById('@Html.IdFor(m => m.Schema)_editor'), {
automaticLayout: true,
language: "json",
lineNumbers: false,
minimap: { enabled: false }
});
var textArea = document.getElementById('@Html.IdFor(m => m.Schema)');
editor.getModel().setValue(textArea.value);
window.addEventListener("submit", function () {
textArea.value = editor.getValue();
});
});
});
</script>

0 comments on commit 5c3ceaf

Please sign in to comment.