From 0e2bfbd3f03fe6d2a9bb35cace21033f04bd1c67 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Wed, 27 Jul 2016 20:54:46 +0800 Subject: [PATCH 01/11] add jsdata function --- js/vnext/projection/index.js | 1 + js/vnext/projection/jsdata.js | 41 +++++++++++++++++++++++++++++++++++ js/vnext/projection/odata.js | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/js/vnext/projection/index.js b/js/vnext/projection/index.js index 1ec8a3e..130c82d 100644 --- a/js/vnext/projection/index.js +++ b/js/vnext/projection/index.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import Promise from 'bluebird'; export { odata } from './odata.js'; +export { jsdata } from './jsdata.js'; export class ProjectionChain extends Backbone.Model { initialize(options) { diff --git a/js/vnext/projection/jsdata.js b/js/vnext/projection/jsdata.js index e69de29..a68c0d2 100644 --- a/js/vnext/projection/jsdata.js +++ b/js/vnext/projection/jsdata.js @@ -0,0 +1,41 @@ +import _ from 'underscore'; +import Promise from 'bluebird'; + +export function jsdataProj (p$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')); +}; \ No newline at end of file diff --git a/js/vnext/projection/odata.js b/js/vnext/projection/odata.js index a215a39..610494b 100644 --- a/js/vnext/projection/odata.js +++ b/js/vnext/projection/odata.js @@ -41,5 +41,5 @@ export function odata (p$state, { reject(new Error(errorThrown)); }); }).then(_.property('value')); -} +}; From 79add009114fdaeafffa713ec565d9669cc5fcad Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Thu, 28 Jul 2016 18:50:57 +0800 Subject: [PATCH 02/11] add cells, rows, columns --- js/vnext/projection/cells.js | 13 +++++++++++-- js/vnext/projection/columns.js | 1 + js/vnext/projection/index.js | 4 +++- js/vnext/projection/rows.js | 12 ++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/js/vnext/projection/cells.js b/js/vnext/projection/cells.js index 0c44dc5..d0eec69 100644 --- a/js/vnext/projection/cells.js +++ b/js/vnext/projection/cells.js @@ -12,10 +12,19 @@ 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 tpl = cell.template || cell.headerTemplate || cell.footerTemplate; + if (tpl) { + cell.html = _.template(tpl, cell); + } + return cell; + }), }; + + return obj; } return row; } diff --git a/js/vnext/projection/columns.js b/js/vnext/projection/columns.js index 5ec1a07..41524df 100644 --- a/js/vnext/projection/columns.js +++ b/js/vnext/projection/columns.js @@ -1,5 +1,6 @@ import _ from 'underscore'; + export function columns(state, { columns = _.chain(state).first().keys().map(name => ({ name, diff --git a/js/vnext/projection/index.js b/js/vnext/projection/index.js index a88f1c2..51e4645 100644 --- a/js/vnext/projection/index.js +++ b/js/vnext/projection/index.js @@ -17,7 +17,9 @@ export class ProjectionChain extends Backbone.Model { update() { return _.reduce( this.projections, - (p$state, proj) => p$state.then(state => proj(state, this.attributes)), + (p$state, proj) => p$state.then(state => { + const newState = proj(state, this.attributes); + return newState;}), Promise.resolve({}) ); } diff --git a/js/vnext/projection/rows.js b/js/vnext/projection/rows.js index 397be5c..b96513d 100644 --- a/js/vnext/projection/rows.js +++ b/js/vnext/projection/rows.js @@ -1,5 +1,6 @@ import _ from 'underscore'; +/* export const rows = (state, { headRows = ['column-header-rows'], footRows = [], @@ -11,5 +12,16 @@ export const rows = (state, { return _.extend(state, { headRows, bodyRows, footRows }); }; +*/ +export function rows(state, { + headRows = ['column-header-rows'], + footRows = [], +} = {}) { + const bodyRows = _.map(state, item => ({ + classes: ['body-row'], + item: _.mapObject(item, value => ({ html: value })), + })); + return _.extend(state, { headRows, bodyRows, footRows }); +}; From cd44a142185927c058532f8cd55f3cd9e2cded21 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 14:56:34 +0800 Subject: [PATCH 03/11] add cell function with template --- demos/grid-view/index.js | 7 +++++++ js/vnext/projection/cells.js | 4 ++-- js/vnext/projection/column-group.js | 6 ++++-- js/vnext/projection/rows.js | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index 1fa04be..a8d9812 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -10,8 +10,10 @@ import { cells, } from '../../js/vnext/projection'; import './index.less'; +import * as tmpl from '../cell-view/key-column-header.jade'; import 'bootstrap-webpack'; +window.t = tmpl; window.gridViewEl = new GridView({ el: '.container-element-viewport', viewport: '.container-element-viewport', @@ -29,6 +31,11 @@ window.gridViewEl = new GridView({ ]).set({ url: 'http://services.odata.org/V4/Northwind/Northwind.svc/Orders', selection: true, + columns: [{name: 'CustomerID', + template:tmpl.default, + },{ + name: 'ShipCity', + }], }).render(); /* diff --git a/js/vnext/projection/cells.js b/js/vnext/projection/cells.js index 9f7ec74..da88918 100644 --- a/js/vnext/projection/cells.js +++ b/js/vnext/projection/cells.js @@ -16,9 +16,9 @@ function translateRow(columnGroup, row) { classes: row.classes, cells: _.map(columnGroup.leafColumns, col => { const cell = row.item[col.name] || {}; - const tpl = cell.template || cell.headerTemplate || cell.footerTemplate; + const tpl = col.template || col.headerTemplate || col.footerTemplate; if (tpl) { - cell.html = _.template(tpl, cell); + cell.html = _.isFunction(tpl) ? tpl(row.item) : tpl; } return cell; }), diff --git a/js/vnext/projection/column-group.js b/js/vnext/projection/column-group.js index 6c9594c..2acdacd 100644 --- a/js/vnext/projection/column-group.js +++ b/js/vnext/projection/column-group.js @@ -8,13 +8,15 @@ class ColumnGroup { const buildColumn = ({ name, width, + template, parent = null, columns = [], html = name, height = 1, }) => { - const col = { name, width, parent, html, height }; - + const col = { name, width, template, parent, html, height }; + + col.template = template ? template : (parent? parent.template : null); col.rowIndex = parent ? parent.rowIndex + parent.height : 0; col.columns = _.map(columns, c => buildColumn(_.extend({ parent: col }, c))); col.treeHeight = height; diff --git a/js/vnext/projection/rows.js b/js/vnext/projection/rows.js index 5615df3..db57f32 100644 --- a/js/vnext/projection/rows.js +++ b/js/vnext/projection/rows.js @@ -17,11 +17,12 @@ export function rows(state, { headRows = ['column-header-rows'], footRows = [], } = {}) { + const columns = state.columns; const bodyRows = _.map(state, item => ({ classes: ['body-row'], item: _.mapObject(item, value => ({ html: value })), })); - return _.extend(state, { headRows, bodyRows, footRows }); + return _.defaults(state, { headRows, bodyRows, footRows }); }; From 9495cc959379b1c0dac3394f72b7d7b4b5f184bf Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 16:39:32 +0800 Subject: [PATCH 04/11] add template --- demos/grid-view/bodyTemplate.jade | 2 ++ demos/grid-view/index.js | 7 +------ js/vnext/projection/cells.js | 2 +- js/vnext/projection/memory.js | 14 ++++++++++++++ js/vnext/projection/rows.js | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 demos/grid-view/bodyTemplate.jade diff --git a/demos/grid-view/bodyTemplate.jade b/demos/grid-view/bodyTemplate.jade new file mode 100644 index 0000000..761867f --- /dev/null +++ b/demos/grid-view/bodyTemplate.jade @@ -0,0 +1,2 @@ +i + span=$text diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index a8d9812..019f2fe 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -10,7 +10,7 @@ import { cells, } from '../../js/vnext/projection'; import './index.less'; -import * as tmpl from '../cell-view/key-column-header.jade'; +import * as tmpl from './bodyTemplate.jade'; import 'bootstrap-webpack'; window.t = tmpl; @@ -31,11 +31,6 @@ window.gridViewEl = new GridView({ ]).set({ url: 'http://services.odata.org/V4/Northwind/Northwind.svc/Orders', selection: true, - columns: [{name: 'CustomerID', - template:tmpl.default, - },{ - name: 'ShipCity', - }], }).render(); /* diff --git a/js/vnext/projection/cells.js b/js/vnext/projection/cells.js index da88918..573a568 100644 --- a/js/vnext/projection/cells.js +++ b/js/vnext/projection/cells.js @@ -16,7 +16,7 @@ function translateRow(columnGroup, row) { classes: row.classes, cells: _.map(columnGroup.leafColumns, col => { const cell = row.item[col.name] || {}; - const tpl = col.template || col.headerTemplate || col.footerTemplate; + const tpl = col.template || col.headTemplate || col.footTemplate; if (tpl) { cell.html = _.isFunction(tpl) ? tpl(row.item) : tpl; } diff --git a/js/vnext/projection/memory.js b/js/vnext/projection/memory.js index e69de29..71cce06 100644 --- a/js/vnext/projection/memory.js +++ b/js/vnext/projection/memory.js @@ -0,0 +1,14 @@ +import _ from 'underscore'; + +export function memory (p$state, { + skip, + take, + filter, + orderby = [], + select = [], +} = {}) { + + return p$state.then(function(data) { + return take ? data.slice(skip || 0, take) : data.slice(skip || 0); + }); +} \ No newline at end of file diff --git a/js/vnext/projection/rows.js b/js/vnext/projection/rows.js index db57f32..71051df 100644 --- a/js/vnext/projection/rows.js +++ b/js/vnext/projection/rows.js @@ -20,7 +20,7 @@ export function rows(state, { const columns = state.columns; const bodyRows = _.map(state, item => ({ classes: ['body-row'], - item: _.mapObject(item, value => ({ html: value })), + item: _.mapObject(item, value => ({ html: value , $text: 'only hehe', })), })); return _.defaults(state, { headRows, bodyRows, footRows }); From 6584f2d3f0c9731428b9385c8701a50dd9ad4c4f Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 16:49:11 +0800 Subject: [PATCH 05/11] change bodyTemplate.jade --- demos/grid-view/bodyTemplate.jade | 2 +- demos/grid-view/index.js | 6 ++++++ js/vnext/projection/rows.js | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/demos/grid-view/bodyTemplate.jade b/demos/grid-view/bodyTemplate.jade index 761867f..670668a 100644 --- a/demos/grid-view/bodyTemplate.jade +++ b/demos/grid-view/bodyTemplate.jade @@ -1,2 +1,2 @@ i - span=$text + span=CustomerID.html diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index 019f2fe..b184560 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -31,6 +31,12 @@ window.gridViewEl = new GridView({ ]).set({ url: 'http://services.odata.org/V4/Northwind/Northwind.svc/Orders', selection: true, + columns: [{ + name: 'CustomerID', + //template:tmpl.default, + },{ + name: 'ShipCity', + }], }).render(); /* diff --git a/js/vnext/projection/rows.js b/js/vnext/projection/rows.js index 71051df..3849fa3 100644 --- a/js/vnext/projection/rows.js +++ b/js/vnext/projection/rows.js @@ -20,7 +20,7 @@ export function rows(state, { const columns = state.columns; const bodyRows = _.map(state, item => ({ classes: ['body-row'], - item: _.mapObject(item, value => ({ html: value , $text: 'only hehe', })), + item: _.mapObject(item, value => ({ html: value })), })); return _.defaults(state, { headRows, bodyRows, footRows }); From cbfd7e3808a57c79753c00bf579a48f4dd7d395c Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 16:52:56 +0800 Subject: [PATCH 06/11] comment one text --- demos/grid-view/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index b184560..0c11cd7 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -13,7 +13,6 @@ import './index.less'; import * as tmpl from './bodyTemplate.jade'; import 'bootstrap-webpack'; -window.t = tmpl; window.gridViewEl = new GridView({ el: '.container-element-viewport', viewport: '.container-element-viewport', From c27225c99d515842d122b9015a4cb6c4b2a276dc Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 17:17:08 +0800 Subject: [PATCH 07/11] fix bug in row.js cause by state.columns --- demos/grid-view/index.js | 2 +- js/vnext/projection/cells.js | 4 ++-- js/vnext/projection/column-group.js | 7 ++++--- js/vnext/projection/rows.js | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index 0c11cd7..96ddf80 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -32,7 +32,7 @@ window.gridViewEl = new GridView({ selection: true, columns: [{ name: 'CustomerID', - //template:tmpl.default, + bodyTemplate:tmpl.default, },{ name: 'ShipCity', }], diff --git a/js/vnext/projection/cells.js b/js/vnext/projection/cells.js index 573a568..8173a24 100644 --- a/js/vnext/projection/cells.js +++ b/js/vnext/projection/cells.js @@ -16,9 +16,9 @@ function translateRow(columnGroup, row) { classes: row.classes, cells: _.map(columnGroup.leafColumns, col => { const cell = row.item[col.name] || {}; - const tpl = col.template || col.headTemplate || col.footTemplate; + const tpl = col.bodyTemplate || col.footTemplate || col.headTemplate; if (tpl) { - cell.html = _.isFunction(tpl) ? tpl(row.item) : tpl; + cell.html = _.isFunction(tpl) ? tpl(col.headTemplate? '' : row.item) : tpl; } return cell; }), diff --git a/js/vnext/projection/column-group.js b/js/vnext/projection/column-group.js index 2acdacd..11fee18 100644 --- a/js/vnext/projection/column-group.js +++ b/js/vnext/projection/column-group.js @@ -8,15 +8,16 @@ class ColumnGroup { const buildColumn = ({ name, width, - template, + bodyTemplate, + footTemplate, parent = null, columns = [], html = name, height = 1, }) => { - const col = { name, width, template, parent, html, height }; + const col = { name, width, bodyTemplate, footTemplate, parent, html, height }; - col.template = template ? template : (parent? parent.template : null); + col.template = bodyTemplate || footTemplate; col.rowIndex = parent ? parent.rowIndex + parent.height : 0; col.columns = _.map(columns, c => buildColumn(_.extend({ parent: col }, c))); col.treeHeight = height; diff --git a/js/vnext/projection/rows.js b/js/vnext/projection/rows.js index 3849fa3..ec0ad54 100644 --- a/js/vnext/projection/rows.js +++ b/js/vnext/projection/rows.js @@ -18,7 +18,7 @@ export function rows(state, { footRows = [], } = {}) { const columns = state.columns; - const bodyRows = _.map(state, item => ({ + const bodyRows = _.map(_.omit(state, 'columns'), item => ({ classes: ['body-row'], item: _.mapObject(item, value => ({ html: value })), })); From c33f5583485ed2e543a1a4a5ce8f5a761bc37637 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 20:43:11 +0800 Subject: [PATCH 08/11] fix indentation --- js/vnext/projection/cells.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/vnext/projection/cells.js b/js/vnext/projection/cells.js index f4a8560..bd204fe 100644 --- a/js/vnext/projection/cells.js +++ b/js/vnext/projection/cells.js @@ -29,7 +29,7 @@ function translateRow(columnGroup, row, group) { } } - return {classes, html}; + return { classes, html }; }), }; From 4642e585c389b1d9a1d71d9d6930577cc4158043 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 21:27:19 +0800 Subject: [PATCH 09/11] height is missing in column-group.js --- demos/grid-view/index.js | 10 ++++++++-- js/vnext/projection/column-group.js | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/demos/grid-view/index.js b/demos/grid-view/index.js index e87e621..1bf8b3c 100644 --- a/demos/grid-view/index.js +++ b/demos/grid-view/index.js @@ -16,8 +16,14 @@ window.gridViewEl = new GridView({ }, selection: true, columns: [{ - name: 'Group0', - bodyTemplate: bodyTemplate, + name: 'Group 0', + html: 'Group 0', + columns: [{ + name: 'CustomerID', + bodyTemplate: bodyTemplate, + },{ + name: 'OrderID', + }], },{ name: 'ShipCity', }], diff --git a/js/vnext/projection/column-group.js b/js/vnext/projection/column-group.js index e852493..d876c4b 100644 --- a/js/vnext/projection/column-group.js +++ b/js/vnext/projection/column-group.js @@ -7,9 +7,11 @@ class ColumnGroup { 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; col.treeWidth = 1; if (!_.isEmpty(col.columns)) { col.treeHeight += _.chain(col.columns) @@ -30,7 +32,8 @@ class ColumnGroup { const colspan = col.treeWidth; const rowspan = _.isEmpty(col.columns) ? this.root.treeHeight - col.rowIndex : col.height; const html = col.html || col.name; - + console.log(this.headerRows); + console.log(col.rowIndex); while (this.headerRows.length <= col.rowIndex) { this.headerRows.push({ cells: [] }); } From 58507f4d3eae461192cfee8fd2c494f80a1f4bf4 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 21:32:50 +0800 Subject: [PATCH 10/11] fix indentation --- js/factory/renderers-plugin.js | 22 +++++++++++----------- js/vnext/projection/column-group.js | 4 ++-- js/vnext/projection/odata.js | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/js/factory/renderers-plugin.js b/js/factory/renderers-plugin.js index fa58a04..8ea0a2d 100644 --- a/js/factory/renderers-plugin.js +++ b/js/factory/renderers-plugin.js @@ -2,17 +2,17 @@ import layout from '../layout/index'; export default definePlugin => definePlugin('renderers', [ 'config', -], function (config) { - const renderers = []; + ], function (config) { + const renderers = []; - if (config.scrollable) { - if (config.scrollable.virtual) { - renderers.push(layout.renderers.Virtualization); + if (config.scrollable) { + if (config.scrollable.virtual) { + renderers.push(layout.renderers.Virtualization); + } + if (config.scrollable.fixedHeader) { + renderers.push(layout.renderers.FixedHeader); + } } - if (config.scrollable.fixedHeader) { - renderers.push(layout.renderers.FixedHeader); - } - } - return renderers; -}); + return renderers; + }); diff --git a/js/vnext/projection/column-group.js b/js/vnext/projection/column-group.js index d876c4b..f114709 100644 --- a/js/vnext/projection/column-group.js +++ b/js/vnext/projection/column-group.js @@ -15,9 +15,9 @@ class ColumnGroup { col.treeWidth = 1; if (!_.isEmpty(col.columns)) { col.treeHeight += _.chain(col.columns) - .map(_.property('treeHeight')).max().value(); + .map(_.property('treeHeight')).max().value(); 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)) { diff --git a/js/vnext/projection/odata.js b/js/vnext/projection/odata.js index e9ad0e1..8042a54 100644 --- a/js/vnext/projection/odata.js +++ b/js/vnext/projection/odata.js @@ -36,10 +36,10 @@ export function odata (state, { return new Promise((resolve, reject) => { $.getJSON(_.result(op, 'url'), _.omit(op, 'url')) - .success(resolve) - .fail((jqXHR, textStatus, errorThrown) => { - reject(new Error(errorThrown)); - }); + .success(resolve) + .fail((jqXHR, textStatus, errorThrown) => { + reject(new Error(errorThrown)); + }); }).then(data => ({ items: data.value || [] })); } From c2abd8f1d4e97118fc83366fbc2b14618c742198 Mon Sep 17 00:00:00 2001 From: "Shulan Pan (PERSON CONSULTING)" Date: Fri, 29 Jul 2016 21:37:13 +0800 Subject: [PATCH 11/11] fix indetation by hand --- js/vnext/projection/jsdata.js | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/js/vnext/projection/jsdata.js b/js/vnext/projection/jsdata.js index c649a6b..ea42c70 100644 --- a/js/vnext/projection/jsdata.js +++ b/js/vnext/projection/jsdata.js @@ -2,40 +2,40 @@ import _ from 'underscore'; import Promise from 'bluebird'; export function jsdata (state, { - query, - entity, - options, - skip, - take, - filter, - orderby = [], - select = [], + query, + entity, + options, + skip, + take, + filter, + orderby = [], + select = [], } = {}) { - const op = {}; + const op = {}; - if (take) { - op.limit = take; - } + if (take) { + op.limit = take; + } - if (skip) { - op.offset = skip; - } + if (skip) { + op.offset = skip; + } - if (filter) { - op.where = filter; - } + if (filter) { + op.where = filter; + } - if (query) { - op.query = query; - } + 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; - }, []); - } + 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')); + return entity.fincAll(op, _.defaults(options, { all: true })) + .then(_.property('value')); }; \ No newline at end of file