Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
rjs_json_form
Commits
afdbbce8
Commit
afdbbce8
authored
Nov 21, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
demo/with_monaco: use url input field for online download and change schema
parent
b285566d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
59 deletions
+84
-59
demo/with_monaco/index.css
demo/with_monaco/index.css
+6
-1
demo/with_monaco/index.html
demo/with_monaco/index.html
+1
-0
demo/with_monaco/index.js
demo/with_monaco/index.js
+77
-58
No files found.
demo/with_monaco/index.css
View file @
afdbbce8
...
...
@@ -8,12 +8,17 @@
display
:
grid
;
grid-gap
:
5px
;
grid-template-columns
:
repeat
(
2
,
1
fr
);
grid-template-rows
:
50%
50%
;
grid-template-rows
:
24pt
50%
50%
;
grid-template-areas
:
"u f"
"s f"
"d f"
;
}
#monaco-schema-url
{
grid-area
:
u
;
}
#monaco-schema
{
grid-area
:
s
;
}
...
...
demo/with_monaco/index.html
View file @
afdbbce8
...
...
@@ -15,6 +15,7 @@
<body>
<div
class=
"container"
>
<input
id=
"monaco-schema-url"
type=
"text"
>
<div
id=
"monaco-schema"
></div>
<div
id=
"monaco-editor"
></div>
<div
id=
"rjs_json_form"
>
...
...
demo/with_monaco/index.js
View file @
afdbbce8
...
...
@@ -6,8 +6,7 @@
"
use strict
"
;
let
repo
=
"
nexedi/slapos
"
;
let
branch
=
"
master
"
;
const
baseUrl
=
`https://lab.nexedi.com/
${
repo
}
/raw/
${
branch
}
/software/erp5/`
;
const
mainSchema
=
"
instance-erp5-input-schema.json
"
;
const
defaultSchema
=
`https://lab.nexedi.com/
${
repo
}
/raw/
${
branch
}
/software/kvm/instance-kvm-input-schema.json`
;
let
monacoSchemaEditor
;
let
monacoEditor
;
...
...
@@ -36,6 +35,19 @@ importScripts('https://unpkg.com/monaco-editor@0.15.5/min/vs/base/worker/workerM
window
.
MonacoEnvironment
=
{
getWorkerUrl
:
()
=>
proxy
};
const
getSchema
=
(
schemaUrl
,
mappedUrl
)
=>
{
return
fetch
(
schemaUrl
)
.
then
(
resp
=>
{
return
resp
.
json
();
})
.
then
(
s
=>
{
return
{
uri
:
mappedUrl
||
schemaUrl
,
schema
:
s
};
});
};
rJS
(
window
)
.
allowPublicAcquisition
(
"
notifyValid
"
,
function
(
arr
,
scope
)
{
})
...
...
@@ -53,102 +65,109 @@ importScripts('https://unpkg.com/monaco-editor@0.15.5/min/vs/base/worker/workerM
});
})
.
ready
(
function
()
{
let
gadget
=
this
;
let
g
=
this
;
g
.
props
=
{};
document
.
getElementById
(
"
monaco-schema-url
"
).
value
=
defaultSchema
;
require
([
"
vs/editor/editor.main
"
],
function
(
monaco
)
{
let
modelUri
=
monaco
.
Uri
.
parse
(
"
tmp://xxx.json
"
);
// a made up unique URI for our model
let
model
=
monaco
.
editor
.
createModel
(
"
{
\n
}
"
,
"
json
"
,
modelUri
);
const
getSchema
=
(
schemaUrl
,
mappedUrl
)
=>
{
return
fetch
(
schemaUrl
)
.
then
(
resp
=>
{
return
resp
.
json
();
})
.
then
(
s
=>
{
return
{
uri
:
mappedUrl
||
schemaUrl
,
schema
:
s
};
});
};
g
.
props
.
monaco
=
monaco
;
g
.
props
.
modelUri
=
monaco
.
Uri
.
parse
(
"
tmp://xxx.json
"
);
// a made up unique URI for our model
let
model
=
monaco
.
editor
.
createModel
(
"
{
\n
}
"
,
"
json
"
,
g
.
props
.
modelUri
);
Promise
.
all
([
getSchema
(
baseUrl
+
mainSchema
).
then
(
s
=>
{
s
.
fileMatch
=
[
modelUri
.
toString
()];
// this is the main schema associated to the model
return
s
;
}),
getSchema
(
"
../../json-schema/schema7.json
"
,
"
http://json-schema.org/draft-07/schema
"
)
]).
then
(
schemas
=>
{
gadget
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
g
=>
{
return
g
.
render
({
key
:
"
rjs_json_form
"
,
schema
:
schemas
[
0
].
schema
,
schema_url
:
schemas
[
0
].
uri
,
value
:
{}
});
});
g
.
props
.
baseSchemas
=
schemas
;
monaco
.
languages
.
json
.
jsonDefaults
.
setDiagnosticsOptions
({
validate
:
true
,
enableSchemaRequest
:
true
,
schemas
:
schemas
});
monacoSchemaEditor
=
monaco
.
editor
.
create
(
document
.
getElementById
(
"
monaco-schema
"
),
monacoEditor
=
monaco
.
editor
.
create
(
document
.
getElementById
(
"
monaco-editor
"
),
{
model
:
mo
naco
.
editor
.
createModel
(
JSON
.
stringify
(
schemas
[
0
].
schema
,
null
,
2
),
"
json
"
,
schemas
[
0
].
uri
)
model
:
mo
del
}
);
monaco
Schema
Editor
.
onDidChangeModelContent
(
e
=>
{
monacoEditor
.
onDidChangeModelContent
(
e
=>
{
if
(
!
monacoIgnoreEvent
)
{
console
.
log
(
"
schema
changed
"
,
monacoEditor
.
getValue
());
console
.
log
(
"
monaco
changed
"
,
monacoEditor
.
getValue
());
let
parsed
;
try
{
parsed
=
JSON
.
parse
(
monaco
Schema
Editor
.
getValue
());
parsed
=
JSON
.
parse
(
monacoEditor
.
getValue
());
}
catch
(
error
)
{
console
.
error
(
"
parse error, ignoring changes from monaco
"
,
error
);
return
;
}
g
adget
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
g
=>
{
g
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
g
=>
{
return
g
.
render
({
key
:
"
rjs_json_form
"
,
schema
:
parsed
,
schema_url
:
schemas
[
0
].
uri
,
value
:
parsed
});
});
}
});
monacoEditor
=
monaco
.
editor
.
create
(
document
.
getElementById
(
"
monaco-editor
"
),
g
.
changeState
({
url
:
defaultSchema
});
});
});
})
.
onStateChange
(
function
()
{
let
g
=
this
;
return
getSchema
(
g
.
state
.
url
).
then
(
s
=>
{
s
.
fileMatch
=
[
g
.
props
.
modelUri
.
toString
()];
// this is the main schema associated to the model
return
s
;
}).
then
(
schema
=>
{
g
.
props
.
monaco
.
languages
.
json
.
jsonDefaults
.
setDiagnosticsOptions
({
validate
:
true
,
enableSchemaRequest
:
true
,
schemas
:
[
schema
].
concat
(
g
.
props
.
baseSchemas
)
});
monacoIgnoreEvent
=
true
;
if
(
monacoSchemaEditor
)
{
monacoSchemaEditor
.
getModel
()
.
setValue
(
JSON
.
stringify
(
schema
.
schema
,
null
,
4
));
}
else
{
monacoSchemaEditor
=
g
.
props
.
monaco
.
editor
.
create
(
document
.
getElementById
(
"
monaco-schema
"
),
{
model
:
model
model
:
g
.
props
.
monaco
.
editor
.
createModel
(
JSON
.
stringify
(
schema
.
schema
,
null
,
4
),
"
json
"
,
schema
.
uri
)
}
);
monacoEditor
.
onDidChangeModelContent
(
e
=>
{
monaco
Schema
Editor
.
onDidChangeModelContent
(
e
=>
{
if
(
!
monacoIgnoreEvent
)
{
console
.
log
(
"
monaco
changed
"
,
monacoEditor
.
getValue
());
console
.
log
(
"
schema
changed
"
,
monacoEditor
.
getValue
());
let
parsed
;
try
{
parsed
=
JSON
.
parse
(
monacoEditor
.
getValue
());
parsed
=
JSON
.
parse
(
monaco
Schema
Editor
.
getValue
());
}
catch
(
error
)
{
console
.
error
(
"
parse error, ignoring changes from monaco
"
,
error
);
return
;
}
g
adget
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
g
=>
{
g
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
g
=>
{
return
g
.
render
({
key
:
"
rjs_json_form
"
,
schema
:
schemas
[
0
].
schema
,
schema_url
:
schemas
[
0
].
uri
,
value
:
parsed
schema
:
parsed
});
});
}
});
}
monacoIgnoreEvent
=
false
;
return
g
.
getDeclaredGadget
(
"
rjs_json_form
"
).
then
(
gadget
=>
{
return
gadget
.
render
({
key
:
"
rjs_json_form
"
,
schema
:
schema
.
schema
,
schema_url
:
g
.
state
.
url
});
});
});
})
.
catch
(
e
=>
{
});
})
.
onEvent
(
'
input
'
,
function
(
evt
)
{
if
(
evt
.
target
.
id
===
"
monaco-schema-url
"
)
{
return
this
.
changeState
({
url
:
evt
.
target
.
value
});
}
});
}(
window
,
document
,
rJS
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment