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
f36630f9
Commit
f36630f9
authored
Sep 27, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve gadget_complex_demo_form.js
parent
ea3510f6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
38 deletions
+91
-38
demo/gadget_complex_demo_form.js
demo/gadget_complex_demo_form.js
+91
-38
No files found.
demo/gadget_complex_demo_form.js
View file @
f36630f9
...
...
@@ -5,31 +5,76 @@
"
use strict
"
;
function
transform_olap_dimensions
(
g
,
dimensions
)
{
var
dimension
;
var
dimension
,
hierarchies
,
i
;
for
(
dimension
in
dimensions
)
{
if
(
dimensions
.
hasOwnProperty
(
dimension
))
{
hierarchies
=
dimensions
[
dimension
];
for
(
i
=
0
;
i
<
hierarchies
.
length
;
i
+=
1
)
{
hierarchies
[
i
].
dimension
=
dimension
;
g
.
props
.
hierarchies
[
hierarchies
[
i
].
const
]
=
hierarchies
[
i
];
}
}
}
}
function
generate_schema
()
{
function
generate_schema
(
g
,
axis
,
title
)
{
console
.
log
(
"
render
"
+
axis
);
var
used_dimensions
=
[],
h
,
hierarchies
=
[],
i
;
if
(
!
g
.
props
.
axes
.
hasOwnProperty
(
axis
))
{
g
.
props
.
axes
[
axis
]
=
[];
}
for
(
i
in
g
.
props
.
axes
)
{
if
(
g
.
props
.
axes
.
hasOwnProperty
(
i
)
&&
i
!==
axis
)
{
used_dimensions
=
used_dimensions
.
concat
(
g
.
props
.
axes
[
i
]);
}
}
for
(
i
in
g
.
props
.
hierarchies
)
{
if
(
g
.
props
.
hierarchies
.
hasOwnProperty
(
i
))
{
h
=
g
.
props
.
hierarchies
[
i
];
if
(
used_dimensions
.
indexOf
(
h
.
dimension
)
<
0
)
{
hierarchies
.
push
(
h
);
}
}
}
return
{
title
:
title
,
type
:
"
array
"
,
uniqueItems
:
true
,
items
:
{
oneOf
:
hierarchies
}
};
}
function
render_form
(
gadget
,
scope
,
schema
)
{
function
render_form
(
gadget
,
scope
,
schema
,
value
)
{
return
gadget
.
getDeclaredGadget
(
scope
)
.
push
(
function
(
g
)
{
return
g
.
render
({
schema
:
schema
schema
:
schema
,
value
:
value
});
});
}
function
updateTextContent
(
g
)
{
document
.
getElementById
(
"
json_document_content
"
).
textContent
=
JSON
.
stringify
({
columns
:
JSON
.
parse
(
g
.
state
.
columns
),
rows
:
JSON
.
parse
(
g
.
state
.
rows
)
},
null
,
2
);
}
rJS
(
window
)
.
ready
(
function
(
g
)
{
g
.
props
=
{};
g
.
props
.
dimensions
=
{
g
.
props
.
hierarchies
=
{};
g
.
props
.
axes
=
[];
transform_olap_dimensions
(
g
,
{
"
Time
"
:
[
{
title
:
'
Year
'
,
const
:
'
[Time].[Time].[Year]
'
},
{
title
:
'
Quarter
'
,
const
:
'
[Time].[Time].[Quarter]
'
}
...
...
@@ -39,31 +84,19 @@
{
title
:
'
Product Department
'
,
const
:
'
[Product].[Products].[Product Department]
'
},
{
title
:
'
Product Category
'
,
const
:
'
[Product].[Products].[Product Category]
'
}
]
});
g
.
state
=
{
columns
:
'
[]
'
,
rows
:
'
[]
'
};
g
.
props
.
dimensions
=
[
{
title
:
'
Year
'
,
const
:
'
[Time].[Time].[Year]
'
},
{
title
:
'
Quarter
'
,
const
:
'
[Time].[Time].[Quarter]
'
},
{
title
:
'
Product Family
'
,
const
:
'
[Product].[Products].[Product Family]
'
},
{
title
:
'
Product Department
'
,
const
:
'
[Product].[Products].[Product Department]
'
},
{
title
:
'
Product Category
'
,
const
:
'
[Product].[Products].[Product Category]
'
}
];
updateTextContent
(
g
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
render_form
(
g
,
"
columns
"
,
{
title
:
"
columns:
"
,
type
:
"
array
"
,
items
:
{
oneOf
:
g
.
props
.
dimensions
}
}),
render_form
(
g
,
"
rows
"
,
{
title
:
"
rows:
"
,
type
:
"
array
"
,
items
:
{
oneOf
:
g
.
props
.
dimensions
}
})
render_form
(
g
,
"
columns
"
,
generate_schema
(
g
,
"
columns
"
,
"
columns:
"
),
[]),
render_form
(
g
,
"
rows
"
,
generate_schema
(
g
,
"
rows
"
,
"
rows:
"
),
[])
]);
});
})
.
allowPublicAcquisition
(
"
notifyValid
"
,
function
(
arr
,
scope
)
{
})
...
...
@@ -78,15 +111,35 @@
})
.
push
(
function
(
ret
)
{
var
z
=
{};
z
[
scope
]
=
ret
;
z
[
scope
]
=
JSON
.
stringify
(
ret
)
;
return
gadget
.
changeState
(
z
);
});
}
})
.
onStateChange
(
function
()
{
var
g
=
this
;
document
.
getElementById
(
"
json_document_content
"
).
textContent
=
JSON
.
stringify
(
g
.
state
,
null
,
2
);
.
onStateChange
(
function
(
modification_dict
)
{
var
g
=
this
,
scope
,
mod
,
i
,
dimension
,
used_dimensions
;
for
(
scope
in
modification_dict
)
{
if
(
modification_dict
.
hasOwnProperty
(
scope
))
{
used_dimensions
=
[];
mod
=
JSON
.
parse
(
modification_dict
[
scope
]);
for
(
i
=
0
;
i
<
mod
.
length
;
i
+=
1
)
{
dimension
=
g
.
props
.
hierarchies
[
mod
[
i
]].
dimension
;
used_dimensions
.
push
(
dimension
);
}
g
.
props
.
axes
[
scope
]
=
used_dimensions
;
}
}
updateTextContent
(
g
);
// if return used here then rendering cancel
RSVP
.
all
([
render_form
(
g
,
"
columns
"
,
generate_schema
(
g
,
"
columns
"
,
"
columns:
"
)),
render_form
(
g
,
"
rows
"
,
generate_schema
(
g
,
"
rows
"
,
"
rows:
"
))
]);
});
}(
window
,
rJS
,
jIO
));
\ 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