Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change query schema editor to monaco-editor #12458

Merged
merged 9 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,3 +1,5 @@

hyzx86 marked this conversation as resolved.
Show resolved Hide resolved

@model EditQueryViewModel

<div class="mb-3" asp-validation-class-for="Name">
Expand All @@ -10,6 +12,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 rows="12" class="form-control" style="text-align:left"></textarea>
<div id="@Html.IdFor(x=>x.Schema)_editor" style="min-height: 300px;" class="form-control"></div>
Skrypt marked this conversation as resolved.
Show resolved Hide resolved
<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>