-
Notifications
You must be signed in to change notification settings - Fork 36
add cells, rows, columns functions #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0e2bfbd
923010c
79add00
5e981dc
cd44a14
9495cc9
6584f2d
cbfd7e3
c27225c
3b99f9a
c33f558
4642e58
58507f4
c2abd8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
i | ||
span= CustomerID |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import _ from 'underscore'; | ||
|
||
function translateRow(columnGroup, row) { | ||
function translateRow(columnGroup, row, group) { | ||
if (_.has(row, 'html')) { | ||
return { | ||
classes: row.classes, | ||
|
@@ -12,10 +12,28 @@ function translateRow(columnGroup, row) { | |
}; | ||
} | ||
if (_.has(row, 'item')) { | ||
return { | ||
const obj = { | ||
classes: row.classes, | ||
cells: _.map(columnGroup.leafColumns, col => (row.item[col.name] || {})), | ||
cells: _.map(columnGroup.leafColumns, col => { | ||
const cell = row.item[col.name] || {}; | ||
const classes = col.classes; | ||
const template = col[group + 'Template']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. give it a default value, _.identity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, the template should always be function, don't need to check it. const html = _.result(cell, 'html', template(group === 'head'? col, row.item)); |
||
let html = ''; | ||
if (cell.html) { | ||
html = cell.html; | ||
} else { | ||
if (template) { | ||
html = _.isFunction(template) ? template(group == 'head' ? columnGroup : row.item) : template; | ||
} else { | ||
html = _.isObject(cell) ? cell.name : cell; | ||
} | ||
} | ||
|
||
return { classes, html }; | ||
}), | ||
}; | ||
|
||
return obj; | ||
} | ||
return row; | ||
} | ||
|
@@ -27,17 +45,17 @@ export function cells(state) { | |
footRows, | ||
columnGroup, | ||
} = state; | ||
|
||
headRows = _.reduce(headRows, (memo, row) => { | ||
if (row === 'column-header-rows') { | ||
return memo.concat(columnGroup.headerRows); | ||
} | ||
memo.push(translateRow(columnGroup, row)); | ||
memo.push(translateRow(columnGroup, row, 'head')); | ||
return memo; | ||
}, []); | ||
|
||
bodyRows = _.map(bodyRows, row => translateRow(columnGroup, row)); | ||
footRows = _.map(footRows, row => translateRow(columnGroup, row)); | ||
bodyRows = _.map(bodyRows, row => translateRow(columnGroup, row, 'body')); | ||
footRows = _.map(footRows, row => translateRow(columnGroup, row, 'foot')); | ||
|
||
return _.defaults({ | ||
headRows, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,19 @@ class ColumnGroup { | |
this.headerRows = []; | ||
this.leafColumns = []; | ||
|
||
const buildColumn = ({ | ||
name, | ||
width, | ||
parent = null, | ||
columns = [], | ||
html = name, | ||
height = 1, | ||
}) => { | ||
const col = { name, width, parent, html, height }; | ||
|
||
const buildColumn = col => { | ||
const { parent, columns, height } = col; | ||
|
||
col.height = _.isNumber(height) ? height : 1; | ||
col.rowIndex = parent ? parent.rowIndex + parent.height : 0; | ||
col.columns = _.map(columns, c => buildColumn(_.extend({ parent: col }, c))); | ||
col.treeHeight = height; | ||
col.treeHeight = _.isNumber(height) ? height : 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. col.treeHeight = col.height |
||
col.treeWidth = 1; | ||
if (!_.isEmpty(col.columns)) { | ||
col.treeHeight += _.chain(col.columns) | ||
.map(_.property('treeHeight')).max().value(); | ||
.map(_.property('treeHeight')).max().value(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er.....sublime reindent removes these indent |
||
col.treeWidth = _.chain(col.columns) | ||
.map(_.property('treeWidth')).reduce((a, b) => a + b, 0).value(); | ||
.map(_.property('treeWidth')).reduce((a, b) => a + b, 0).value(); | ||
} | ||
|
||
if (_.isEmpty(col.columns)) { | ||
|
@@ -37,12 +31,13 @@ class ColumnGroup { | |
if (col.parent) { | ||
const colspan = col.treeWidth; | ||
const rowspan = _.isEmpty(col.columns) ? this.root.treeHeight - col.rowIndex : col.height; | ||
const html = col.html; | ||
|
||
const html = col.html || col.name; | ||
console.log(this.headerRows); | ||
console.log(col.rowIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're going to remove this :) |
||
while (this.headerRows.length <= col.rowIndex) { | ||
this.headerRows.push({ cells: [] }); | ||
} | ||
this.headerRows[col.rowIndex].cells.push({ colspan, rowspan, html }); | ||
this.headerRows[col.rowIndex].cells.push({ colspan, rowspan, html, name }); | ||
} | ||
_.each(col.columns, buildColumnHeader); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export { odata } from './odata.js'; | ||
export { jsdata } from './jsdata.js'; | ||
export { selection } from './selection.js'; | ||
export { columns } from './columns.js'; | ||
export { rows } from './rows.js'; | ||
export { columnGroup } from './column-group.js'; | ||
export { cells } from './cells.js'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import _ from 'underscore'; | ||
import Promise from 'bluebird'; | ||
|
||
export function jsdata (state, { | ||
query, | ||
entity, | ||
options, | ||
skip, | ||
take, | ||
filter, | ||
orderby = [], | ||
select = [], | ||
} = {}) { | ||
const op = {}; | ||
|
||
if (take) { | ||
op.limit = take; | ||
} | ||
|
||
if (skip) { | ||
op.offset = skip; | ||
} | ||
|
||
if (filter) { | ||
op.where = filter; | ||
} | ||
|
||
if (query) { | ||
op.query = query; | ||
} | ||
|
||
if (orderby && orderby.length) { | ||
op.orderby = _.reduce(orderby, (memo, obj) => { | ||
_.each(obj, (key, value) => {memo.push([key, value > 0 ? 'ASC' : 'DESC']);}); | ||
return memo; | ||
}, []); | ||
} | ||
|
||
return entity.fincAll(op, _.defaults(options, { all: true })) | ||
.then(_.property('value')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent by 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sublime auto reindent does not work on this file~ So I fix the indentation by hand T_T |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import _ from 'underscore'; | ||
|
||
export function memory (state, { | ||
skip, | ||
take, | ||
filter, | ||
orderby = [], | ||
select = [], | ||
} = {}) { | ||
|
||
return p$state.then(function(data) { | ||
return take ? data.slice(skip || 0, take) : data.slice(skip || 0); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ export function rows(state, { | |
headRows = ['column-header-rows'], | ||
footRows = [], | ||
} = {}) { | ||
const columns = state.columns; | ||
const bodyRows = _.map(state.items, item => ({ | ||
classes: ['body-row'], | ||
item: _.mapObject(item, value => ({ html: value })), | ||
})); | ||
|
||
return { headRows, bodyRows, footRows, columns: state.columns }; | ||
item: item, //_.mapObject(item, value => ({ html: value })), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can simply be {
classes: ['body-row'],
item,
} |
||
})); | ||
return _.defaults({ headRows, bodyRows, footRows }, state); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not intended to change this file?