Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#189 included rows (wip) #2
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed Jan 20, 2017
1 parent dab04c5 commit 5254028
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/actions/MenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ export function getWindowBreadcrumb(id){

// UTILITIES

export function flattenLastElem(node) {
export function flattenLastElem(node, prop = "children") {
let result = [];

if(!!node.children){
node.children.map(child => {
if(!!node[prop]){
node[prop].map(child => {
const flat = flattenLastElem(child);

if(typeof flat === "object"){
Expand Down
9 changes: 9 additions & 0 deletions src/assets/css/font-meta.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@
.meta-icon-collapse:before {
content: "\55";
}
.meta-icon-package:before {
content: "\56";
}
.meta-icon-palette:before {
content: "\57";
}
.meta-icon-product:before {
content: "\58";
}
Binary file modified src/assets/css/fonts/meta.eot
Binary file not shown.
3 changes: 3 additions & 0 deletions src/assets/css/fonts/meta.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/css/fonts/meta.ttf
Binary file not shown.
Binary file modified src/assets/css/fonts/meta.woff
Binary file not shown.
1 change: 0 additions & 1 deletion src/assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,3 @@ td.pulse-off input {
font-size: .75rem;
color: $brand-font-color-weak;
}

5 changes: 5 additions & 0 deletions src/assets/css/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,8 @@ th {
.pagination-link {
text-decoration: underline;
}

.table.table-bordered-vertically td.indent {
min-width:0;
border-right:0;
}
17 changes: 6 additions & 11 deletions src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,9 @@ class Table extends Component {
}
}

changeListenOnTrue = () => {
changeListen = (listenOnKeys) => {
this.setState(Object.assign({}, this.state, {
listenOnKeys: true
}))
}

changeListenOnFalse = () => {
this.setState(Object.assign({}, this.state, {
listenOnKeys: false
listenOnKeys: !!listenOnKeys
}))
}

Expand Down Expand Up @@ -417,6 +411,7 @@ class Table extends Component {
const key = keys[i];
const index = keyProperty ? keyProperty : "rowId";
const included = item[key].includedDocuments;

ret.push(
<TableItemWrapper
included={included}
Expand All @@ -432,10 +427,10 @@ class Table extends Component {
mainTable={mainTable}
isSelected={selected.indexOf(item[key][index]) > -1}
onDoubleClick={() => onDoubleClick && onDoubleClick(item[key][index])}
onMouseDown={(e) => this.handleClick(e, item[key][index])}
handleClick={(e) => this.handleClick(e, item[key][index])}
onContextMenu={(e) => this.handleRightClick(e, item[key][index])}
changeListenOnTrue={() => this.changeListenOnTrue()}
changeListenOnFalse={() => this.changeListenOnFalse()}
changeListenOnTrue={() => this.changeListen(true)}
changeListenOnFalse={() => this.changeListen(false)}
newRow={i === keys.length-1 ? newRow : false}
/>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/table/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TableHeader extends Component {
const {cols, mainTable} = this.props;
return (
<tr>
<th
className="indent"
/>
{this.renderCols(cols, mainTable)}
</tr>
)
Expand Down
35 changes: 10 additions & 25 deletions src/components/table/TableItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ class TableItem extends Component {
const {
isSelected, fields, selectedProducts, onContextMenu, rowId, cols,
onMouseDown, onDoubleClick, included, tabid, type, docId,
tabIndex, mainTable, entity, readonly
tabIndex, mainTable, entity, readonly, indent
} = this.props;

const huType = findRowByPropName(fields, "HU_UnitType").value;

return (
<tr
Expand All @@ -140,36 +141,20 @@ class TableItem extends Component {
(isSelected ? "row-selected" : "")
}
>
<td
className="indent"
style={{paddingLeft: (indent * 10 + 10) + "px"}}
>
{huType == "LU" && <i className="meta-icon-palette"/>}
{huType == "TU" && <i className="meta-icon-package"/>}
{huType == "V" && <i className="meta-icon-product"/>}
</td>
{this.renderCells(cols, fields)}
</tr>
);
}
}

// {included && included.map((item, index) =>
// <TableItem
// entity={entity}
// fields={item.fields}
// key={index + item.rowId}
// rowId={item.rowId}
// tabId={tabid}
// cols={cols}
// type={type}
// docId={docId}
// isSelected={false}
// onDoubleClick={null}
// onMouseDown={null}
// onContextMenu={null}
// changeListenOnTrue={null}
// changeListenOnFalse={null}
// readonly={readonly}
// mainTable={mainTable}
// newRow={false}
// tabIndex={tabIndex}
// included={item.includedDocuments}
// />
// )}

TableItem.propTypes = {
dispatch: PropTypes.func.isRequired
};
Expand Down
78 changes: 59 additions & 19 deletions src/components/table/TableItemWrapper.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,78 @@
import React, { Component, PropTypes } from 'react';
import TableItem from './TableItem';
import update from 'react-addons-update';

import {flattenLastElem} from '../../actions/MenuActions';

class TableItemWrapper extends Component {
constructor(props){
super(props);

this.state = {
rows: []
}
}

componentDidMount(){
const {item} = this.props;
this.setState(Object.assign({}, this.state, {
rows: this.mapIncluded(item)
}))
}

mapIncluded = (node, indent) => {
let ind = indent ? indent : 0;
let result = [];

const nodeCopy = Object.assign({}, node, {
indent: ind
});

result = result.concat([nodeCopy]);

if(node.includedDocuments){
node.includedDocuments.map(item => {
result = result.concat(this.mapIncluded(item, ind + 1))
})
}

return result;
}

render() {
const {
included, item, entity, tabid, cols, type, docId, isSelected, onDoubleClick,
handleClick, handleRightClick, changeListenOnTrue, changeListenOnFalse,
newRow, tabIndex, readonly, mainTable
} = this.props;

const {rows} = this.state;

return (
<tbody>
<TableItem
entity={entity}
fields={item.fields}
rowId={item.rowId}
tabId={tabid}
cols={cols}
type={type}
docId={docId}
tabIndex={tabIndex}
readonly={readonly}
mainTable={mainTable}
isSelected={isSelected}
onDoubleClick={() => onDoubleClick && onDoubleClick()}
onMouseDown={(e) => handleClick && handleClick(e)}
onContextMenu={(e) => handleRightClick && handleRightClick(e)}
changeListenOnTrue={() => changeListenOnTrue && changeListenOnTrue()}
changeListenOnFalse={() => changeListenOnFalse && changeListenOnFalse()}
newRow={newRow}
/>
{rows.map((item, index) =>
<TableItem
entity={entity}
fields={item.fields}
rowId={item.rowId}
tabId={tabid}
cols={cols}
type={type}
docId={docId}
tabIndex={tabIndex}
readonly={readonly}
mainTable={mainTable}
onDoubleClick={() => onDoubleClick && onDoubleClick()}
onMouseDown={(e) => handleClick && handleClick(e)}
onContextMenu={(e) => handleRightClick && handleRightClick(e)}
changeListenOnTrue={() => changeListenOnTrue && changeListenOnTrue()}
changeListenOnFalse={() => changeListenOnFalse && changeListenOnFalse()}
newRow={newRow}
isSelected={isSelected}
key={index}
indent={item.indent}
/>
)}
</tbody>
);
}
Expand Down

0 comments on commit 5254028

Please sign in to comment.