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
c6c96e4f
Commit
c6c96e4f
authored
Dec 28, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add schema_path and path options to resolveExternalReference() run
so we can get context of fetched schema
parent
a4934a6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
55 deletions
+121
-55
jsonform.gadget.js
jsonform.gadget.js
+30
-27
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+91
-28
No files found.
jsonform.gadget.js
View file @
c6c96e4f
...
...
@@ -245,7 +245,7 @@
return
new
URL
(
mapped_url
+
hash
);
}
function
loadJSONSchema
(
g
,
$ref
,
path
)
{
function
loadJSONSchema
(
g
,
$ref
,
schema_path
,
path
)
{
var
protocol
,
abs_url
,
url
,
...
...
@@ -253,10 +253,10 @@
hash
,
queue
;
// XXX need use `id` property
if
(
!
path
)
{
path
=
"
/
"
;
if
(
!
schema_
path
)
{
schema_
path
=
"
/
"
;
}
abs_url
=
convertUrlToAbsolute
(
g
,
path
,
decodeURI
(
$ref
),
window
.
location
);
abs_url
=
convertUrlToAbsolute
(
g
,
schema_
path
,
decodeURI
(
$ref
),
window
.
location
);
url
=
map_url
(
g
,
abs_url
);
abs_url
=
abs_url
.
href
;
protocol
=
url
.
protocol
;
...
...
@@ -273,7 +273,7 @@
if
(
download_url
.
startsWith
(
"
urn:jio:
"
))
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
g
.
resolveExternalReference
(
download_url
);
return
g
.
resolveExternalReference
(
download_url
,
schema_path
,
path
);
});
}
else
{
queue
=
RSVP
.
Queue
()
...
...
@@ -283,7 +283,7 @@
}
return
queue
.
push
(
function
(
json
)
{
if
(
checkHardCircular
(
g
,
path
,
url
))
{
if
(
checkHardCircular
(
g
,
schema_
path
,
url
))
{
throw
new
Error
(
"
Circular reference detected
"
);
}
return
resolveLocalReference
(
json
,
hash
);
...
...
@@ -292,7 +292,7 @@
// XXX it will be great to have ability convert json_pointers(hash)
// in line numbers for pointed to line in rich editors.
// we can use https://github.com/vtrushin/json-to-ast for it
var
url_from_pointed
=
convertToRealWorldSchemaPath
(
g
,
path
),
var
url_from_pointed
=
convertToRealWorldSchemaPath
(
g
,
schema_
path
),
schema_a
=
document
.
createElement
(
"
a
"
),
pointed_a
=
document
.
createElement
(
"
a
"
);
schema_a
.
setAttribute
(
"
href
"
,
download_url
);
...
...
@@ -300,7 +300,7 @@
pointed_a
.
setAttribute
(
"
href
"
,
url_from_pointed
);
pointed_a
.
text
=
(
new
URLwithJio
(
url_from_pointed
)).
pathname
;
g
.
props
.
schema_resolve_errors
[
url_from_pointed
]
=
{
schemaPath
:
path
,
schemaPath
:
schema_
path
,
message
:
[
document
.
createTextNode
(
"
schema error:
"
),
document
.
createTextNode
(
err
.
message
),
...
...
@@ -312,7 +312,6 @@
return
null
;
// schema part can't be null
})
.
push
(
function
(
schema_part
)
{
// console.log(path);
if
(
schema_part
===
null
)
{
// if resolving schema part contain errors
// use {} as failback
...
...
@@ -320,16 +319,16 @@
}
else
{
// save map url only for correctly resolved schema
// otherwise we have issue in convertToRealWorldSchemaPath
if
(
!
g
.
props
.
hasOwnProperty
(
path
))
{
g
.
props
.
schema_map
[
path
]
=
abs_url
;
if
(
!
g
.
props
.
hasOwnProperty
(
schema_
path
))
{
g
.
props
.
schema_map
[
schema_
path
]
=
abs_url
;
}
}
schemaPushSchemaPart
(
g
.
props
.
schema
,
path
,
JSON
.
parse
(
JSON
.
stringify
(
schema_part
)));
schemaPushSchemaPart
(
g
.
props
.
schema
,
schema_
path
,
JSON
.
parse
(
JSON
.
stringify
(
schema_part
)));
// console.log(g.props.schema[""]);
return
expandSchema
(
g
,
schema_part
,
path
,
$ref
);
return
expandSchema
(
g
,
schema_part
,
schema_path
,
path
,
$ref
);
})
.
push
(
function
(
schema_arr
)
{
checkAndMarkSoftCircular
(
g
,
schema_arr
,
path
,
url
);
checkAndMarkSoftCircular
(
g
,
schema_arr
,
schema_
path
,
url
);
return
schema_arr
;
});
}
...
...
@@ -495,13 +494,13 @@
return
x
;
}
function
allOf
(
g
,
schema_array
,
schema_path
,
base_schema
)
{
function
allOf
(
g
,
schema_array
,
schema_path
,
path
,
base_schema
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
var
i
,
arr
=
[];
for
(
i
=
0
;
i
<
schema_array
.
length
;
i
+=
1
)
{
arr
.
push
(
expandSchema
(
g
,
schema_array
[
i
],
schema_path
+
'
/
'
+
i
.
toString
()));
arr
.
push
(
expandSchema
(
g
,
schema_array
[
i
],
schema_path
+
'
/
'
+
i
.
toString
()
,
path
));
}
return
RSVP
.
all
(
arr
);
})
...
...
@@ -535,13 +534,13 @@
});
}
function
anyOf
(
g
,
schema_array
,
schema_path
,
base_schema
)
{
function
anyOf
(
g
,
schema_array
,
schema_path
,
path
,
base_schema
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
var
i
,
arr
=
[];
for
(
i
=
0
;
i
<
schema_array
.
length
;
i
+=
1
)
{
arr
.
push
(
expandSchema
(
g
,
schema_array
[
i
],
schema_path
+
'
/
'
+
i
.
toString
()));
arr
.
push
(
expandSchema
(
g
,
schema_array
[
i
],
schema_path
+
'
/
'
+
i
.
toString
()
,
path
));
}
return
RSVP
.
all
(
arr
);
})
...
...
@@ -569,7 +568,7 @@
});
}
expandSchema
=
function
(
g
,
schema
,
schema_path
,
ref
)
{
expandSchema
=
function
(
g
,
schema
,
schema_path
,
path
,
ref
)
{
// XXX `if then else` construction can be simplify to
// anyOf(allOf(if_schema, then_schema), else_schema)
// and realized by existed rails
...
...
@@ -578,16 +577,16 @@
schema
=
true
;
}
if
(
schema
.
anyOf
!==
undefined
)
{
return
anyOf
(
g
,
schema
.
anyOf
,
schema_path
+
'
/anyOf
'
,
schema
);
return
anyOf
(
g
,
schema
.
anyOf
,
schema_path
+
'
/anyOf
'
,
path
,
schema
);
}
if
(
schema
.
oneOf
!==
undefined
)
{
return
anyOf
(
g
,
schema
.
oneOf
,
schema_path
+
'
/oneOf
'
,
schema
);
return
anyOf
(
g
,
schema
.
oneOf
,
schema_path
+
'
/oneOf
'
,
path
,
schema
);
}
if
(
schema
.
allOf
!==
undefined
)
{
return
allOf
(
g
,
schema
.
allOf
,
schema_path
+
'
/allOf
'
,
schema
);
return
allOf
(
g
,
schema
.
allOf
,
schema_path
+
'
/allOf
'
,
path
,
schema
);
}
if
(
schema
.
$ref
)
{
return
loadJSONSchema
(
g
,
schema
.
$ref
,
schema_path
);
return
loadJSONSchema
(
g
,
schema
.
$ref
,
schema_path
,
path
);
}
if
(
schema
.
definitions
)
{
var
key
,
...
...
@@ -635,7 +634,7 @@
return
schema_arr
;
}
function
expandSchemaForField
(
g
,
schema
,
schema_path
,
for_required
)
{
function
expandSchemaForField
(
g
,
schema
,
schema_path
,
path
,
for_required
)
{
var
required_stack
,
prev_field_path
;
if
(
for_required
)
{
...
...
@@ -645,7 +644,7 @@
required_stack
=
[];
}
g
.
props
.
schema_required_urls
[
schema_path
]
=
required_stack
;
return
expandSchema
(
g
,
schema
,
schema_path
)
return
expandSchema
(
g
,
schema
,
schema_path
,
path
)
.
push
(
schema_arr_marker
);
}
...
...
@@ -783,6 +782,10 @@
});
})
.
allowPublicAcquisition
(
'
parentGetJsonPath
'
,
function
(
arr
,
scope
)
{
return
""
;
})
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
z
=
{
saveOrigValue
:
options
.
saveOrigValue
,
...
...
@@ -871,7 +874,7 @@
g
.
props
.
schema_map
[
"
/
"
]
=
schema_url
;
g
.
props
.
schemas
[
schema_url
]
=
URL
.
createObjectURL
(
new
Blob
([
g
.
state
.
schema
],
{
type
:
'
application/json
'
}));
queue
=
expandSchemaForField
(
g
,
schema
,
"
/
"
,
true
);
queue
=
expandSchemaForField
(
g
,
schema
,
"
/
"
,
"
/
"
.
true
);
}
else
{
schema_url
=
g
.
state
.
schema_url
||
(
json_document
&&
json_document
.
$schema
);
...
...
@@ -910,7 +913,7 @@
});
})
.
allowPublicAcquisition
(
"
expandSchema
"
,
function
(
arr
)
{
return
expandSchemaForField
(
this
,
arr
[
0
],
arr
[
1
],
arr
[
2
]);
return
expandSchemaForField
(
this
,
arr
[
0
],
arr
[
1
],
arr
[
2
]
,
arr
[
3
]
);
})
.
onLoop
(
function
()
{
var
gadget
=
this
;
...
...
jsonform/gadget_json_generated_form_child.js
View file @
c6c96e4f
...
...
@@ -285,8 +285,8 @@
scope
;
scope
=
"
j
"
+
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
);
parent_path
=
options
.
parent_path
;
if
(
options
.
parent_type
!==
"
array
"
)
{
parent_path
=
options
.
path
;
property_name
=
options
.
property_name
;
if
(
!
property_name
)
{
property_name
=
input_element
.
value
;
...
...
@@ -310,9 +310,9 @@
.
push
(
function
(
form_gadget
)
{
form_gadget
.
element
.
setAttribute
(
"
data-gadget-parent-scope
"
,
g
.
element
.
getAttribute
(
"
data-gadget-scope
"
));
form_gadget
.
element
.
setAttribute
(
"
data-json-parent
"
,
parent_path
);
if
(
options
.
parent_type
!==
"
array
"
)
{
g
.
props
.
objects
[
parent_path
][
property_name
]
=
scope
;
form_gadget
.
element
.
setAttribute
(
"
data-json-parent
"
,
parent_path
);
form_gadget
.
element
.
setAttribute
(
"
data-json-property-name
"
,
property_name
);
}
return
form_gadget
.
renderForm
({
...
...
@@ -335,14 +335,14 @@
});
}
function
expandItems
(
g
,
items
,
schema_path
,
minItems
)
{
function
expandItems
(
g
,
items
,
schema_path
,
path
,
minItems
)
{
if
(
!
(
items
instanceof
Array
))
{
return
g
.
expandSchema
(
items
,
schema_path
,
minItems
!==
0
);
return
g
.
expandSchema
(
items
,
schema_path
,
path
,
minItems
!==
0
);
}
var
i
,
tasks
=
[];
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
tasks
.
push
(
g
.
expandSchema
(
items
[
i
],
schema_path
+
'
/
'
+
i
,
i
<
minItems
));
tasks
.
push
(
g
.
expandSchema
(
items
[
i
],
schema_path
+
'
/
'
+
i
,
path
,
i
<
minItems
));
}
return
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
@@ -350,27 +350,29 @@
});
}
function
expandProperties
(
g
,
properties
,
schema_path
,
required
)
{
function
expandProperties
(
g
,
properties
,
schema_path
,
path
,
required
)
{
var
ret_obj
=
{};
return
RSVP
.
Queue
()
.
push
(
function
()
{
var
property_name
,
arr
=
[];
function
addPropertyName
(
p_name
)
{
return
function
(
schema_array
)
{
ret_obj
[
p_name
]
=
schema_array
;
};
return
g
.
getJsonPath
(
path
)
.
push
(
function
(
p
)
{
return
g
.
expandSchema
(
properties
[
p_name
],
schema_path
+
encodeJsonPointer
(
p_name
),
p
+
encodeJsonPointer
(
p_name
),
required
.
indexOf
(
p_name
)
>=
0
);
})
.
push
(
function
(
schema_array
)
{
ret_obj
[
p_name
]
=
schema_array
;
});
}
for
(
property_name
in
properties
)
{
if
(
properties
.
hasOwnProperty
(
property_name
))
{
arr
.
push
(
g
.
expandSchema
(
properties
[
property_name
],
schema_path
+
encodeJsonPointer
(
property_name
),
required
.
indexOf
(
property_name
)
>=
0
)
.
push
(
addPropertyName
(
property_name
))
);
arr
.
push
(
addPropertyName
(
property_name
));
}
}
return
RSVP
.
all
(
arr
);
...
...
@@ -744,11 +746,11 @@
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return
RSVP
.
Queue
(
)
.
push
(
function
()
{
return
gadget
.
getJsonPath
(
path
)
.
push
(
function
(
p
)
{
return
RSVP
.
all
([
expandItems
(
gadget
,
schema
.
items
,
schema_path
+
'
/items
'
,
minItems
),
gadget
.
expandSchema
(
schema
.
additionalItems
,
schema_path
+
'
/additionalItems
'
,
false
)
expandItems
(
gadget
,
schema
.
items
,
schema_path
+
'
/items
'
,
p
,
minItems
),
gadget
.
expandSchema
(
schema
.
additionalItems
,
schema_path
+
'
/additionalItems
'
,
p
,
false
)
]);
})
.
push
(
function
(
arr
)
{
...
...
@@ -773,6 +775,7 @@
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_path
:
path
,
schema_arr
:
schema_arr
,
json_document
:
json_document
[
i
],
required
:
i
<
minItems
...
...
@@ -799,6 +802,7 @@
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_path
:
path
,
schema_arr
:
schema_arr
,
required
:
true
})
...
...
@@ -818,6 +822,7 @@
return
addSubForm
({
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_path
:
path
,
type
:
value
.
type
,
selected_schema
:
value
,
schema_arr
:
schema_arr
...
...
@@ -832,6 +837,7 @@
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_path
:
path
,
schema_arr
:
schema_arr
,
required
:
true
})
...
...
@@ -846,6 +852,7 @@
return
addSubForm
({
gadget
:
gadget
,
parent_type
:
'
array
'
,
parent_path
:
path
,
type
:
value
.
type
,
selected_schema
:
value
,
schema_arr
:
schema_arr
...
...
@@ -1154,7 +1161,10 @@
input
.
placeholder
=
"
name of
"
+
title
;
div_input
.
appendChild
(
input
);
return
g
.
expandSchema
(
schema
,
schema_path
)
return
g
.
getJsonPath
(
path
)
.
push
(
function
(
p
)
{
return
g
.
expandSchema
(
schema
,
schema_path
,
p
);
})
.
push
(
function
(
schema_arr
)
{
var
queue
=
RSVP
.
Queue
(),
property_name
;
...
...
@@ -1171,7 +1181,7 @@
addSubForm
.
bind
(
g
,
{
gadget
:
g
,
property_name
:
property_name
,
path
:
path
,
pa
rent_pa
th
:
path
,
schema_arr
:
schema_arr
,
json_document
:
json_document
[
property_name
]
})
...
...
@@ -1184,7 +1194,7 @@
return
addSubForm
({
gadget
:
g
,
element
:
input
,
path
:
path
,
pa
rent_pa
th
:
path
,
type
:
value
.
type
,
schema_arr
:
[
value
]
})
...
...
@@ -1344,7 +1354,7 @@
json_document
=
{};
}
return
expandProperties
(
g
,
schema
.
properties
,
schema_path
+
'
/properties/
'
,
required
)
return
expandProperties
(
g
,
schema
.
properties
,
schema_path
+
'
/properties/
'
,
path
,
required
)
.
push
(
function
(
ret
)
{
var
schema_arr
,
q
=
RSVP
.
Queue
(),
...
...
@@ -1382,7 +1392,7 @@
addSubForm
.
bind
(
g
,
{
gadget
:
g
,
property_name
:
key
,
path
:
path
,
pa
rent_pa
th
:
path
,
schema_arr
:
filtered_schema_arr
,
json_document
:
json_document
[
key
]
})
...
...
@@ -1400,7 +1410,7 @@
return
addSubForm
({
gadget
:
g
,
property_name
:
value
.
property_name
,
path
:
path
,
pa
rent_pa
th
:
path
,
type
:
value
.
type
,
schema_arr
:
[
value
]
})
...
...
@@ -1511,7 +1521,7 @@
addSubForm
.
bind
(
g
,
{
gadget
:
g
,
property_name
:
key
,
path
:
path
,
pa
rent_pa
th
:
path
,
schema_arr
:
[{
schema
:
undefined
,
schema_path
:
""
...
...
@@ -1765,6 +1775,59 @@
});
})
.
declareAcquiredMethod
(
'
parentGetJsonPath
'
,
'
parentGetJsonPath
'
)
.
allowPublicAcquisition
(
'
parentGetJsonPath
'
,
function
(
arr
,
scope
)
{
var
g
=
this
,
key
,
arrays
=
g
.
props
.
arrays
,
array
,
len
,
i
,
objects
=
g
.
props
.
objects
,
o
,
element
=
getSubGadgetElement
(
g
,
scope
),
parent
;
if
(
element
)
{
parent
=
element
.
getAttribute
(
"
data-json-parent
"
);
}
else
{
parent
=
arr
[
0
];
}
if
(
arrays
.
hasOwnProperty
(
parent
))
{
array
=
arrays
[
parent
]
.
querySelectorAll
(
"
div[data-gadget-parent-scope='
"
+
g
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
"
']
"
);
len
=
array
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
if
(
array
[
i
].
getAttribute
(
'
data-gadget-scope
'
)
===
scope
)
{
break
;
}
}
return
g
.
parentGetJsonPath
(
this
.
element
.
getAttribute
(
"
data-json-parent
"
))
.
push
(
function
(
path
)
{
return
path
+
parent
+
i
;
});
}
if
(
objects
.
hasOwnProperty
(
parent
))
{
o
=
objects
[
parent
];
for
(
key
in
o
)
{
if
(
o
.
hasOwnProperty
(
key
))
{
if
(
o
[
key
]
===
scope
)
{
break
;
}
}
}
return
g
.
parentGetJsonPath
(
this
.
element
.
getAttribute
(
"
data-json-parent
"
))
.
push
(
function
(
path
)
{
return
path
+
parent
+
encodeJsonPointer
(
key
);
});
}
})
.
declareMethod
(
'
getJsonPath
'
,
function
(
parent_path
)
{
return
this
.
parentGetJsonPath
(
this
.
element
.
getAttribute
(
"
data-json-parent
"
))
.
push
(
function
(
p
)
{
return
p
+
parent_path
;
});
})
.
declareMethod
(
'
getElementByPath
'
,
function
(
data_path
)
{
var
g
=
this
,
array
,
...
...
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