|
@@ -1,5 +1,15 @@
|
1
|
1
|
import * as _ from 'lodash';
|
2
|
2
|
|
|
3
|
+const Types = {
|
|
4
|
+ Container: 'Container',
|
|
5
|
+ ContainerStack: 'ContainerStack',
|
|
6
|
+ Tabs: 'Tabs',
|
|
7
|
+ SideMenuRoot: 'SideMenuRoot',
|
|
8
|
+ SideMenuCenter: 'SideMenuCenter',
|
|
9
|
+ SideMenuLeft: 'SideMenuLeft',
|
|
10
|
+ SideMenuRight: 'SideMenuRight'
|
|
11
|
+};
|
|
12
|
+
|
3
|
13
|
export default class LayoutTreeParser {
|
4
|
14
|
constructor(uniqueIdProvider) {
|
5
|
15
|
this.uniqueIdProvider = uniqueIdProvider;
|
|
@@ -8,73 +18,68 @@ export default class LayoutTreeParser {
|
8
|
18
|
parseFromSimpleJSON(simpleJsonApi) {
|
9
|
19
|
// TOOD deepclone
|
10
|
20
|
if (simpleJsonApi.sideMenu) {
|
11
|
|
- return {
|
12
|
|
- type: 'SideMenuRoot',
|
13
|
|
- id: this.uniqueIdProvider.generate('SideMenuRoot'),
|
14
|
|
- children: this.createSideMenuChildren(simpleJsonApi)
|
15
|
|
- };
|
|
21
|
+ return this._createSideMenu(simpleJsonApi);
|
16
|
22
|
}
|
17
|
23
|
if (simpleJsonApi.tabs) {
|
18
|
|
- return this.createTabs(simpleJsonApi.tabs);
|
|
24
|
+ return this._createTabs(simpleJsonApi.tabs);
|
19
|
25
|
}
|
|
26
|
+ return this._createContainerStackWithContainer(simpleJsonApi.container);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ _node(node) {
|
|
30
|
+ node.id = this.uniqueIdProvider.generate(node.type);
|
|
31
|
+ node.children = node.children || [];
|
|
32
|
+ return node;
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ _createTabs(tabs) {
|
|
36
|
+ return this._node({
|
|
37
|
+ type: Types.Tabs,
|
|
38
|
+ children: _.map(tabs, (t) => this._createContainerStackWithContainer(t.container))
|
|
39
|
+ });
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ _createContainerStackWithContainer(container) {
|
|
43
|
+ return this._node({
|
|
44
|
+ type: Types.ContainerStack,
|
|
45
|
+ children: [this._createContainer(container)]
|
|
46
|
+ });
|
|
47
|
+ }
|
20
|
48
|
|
21
|
|
- return this.createContainerStackWithContainer(simpleJsonApi.container);
|
|
49
|
+ _createContainer(container) {
|
|
50
|
+ return this._node({
|
|
51
|
+ type: Types.Container,
|
|
52
|
+ data: container
|
|
53
|
+ });
|
22
|
54
|
}
|
23
|
55
|
|
24
|
|
- createSideMenuChildren(layout) {
|
|
56
|
+ _createSideMenu(layout) {
|
|
57
|
+ return this._node({
|
|
58
|
+ type: Types.SideMenuRoot,
|
|
59
|
+ children: this._createSideMenuChildren(layout)
|
|
60
|
+ });
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ _createSideMenuChildren(layout) {
|
25
|
64
|
const children = [];
|
26
|
65
|
if (layout.sideMenu.left) {
|
27
|
|
- children.push({
|
28
|
|
- type: 'SideMenuLeft',
|
29
|
|
- id: this.uniqueIdProvider.generate('SideMenuLeft'),
|
30
|
|
- children: [
|
31
|
|
- this.createContainer(layout.sideMenu.left.container)
|
32
|
|
- ]
|
33
|
|
- });
|
|
66
|
+ children.push(this._node({
|
|
67
|
+ type: Types.SideMenuLeft,
|
|
68
|
+ children: [this._createContainer(layout.sideMenu.left.container)]
|
|
69
|
+ }));
|
34
|
70
|
}
|
35
|
|
- children.push({
|
36
|
|
- type: 'SideMenuCenter',
|
37
|
|
- id: this.uniqueIdProvider.generate('SideMenuCenter'),
|
|
71
|
+ children.push(this._node({
|
|
72
|
+ type: Types.SideMenuCenter,
|
38
|
73
|
children: [
|
39
|
|
- this.createContainerStackWithContainer(layout.container)
|
|
74
|
+ layout.tabs ? this._createTabs(layout.tabs) : this._createContainerStackWithContainer(layout.container)
|
40
|
75
|
]
|
41
|
|
- });
|
|
76
|
+ }));
|
42
|
77
|
if (layout.sideMenu.right) {
|
43
|
|
- children.push({
|
44
|
|
- type: 'SideMenuRight',
|
45
|
|
- id: this.uniqueIdProvider.generate('SideMenuRight'),
|
46
|
|
- children: [
|
47
|
|
- this.createContainer(layout.sideMenu.right.container)
|
48
|
|
- ]
|
49
|
|
- });
|
|
78
|
+ children.push(this._node({
|
|
79
|
+ type: Types.SideMenuRight,
|
|
80
|
+ children: [this._createContainer(layout.sideMenu.right.container)]
|
|
81
|
+ }));
|
50
|
82
|
}
|
51
|
83
|
return children;
|
52
|
84
|
}
|
53
|
|
-
|
54
|
|
- createTabs(tabs) {
|
55
|
|
- return {
|
56
|
|
- type: 'Tabs',
|
57
|
|
- id: this.uniqueIdProvider.generate(`Tabs`),
|
58
|
|
- children: _.map(tabs, (t) => this.createContainerStackWithContainer(t.container))
|
59
|
|
- };
|
60
|
|
- }
|
61
|
|
-
|
62
|
|
- createContainerStackWithContainer(container) {
|
63
|
|
- return {
|
64
|
|
- type: 'ContainerStack',
|
65
|
|
- id: this.uniqueIdProvider.generate(`ContainerStack`),
|
66
|
|
- children: [
|
67
|
|
- this.createContainer(container)
|
68
|
|
- ]
|
69
|
|
- };
|
70
|
|
- }
|
71
|
|
-
|
72
|
|
- createContainer(container) {
|
73
|
|
- return {
|
74
|
|
- data: container,
|
75
|
|
- type: 'Container',
|
76
|
|
- id: this.uniqueIdProvider.generate(`Container`),
|
77
|
|
- children: []
|
78
|
|
- };
|
79
|
|
- }
|
80
|
85
|
}
|