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
Jérome Perrin
rjs_json_form
Commits
e59f79f6
Commit
e59f79f6
authored
Apr 06, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add schema_path and so fix base_url computation
parent
c4a0f84d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
16 deletions
+54
-16
gadget_json_generated_form.js
gadget_json_generated_form.js
+54
-16
No files found.
gadget_json_generated_form.js
View file @
e59f79f6
...
@@ -162,6 +162,7 @@
...
@@ -162,6 +162,7 @@
}
}
return
form_gadget
.
renderForm
({
return
form_gadget
.
renderForm
({
schema
:
options
.
schema_part
,
schema
:
options
.
schema_part
,
schema_path
:
options
.
schema_path
,
document
:
options
.
default_dict
,
document
:
options
.
default_dict
,
display_label
:
options
.
parent_type
!==
"
array
"
,
display_label
:
options
.
parent_type
!==
"
array
"
,
scope
:
scope
scope
:
scope
...
@@ -169,7 +170,7 @@
...
@@ -169,7 +170,7 @@
});
});
}
}
function
render_array
(
gadget
,
json_field
,
default_array
,
root
,
path
)
{
function
render_array
(
gadget
,
json_field
,
default_array
,
root
,
path
,
schema_path
)
{
var
queue
=
RSVP
.
Queue
(),
var
queue
=
RSVP
.
Queue
(),
div
,
div
,
div_input
,
div_input
,
...
@@ -206,6 +207,7 @@
...
@@ -206,6 +207,7 @@
gadget
:
gadget
,
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_type
:
'
array
'
,
element
:
input
,
element
:
input
,
schema_path
:
schema_path
+
'
/items
'
,
schema_part
:
item_schema
schema_part
:
item_schema
})
})
.
push
(
element_append
);
.
push
(
element_append
);
...
@@ -228,6 +230,7 @@
...
@@ -228,6 +230,7 @@
parent_type
:
'
array
'
,
parent_type
:
'
array
'
,
path
:
path
,
path
:
path
,
element
:
input
,
element
:
input
,
schema_path
:
schema_path
+
'
/items
'
,
schema_part
:
item_schema
,
schema_part
:
item_schema
,
default_dict
:
default_array
[
i
]
default_dict
:
default_array
[
i
]
})
})
...
@@ -241,7 +244,7 @@
...
@@ -241,7 +244,7 @@
return
queue
;
return
queue
;
}
}
function
render_field
(
gadget
,
key
,
path
,
json_field
,
default_value
,
root
,
editable_label
)
{
function
render_field
(
gadget
,
key
,
path
,
json_field
,
default_value
,
root
,
schema_path
)
{
var
div
,
var
div
,
label
,
label
,
div_input
,
div_input
,
...
@@ -262,9 +265,9 @@
...
@@ -262,9 +265,9 @@
}
}
if
(
json_field
.
$ref
!==
undefined
)
{
if
(
json_field
.
$ref
!==
undefined
)
{
return
gadget
.
loadJSONSchema
(
json_field
.
$ref
,
first
_path
)
return
gadget
.
loadJSONSchema
(
json_field
.
$ref
,
schema
_path
)
.
push
(
function
(
schema_part
)
{
.
push
(
function
(
schema_part
)
{
return
render_field
(
gadget
,
key
,
path
,
schema_part
,
default_value
,
root
);
return
render_field
(
gadget
,
key
,
path
,
schema_part
,
default_value
,
root
,
schema_path
);
});
});
}
}
...
@@ -340,7 +343,8 @@
...
@@ -340,7 +343,8 @@
json_field
,
json_field
,
default_value
,
default_value
,
div_input
,
div_input
,
first_path
+
'
/
'
first_path
+
'
/
'
,
schema_path
);
);
div
.
setAttribute
(
"
data-json-path
"
,
first_path
+
'
/
'
);
div
.
setAttribute
(
"
data-json-path
"
,
first_path
+
'
/
'
);
gadget
.
props
.
arrays
[
first_path
+
'
/
'
]
=
div
;
gadget
.
props
.
arrays
[
first_path
+
'
/
'
]
=
div
;
...
@@ -355,7 +359,8 @@
...
@@ -355,7 +359,8 @@
json_field
,
json_field
,
default_value
,
default_value
,
div_input
,
div_input
,
first_path
+
'
/
'
first_path
+
'
/
'
,
schema_path
);
);
});
});
div
.
setAttribute
(
"
data-json-path
"
,
first_path
+
'
/
'
);
div
.
setAttribute
(
"
data-json-path
"
,
first_path
+
'
/
'
);
...
@@ -387,10 +392,11 @@
...
@@ -387,10 +392,11 @@
});
});
}
}
render_object
=
function
(
g
,
json_field
,
default_dict
,
root
,
path
)
{
render_object
=
function
(
g
,
json_field
,
default_dict
,
root
,
path
,
schema_path
)
{
var
additionalProperties
,
var
additionalProperties
,
key
,
key
,
required
=
json_field
.
required
||
[],
required
=
json_field
.
required
||
[],
properties
=
json_field
.
properties
,
used_properties
=
{},
used_properties
=
{},
queue
=
RSVP
.
Queue
(),
queue
=
RSVP
.
Queue
(),
scope
=
"
property_add_
"
+
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
),
scope
=
"
property_add_
"
+
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
),
...
@@ -400,13 +406,27 @@
...
@@ -400,13 +406,27 @@
.
push
(
function
(
z
)
{
.
push
(
function
(
z
)
{
return
z
.
getContent
()
return
z
.
getContent
()
.
push
(
function
(
value
)
{
.
push
(
function
(
value
)
{
var
property_name
=
value
[
scope
];
var
property_name_array
=
value
[
scope
].
split
(
'
/
'
),
property_name
,
schema
,
schema_path_local
,
anyOfidx
=
property_name_array
[
1
];
property_name
=
decodeJsonPointer
(
property_name_array
[
0
]);
schema_path_local
=
schema_path
+
'
/properties/
'
+
encodeJsonPointer
(
property_name
);
if
(
property_name_array
.
length
>
1
)
{
schema
=
json_field
.
properties
[
property_name
].
anyOf
[
anyOfidx
];
schema_path_local
+=
'
/
'
+
anyOfidx
;
}
else
{
schema
=
json_field
.
properties
[
property_name
];
}
used_properties
[
property_name
]
=
""
;
used_properties
[
property_name
]
=
""
;
return
addSubForm
({
return
addSubForm
({
gadget
:
g
,
gadget
:
g
,
property_name
:
property_name
,
property_name
:
property_name
,
path
:
path
,
path
:
path
,
schema_part
:
json_field
.
properties
[
property_name
]
schema_path
:
schema_path_local
,
schema_part
:
schema
});
});
})
})
.
push
(
function
(
element
)
{
.
push
(
function
(
element
)
{
...
@@ -419,13 +439,30 @@
...
@@ -419,13 +439,30 @@
return
g
.
getDeclaredGadget
(
scope
)
return
g
.
getDeclaredGadget
(
scope
)
.
push
(
function
(
g
)
{
.
push
(
function
(
g
)
{
var
property_name
,
var
property_name
,
i
,
anyOf
,
description
,
item_list
=
[[
"
add property
"
,
"
add property
"
]];
item_list
=
[[
"
add property
"
,
"
add property
"
]];
for
(
property_name
in
json_field
.
properties
)
{
for
(
property_name
in
properties
)
{
if
(
json_field
.
properties
.
hasOwnProperty
(
property_name
)
&&
if
(
properties
.
hasOwnProperty
(
property_name
)
&&
!
used_properties
.
hasOwnProperty
(
property_name
))
{
!
used_properties
.
hasOwnProperty
(
property_name
))
{
anyOf
=
properties
[
property_name
].
anyOf
;
if
(
anyOf
)
{
for
(
i
=
0
;
i
<
anyOf
.
length
;
i
+=
1
)
{
description
=
anyOf
[
i
].
$ref
||
anyOf
[
i
].
title
||
anyOf
[
i
].
type
||
anyOf
[
i
].
description
;
item_list
.
push
([
property_name
+
'
/
'
+
description
,
encodeJsonPointer
(
property_name
)
+
'
/
'
+
i
.
toString
()
]);
}
}
else
{
item_list
.
push
([
property_name
,
property_name
]);
item_list
.
push
([
property_name
,
property_name
]);
}
}
}
}
}
return
g
.
render
({
return
g
.
render
({
name
:
scope
,
name
:
scope
,
editable
:
true
,
editable
:
true
,
...
@@ -484,6 +521,7 @@
...
@@ -484,6 +521,7 @@
return
addSubForm
({
return
addSubForm
({
gadget
:
g
,
gadget
:
g
,
element
:
input
,
element
:
input
,
schema_path
:
schema_path
+
'
/additionalProperties
'
,
schema_part
:
schema
schema_part
:
schema
})
})
.
push
(
element_append
);
.
push
(
element_append
);
...
@@ -503,6 +541,7 @@
...
@@ -503,6 +541,7 @@
property_name
:
property_name
,
property_name
:
property_name
,
path
:
path
,
path
:
path
,
element
:
input
,
element
:
input
,
schema_path
:
schema_path
+
'
/additionalProperties
'
,
schema_part
:
schema
,
schema_part
:
schema
,
default_dict
:
default_dict
[
property_name
]
default_dict
:
default_dict
[
property_name
]
})
})
...
@@ -538,6 +577,7 @@
...
@@ -538,6 +577,7 @@
gadget
:
g
,
gadget
:
g
,
property_name
:
key
,
property_name
:
key
,
path
:
path
,
path
:
path
,
schema_path
:
schema_path
+
'
/properties/
'
+
encodeJsonPointer
(
key
),
schema_part
:
json_field
.
properties
[
key
],
schema_part
:
json_field
.
properties
[
key
],
default_dict
:
default_dict
[
key
]
default_dict
:
default_dict
[
key
]
})
})
...
@@ -896,7 +936,7 @@
...
@@ -896,7 +936,7 @@
g
.
props
.
delete_button
=
delete_button
;
g
.
props
.
delete_button
=
delete_button
;
root
.
appendChild
(
delete_button
);
root
.
appendChild
(
delete_button
);
}
}
return
render_field
(
g
,
property_name
,
""
,
schema
,
options
.
document
,
root
)
return
render_field
(
g
,
property_name
,
""
,
schema
,
options
.
document
,
root
,
options
.
schema_path
)
.
push
(
function
()
{
.
push
(
function
()
{
g
.
listenEvents
();
g
.
listenEvents
();
return
g
.
element
;
return
g
.
element
;
...
@@ -910,9 +950,6 @@
...
@@ -910,9 +950,6 @@
base_url
,
base_url
,
hash
;
hash
;
if
(
!
g
.
props
.
toplevel
)
{
if
(
!
g
.
props
.
toplevel
)
{
path
=
g
.
element
.
getAttribute
(
'
data-json-parent
'
)
+
encodeJsonPointer
(
g
.
element
.
getAttribute
(
'
data-json-property-name
'
))
+
path
;
return
g
.
loadJSONSchemaParent
(
url
,
path
);
return
g
.
loadJSONSchemaParent
(
url
,
path
);
}
}
// XXX need use $id
// XXX need use $id
...
@@ -980,6 +1017,7 @@
...
@@ -980,6 +1017,7 @@
g
.
options
.
schema
=
schema
;
g
.
options
.
schema
=
schema
;
return
g
.
renderForm
({
return
g
.
renderForm
({
schema
:
schema
,
schema
:
schema
,
schema_path
:
""
,
document
:
options
.
value
document
:
options
.
value
});
});
})
})
...
...
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