dtable-statistic 5.0.42-alpha.3 → 5.0.42-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,6 @@ const exportOneDimensionToTable = _ref => {
48
48
  let {
49
49
  statisticalResult
50
50
  } = _ref;
51
- console.log('exportOneDimensionToTable');
52
51
  const {
53
52
  pivotResult,
54
53
  groupbyColumn,
@@ -111,12 +110,23 @@ const exportOneDimensionToTable = _ref => {
111
110
  }
112
111
  }
113
112
 
113
+ // count column
114
+ if (summaryColumn) {
115
+ const countColumn = {
116
+ type: _isDateSummaryColumn ? _dtableUtils.CellType.DATE : _dtableUtils.CellType.NUMBER,
117
+ name: summaryColumn === null || summaryColumn === void 0 ? void 0 : summaryColumn.name,
118
+ data: columnData
119
+ };
120
+ columns.push(countColumn);
121
+ }
122
+
114
123
  // total column
115
124
  const totalColumn = {
116
125
  type: _isDateSummaryColumn ? _dtableUtils.CellType.DATE : _dtableUtils.CellType.NUMBER,
117
126
  name: _reactIntlUniversal.default.get('Total'),
118
127
  data: columnData
119
128
  };
129
+ console.log('totalColumn', totalColumn);
120
130
  columns.push(totalColumn);
121
131
 
122
132
  // generator rows
@@ -135,6 +145,9 @@ const exportOneDimensionToTable = _ref => {
135
145
  [groupbyColumn.name]: groupName,
136
146
  [_reactIntlUniversal.default.get('Total')]: cellValue
137
147
  };
148
+ if (summaryColumn) {
149
+ newRow[summaryColumn.name] = cellValue;
150
+ }
138
151
  rows.push(newRow);
139
152
  });
140
153
  return {
@@ -142,17 +155,15 @@ const exportOneDimensionToTable = _ref => {
142
155
  rows
143
156
  };
144
157
  }
145
- console.log('pivot_columns', pivot_columns);
146
- console.log('statisticTableColumns', statisticTableColumns);
158
+
147
159
  // one dimension table with number columns
