This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
ToolBar.js
227 lines (206 loc) · 8.15 KB
/
ToolBar.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// React
import React, { PropTypes } from 'react';
import { propTypes } from './react-props-decorators.js';
// Cerebral
import { Decorator as Cerebral } from 'cerebral-view-react';
// Material UI
import Toolbar from 'material-ui/lib/toolbar/toolbar';
import ToolbarGroup from 'material-ui/lib/toolbar/toolbar-group';
import IconMenu from 'material-ui/lib/menus/icon-menu';
import IconButton from 'material-ui/lib/icon-button';
import RaisedButton from 'material-ui/lib/raised-button';
import SettingsIcon from 'material-ui/lib/svg-icons/action/settings';
import FileIcon from 'material-ui/lib/svg-icons/editor/insert-drive-file';
import SaveIcon from 'material-ui/lib/svg-icons/action/backup';
import downloadIcon from 'material-ui/lib/svg-icons/file/file-download';
import uploadIcon from 'material-ui/lib/svg-icons/file/file-upload';
import PrintIcon from 'material-ui/lib/svg-icons/action/print';
import MenuItem from 'material-ui/lib/menus/menu-item';
import TextField from 'material-ui/lib/text-field';
@Cerebral({
embedded: ['embedded'],
readOnly: ['readOnly'],
showOrfs: ['showOrfs'],
showCutsites: ['showCutsites'],
showParts: ['showParts'],
showFeatures: ['showFeatures'],
showTranslations: ['showTranslations'],
showSidebar: ['showSidebar']
})
@propTypes({
embedded: PropTypes.bool.isRequired,
readOnly: PropTypes.bool.isRequired,
showOrfs: PropTypes.bool.isRequired,
showCutsites: PropTypes.bool.isRequired,
showParts: PropTypes.bool.isRequired,
showFeatures: PropTypes.bool.isRequired,
showTranslations: PropTypes.bool.isRequired
})
export default class ToolBar extends React.Component {
search() {
this.props.signals.searchSequence({ searchString: this.refs.searchField.getValue() });
}
clearSearch() {
this.props.signals.searchSequence({ searchString: "" });
}
render() {
var {
embedded,
readOnly,
showFeatures,
showParts,
showTranslations,
showOrfs,
showCutsites,
showSidebar,
signals
} = this.props;
var annotationList = [
{
type: 'features',
label: 'Features',
state: showFeatures
},
{
type: 'parts',
label: 'Parts',
state: showParts
},
{
type: 'translations',
label: 'Translations',
state: showTranslations
},
{
type: 'orfs',
label: 'ORFs',
state: showOrfs
},
{
type: 'cutsites',
label: 'Cutsites',
state: showCutsites
}
];
// show/hide views buttons that only appear in embedded mode
var embeddedControls = (
embedded ?
<div>
<RaisedButton
label='Row'
onTouchTap={function() {
document.getElementById("circularView").setAttribute("style", "display: none");
document.getElementById("rowView").setAttribute("style", "display: block");
}}
/>
<RaisedButton
label='Map'
onTouchTap={function() {
document.getElementById("circularView").setAttribute("style", "display: block");
document.getElementById("rowView").setAttribute("style", "display: none");
}}
/>
</div> : null
)
// upload and download files items
var fileMenuItems = (
<div>
<MenuItem key={1} primaryText="Download SBOL" insetChildren={true} onClick={function () {
signals.clickSaveFile({fileExt: 'sbol'});
}} />
<MenuItem key={2} primaryText="Download GenBank" insetChildren={true} onClick={function () {
signals.clickSaveFile({fileExt: 'genbank'});
}} />
<MenuItem key={3} primaryText="Download Fasta" insetChildren={true} onClick={function () {
signals.clickSaveFile({fileExt: 'fasta'});
}} />
<MenuItem key={4} primaryText="Upload from file ..." insetChildren={true} onClick={function () {
signals.clickLoadFile();
}} />
</div>
);
var fileButtonElement = (
<IconButton tooltip="File">
<FileIcon />
</IconButton>
);
// pop out sidebar
var toggleMenuItems = annotationList.map(function(annotationType, index){
return (
<MenuItem key={index} primaryText={annotationType.label} insetChildren={true} checked={annotationType.state} onClick={function () {
signals.toggleAnnotationDisplay({type: String(annotationType.type)});
}} />
);
});
// show/hide annotations
var iconButtonElement = (
<IconButton tooltip="Settings">
<SettingsIcon />
</IconButton>
);
// pulls out the current view and necessary resizing js to a new tab
// and applies some styling to cleanup for print version
var prepPrintPage = function() {
var contents = document.getElementById("allViews").innerHTML;
var head = document.head.innerHTML;
var stylePage = "<style>@page{margin: 1in;} #allViews{width: 8.5in}</style>";
var printTab = window.open();
printTab.document.body.innerHTML = head + stylePage + contents;
printTab.document.close();
printTab.focus();
printTab.print();
printTab.close();
}
return (
<Toolbar>
<ToolbarGroup key={0}>
{embeddedControls}
<IconButton
disabled={ readOnly } // you can't save in read only
label='Save to Server'
onTouchTap={function() {
signals.saveChanges();
}}
>
<SaveIcon />
</IconButton>
<IconButton
label='Print Current View'
onTouchTap={function() {
prepPrintPage();
}}
>
<PrintIcon />
</IconButton>
<RaisedButton
label='F'
onTouchTap={function() {
signals.toggleAnnotationTable({ annotationType: 'features' });
}}
/>
<RaisedButton
label='C'
onTouchTap={function() {
signals.toggleAnnotationTable({ annotationType: 'cutsites' });
}}
/>
<RaisedButton
label='O'
onTouchTap={function() {
signals.toggleAnnotationTable({ annotationType: 'orfs' });
}}
/>
<IconMenu iconButtonElement={fileButtonElement} openDirection="bottom-right">
{fileMenuItems}
</IconMenu>
<IconMenu iconButtonElement={iconButtonElement} openDirection="bottom-right">
{toggleMenuItems}
</IconMenu>
<TextField ref="searchField" hintText="search" />
<RaisedButton label='Search' onClick={this.search.bind(this)}/>
<RaisedButton label='Clear Search' onClick={this.clearSearch.bind(this)}/>
</ToolbarGroup>
</Toolbar>
);
}
}