1 | /*global Module*/ |
---|
2 | "use strict"; |
---|
3 | import React from 'react'; |
---|
4 | import TitlePanel from './viewskeleton/titlepanel'; |
---|
5 | import WidgetsContainer from './viewskeleton/widgetscontainer'; |
---|
6 | import SimilViewer from './widgets/similviewer'; |
---|
7 | |
---|
8 | const styles = { |
---|
9 | contentHeaderMenuLink: { |
---|
10 | textDecoration: 'none', |
---|
11 | color: 'white', |
---|
12 | padding: 8, |
---|
13 | }, |
---|
14 | content: { |
---|
15 | padding: '16px', |
---|
16 | }, |
---|
17 | sidebarLink: { |
---|
18 | display: 'block', |
---|
19 | padding: '16px 0px', |
---|
20 | color: 'gray', |
---|
21 | textDecoration: 'none', |
---|
22 | }, |
---|
23 | divider: { |
---|
24 | margin: '8px 0', |
---|
25 | height: 1, |
---|
26 | backgroundColor: 'gray', |
---|
27 | }, |
---|
28 | }; |
---|
29 | |
---|
30 | //const mql = window.matchMedia('(min-width: 800px)'); |
---|
31 | |
---|
32 | /** |
---|
33 | * Main class running Framsticks.JS page. |
---|
34 | */ |
---|
35 | class MainView extends React.Component { |
---|
36 | /** |
---|
37 | * Basic constructor holding informations about sidebar states |
---|
38 | * @param {any} props component properties |
---|
39 | */ |
---|
40 | constructor(props) { |
---|
41 | super(props); |
---|
42 | this.onLayoutChange = this.onLayoutChange.bind(this); |
---|
43 | |
---|
44 | window.genetics = new Module.PreconfiguredGenetics(); |
---|
45 | this.layout = [ |
---|
46 | {name:'0,similviewer', x: 0, y: 0, w: 12, h: 4} |
---|
47 | ]; |
---|
48 | |
---|
49 | this.container = <WidgetsContainer onRef={ref => (this.widgetscontainer = ref)} onLayoutChange={this.onLayoutChange} />; |
---|
50 | |
---|
51 | this.state = { |
---|
52 | parametersmodal: false |
---|
53 | }; |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Uses default layout. |
---|
58 | */ |
---|
59 | componentDidMount() { |
---|
60 | this.useLayout(this.layout); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Calls resize event in order to properly set layout |
---|
65 | */ |
---|
66 | componentDidUpdate() { |
---|
67 | window.dispatchEvent(new Event('resize')); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Stores layout, for LocalStorage layout saving |
---|
72 | * @param {any} layout layout to be saved |
---|
73 | */ |
---|
74 | onLayoutChange(layout) { |
---|
75 | let newlayout = []; |
---|
76 | for (let i = 0; i < layout.length; i++) { |
---|
77 | newlayout.push({name: layout[i].i, x: layout[i].x, y: layout[i].y, w: layout[i].w, h: layout[i].h}); |
---|
78 | } |
---|
79 | } |
---|
80 | /** |
---|
81 | * Passes layout to widgetscontainer. |
---|
82 | * @param {any} layout layout to be used |
---|
83 | */ |
---|
84 | useLayout(layout) { |
---|
85 | let items = []; |
---|
86 | for (let i = 0; i < layout.length; i++) { |
---|
87 | let name = layout[i].name.split(',')[1]; |
---|
88 | switch (name) { |
---|
89 | case 'similviewer': |
---|
90 | items.push({content: <SimilViewer/>, i: "" + i + 'similviewer', |
---|
91 | x: layout[i].x, y: layout[i].y, w: layout[i].w, h: layout[i].h}); |
---|
92 | break; |
---|
93 | } |
---|
94 | } |
---|
95 | this.widgetscontainer.addMultipleItems(items); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Render function. |
---|
100 | * @returns {JSX.Element} main page of Framsticks.JS |
---|
101 | */ |
---|
102 | render() { |
---|
103 | |
---|
104 | const contentHeader = ( |
---|
105 | <span> |
---|
106 | <span style={{marginLeft: '20px'}}>Matching in 3D</span> |
---|
107 | </span> |
---|
108 | ); |
---|
109 | |
---|
110 | return ( |
---|
111 | <TitlePanel title={contentHeader}> |
---|
112 | <div style={styles.content}> |
---|
113 | {this.container} |
---|
114 | </div> |
---|
115 | </TitlePanel> |
---|
116 | ); |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | export default MainView; |
---|