From 653e0cadcbfc65eb02abd6ee36fceb90ffca0818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 21 May 2015 14:51:15 +0200 Subject: [PATCH 1/5] Complete ordering functionality --- js/components/table_header.js | 63 +++++------------------ js/components/table_header_item.js | 47 ++++++++++++++++- js/components/table_header_item_carret.js | 24 +++++++++ 3 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 js/components/table_header_item_carret.js diff --git a/js/components/table_header.js b/js/components/table_header.js index 8754e477..d4afb409 100644 --- a/js/components/table_header.js +++ b/js/components/table_header.js @@ -2,6 +2,7 @@ import React from 'react'; import TableColumnMixin from '../mixins/table_column_mixin'; import GeneralUtils from '../utils/general_utils'; +import TableHeaderItem from './table_header_item'; let TableHeader = React.createClass({ @@ -14,66 +15,30 @@ let TableHeader = React.createClass({ orderBy: React.PropTypes.string.isRequired }, - sortIndex(i) { - - let orderAsc; - - if(this.props.orderAsc) { - orderAsc = false; - } else { - orderAsc = true; - } - - this.props.fetchList(1, 10, null, Object.keys(this.props.columnMap)[i], orderAsc); - }, - render() { let columnMapValuesList = GeneralUtils.valuesOfObject(this.props.columnMap); - let calcHeaderText = (val, i, columnClass) => { - - if(columnMapValuesList[i].canBeOrdered && Object.keys(this.props.columnMap)[i] === this.props.orderBy) { - - let boundClick = this.sortIndex.bind(this, i); - let carretDirection = 'glyphicon-triangle-'; - - if(this.props.orderAsc) { - carretDirection += 'top'; - } else { - carretDirection += 'bottom'; - } - - return ( -
- - {val.displayName} - - -
- ); - } else { - return ( -
- - {val.displayName} - -
- ); - } - }; - return (
{columnMapValuesList.map((val, i) => { - let columnClass = this.calcColumnClasses(this.props.columnMap, i); + let columnClasses = this.calcColumnClasses(this.props.columnMap, i); + let columnName = Object.keys(this.props.columnMap)[i]; + let canBeOrdered = columnMapValuesList[i].canBeOrdered; return ( -
- {calcHeaderText(val, i, columnClass)} -
+ + ); })}
diff --git a/js/components/table_header_item.js b/js/components/table_header_item.js index d566975c..d918f6e3 100644 --- a/js/components/table_header_item.js +++ b/js/components/table_header_item.js @@ -1,9 +1,52 @@ import React from 'react'; +import TableHeaderItemCarret from './table_header_item_carret'; let TableHeaderItem = React.createClass({ - mixins: [TableColumnMixin], + + propTypes: { + columnClasses: React.PropTypes.string.isRequired, + displayName: React.PropTypes.string.isRequired, + columnName: React.PropTypes.string.isRequired, + canBeOrdered: React.PropTypes.bool.isRequired, + orderAsc: React.PropTypes.bool.isRequired, + orderBy: React.PropTypes.string.isRequired, + fetchList: React.PropTypes.func.isRequired + }, + + changeOrder() { + this.props.fetchList(1, 10, null, this.props.columnName, !this.props.orderAsc); + }, + render() { - return() + if(this.props.canBeOrdered) { + if(this.props.columnName === this.props.orderBy) { + return ( +
+ {this.props.displayName} +
+ ); + } else { + return ( +
+ {this.props.displayName} +
+ ); + } + } else { + return ( +
+ + {this.props.displayName} + +
+ ); + } } }); + +export default TableHeaderItem; diff --git a/js/components/table_header_item_carret.js b/js/components/table_header_item_carret.js new file mode 100644 index 00000000..8d33eb75 --- /dev/null +++ b/js/components/table_header_item_carret.js @@ -0,0 +1,24 @@ +import React from 'react'; + +let TableHeaderItemCarret = React.createClass({ + propTypes: { + orderAsc: React.PropTypes.bool.isRequired + }, + + render() { + let carretDirection = 'glyphicon-triangle-'; + + if(this.props.orderAsc) { + carretDirection += 'top'; + } else { + carretDirection += 'bottom'; + } + + return ( + + + ); + } +}); + +export default TableHeaderItemCarret; \ No newline at end of file From 8376032b95e0f18d5f6c3d4238d125698daf700a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 21 May 2015 15:14:05 +0200 Subject: [PATCH 2/5] group table component --- js/components/{ => ascribe_table}/table.js | 0 js/components/{ => ascribe_table}/table_header.js | 4 ++-- js/components/{ => ascribe_table}/table_header_item.js | 0 .../{ => ascribe_table}/table_header_item_carret.js | 0 js/components/{ => ascribe_table}/table_item.js | 2 +- js/components/{ => ascribe_table}/table_item_img.js | 0 js/components/{ => ascribe_table}/table_item_text.js | 0 js/components/header.js | 1 + js/components/piece_list.js | 6 +++--- 9 files changed, 7 insertions(+), 6 deletions(-) rename js/components/{ => ascribe_table}/table.js (100%) rename js/components/{ => ascribe_table}/table_header.js (93%) rename js/components/{ => ascribe_table}/table_header_item.js (100%) rename js/components/{ => ascribe_table}/table_header_item_carret.js (100%) rename js/components/{ => ascribe_table}/table_item.js (96%) rename js/components/{ => ascribe_table}/table_item_img.js (100%) rename js/components/{ => ascribe_table}/table_item_text.js (100%) diff --git a/js/components/table.js b/js/components/ascribe_table/table.js similarity index 100% rename from js/components/table.js rename to js/components/ascribe_table/table.js diff --git a/js/components/table_header.js b/js/components/ascribe_table/table_header.js similarity index 93% rename from js/components/table_header.js rename to js/components/ascribe_table/table_header.js index d4afb409..38d32705 100644 --- a/js/components/table_header.js +++ b/js/components/ascribe_table/table_header.js @@ -1,7 +1,7 @@ import React from 'react'; -import TableColumnMixin from '../mixins/table_column_mixin'; -import GeneralUtils from '../utils/general_utils'; +import TableColumnMixin from '../../mixins/table_column_mixin'; +import GeneralUtils from '../../utils/general_utils'; import TableHeaderItem from './table_header_item'; diff --git a/js/components/table_header_item.js b/js/components/ascribe_table/table_header_item.js similarity index 100% rename from js/components/table_header_item.js rename to js/components/ascribe_table/table_header_item.js diff --git a/js/components/table_header_item_carret.js b/js/components/ascribe_table/table_header_item_carret.js similarity index 100% rename from js/components/table_header_item_carret.js rename to js/components/ascribe_table/table_header_item_carret.js diff --git a/js/components/table_item.js b/js/components/ascribe_table/table_item.js similarity index 96% rename from js/components/table_item.js rename to js/components/ascribe_table/table_item.js index 41a40d11..5245a352 100644 --- a/js/components/table_item.js +++ b/js/components/ascribe_table/table_item.js @@ -1,6 +1,6 @@ import React from 'react'; -import TableColumnMixin from '../mixins/table_column_mixin'; +import TableColumnMixin from '../../mixins/table_column_mixin'; import TableItemImg from './table_item_img'; import TableItemText from './table_item_text'; diff --git a/js/components/table_item_img.js b/js/components/ascribe_table/table_item_img.js similarity index 100% rename from js/components/table_item_img.js rename to js/components/ascribe_table/table_item_img.js diff --git a/js/components/table_item_text.js b/js/components/ascribe_table/table_item_text.js similarity index 100% rename from js/components/table_item_text.js rename to js/components/ascribe_table/table_item_text.js diff --git a/js/components/header.js b/js/components/header.js index c7ad3965..c9a4fc24 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -1,4 +1,5 @@ import React from 'react'; + import AltContainer from 'alt/AltContainer'; import UserActions from '../actions/user_actions'; import UserStore from '../stores/user_store'; diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 1638f55d..aaf05405 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -5,9 +5,9 @@ import AltContainer from 'alt/AltContainer'; import PieceListStore from '../stores/piece_list_store'; import PieceListActions from '../actions/piece_list_actions'; -import Table from './table'; -import TableItemImg from './table_item_img'; -import TableItemText from './table_item_text'; +import Table from './ascribe_table/table'; +import TableItemImg from './ascribe_table/table_item_img'; +import TableItemText from './ascribe_table/table_item_text'; let Link = Router.Link; From 0f6dc6b3e002a5ef4e26f4857c47c54c3774df79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 21 May 2015 15:16:56 +0200 Subject: [PATCH 3/5] put link in header --- js/components/ascribe_app.js | 3 --- js/components/header.js | 10 +++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/js/components/ascribe_app.js b/js/components/ascribe_app.js index 7d19c1b0..bab7de97 100644 --- a/js/components/ascribe_app.js +++ b/js/components/ascribe_app.js @@ -11,9 +11,6 @@ let AscribeApp = React.createClass({ return (
-
); diff --git a/js/components/header.js b/js/components/header.js index c9a4fc24..a3d32de0 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -1,9 +1,11 @@ import React from 'react'; +import Router from 'react-router'; import AltContainer from 'alt/AltContainer'; import UserActions from '../actions/user_actions'; import UserStore from '../stores/user_store'; +let Link = Router.Link; let Header = React.createClass({ @@ -32,11 +34,17 @@ let Header = React.createClass({ - ascribe + ascribe
+