forked from drinky78/sortello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
148 lines (132 loc) · 4.27 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React from "react"
import ApiKey from "./components/ApiKey.jsx"
import ColumnSelection from "./components/ColumnSelection.jsx"
import Choices from "./components/Choices.jsx"
import ChoicesVoter from "./components/ChoicesVoter.jsx"
import Results from "./components/Results.jsx"
import treeNodeFactory from "./model/treeNodeFactory"
import queryString from "query-string"
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
Trello: Trello,
nodes: Array(),
rootNode: null,
currentView: 1,
startTimeStamp: null,// 1-ApiKey 2-ColumnSelect 3-Choices 4-SendDataToServer
boardId: null
};
this.getCurrentView = this.getCurrentView.bind(this)
this.setStartTimeStamp = this.setStartTimeStamp.bind(this)
this.setSortedRootNode = this.setSortedRootNode.bind(this)
this.setSortedRootNode = this.setSortedRootNode.bind(this)
this.handleCards = this.handleCards.bind(this)
this.handleAuthentication = this.handleAuthentication.bind(this)
this.componentDidMount = this.componentDidMount.bind(this)
}
componentDidMount () {
jQuery('.choice_button .card_link').click(function (e) {
e.stopPropagation();
});
}
handleAuthentication () {
const params = queryString.parse(location.search);
if (params.roomKey !== undefined) {
this.setState({
rootNode: [],
nodes: [],
currentView: 5
})
} else {
this.setState({
currentView: 2
});
}
}
handleCards (listCards, boardId) {
let that = this;
let nodes = [];
for (let i = 0; i < listCards.length; i++) {
let node = treeNodeFactory(listCards[i]);
nodes.push(node);
}
this.setState({
boardId: boardId,
rootNode: nodes.shift(),
nodes: nodes,
currentView: 3
}, function () {
that.refs.choices.startChoices();
})
}
setSortedRootNode (rootNode) {
this.setState({
rootNode: rootNode,
currentView: 4
})
}
setStartTimeStamp (timeStamp) {
this.setState({
startTimeStamp: timeStamp
})
}
renderApiKeyForm () {
return <ApiKey Trello={this.state.Trello} onAuthentication={this.handleAuthentication}/>
}
renderColumnSelection () {
return <ColumnSelection Trello={this.state.Trello} handleCards={this.handleCards}/>
}
renderChoicesVoter () {
return (
<ChoicesVoter Trello={this.state.Trello}
ref="choicesVoter" setSortedRootNode={this.setSortedRootNode}
setStartTimeStamp={this.setStartTimeStamp}
nodes={this.state.nodes}
rootNode={this.state.rootNode}/>
)
}
renderChoices () {
return (
<Choices Trello={this.state.Trello}
ref="choices" setSortedRootNode={this.setSortedRootNode}
setStartTimeStamp={this.setStartTimeStamp}
nodes={this.state.nodes}
boardId={this.state.boardId}
rootNode={this.state.rootNode}/>
)
}
renderResults () {
return (
<Results rootNode={this.state.rootNode} Trello={this.state.Trello}
startTimeStamp={this.state.startTimeStamp}/>
)
}
renderError(){
return <h3>Error</h3>
}
getCurrentView () {
switch (this.state.currentView) {
case 1:
return this.renderApiKeyForm()
case 2:
return this.renderColumnSelection()
case 3:
return this.renderChoices()
case 4:
return this.renderResults()
case 5:
return this.renderChoicesVoter()
default:
return this.renderError()
}
}
render () {
return (
<div id="container_div">
{this.getCurrentView()}
</div>
)
}
}
export default App