Skip to content

Commit 355da74

Browse files
authored
Merge branch 'master' into ScrollServiceN
2 parents 07397f9 + 56a6dee commit 355da74

55 files changed

Lines changed: 617 additions & 377 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
## [Unreleased]
77
* Auto-complete cell editor.
88
* Row edit form.
9+
* Batch edit support.
910
* Infinite scrolling.
1011
* Validation framework.
1112
* Copy/paste selection to excel.
1213
* Live data plugin.
1314
* Float Row Navigation.
1415

16+
## [6.2.0]
17+
### Fixed
18+
- Column filter `blanks` is removed when reset clicked.
19+
20+
### Added
21+
- Column hierarchy and dnd support in the column chooser.
22+
- Cohort column dnd support.
23+
24+
### BREAKING
25+
- `model.columnList().index` now contains tree of columns, not a column key list.
26+
1527
## [6.1.5] - 2018-07-03
1628
### Fixed
1729
- Row highlight in details modes.
@@ -197,8 +209,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
197209

198210
## [5.1.2] - 2018-01-03
199211
### Added
200-
* Possibility to change row size `<q-grid-row canResize="true"`.
201-
* Possibility to drag and drop rows `<q-grid-row canMove="true"`.
212+
* Possibility to change row size `<q-grid-row [canResize]="true"`.
213+
* Possibility to drag and drop rows `<q-grid-row [canMove]="true"`.
202214
* Style queue to the style Api, accessible through style model cells/rows props.
203215
* Rows property to the layout property.
204216

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng2-qgrid",
3-
"version": "6.1.5",
3+
"version": "6.2.0",
44
"scripts": {
55
"ng": "ng",
66
"start": "node build.serve",

package5.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng2-qgrid",
3-
"version": "5.4.5",
3+
"version": "5.5.0",
44
"dependencies": {
55
"@angular/animations": "^5.2.11",
66
"@angular/common": "^5.2.11",

src/core/body/body.ctrl.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class BodyCtrl {
2020
}
2121

2222
onScroll(e) {
23-
const scroll = this.model.scroll;
23+
const { scroll } = this.model;
2424

2525
const oldValue = scroll();
2626
const newValue = {};
@@ -73,15 +73,14 @@ export class BodyCtrl {
7373

7474
onMouseDown(e) {
7575
if (e.which === MOUSE_LEFT_BUTTON) {
76-
const selectionState = this.selection;
77-
if (selectionState.area !== 'body') {
76+
const { area, mode } = this.selection;
77+
if (area !== 'body') {
7878
return;
7979
}
8080

8181
const pathFinder = new PathService(this.bag.body);
8282
const cell = pathFinder.cell(e.path);
83-
84-
if (selectionState.mode === 'range') {
83+
if (mode === 'range') {
8584
this.rangeStartCell = cell;
8685

8786
if (this.rangeStartCell) {
@@ -152,8 +151,8 @@ export class BodyCtrl {
152151
onMouseUp(e) {
153152
this.scrollService.stop();
154153

155-
const mode = this.selection.mode;
156-
const edit = this.model.edit;
154+
const { mode } = this.selection;
155+
const { edit } = this.model;
157156

158157
if (e.which === MOUSE_LEFT_BUTTON) {
159158
const pathFinder = new PathService(this.bag.body);
@@ -164,7 +163,7 @@ export class BodyCtrl {
164163
}
165164

166165
if (edit().state === 'startBatch') {
167-
edit({ state: 'endBatch' });
166+
edit({ state: 'endBatch' }, { source: 'body.ctrl' });
168167
return;
169168
}
170169

@@ -183,15 +182,14 @@ export class BodyCtrl {
183182
}
184183

185184
select(cell) {
186-
const selectionState = this.selection;
187-
if (cell.column.type !== 'select' &&
188-
(selectionState.area !== 'body' || selectionState.mode === 'range')) {
185+
const { area, mode, unit } = this.selection;
186+
if (cell.column.type !== 'select' && (area !== 'body' || mode === 'range')) {
189187
return;
190188
}
191189

192190
const model = this.model;
193191
const editMode = model.edit().mode;
194-
switch (selectionState.unit) {
192+
switch (unit) {
195193
case 'row': {
196194
if (cell.column.type === 'select' && cell.column.editorOptions.trigger === 'focus') {
197195
const focusState = model.focus();

src/core/column-list/column.list.ctrl.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export declare class ColumnListCtrl {
88
)
99

1010
copy(target: any, source: any): void;
11-
add(column: ColumnModel, parent?: ColumnModel): void;
11+
add(column: ColumnModel): void;
1212
register(column: ColumnModel): void;
1313
generateKey(source: any): string;
1414
extract(key: string, type: string): ColumnModel;

src/core/column-list/column.list.ctrl.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,14 @@ export class ColumnListCtrl {
4848
});
4949
}
5050

51-
add(column, parent) {
52-
if (parent) {
53-
parent.type = 'cohort';
54-
if (!parent.key || parent.key === '$default') {
55-
parent.key = `$cohort-from-${column.key}`;
56-
}
57-
58-
parent.children.push(column);
59-
60-
const { columns } = this.model.columnList();
61-
if (columns.indexOf(parent) < 0) {
62-
this.add(parent);
63-
}
64-
}
65-
else {
66-
const { columnList } = this.model;
67-
const columns = columnList().columns.concat([column]);
68-
columnList({ columns }, {
69-
source: 'column.list.ctrl',
70-
behavior: 'core'
71-
});
72-
}
51+
add(column) {
52+
53+
const { columnList } = this.model;
54+
const columns = columnList().columns.concat([column]);
55+
columnList({ columns }, {
56+
source: 'column.list.ctrl',
57+
behavior: 'core'
58+
});
7359
}
7460

7561
register(column) {

src/core/column-list/column.list.sort.js

Lines changed: 152 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
export function sortIndexFactory(model) {
1+
import { bend, copy } from '../node/node.service';
2+
import { preOrderDFS } from '../node/node.service';
3+
4+
export { sortIndexFactory, merge };
5+
6+
function sortIndexFactory(model) {
27
const templateIndex = model.columnList().columns.map(c => c.key);
38

49
return (columns, scores) => {
510
const { length } = columns;
611
scores = Object.assign({
7-
list: column => column.class === 'data' ? 0.1 : 0.3,
12+
list: column => (column.class === 'data' || column.class === 'cohort') ? 0.1 : 0.3,
813
index: () => 0.2,
9-
view: column => length + (column.class !== 'data' ? 0.1 : 0.3),
14+
view: column => length + ((column.class !== 'data' && column.class !== 'cohort') ? 0.1 : 0.3),
1015
template: () => length + 0.4
1116
}, scores);
1217

@@ -66,13 +71,12 @@ function compareFactory(scoreFor, templateIndex, viewIndex) {
6671
}
6772

6873
function findFactory(index) {
69-
const map =
70-
index.reduce((memo, key, i) => {
71-
memo.set(key, i);
72-
return memo;
73-
}, new Map());
74+
const map = index.reduce((memo, key, i) => {
75+
memo.set(key, i);
76+
return memo;
77+
}, new Map());
7478

75-
return key => map.has(key) ? map.get(key) : -1;
79+
return key => (map.has(key) ? map.get(key) : -1);
7680
}
7781

7882
function equals(xs, ys) {
@@ -86,5 +90,143 @@ function equals(xs, ys) {
8690
return false;
8791
}
8892
}
93+
8994
return true;
90-
}
95+
}
96+
97+
function merge(newTree, oldTree, buildIndex) {
98+
const current = running(newTree, buildIndex);
99+
const screen = former(oldTree, current);
100+
const insertNear = insertFactory(current, screen);
101+
const insertCohort = insertCohortFactory(current, screen);
102+
103+
const root = current.line[0];
104+
if (!screen.set.has(root.key.model.key)) {
105+
screen.line.unshift(copy(root));
106+
screen.line.forEach(n => n.level++);
107+
}
108+
109+
for (let i = 1, length = current.line.length; i < length; i++) {
110+
const node = current.line[i];
111+
const { model } = node.key;
112+
if (screen.set.has(model.key)) {
113+
continue;
114+
}
115+
116+
const prevNode = current.line[i - 1];
117+
if (model.type === 'cohort') {
118+
insertCohort(prevNode, node);
119+
} else {
120+
insertNear(prevNode, node, i);
121+
}
122+
}
123+
124+
return bend(screen.line);
125+
}
126+
127+
function running(tree, buildIndex) {
128+
const result = {
129+
line: [],
130+
map: new Map()
131+
};
132+
133+
preOrderDFS([tree], node => {
134+
result.line.push(node);
135+
result.map.set(node.key.model.key, node.key);
136+
137+
// As we use pre order direction we can manipulate with children without affecting on algorithm.
138+
// Below we sort columns in appropriate order.
139+
const columns = node.children.map(child => child.key.model);
140+
const index = buildIndex(columns);
141+
142+
let cursor = 0;
143+
const indexMap = index.reduce((memo, key) => {
144+
memo[key] = cursor++;
145+
return memo;
146+
}, {});
147+
148+
node.children.sort((x, y) => indexMap[x.key.model.key] - indexMap[y.key.model.key]);
149+
});
150+
151+
return result;
152+
}
153+
154+
function former(tree, current) {
155+
const result = {
156+
line: [],
157+
set: new Set()
158+
};
159+
160+
preOrderDFS([tree], node => {
161+
// Filter out nodes if they were deleted from newTree.
162+
const { key } = node.key.model;
163+
const view = current.map.get(key);
164+
if (view) {
165+
const newNode = copy(node);
166+
newNode.key = view;
167+
result.line.push(newNode);
168+
result.set.add(key);
169+
}
170+
});
171+
172+
return result;
173+
}
174+
175+
function insertFactory(current, screen) {
176+
const { line } = screen;
177+
return (prevNode, node, i) => {
178+
let pos = line.findIndex(n => n.key.model.key === prevNode.key.model.key);
179+
180+
const target = copy(node);
181+
target.level = node.level;
182+
183+
if (everyNextIsNew(current, screen, i)) {
184+
line.push(target);
185+
} else {
186+
line.splice(pos + 1, 0, target);
187+
}
188+
};
189+
}
190+
191+
function insertCohortFactory(current, screen) {
192+
const insertNear = insertFactory(current, screen);
193+
const { line } = screen;
194+
return (prevNode, node) => {
195+
const set = new Set(node.children.map(n => n.key.model.key));
196+
const index = line.findIndex(n => set.has(n.key.model.key));
197+
198+
if (index < 0) {
199+
insertNear(prevNode, node);
200+
return;
201+
}
202+
203+
const target = copy(node);
204+
const { level } = line[index];
205+
target.level = level;
206+
line.splice(index, 0, target);
207+
208+
for (let i = index + 1, end = line.length; i < end; i++) {
209+
const child = line[i];
210+
if (child.level !== level) {
211+
break;
212+
}
213+
214+
if (set.has(child.key.model.key)) {
215+
child.level = level + 1;
216+
}
217+
}
218+
};
219+
}
220+
221+
function everyNextIsNew(current, screen, index) {
222+
const { line } = current;
223+
224+
let n;
225+
while ((n = line[++index])) {
226+
if (screen.set.has(n.key.model.key)) {
227+
return false;
228+
}
229+
}
230+
231+
return true;
232+
}

src/core/column-type/cohort.column.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class CohortColumnModel extends ColumnModel {
2020
this.canResize = false;
2121
this.canFocus = false;
2222
this.canFilter = false;
23+
this.class = 'cohort';
2324
}
2425
}
2526

src/core/column-type/column.model.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export declare class ColumnModel {
232232
* * `markup` used for the internal markup needs (e.g. `pad` type column).
233233
* * `pivot`multi head pivot.
234234
*/
235-
class?: 'data' | 'control' | 'markup' | 'pivot';
235+
class?: 'data' | 'control' | 'markup' | 'pivot' | 'cohort';
236236

237237
/**
238238
* Editor type, will be shown in cell edit mode instead of default column type editor.

src/core/dom/virtual/box.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class VirtualBox extends Box {
8181

8282
columns() {
8383
const columns = this.context.view.columns();
84-
return columns.map(column => this.createColumnCore(column.index));
84+
return columns.map((_, i) => this.createColumnCore(i));
8585
}
8686

8787
rows(columnIndex) {

0 commit comments

Comments
 (0)