mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Refactor TableColumnMixin
This commit is contained in:
parent
65ccaf10cf
commit
ca97bd9af5
@ -23,7 +23,7 @@ let TableHeader = React.createClass({
|
|||||||
<div className="row">
|
<div className="row">
|
||||||
{this.props.columnList.map((val, i) => {
|
{this.props.columnList.map((val, i) => {
|
||||||
|
|
||||||
let columnClasses = this.calcColumnClasses(this.props.columnList, i);
|
let columnClasses = this.calcColumnClasses(this.props.columnList, i, 12);
|
||||||
let columnName = this.props.columnList[i].columnName;
|
let columnName = this.props.columnList[i].columnName;
|
||||||
let canBeOrdered = this.props.columnList[i].canBeOrdered;
|
let canBeOrdered = this.props.columnList[i].canBeOrdered;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ let TableItem = React.createClass({
|
|||||||
return this.props.columnList.map((column, i) => {
|
return this.props.columnList.map((column, i) => {
|
||||||
|
|
||||||
let TypeElement = column.displayType;
|
let TypeElement = column.displayType;
|
||||||
let columnClass = this.calcColumnClasses(this.props.columnList, i);
|
let columnClass = this.calcColumnClasses(this.props.columnList, i, 12);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={columnClass + ' ascribe-table-item-column'} key={i}>
|
<div className={columnClass + ' ascribe-table-item-column'} key={i}>
|
||||||
|
@ -56,7 +56,7 @@ let TableItemSubtable = React.createClass({
|
|||||||
return this.props.columnList.map((column, i) => {
|
return this.props.columnList.map((column, i) => {
|
||||||
|
|
||||||
let TypeElement = column.displayType;
|
let TypeElement = column.displayType;
|
||||||
let columnClass = this.calcColumnClasses(this.props.columnList, i);
|
let columnClass = this.calcColumnClasses(this.props.columnList, i, 12);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={columnClass + ' ascribe-table-item-column'} key={i}>
|
<div className={columnClass + ' ascribe-table-item-column'} key={i}>
|
||||||
|
@ -7,14 +7,14 @@ let TableColumnMixin = {
|
|||||||
* Generates the bootstrap grid column declarations automatically using
|
* Generates the bootstrap grid column declarations automatically using
|
||||||
* the columnMap.
|
* the columnMap.
|
||||||
*/
|
*/
|
||||||
calcColumnClasses(list, i) {
|
calcColumnClasses(list, i, numOfColumns) {
|
||||||
let bootstrapClasses = ['col-xs-', 'col-sm-', 'col-md-', 'col-lg-'];
|
let bootstrapClasses = ['col-xs-', 'col-sm-', 'col-md-', 'col-lg-'];
|
||||||
|
|
||||||
let listOfRowValues = list.map((column) => column.rowWidth );
|
let listOfRowValues = list.map((column) => column.rowWidth );
|
||||||
let numOfColumns = GeneralUtils.sumNumList(listOfRowValues);
|
let numOfUsedColumns = GeneralUtils.sumNumList(listOfRowValues);
|
||||||
|
|
||||||
if(numOfColumns > 12) {
|
if(numOfUsedColumns > numOfColumns) {
|
||||||
throw new Error('Bootstrap has only 12 columns to assign. You defined ' + numOfColumns + '. Change this in the columnMap you\'re passing to the table.')
|
throw new Error('This table has only ' + numOfColumns + ' columns to assign. You defined ' + numOfUsedColumns + '. Change this in the columnMap you\'re passing to the table.')
|
||||||
} else {
|
} else {
|
||||||
return bootstrapClasses.join( listOfRowValues[i] + ' ') + listOfRowValues[i];
|
return bootstrapClasses.join( listOfRowValues[i] + ' ') + listOfRowValues[i];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user