-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Done: #2 all classes has been migrated to typescript
- Loading branch information
Pawel Siemienik
committed
Feb 15, 2020
1 parent
f1f5bb4
commit 5c601d3
Showing
10 changed files
with
151 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
import BaseCell from "./BaseCell"; | ||
import Scope from "../Scope"; | ||
import {ValueType} from "exceljs"; | ||
|
||
export default class AverageCell extends BaseCell { | ||
/** | ||
* @param {Scope} scope | ||
* @returns {AverageCell} | ||
*/ | ||
apply(scope) { | ||
import { BaseCell } from './BaseCell'; | ||
import { Scope } from '../Scope'; | ||
import { Cell, CellFormulaValue, ValueType } from 'exceljs'; | ||
|
||
export class AverageCell extends BaseCell { | ||
public apply(scope: Scope): AverageCell { | ||
super.apply(scope); | ||
|
||
const target = AverageCell._getTargetParam(scope); | ||
const target = AverageCell.getTargetParam(scope); | ||
const __startOutput = scope.vm[target] && scope.vm[target].__startOutput; | ||
const __endOutput = scope.vm[target] && scope.vm[target].__endOutput; | ||
|
||
if (__startOutput && __endOutput) { | ||
const start = scope.output.worksheets[scope.outputCell.ws].getCell(__startOutput, scope.outputCell.c).address; //todo refactoring | ||
const end = scope.output.worksheets[scope.outputCell.ws].getCell(__endOutput, scope.outputCell.c).address; //todo refactoring | ||
|
||
scope.setCurrentOutputValue({formula: `average(${start}:${end})`}); | ||
scope.setCurrentOutputValue({ formula: `average(${start}:${end})` } as CellFormulaValue); | ||
} | ||
|
||
scope.incrementCol(); | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* @param {Scope} scope | ||
* @returns {string} | ||
* @protected | ||
*/ | ||
static _getTargetParam(scope) { | ||
return scope.getCurrentTemplateValue().split(' ')[2]; | ||
protected static getTargetParam(scope: Scope): string { | ||
return scope.getCurrentTemplateValue()?.toString().split(' ')[2] || ''; | ||
} | ||
|
||
/** | ||
* @param {Cell} cell | ||
* @returns {boolean} | ||
*/ | ||
static match(cell) { | ||
public static match(cell: Cell): boolean { | ||
return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 10) === '#! AVERAGE'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ForEachCell } from './ForEachCell'; | ||
import { Cell, ValueType } from 'exceljs'; | ||
import { Scope } from '../Scope'; | ||
|
||
export class ContinueCell extends ForEachCell { | ||
public static match(cell: Cell): boolean { | ||
return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 11) === '#! CONTINUE'; | ||
} | ||
|
||
public getSourceParam(scope: Scope): string { | ||
const target = ForEachCell.getTargetParam(scope); | ||
|
||
return scope.vm[target] && scope.vm[target].__from; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { BaseCell } from './BaseCell'; | ||
import { Cell, ValueType } from 'exceljs'; | ||
import { Scope } from '../Scope'; | ||
|
||
export class DumpColsCell extends BaseCell { | ||
static match(cell: Cell): boolean { | ||
return cell && cell.type === ValueType.String && typeof cell.value === 'string' && cell.value.substring(0, 12) === '#! DUMP_COLS'; | ||
} | ||
|
||
public apply(scope: Scope): DumpColsCell { | ||
super.apply(scope); | ||
|
||
const path = scope.getCurrentTemplateValue()?.toString().substring(13).split('.') || ''; | ||
const cols = Array.from(path).reduce((p, c) => p[c] || [], scope.vm); | ||
|
||
scope.setCurrentOutputValue(null); | ||
|
||
cols.forEach((x: any) => { | ||
scope.setCurrentOutputValue(x); | ||
scope.applyStyles(); | ||
scope.outputCell = Object.freeze({ ...scope.outputCell, c: scope.outputCell.c + 1 }); | ||
}); | ||
|
||
scope.incrementCol(); | ||
|
||
return this; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { BaseCell } from './BaseCell'; | ||
import { Cell, ValueType } from 'exceljs'; | ||
import { Scope } from '../Scope'; | ||
|
||
export class EndLoopCell extends BaseCell { | ||
public static match(cell: Cell): boolean { | ||
return ( | ||
cell && | ||
cell.type === ValueType.String && | ||
typeof cell.value === 'string' && | ||
cell.value.substring(0, 11) === '#! END_LOOP' | ||
); | ||
} | ||
|
||
public apply(scope: Scope): EndLoopCell { | ||
super.apply(scope); | ||
|
||
const target = | ||
scope | ||
.getCurrentTemplateValue() | ||
?.toString() | ||
.split(' ')[2] || ''; | ||
const __start = scope.vm[target] && scope.vm[target].__start; | ||
const __iterated = scope.vm[target] && scope.vm[target].__iterated; | ||
|
||
scope.unfreezeOutput(); | ||
|
||
scope.vm[target] = Object.freeze({ | ||
...scope.vm[target], | ||
__end: scope.templateCell, | ||
__insetRows: true, | ||
}); | ||
|
||
if (__start && !__iterated) { | ||
scope.templateCell = __start; | ||
} else { | ||
scope.incrementRow(); | ||
} | ||
|
||
return this; | ||
} | ||
} |
Oops, something went wrong.