123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846 |
- var Unibase;
- (function (Unibase) {
- let Apps;
- (function (Apps) {
- let Collaboration;
- (function (Collaboration) {
- let Components;
- (function (Components) {
- let Sheets;
- (function (Sheets) {
- class Autofill {
- constructor() {
- this.hederText = {};
- this.colType = { String: "string", Number: "number", Custom: "custom", Formula: "formula", Time: "time", LongDate: "longdate", ShortDate: "shortdate", Scientific: "scientific", Fraction: "fraction", Text: "text", General: "general", Accounting: "accounting", Currency: "currency", Percentage: "percentage", Date: "date", DateTime: "datetime" };
- this.customList = [
- ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
- ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
- ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
- ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
- ];
- this.UC = {
- uniqueOBracket: String.fromCharCode(129),
- uniqueCBracket: String.fromCharCode(130),
- uniqueCSeparator: String.fromCharCode(131),
- uniqueCOperator: String.fromCharCode(132),
- uniquePOperator: String.fromCharCode(133),
- uniqueSOperator: String.fromCharCode(134),
- uniqueMOperator: String.fromCharCode(135),
- uniqueDOperator: String.fromCharCode(136),
- uniqueModOperator: String.fromCharCode(137),
- uniqueConcateOperator: String.fromCharCode(138),
- uniqueEqualOperator: String.fromCharCode(139),
- uniqueExpOperator: String.fromCharCode(140),
- uniqueGTOperator: String.fromCharCode(141),
- uniqueLTOperator: String.fromCharCode(142)
- };
- }
- init(base) {
- this.base = base;
- this.ssObj = base.ssObj;
- this.initProp();
- }
- initProp() {
- this.beforeSelectFn = this.beforeSelect.bind(this);
- this.base.ssObj.addEventListener("beforeSelect", this.beforeSelectFn);
- this.selectFn = this.selected.bind(this);
- this.base.ssObj.addEventListener("select", this.selectFn);
- this.actionCompleteFn = this.updateAutofill.bind(this);
- this.base.ssObj.addEventListener("actionComplete", this.actionCompleteFn);
- this.createdFn = this.created.bind(this);
- this.base.ssObj.addEventListener("created", this.createdFn);
- this.dataBoundFn = this.dataBound.bind(this);
- this.base.ssObj.addEventListener("dataBound", this.dataBoundFn);
- this.cellEditFn = this.cellEdit.bind(this);
- this.base.ssObj.addEventListener("cellEditing", this.cellEditFn);
- this.cellSaveFn = this.cellSave.bind(this);
- this.base.ssObj.addEventListener("cellSave", this.cellSaveFn);
- this.base.ssObj.on("activeSheetChanged", this.updateAutofill, this);
- this.base.ssObj.on("mouseDown", this.mouseDown, this);
- }
- destroy() {
- this.base.ssObj.removeEventListener("beforeSelect", this.beforeSelectFn);
- this.base.ssObj.removeEventListener("select", this.selectFn);
- this.base.ssObj.removeEventListener("actionComplete", this.actionCompleteFn);
- this.base.ssObj.removeEventListener("created", this.createdFn);
- this.base.ssObj.removeEventListener("dataBound", this.dataBoundFn);
- this.base.ssObj.removeEventListener("cellEditing", this.cellEditFn);
- this.base.ssObj.removeEventListener("cellSave", this.cellSaveFn);
- this.base.ssObj.off("activeSheetChanged", this.updateAutofill);
- this.base.ssObj.on("mouseDown", this.mouseDown, this);
- ej.base.EventHandler.remove(this.base.ssObj.element, 'mouseup', this.mouseUp);
- ej.base.EventHandler.remove(this.base.ssObj.element, 'keydown', this.keypress);
- ej.base.EventHandler.remove(this.base.ssObj.element, 'dblclick', this.dblClick);
- }
- cellEdit() {
- this.hideAutofill();
- }
- cellSave() {
- this.updateAutofill();
- }
- dataBound() {
- this.updateAutofill();
- }
- createBorders() {
- if (!this.base.ssObj.element.getElementsByClassName('biz-af-bdr')[0]) {
- let content = this.base.ssObj.element.getElementsByClassName('e-sheet-content')[0];
- this.bdrAF = content.appendChild(ej.base.createElement('div', { className: 'biz-af-bdr' }));
- }
- }
- hideBorders() {
- if (this.bdrAF) {
- this.bdrAF.style.display = 'none';
- }
- }
- showBorders() {
- if (this.bdrAF) {
- this.bdrAF.style.display = '';
- }
- }
- updateBorderDirection(hideDirecton) {
- this.bdrAF.style.borderRightWidth = '1px';
- this.bdrAF.style.borderLeftWidth = '1px';
- this.bdrAF.style.borderTopWidth = '1px';
- this.bdrAF.style.borderBottomWidth = '1px';
- this.bdrAF.style["border" + hideDirecton + "Width"] = '0px';
- }
- mouseDown(e) {
- if (e.target.classList.contains('biz-autofill')) {
- this.isDrag = true;
- ej.base.EventHandler.add(this.base.ssObj.element, 'mousemove', this.mouseMoveHandler, this);
- this.x = e.clientX;
- this.y = e.clientY;
- this.indexes = this.base.ssObj.biz.getIndexes();
- this.createBorders();
- let sel = this.base.ssObj.element.getElementsByClassName('e-selection')[0];
- let activecell = this.base.ssObj.element.getElementsByClassName('e-active-cell')[0];
- this.selection = sel.classList.contains('e-hide') ? activecell : sel;
- this.selOffset = this.selection.getBoundingClientRect();
- this.parentOffset = this.selection.offsetParent.getBoundingClientRect();
- this.left = parseInt(this.selection.style.left);
- this.top = parseInt(this.selection.style.top);
- }
- }
- mouseUp(e) {
- this.isDrag = false;
- ej.base.EventHandler.remove(this.base.ssObj.element, 'mousemove', this.mouseMoveHandler);
- if (this.direction != undefined) {
- this.autoFill();
- }
- this.direction = undefined;
- this.hideBorders();
- this.isDragged = false;
- this.prevTarget = undefined;
- }
- createAutofill() {
- if (!this.base.ssObj.element.getElementsByClassName('biz-autofill')[0]) {
- this.element = document.createElement('div');
- this.element.classList.add('biz-autofill');
- let content = this.base.ssObj.element.getElementsByClassName('e-sheet-content')[0];
- content && content.appendChild(this.element);
- }
- this.element.classList.remove('biz-hide');
- }
- updateAutofill() {
- if (!this.base.ssObj.isEdit) {
- this.positionAutofill();
- }
- else {
- this.hideAutofill();
- }
- }
- dblClick() {
- setTimeout(() => {
- this.hideAutofill();
- }, 1);
- }
- positionAutofill() {
- setTimeout(() => {
- this.createAutofill();
- let selection = this.base.ssObj.element.getElementsByClassName('e-selection')[0];
- let activecell = this.base.ssObj.element.getElementsByClassName('e-active-cell')[0];
- if (selection && !selection.classList.contains('e-hide')) {
- activecell = selection;
- }
- (this.element && activecell) && (this.element.style.top = parseInt(activecell.style.top) + parseInt(activecell.style.height) - 6 + 'px');
- (this.element && activecell) && (this.element.style.left = parseInt(activecell.style.left) + parseInt(activecell.style.width) + -5 + 'px');
- }, 10);
- }
- hideAutofill() {
- let ele = this.base.ssObj.element.getElementsByClassName('biz-autofill')[0];
- if (ele) {
- ele.classList.add('biz-hide');
- }
- }
- mouseMoveHandler(e) {
- e.preventDefault();
- let x = e.clientX;
- let y = e.clientY;
- if (e.target === this.prevTarget) {
- return;
- }
- let tr = ej.base.closest(e.target, 'tr');
- let td = ej.base.closest(e.target, '.e-cell');
- if (!this.isDragged) {
- this.showBorders();
- }
- this.isDragged = true;
- if (!tr || !td) {
- return;
- }
- let colIdx = parseInt(td.getAttribute('aria-colindex')) - 1;
- let rowIdx = parseInt(tr.getAttribute('aria-rowindex')) - 1;
- if (this.indexes[0] <= rowIdx && this.indexes[2] >= rowIdx && this.indexes[1] <= colIdx && this.indexes[3] >= colIdx) {
- this.hideBorders();
- return;
- }
- let tdOffset = td.getBoundingClientRect();
- let px = 'px';
- this.showBorders();
- let sheet = this.base.ssObj.biz.getActiveSheet();
- let freezeRow = this.base.ssObj.frozenRowCount(sheet);
- let freezeCol = this.base.ssObj.frozenColCount(sheet);
- let left;
- let width;
- let top;
- let height;
- switch (true) {
- case this.indexes[3] < colIdx && this.indexes[0] - rowIdx < colIdx - this.indexes[3] && rowIdx - this.indexes[2] < colIdx - this.indexes[3]:
- this.direction = "right";
- left = this.left + this.selOffset.width;
- width = ej.spreadsheet.getCellPosition(sheet, [rowIdx - 1, colIdx + 1], freezeRow, freezeCol).left - (this.left + this.selOffset.width);
- this.updateBorderDirection('Left');
- this.bdrAF.style.top = this.top + px;
- this.bdrAF.style.left = left + px;
- this.bdrAF.style.height = this.selOffset.height + px;
- this.bdrAF.style.width = width + px;
- this.fIndexes = [this.indexes[0], this.indexes[3] + 1, this.indexes[2], colIdx];
- this.startCell = { rowIndex: this.indexes[0], colIndex: this.indexes[1] };
- this.endCell = { rowIndex: this.indexes[2], colIndex: colIdx };
- break;
- case this.indexes[1] > colIdx && this.indexes[0] - rowIdx <= this.indexes[1] - colIdx && rowIdx - this.indexes[2] < this.indexes[1] - colIdx:
- this.direction = "left";
- left = ej.spreadsheet.getCellPosition(sheet, [rowIdx - 1, colIdx], freezeRow, freezeCol).left;
- width = this.left - left;
- this.updateBorderDirection('Right');
- this.bdrAF.style.top = this.top + px;
- this.bdrAF.style.left = left + px;
- this.bdrAF.style.height = this.selOffset.height + px;
- this.bdrAF.style.width = width + px;
- this.fIndexes = [this.indexes[0], colIdx, this.indexes[2], this.indexes[3] - 1];
- this.startCell = { rowIndex: this.indexes[0], colIndex: colIdx };
- this.endCell = { rowIndex: this.indexes[2], colIndex: this.indexes[3] };
- break;
- case this.indexes[0] > rowIdx:
- this.direction = "up";
- top = ej.spreadsheet.getCellPosition(sheet, [rowIdx, colIdx - 1], freezeRow, freezeCol).top;
- height = this.top - top;
- this.updateBorderDirection('Bottom');
- this.bdrAF.style.top = top + px;
- this.bdrAF.style.left = this.left + px;
- this.bdrAF.style.height = height + px;
- this.bdrAF.style.width = this.selOffset.width + px;
- this.fIndexes = [rowIdx, this.indexes[1], this.indexes[0] - 1, this.indexes[3]];
- this.startCell = { rowIndex: rowIdx, colIndex: this.indexes[1] };
- this.endCell = { rowIndex: this.indexes[2], colIndex: this.indexes[3] };
- break;
- case this.indexes[2] < rowIdx:
- this.direction = "down";
- top = this.top + this.selOffset.height;
- height = ej.spreadsheet.getCellPosition(sheet, [rowIdx + 1, colIdx - 1], freezeRow, freezeCol).top - (this.top + this.selOffset.height);
- this.updateBorderDirection('Top');
- this.bdrAF.style.top = top + px;
- this.bdrAF.style.left = this.left + px;
- this.bdrAF.style.height = height + px;
- this.bdrAF.style.width = this.selOffset.width + px;
- this.fIndexes = [this.indexes[2] + 1, this.indexes[1], rowIdx, this.indexes[3]];
- this.startCell = { rowIndex: this.indexes[0], colIndex: this.indexes[1] };
- this.endCell = { rowIndex: rowIdx, colIndex: this.indexes[3] };
- break;
- default:
- this.direction = undefined;
- break;
- }
- this.prevTarget = e.target;
- this.drawAutoFill(e);
- }
- drawAutoFill(e) {
- }
- selected(e) {
- this.range = e.range;
- this.updateAutofill();
- }
- beforeSelect(e) {
- if (this.isDrag) {
- e.cancel = true;
- }
- this.hideAutofill();
- }
- created() {
- ej.base.EventHandler.add(this.base.ssObj.element, 'mouseup', this.mouseUp, this);
- ej.base.EventHandler.add(this.base.ssObj.element, 'keydown', this.keypress, this);
- ej.base.EventHandler.add(this.base.ssObj.element, 'dblclick', this.dblClick, this);
- }
- keypress() {
- this.updateAutofill();
- }
- autoFill() {
- let options = {};
- let sheetIdx = this.base.getSheetIndex();
- options.sheetIdx = sheetIdx;
- options.dataRange = this.indexes;
- options.fillRange = this.fIndexes;
- this.base.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'autofill', options: options, direction: this.direction, oldCells: this.base.getCellsFromIndexes(options.fillRange) } });
- this.applyValues(options);
- this.base.ssObj.selectRange(this.base.generateHeaderText(this.startCell.colIndex + 1) + (this.startCell.rowIndex + 1) + ':' + this.base.generateHeaderText(this.endCell.colIndex + 1) + (this.endCell.rowIndex + 1));
- let args = { action: "autofill" };
- Unibase.Apps.Collaboration.Components.Common.Download.Instance().ssAutoSave(args, this.base, true);
- this.updateAutofill();
- }
- applyAutofill(options, direction) {
- this.direction = direction;
- this.applyValues(options);
- this.direction = undefined;
- }
- applyValues(options) {
- let pos = { Down: 'down', Up: 'up', Left: 'left', Right: 'right' };
- let val, plen, patterns, patrn, pRanges, patrnRange, fillRange, cellObjs, data, temp, dlen, j, k, l, tlen, tot, hasRef, format, formats, cells, clen, cellIdx, cellProps, i = 0, dataObj = {};
- let drSR = options.dataRange[0];
- let drSC = options.dataRange[1];
- let drER = options.dataRange[2];
- let drEC = options.dataRange[3];
- let frSR = options.fillRange[0];
- let frSC = options.fillRange[1];
- let frER = options.fillRange[2];
- let frEC = options.fillRange[3];
- let isVFill = [pos.Down, pos.Up].indexOf(this.direction) > -1;
- let isRFill = [pos.Up, pos.Left].indexOf(this.direction) > -1;
- let sheet = this.base.ssObj.biz.getActiveSheet();
- let len = isVFill ? drEC - drSC : drER - drSR;
- while (i <= len) {
- pRanges = this.updateFillValues(isVFill, drSR, drSC, drER, drEC, frSR, frSC, frER, frEC, i);
- patrnRange = pRanges.patrnRange;
- fillRange = pRanges.fillRange;
- patterns = this.createPattern(patrnRange, { isRFill: isRFill, isVFill: isVFill });
- cellObjs = this.getData(patrnRange);
- data = this.getRawData(cellObjs);
- dlen = data.length;
- if (!patterns)
- return;
- plen = patterns.length;
- cells = this.getSelectedRange({ rowIndex: fillRange[0], colIndex: fillRange[1] }, { rowIndex: fillRange[2], colIndex: fillRange[3] });
- clen = cells.length;
- if (isRFill) {
- cells = cells.reverse();
- patterns = patterns.reverse();
- patterns = this.ensurePattern(patterns);
- cellObjs = cellObjs.reverse();
- data = data.reverse();
- }
- j = 0;
- while (j < clen) {
- dataObj = {};
- cellIdx = cells[j];
- patrn = patterns[j % plen];
- if (this.isNumber(patrn))
- patrn = patterns[patrn];
- switch (patrn.type) {
- case this.colType.Number:
- val = this.round(patrn.regVal.a + (patrn.regVal.b * patrn.i), 5);
- if (isRFill)
- patrn.i--;
- else
- patrn.i++;
- break;
- case this.colType.String:
- val = patrn.val[patrn.i % patrn.val.length];
- patrn.i++;
- break;
- case this.colType.Formula:
- hasRef = false;
- val = "=";
- k = 0;
- tlen = patrn.val.length;
- while (k < tlen) {
- temp = patrn.val[k];
- if (this.isObject(temp)) {
- hasRef = true;
- tot = this.round(temp.a + (temp.b * patrn.i), 0);
- if (tot < 1)
- val += "#REF!";
- else
- val += isVFill ? temp.c + (temp.b ? tot : '$' + tot) : (temp.b ? this.base.generateHeaderText(tot) : '$' + this.base.generateHeaderText(tot)) + temp.c;
- }
- else
- val += temp;
- k++;
- }
- if (hasRef && isRFill)
- patrn.i--;
- else
- patrn.i++;
- break;
- case this.colType.Custom:
- val = this.round(patrn.regVal.a + (patrn.regVal.b * patrn.i), 0);
- if (val < 0)
- val = (val % patrn.len) + patrn.len;
- if (val >= patrn.len)
- val = val % patrn.len;
- val = patrn.val[val];
- if (isRFill)
- patrn.i--;
- else
- patrn.i++;
- break;
- }
- l = j % dlen;
- let cell = ej.spreadsheet.getCell(cellIdx.rowIndex, cellIdx.colIndex, sheet);
- if (cellObjs[l]) {
- cell = this.formObjFromValues(cellObjs[l], ['style', 'format', 'wrap', 'isLocked', 'validation', 'hyperlink',]);
- cell['value'] = val;
- }
- else {
- cell = {};
- }
- this.base.ssObj.biz.setCell(cellIdx.rowIndex, cellIdx.colIndex, sheet, cell);
- if (cell.validation && cell.validation.isHighlighted) {
- this.base.ssObj.addInvalidHighlight(this.base.generateHeaderText(cellIdx.colIndex + 1) + (cellIdx.rowIndex + 1));
- }
- j++;
- }
- i++;
- }
- let args = { options: options, direction: this.direction, action: 'autofill', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
- Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
- }
- formObjFromValues(cellObj, props) {
- let obj = {};
- for (let i = 0; i < props.length; i++) {
- if (cellObj[props[i]]) {
- obj[props[i]] = cellObj[props[i]];
- }
- }
- return obj;
- }
- updateFillValues(isVFill, drSR, drSC, drER, drEC, frSR, frSC, frER, frEC, i) {
- let pStart, pEnd, fStart, fEnd, patrnRange, fillRange;
- if (isVFill) {
- pStart = { rowIndex: drSR, colIndex: drSC + i };
- pEnd = { rowIndex: drER, colIndex: drSC + i };
- fStart = { rowIndex: frSR, colIndex: frSC + i };
- fEnd = { rowIndex: frER, colIndex: frSC + i };
- }
- else {
- pStart = { rowIndex: drSR + i, colIndex: drSC };
- pEnd = { rowIndex: drSR + i, colIndex: drEC };
- fStart = { rowIndex: frSR + i, colIndex: frSC };
- fEnd = { rowIndex: frSR + i, colIndex: frEC };
- }
- patrnRange = [pStart.rowIndex, pStart.colIndex, pEnd.rowIndex, pEnd.colIndex];
- fillRange = [fStart.rowIndex, fStart.colIndex, fEnd.rowIndex, fEnd.colIndex];
- return { patrnRange: patrnRange, fillRange: fillRange };
- }
- createPattern(range, options) {
- let j, idx, temp, regVal, custColl, lCaseColl, lCaseVal, isLCase, diff, len, i = 0, pattern = [];
- let patrns = this.createDataPattern(range);
- let plen = patrns.length;
- let patrn;
- if (patrns) {
- while (i < plen) {
- patrn = patrns[i];
- switch (patrn.type) {
- case this.colType.Number:
- idx = pattern.length;
- len = patrn.val.length;
- diff = options.isRFill ? -1 : len;
- if (len === 1)
- patrn.val.push(patrn.val[0] + 1);
- regVal = this.getPredictionValue(patrn.val);
- temp = { regVal: regVal, type: patrn.type, i: diff };
- pattern.push(temp);
- j = 1;
- while (j < len) {
- pattern.push(idx);
- j++;
- }
- break;
- case this.colType.String:
- idx = pattern.length;
- temp = { val: patrn.val, type: patrn.type, i: 0 };
- pattern.push(temp);
- j = 1;
- len = patrn.val.length;
- while (j < len) {
- pattern.push(idx);
- j++;
- }
- break;
- case this.colType.Formula:
- len = patrn.val.length;
- patrn = this.createFormulaPattern(patrn.val, options);
- diff = options.isRFill ? -1 : len;
- if (patrn.isInPattern) {
- idx = pattern.length;
- temp = { val: patrn.val, type: this.colType.Formula, i: diff };
- pattern.push(temp);
- j = 1;
- while (j < len) {
- pattern.push(idx);
- j++;
- }
- }
- else {
- j = 0;
- diff = options.isRFill ? -1 : 1;
- while (j < len) {
- pattern.push({ val: patrn.val[j], type: this.colType.Formula, i: diff });
- j++;
- }
- }
- break;
- }
- i++;
- }
- return pattern;
- }
- }
- createDataPattern(range) {
- let val, type, i = 0;
- let obj = {};
- let patrn = [];
- let cellObjs;
- cellObjs = this.getData(range);
- let data = this.getRawData(cellObjs);
- let dlen = data.length;
- if (dlen) {
- while (i < dlen) {
- val = data[i];
- type = this.getType(val);
- if (i === 0)
- obj = { val: [val], type: type };
- else if (type === obj.type)
- obj.val.push(val);
- else {
- patrn.push(obj);
- obj = { val: [val], type: type };
- }
- i++;
- }
- patrn.push(obj);
- return patrn;
- }
- }
- createFormulaPattern(data, options) {
- let patrn, j, temp, isInPatrn, patrns = [], i = 0, len = data.length, cRfrType;
- while (i < len) {
- patrns.push(this.parseFormula(data[i]));
- i++;
- }
- isInPatrn = this.isInPattern(patrns, options.isVFill);
- if (isInPatrn) {
- patrn = patrns[0];
- i = patrn.length;
- while (i--) {
- temp = patrn[i];
- cRfrType = this.isCellReference(temp);
- if (cRfrType && (cRfrType !== "absolute"))
- patrn[i] = this.getCellRefPrediction(temp, options, null, cRfrType);
- }
- return { isInPattern: isInPatrn, val: patrn };
- }
- else {
- i = 0;
- while (i < len) {
- patrn = patrns[i];
- j = patrn.length;
- while (j--) {
- temp = patrn[j];
- cRfrType = this.isCellReference(temp);
- if (cRfrType && (cRfrType !== "absolute"))
- patrns[i][j] = this.getCellRefPrediction(temp, options, len, cRfrType);
- }
- i++;
- }
- return { isInPattern: isInPatrn, val: patrns };
- }
- }
- parseFormula(formula) {
- var temp, str, len, i = 0, arr = [];
- formula = this.markSpecialChar(formula.replace("=", ""));
- formula = formula.split(/\(|\)|=|\^|>|<|,|:|\+|-|\*|\/|%|&/g);
- len = formula.length;
- while (i < len) {
- temp = formula[i];
- if (!temp) {
- i++;
- continue;
- }
- if (temp.length === 1)
- arr.push(this.isUniqueChar(temp) ? this.getUniqueCharVal(temp) : temp);
- else {
- str = temp[0];
- if (temp.indexOf('!') > 0) {
- if (this.isUniqueChar(str)) {
- arr.push(this.getUniqueCharVal(str));
- temp = temp.substr(1);
- }
- str = temp.indexOf('!') + 1;
- arr.push(temp.substr(0, str));
- arr.push(temp.substr(str));
- }
- else if (this.isUniqueChar(str)) {
- arr.push(this.getUniqueCharVal(str));
- arr.push(temp.substr(1));
- }
- else
- arr.push(temp);
- }
- i++;
- }
- return arr;
- }
- getUniqueCharVal(str) {
- switch (str) {
- case this.UC.uniqueOBracket:
- return "(";
- case this.UC.uniqueCBracket:
- return ")";
- case this.UC.uniqueCSeparator:
- return ",";
- case this.UC.uniqueCOperator:
- return ':';
- case this.UC.uniquePOperator:
- return "+";
- case this.UC.uniqueSOperator:
- return "-";
- case this.UC.uniqueMOperator:
- return "*";
- case this.UC.uniqueDOperator:
- return "/";
- case this.UC.uniqueModOperator:
- return "%";
- case this.UC.uniqueConcateOperator:
- return "&";
- case this.UC.uniqueEqualOperator:
- return "=";
- case this.UC.uniqueExpOperator:
- return "^";
- case this.UC.uniqueGTOperator:
- return ">";
- case this.UC.uniqueLTOperator:
- return "<";
- }
- return "";
- }
- isUniqueChar(str) {
- var code = str.charCodeAt(str);
- return code >= 129 && code <= 142;
- }
- markSpecialChar(formula) {
- formula = formula.replace(/\(/g, "(" + this.UC.uniqueOBracket).replace(/\)/g, ")" + this.UC.uniqueCBracket);
- formula = formula.replace(/,/g, "," + this.UC.uniqueCSeparator).replace(/:/g, ":" + this.UC.uniqueCOperator);
- formula = formula.replace(/\+/g, "+" + this.UC.uniquePOperator).replace(/-/g, "-" + this.UC.uniqueSOperator);
- formula = formula.replace(/\*/g, "*" + this.UC.uniqueMOperator).replace(/\//g, "/" + this.UC.uniqueDOperator);
- formula = formula.replace(/&/g, "&" + this.UC.uniqueConcateOperator);
- formula = formula.replace(/=/g, "=" + this.UC.uniqueEqualOperator);
- formula = formula.replace(/\^/g, "^" + this.UC.uniqueExpOperator);
- formula = formula.replace(/>/g, ">" + this.UC.uniqueGTOperator).replace(/</g, "<" + this.UC.uniqueLTOperator);
- return formula.replace(/%/g, "%" + this.UC.uniqueModOperator);
- }
- isInPattern(patrn, isVFill) {
- var oldPatrn, olen, newPatrn, nlen, oldStr, newStr, oldInt, newInt, eStr = "", i = 0, j = 1, plen = patrn.length, nregx = new RegExp("[0-9$]", "g"), aregx = new RegExp("[a-z$]", "gi");
- if (plen === 1)
- return false;
- while (j < plen) {
- oldPatrn = patrn[i];
- newPatrn = patrn[j];
- olen = oldPatrn.length;
- nlen = newPatrn.length;
- if (olen !== nlen)
- return false;
- else {
- while (olen--) {
- oldStr = oldPatrn[olen];
- newStr = newPatrn[olen];
- if (this.isCellReference(oldStr) === this.isCellReference(newStr)) {
- if (isVFill) {
- oldInt = Number(oldStr.replace(aregx, eStr));
- newInt = Number(newStr.replace(aregx, eStr));
- }
- else {
- oldInt = this.generateColCount(oldStr.replace(nregx, eStr));
- newInt = this.generateColCount(newStr.replace(nregx, eStr));
- }
- if (oldInt !== newInt - 1)
- return false;
- }
- else if (oldStr !== newStr)
- return false;
- }
- }
- i++;
- j++;
- }
- return true;
- }
- generateColCount(text) {
- var colCount = 0;
- text = text.split('').reverse().join('');
- for (var i = text.length - 1; i >= 0; i--) {
- colCount += (text[i].charCodeAt(text[i]) - 64) * (Math.pow(26, i));
- }
- return colCount;
- }
- getData(range) {
- let sheet = this.base.ssObj.biz.getActiveSheet();
- let data = [];
- let obj;
- let newRange = this.base.swapRange(range);
- for (let i = newRange[0]; i <= newRange[2]; i++) {
- for (let j = newRange[1]; j <= newRange[3]; j++) {
- obj = sheet.rows[i] ? sheet.rows[i].cells[j] : undefined;
- data.push(obj);
- }
- }
- return data;
- }
- getRawData(arr) {
- let len = arr.length;
- let newArr = [];
- for (let i = 0; i < len; i++) {
- if (!arr[i] || !arr[i].value || arr[i].value.length === 0) {
- newArr.push('');
- }
- else if (arr[i].formula) {
- newArr.push(arr[i].formula);
- }
- else if (arr[i].value) {
- newArr.push(arr[i].value);
- }
- }
- return newArr;
- }
- isCellReference(text) {
- return /^[a-z]{1,3}\d{1,7}$/gi.test(text) ? "relative" : (/^\$[a-z]{1,3}\$\d{1,7}$/gi.test(text) ? "absolute" : (/^((\$[a-z]{1,3})\d{1,7}|[a-z]{1,3}(\$\d{1,7}))$/gi.test(text) ? "mixed" : false));
- }
- getCellRefPrediction(text, options, length, rfrType) {
- text = text.toUpperCase();
- var eStr = "", aRegx = new RegExp("[a-z$]", "gi"), nRegx = new RegExp("[0-9$]", "g"), str = options.isVFill ? text.replace(nRegx, eStr) : text.replace(aRegx, eStr);
- let temp = options.isVFill ? Number(text.replace(aRegx, eStr)) : this.generateColCount(text.replace(nRegx, eStr)), arr = [temp], isColAbslt = text[0] === '$';
- if (length && length !== 1)
- arr.push(temp + length);
- else
- arr.push(temp + 1);
- temp = this.getPredictionValue(arr);
- if (rfrType && (rfrType === "mixed")) {
- if (isColAbslt === options.isVFill)
- str = '$' + str;
- else
- temp.b = 0;
- }
- temp.c = str;
- return temp;
- }
- getType(val) {
- let type1;
- let type = this.isCustomType(val);
- if (type)
- type1 = type;
- else if (this.isFormula(val))
- type1 = this.colType.Formula;
- else if (this.isNumber(val))
- type1 = this.colType.Number;
- return type1 || this.colType.String;
- }
- isCustomType(val) {
- val = val + "";
- val = val.toLowerCase();
- let i = this.customList.length;
- while (i--) {
- if (this.toArrayLowerCase(this.customList[i].slice(0)).indexOf(val) > -1)
- return this.colType.Custom + i;
- }
- return false;
- }
- toArrayLowerCase(args) {
- for (let i = 0; i < args.length; i++)
- args[i] = args[i].toString().toLowerCase();
- return args;
- }
- isFormula(formula) {
- let obrackets, cbrackets;
- if (formula) {
- if (!formula.toString().indexOf("=") && formula.length > 1) {
- obrackets = formula.split("(").length - 1;
- cbrackets = formula.split(")").length - 1;
- return obrackets === cbrackets;
- }
- }
- return false;
- }
- isNumber(val) {
- return val - parseFloat(val) >= 0;
- }
- round(val, digits) {
- let str = val + 'e' + digits;
- let str1 = 'e-' + digits;
- return Number(Math.round(str) + str1);
- }
- getPredictionValue(args) {
- let i = 0, sumx = 0, sumy = 0, sumxy = 0, sumxx = 0, n = args.length;
- while (i < n) {
- sumx = sumx + i;
- sumy = sumy + Number(args[i]);
- sumxy = sumxy + (i * Number(args[i]));
- sumxx = sumxx + (i * i);
- i++;
- }
- let a = this.round(((sumy * sumxx) - (sumx * sumxy)) / ((n * sumxx) - (sumx * sumx)), 5), b = this.round(((n * sumxy) - (sumx * sumy)) / ((n * sumxx) - (sumx * sumx)), 5);
- return { a: a, b: b };
- }
- ensurePattern(patterns) {
- let patrn, idx = -1, i = patterns.length;
- while (i--) {
- patrn = patterns[i];
- if (this.isObject(patrn)) {
- idx = i;
- if (patrn.type === this.colType.String)
- patrn.val = patrn.val.reverse();
- }
- else
- patterns[i] = idx;
- }
- return patterns;
- }
- isObject(obj) {
- if (typeof obj !== "object")
- return false;
- return Object.prototype.toString.call(obj) === "[object Object]";
- }
- getSelectedRange(startcell, endcell) {
- let i, j, k, l, arr = [], range = this.base.swapRange([startcell.rowIndex, startcell.colIndex, endcell.rowIndex, endcell.colIndex]);
- i = range[0], j = range[2];
- while (i <= j) {
- k = range[1];
- l = range[3];
- while (k <= l) {
- arr.push({ rowIndex: i, colIndex: k });
- k++;
- }
- i++;
- }
- return arr;
- }
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new Autofill();
- }
- return this.instance;
- }
- }
- Sheets.Autofill = Autofill;
- })(Sheets = Components.Sheets || (Components.Sheets = {}));
- })(Components = Collaboration.Components || (Collaboration.Components = {}));
- })(Collaboration = Apps.Collaboration || (Apps.Collaboration = {}));
- })(Apps = Unibase.Apps || (Unibase.Apps = {}));
- })(Unibase || (Unibase = {}));
|