148
160
  Array.isArray(pivot_columns) && pivot_columns.forEach(item => {
149
161
  const {
150
162
  key
151
163
  } = item;
152
- console.log('item', item);
153
164
  const column = statisticTableColumns.find(column => column.key === key);
154
- console.log('column', column);
155
165
  if (column) {
166
+ console.log('column', column);
156
167
  const columnName = column.name;
157
168
  let columnData;
158
169
  let columnType = _dtableUtils.CellType.NUMBER;
@@ -194,7 +205,22 @@ const exportOneDimensionToTable = _ref => {
194
205
  columns.push(newColumn);
195
206
  }
196
207
  });
197
- console.log('pivot_rows', pivot_rows);
208
+
209
+ // total column
210
+ const totalColumn = {
211
+ type: _dtableUtils.CellType.NUMBER,
212
+ name: _reactIntlUniversal.default.get('Total'),
213
+ data: {
214
+ decimal: "dot",
215
+ enable_precision: false,
216
+ format: "yuan",
217
+ precision: 2,
218
+ thousands: "no"
219
+ }
220
+ };
221
+ columnMap['total'] = totalColumn;
222
+ columns.push(totalColumn);
223
+
198
224
  // generator rows
199
225
  pivot_rows.forEach(item => {
200
226
  const {
@@ -202,17 +228,17 @@ const exportOneDimensionToTable = _ref => {
202
228
  original_name,
203
229
  total
204
230
  } = item;
231
+ let rowTotal = 0;
205
232
  const groupName = isEmptyName(original_name) ? _reactIntlUniversal.default.get(_constants.EMPTY_NAME) : name;
206
233
  let newRow = {
207
234
  [groupbyColumn.name]: groupName
208
235
  };
209
236
  Array.isArray(pivot_columns) && pivot_columns.forEach(item => {
210
237
  const {
211
- key,
212
- method
238
+ key
213
239
  } = item;
214
240
  const column = columnMap[key];
215
- const cellValueKey = key + method;
241
+ const cellValueKey = key;
216
242
  const {
217
243
  name,
218
244
  type,
@@ -224,9 +250,16 @@ const exportOneDimensionToTable = _ref => {
224
250
  cellValue = (0, _dayjs.default)(cellValue).format(dateFormat);
225
251
  }
226
252
  newRow[name] = cellValue;
253
+ rowTotal = rowTotal + Number(cellValue);
227
254
  });
255
+ // total row
256
+ newRow[_reactIntlUniversal.default.get('Total')] = rowTotal;
228
257
  rows.push(newRow);
229
258
  });
259
+ console.log(11, {
260
+ columns,
261
+ rows
262
+ });
230
263
  return {
231
264
  columns,
232
265
  rows
@@ -236,7 +269,6 @@ const exportTwoDimensionToTable = _ref2 => {
236
269
  let {
237
270
  statisticalResult
238
271
  } = _ref2;
239
- console.log('exportTwoDimensionToTable');
240
272
  const {
241
273
  pivotResult,
242
274
  groupbyColumn,
@@ -460,7 +492,6 @@ const exportTwoDimensionWithSummaryColumnsToTable = _ref4 => {
460
492
  let {
461
493
  statisticalResult
462
494
  } = _ref4;
463
- console.log('exportTwoDimensionWithSummaryColumnsToTable');
464
495
  return getTwoDimensionWithSummaryColumns({
465
496
  statisticalResult
466
497
  });
@@ -473,7 +504,8 @@ const updatedOneDimensionToTable = _ref5 => {
473
504
  const {
474
505
  pivotResult,
475
506
  groupbyColumn,
476
- statisticTableColumns
507
+ statisticTableColumns,
508
+ summaryColumn
477
509
  } = statisticalResult;
478
510
  if (!groupbyColumn) return {};
479
511
  const nameColumn = (0, _dtableUtils.getTableColumnByName)(updateTable, groupbyColumn.name);
@@ -494,6 +526,9 @@ const updatedOneDimensionToTable = _ref5 => {
494
526
  // one dimension table no summary columns
495
527
  if (pivot_columns.length < 2) {
496
528
  columnMap['total'] = (0, _dtableUtils.getTableColumnByName)(updateTable, _reactIntlUniversal.default.get('Total'));
529
+ if (summaryColumn) {
530
+ columnMap['sumary_column'] = (0, _dtableUtils.getTableColumnByName)(updateTable, summaryColumn.name);
531
+ }
497
532
 
498
533
  // updated rows
499
534
  pivot_rows.forEach(item => {
@@ -505,6 +540,7 @@ const updatedOneDimensionToTable = _ref5 => {
505
540
  const groupName = isEmptyName(original_name) ? _reactIntlUniversal.default.get(_constants.EMPTY_NAME) : name;
506
541
  const row = tableRows.find(row => row[nameColumn.key] === groupName);
507
542
  const totalColumn = columnMap['total'];
543
+ const sumary_column = columnMap['sumary_column'];
508
544
  if (row) {
509
545
  // update old row
510
546
  let updateRow = {};
@@ -514,6 +550,11 @@ const updatedOneDimensionToTable = _ref5 => {
514
550
  updateRow[totalColumn.key] = validTotalCellValue;
515
551
  oldRow[totalColumn.key] = row[totalColumn.key];
516
552
  }
553
+ const validSummaryCellValue = getValidValueForColumn(sumary_column, total.total);
554
+ if (sumary_column && (0, _cellValue.isCellValueChanged)(row[sumary_column.key], validSummaryCellValue, sumary_column.type)) {
555
+ updateRow[sumary_column.key] = validSummaryCellValue;
556
+ oldRow[sumary_column.key] = row[sumary_column.key];
557
+ }
517
558
  if (Object.keys(updateRow).length > 0) {
518
559
  const rowId = row._id;
519
560
  rowIds.push(rowId);
@@ -527,6 +568,9 @@ const updatedOneDimensionToTable = _ref5 => {
527
568
  if (totalColumn) {
528
569
  newRow[totalColumn.key] = getValidValueForColumn(totalColumn, total.total);
529
570
  }
571
+ if (sumary_column) {
572
+ newRow[sumary_column.key] = getValidValueForColumn(sumary_column, total.total);
573
+ }
530
574
  newRows.push(newRow);
531
575
  }
532
576
  });
@@ -561,23 +605,33 @@ const updatedOneDimensionToTable = _ref5 => {
561
605
  } = item;
562
606
  const groupName = isEmptyName(original_name) ? _reactIntlUniversal.default.get(_constants.EMPTY_NAME) : name;
563
607
  const row = tableRows.find(row => row[nameColumnKey] === groupName);
608
+ let rowTotal = 0;
564
609
  if (row) {
565
610
  let updateRow = {};
566
611
  let oldRow = {};
567
612
  Array.isArray(pivot_columns) && pivot_columns.forEach(item => {
568
613
  const {
569
- key,
570
- method
614
+ key
571
615
  } = item;
572
616
  const column = columnMap[key];
573
- const cellValueKey = key + method;
617
+ const cellValueKey = key;
574
618
  const totalCellValue = getValidValueForColumn(column, total[cellValueKey]);
575
619
  if (column && (0, _cellValue.isCellValueChanged)(row[column.key], totalCellValue, column.type)) {
576
620
  updateRow[column.key] = totalCellValue;
577
621
  oldRow[column.key] = row[column.key];
622
+ console.log('totalCellValue', Number(totalCellValue));
623
+ rowTotal = rowTotal + Number(totalCellValue);
578
624
  }
579
625
  });
626
+
627
+ // total column
628
+ console.log('row', row);
629
+ console.log('item', item);
630
+ console.log('rowTotal', rowTotal);
631
+ updateRow[_reactIntlUniversal.default.get('Total')] = rowTotal;
632
+ oldRow[_reactIntlUniversal.default.get('Total')] = row[_reactIntlUniversal.default.get('Total')];
580
633
  if (Object.keys(updateRow).length > 0) {
634
+ console.log(222);
581
635
  const rowId = row._id;
582
636
  rowIds.push(rowId);
583
637
  updatedRows[rowId] = updateRow;
@@ -602,6 +656,12 @@ const updatedOneDimensionToTable = _ref5 => {
602
656
  newRows.push(newRow);
603
657
  }
604
658
  });
659
+ console.log('update', {
660
+ newRows,
661
+ updatedRows,
662
+ rowIds,
663
+ oldRows
664
+ });
605
665
  return {
606
666
  newRows,
607
667
  updatedRows,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "5.0.42-alpha.3",
3
+ "version": "5.0.42-alpha.30",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",