Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
47689cd4
Commit
47689cd4
authored
Dec 19, 2014
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP on dynamic field
parent
702d8495
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
10 deletions
+113
-10
dream/platform/src/fieldset/fieldset.js
dream/platform/src/fieldset/fieldset.js
+19
-1
dream/platform/src/jsplumb/jsplumb.js
dream/platform/src/jsplumb/jsplumb.js
+94
-9
No files found.
dream/platform/src/fieldset/fieldset.js
View file @
47689cd4
...
...
@@ -8,7 +8,7 @@
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var
gadget_klass
=
rJS
(
window
),
var
i
,
gadget_klass
=
rJS
(
window
),
source
=
gadget_klass
.
__template_element
.
getElementById
(
"
label-template
"
)
.
innerHTML
,
...
...
@@ -28,6 +28,7 @@
function
addField
(
property_id
,
property_definition
,
value
)
{
var
sub_gadget
;
console
.
log
(
"
addField
"
,
property_id
,
property_definition
,
value
);
queue
.
push
(
function
()
{
// XXX this is incorrect for recursive fieldsets.
...
...
@@ -41,6 +42,17 @@
property_id
)
})
);
//console.log("PD", property_definition);
if
(
property_definition
.
oneOf
)
{
// if we got a oneOf, then we use the first one that matches our
// data.
console
.
log
(
value
);
for
(
i
=
0
;
i
<
property_definition
.
oneOf
.
length
;
i
+=
1
)
{
console
.
log
(
property_definition
.
oneOf
[
i
]);
};
}
if
(
property_definition
.
type
===
"
object
"
)
{
// Create a recursive fieldset for this key.
return
gadget
.
declareGadget
(
"
../fieldset/index.html
"
);
...
...
@@ -75,12 +87,14 @@
if
(
node_id
)
{
addField
(
'
id
'
,
{
'
type
'
:
'
string
'
},
node_id
);
}
console
.
log
(
options
.
property_definition
);
Object
.
keys
(
options
.
property_definition
.
properties
).
forEach
(
function
(
property_name
)
{
var
property_definition
=
options
.
property_definition
.
properties
[
property_name
],
value
=
(
options
.
value
||
{})[
property_name
]
===
undefined
?
property_definition
.
_default
:
options
.
value
[
property_name
];
//console.log(property_name, property_definition);
// XXX some properties are not editable
// XXX should not be defined here
if
(
property_name
!==
'
coordinate
'
&&
property_name
!==
'
_class
'
)
{
...
...
@@ -91,6 +105,10 @@
return
queue
;
})
.
declareMethod
(
"
notifyDataChanged
"
,
function
()
{
console
.
log
(
"
content changed
"
);
})
// getContent of all subfields
.
declareMethod
(
"
getContent
"
,
function
()
{
var
i
,
promise_list
=
[],
gadget
=
this
;
...
...
dream/platform/src/jsplumb/jsplumb.js
View file @
47689cd4
...
...
@@ -381,30 +381,114 @@
connection
.
id
=
edge_id
;
}
function
resolveReference
(
ref
,
schema
)
{
// 2 here is for #/
var
i
,
ref_path
=
ref
.
substr
(
2
,
ref
.
length
),
parts
=
ref_path
.
split
(
"
/
"
);
for
(
i
=
0
;
i
<
parts
.
length
;
i
++
)
{
schema
=
schema
[
parts
[
i
]];
}
return
schema
;
}
function
expandSchema
(
class_definition
,
full_schema
)
{
// minimal expanding of json schema, supports merging allOf and $ref
// references
// TODO: check for a library that would provide full support
// XXX this should probably be moved to fieldset ( and not handle
// class_definition here)
// XXX known limitation: we do not expand refs inside oneOf
var
property
,
referenced
,
i
,
expanded_class_definition
=
{
properties
:
class_definition
.
properties
||
{}};
console
.
log
(
'
expandSchema
'
,
class_definition
);
// expand direct ref
if
(
class_definition
.
$ref
)
{
console
.
log
(
'
DI
'
,
class_definition
.
$ref
);
referenced
=
expandSchema
(
resolveReference
(
class_definition
.
$ref
,
full_schema
.
class_definition
),
full_schema
);
if
(
referenced
.
properties
)
{
delete
referenced
.
properties
;
}
$
.
extend
(
expanded_class_definition
,
referenced
);
console
.
log
(
"
after direct expand
"
,
Object
.
create
(
referenced
));
}
/*
// expand refs inside properties
for (property in expanded_class_definition.properties) {
if (expanded_class_definition.properties.hasOwnProperty(property)) {
referenced = expanded_class_definition.properties[property];
if (referenced.$ref) {
if (!expanded_class_definition.properties[property]){
expanded_class_definition.properties[property] = {};
}
$.extend(expanded_class_definition.properties[property], expandSchema(
resolveReference(referenced.$ref, full_schema.class_definition),
full_schema));
}
}
}
*/
if
(
class_definition
.
oneOf
)
{
expanded_class_definition
.
oneOf
=
[];
for
(
i
=
0
;
i
<
class_definition
.
oneOf
.
length
;
i
+=
1
)
{
expanded_class_definition
.
oneOf
.
push
(
expandSchema
(
class_definition
.
oneOf
[
i
],
full_schema
)
);
}
}
if
(
class_definition
.
allOf
)
{
for
(
i
=
0
;
i
<
class_definition
.
allOf
.
length
;
i
+=
1
)
{
referenced
=
expandSchema
(
class_definition
.
allOf
[
i
],
full_schema
);
if
(
referenced
.
properties
)
{
$
.
extend
(
expanded_class_definition
.
properties
,
referenced
.
properties
);
delete
referenced
.
properties
;
}
$
.
extend
(
expanded_class_definition
,
referenced
);
}
}
if
(
expanded_class_definition
.
$ref
)
{
delete
expanded_class_definition
.
$ref
;
}
console
.
log
(
'
R
'
,
expanded_class_definition
);
return
Object
.
create
(
expanded_class_definition
);
// expand refs directly in allOf
if
(
class_definition
.
xallOf
)
{
for
(
i
=
0
;
i
<
class_definition
.
allOf
.
length
;
i
+=
1
)
{
referenced
=
class_definition
.
allOf
[
i
];
if
(
referenced
.
$ref
)
{
referenced
=
expandSchema
(
full_schema
.
class_definition
[
// 2 here is for #/
referenced
.
$ref
.
substr
(
2
,
referenced
.
$ref
.
length
)
],
full_schema
);
referenced
=
Object
.
create
(
referenced
);
$
.
extend
(
referenced
,
expandSchema
(
resolveReference
(
referenced
.
$ref
,
full_schema
.
class_definition
),
full_schema
));
}
if
(
referenced
.
properties
)
{
for
(
property
in
referenced
.
properties
)
{
if
(
referenced
.
properties
.
hasOwnProperty
(
property
))
{
//console.log('property2', property, referenced.properties[property]);
// and in allOf references. XXX I guess this can be merged with
// "expand ref inside properties"
if
(
referenced
.
properties
[
property
].
$ref
)
{
expanded_class_definition
.
properties
[
property
]
=
referenced
.
properties
[
property
];
$
.
extend
(
expanded_class_definition
.
properties
[
property
],
expandSchema
(
resolveReference
(
referenced
.
properties
[
property
].
$ref
,
full_schema
.
class_definition
),
full_schema
));
}
if
(
referenced
.
properties
[
property
].
type
)
{
expanded_class_definition
.
properties
[
property
]
=
referenced
.
properties
[
property
];
if
(
!
expanded_class_definition
.
properties
[
property
]
)
{
expanded_class_definition
.
properties
[
property
]
=
{};
}
$
.
extend
(
expanded_class_definition
.
properties
[
property
],
referenced
.
properties
[
property
]);
}
}
}
...
...
@@ -531,6 +615,7 @@
gadget
.
props
.
data
.
class_definition
[
node_data
.
_class
],
gadget
.
props
.
data
);
console
.
log
(
'
editing node with
'
,
schema
);
if
(
node_edit_popup
.
length
!==
0
)
{
node_edit_popup
.
remove
();
...
...
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