Skip to content

Commit 9f5f43c

Browse files
committed
Some stylistic changes
1 parent 75f3c01 commit 9f5f43c

File tree

4 files changed

+43
-63
lines changed

4 files changed

+43
-63
lines changed

esp/esp/program/modules/handlers/schedulingcheckmodule.py

+5-24
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,9 @@ def format_list(self, l, help_text=""): # needs verify
6464
output["headings"] = [] # no headings
6565

6666
# might be redundant, but it makes sure things aren't in a weird format
67-
body = []
68-
for row in l:
69-
body.append(self._table_row([row]))
70-
output["body"] = body
67+
output["body"] = [self._table_row([row]) for row in l]
7168
return json.dumps(output)
7269

73-
def _table_headings(self, headings): # in case headings are a dict
74-
#column headings
75-
next_row = []
76-
for h in headings:
77-
next_row.append(str(h))
78-
return next_row
79-
8070
def _table_row(self, row):
8171
next_row = []
8272
for r in row:
@@ -89,25 +79,16 @@ def _table_row(self, row):
8979
def _format_list_table(self, d, headings, help_text=""): #needs verify
9080
output = {}
9181
output["help_text"] = help_text
92-
output["headings"] = self._table_headings(headings)
93-
body = []
94-
for row in d:
95-
ordered_row = [row[h] for h in headings]
96-
body.append(self._table_row(ordered_row)) # maybe?
97-
output["body"] = body
82+
output["headings"] = map(str, headings)
83+
output["body"] = [self._table_row([row[h] for h in headings]) for row in d]
9884
return output
9985

10086
def _format_dict_table(self, d, headings, help_text=""): #needs verify
10187
headings = [""] + headings[:]
10288
output = {}
10389
output["help_text"] = help_text
104-
output["headings"] = self._table_headings(headings)
105-
106-
body = []
107-
for key, row in sorted(d.iteritems()):
108-
ordered_row = [row[h] for h in headings if h]
109-
body.append(self._table_row([key] + ordered_row)) #maybe
110-
output["body"] = body
90+
output["headings"] = map(str, headings)
91+
output["body"] = [self._table_row([key] + [row[h] for h in headings if h]) for key, row in sorted(d.iteritems())]
11192
return output
11293

11394
class SchedulingCheckRunner:

esp/public/media/scripts/program/modules/scheduling_checks.jsx

+36-38
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var SchedulingCheck = React.createClass({
3737
open: false,
3838
failed: false,
3939
timestamp: "never",
40-
tableState: {
40+
tableState: { // gets modified by functions in the definition of SelectTable
4141
greyed: {},
4242
sort: -1
4343
}
@@ -96,23 +96,17 @@ var SchedulingCheck = React.createClass({
9696
var data = JSON.parse(this.state.data); // Might not work on old browsers
9797
var table;
9898
if (data.headings.length == 0) {
99-
var settings = {
100-
header: false
101-
};
102-
table = <SelectTable rows = {data.body} settings = {settings} saveState = {this.state.tableState} />;
99+
table = <SelectTable rows = {data.body} header = {false} saveState = {this.state.tableState} />;
103100
} else {
104101
var columns = [];
105102
for (i = 0; i < data.headings.length; i++) {
106-
if (!!data.headings[i]) {
103+
if (data.headings[i]) {
107104
columns[i] = {key: String(i), label: data.headings[i]};
108105
} else {
109106
columns[i] = {key: String(i), label: " "};
110107
}
111108
}
112-
var settings = {
113-
header: true
114-
};
115-
table = <SelectTable rows = {data.body} columns = {columns} settings = {settings} saveState = {this.state.tableState} />;
109+
table = <SelectTable rows = {data.body} columns = {columns} header = {true} saveState = {this.state.tableState} />;
116110
}
117111
body = <div>
118112
<div className="placeholder">
@@ -151,57 +145,61 @@ var RefreshButton = React.createClass({
151145

152146

153147
// Modified from react-json-table example code.
154-
// Required props: rows, saveState (with sort and greyed attributes), settings (with header attribute)
155148
var SelectTable = React.createClass({
149+
150+
propTypes: {
151+
rows: React.PropTypes.array.isRequired,
152+
savestate: React.PropTypes.shape({
153+
greyed: React.PropTypes.object.isRequired,
154+
sort: React.PropTypes.any.isRequired
155+
}).isRequired,
156+
header: React.PropTypes.bool.isRequired,
157+
columns: React.PropTypes.object
158+
},
159+
156160
getInitialState: function(){
157161
// We will store the sorted column and whether each row is greyed out
158-
return {sort: this.props.saveState.sort, greyed : this.props.saveState.greyed};
162+
return {sort: this.props.saveState.sort, greyed: this.props.saveState.greyed};
159163
},
160164
render: function(){
161165
var me = this,
162166
// clone the rows
163167
items = this.props.rows.slice()
164168
;
165-
// Sort the table
166-
if( this.state.sort ){
167-
items.sort( function( a, b ){
168-
return a[ me.state.sort ] > b[ me.state.sort ] ? 1 : -1;
169+
170+
items = _.sortBy(items, function( item ){
171+
return item[ me.state.sort ];
169172
});
170-
}
171173

172-
if (this.props.columns == undefined) {
173-
return <JsonTable
174-
rows={items}
175-
settings={ this.getSettings() }
176-
onClickHeader={ this.onClickHeader }
177-
onClickRow={ this.onClickRow }
178-
/>;
179-
} else {
180-
return <JsonTable
181-
rows={items}
182-
columns={this.props.columns}
183-
settings={ this.getSettings() }
184-
onClickHeader={ this.onClickHeader }
185-
onClickRow={ this.onClickRow }
186-
/>;
187-
}
174+
175+
return <JsonTable
176+
rows={items}
177+
columns={this.props.columns}
178+
settings={ this.getSettings() }
179+
onClickHeader={ this.onClickHeader }
180+
onClickRow={ this.onClickRow }
181+
/>;
188182
},
189183

190184
getSettings: function(){
191185
var me = this;
192186
// We will add some classes to the selected rows and cells
193187
return {
194188
headerClass: function( current, key ){
195-
if( me.state.sort == key )
189+
if( me.state.sort == key ) {
196190
return current + ' headerSelected';
197-
return current;
191+
} else {
192+
return current;
193+
}
198194
},
199195
rowClass: function( current, item ){
200-
if( me.state.greyed[item] )
196+
if( me.state.greyed[item] ) {
201197
return current + ' rowGreyed';
202-
return current;
198+
} else {
199+
return current;
200+
}
203201
},
204-
header: this.props.settings.header
202+
header: this.props.header
205203
};
206204
},
207205

esp/templates/elements/html

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
4848
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
49-
<script type="text/javascript" src="https://rawgit.com/arqex/react-json-table/master/build/react-json-table.min.js"></script>
5049
<script type="text/javascript" src="/media/scripts/lodash.compat.min.js"></script>
5150

5251
{% block js1 %}

esp/templates/program/modules/schedulingcheckmodule/output.html

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
}
1515
//-->
1616
</script>
17+
<script type="text/javascript" src="https://rawgit.com/arqex/react-json-table/6518983b5ecc0a314e50a4b7f26985c04069babd/build/react-json-table.min.js"></script>
1718
<script type="text/jsx" src="/media/scripts/program/modules/scheduling_checks.jsx"></script>
19+
1820
{% endblock %}
1921

2022
{% block stylesheets %}

0 commit comments

Comments
 (0)