/
app.js
67 lines (56 loc) · 2.21 KB
/
app.js
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
'use strict';
var app = undefined;
class App extends React.Component {
constructor(props) {
super(props);
this.state = { hideNavbar: false, navbarMode: "menu", content: "rulegraph", ruleinfo: undefined, category: undefined, subcategory: undefined, searchTerm: undefined, resultPath: undefined, contentPath: undefined };
this.setView = this.setView.bind(this);
this.showCategory = this.showCategory.bind(this);
this.showResultInfo = this.showResultInfo.bind(this);
this.showReportInfo = this.showReportInfo.bind(this);
// store in global variable
app = this;
}
render() {
return [
e(Navbar, { key: "navbar", app: this }),
e(ContentDisplay, { key: "content", app: this })
];
}
setView(view) {
this.setState({
hideNavbar: view.hideNavbar || this.hideNavbar,
navbarMode: view.navbarMode || this.state.navbarMode,
content: view.content || this.state.content,
ruleinfo: view.ruleinfo || this.state.ruleinfo,
category: view.category || this.state.category,
subcategory: view.subcategory || this.state.subcategory,
searchTerm: view.searchTerm || this.state.searchTerm,
resultPath: view.resultPath || this.state.resultPath,
contentPath: view.contentPath || this.state.contentPath,
contentText: view.contentText || this.state.contentText,
})
}
showCategory(category) {
let subcategory = undefined;
let mode = "category";
if (isSingleSubcategory(category)) {
subcategory = Object.keys(categories[category])[0];
mode = "subcategory";
}
this.setView({ navbarMode: mode, category: category, subcategory: subcategory })
}
showReportInfo() {
this.setView({ navbarMode: "reportinfo" });
}
showResultInfo(resultPath) {
this.setView({ navbarMode: "resultinfo", resultPath: resultPath });
}
showLicense(package_name) {
this.setView({
content: "text",
contentText: packages[package_name].license
});
}
}
ReactDOM.render(e(App), document.querySelector('#app'));