Skip to content

Commit

Permalink
New annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Jul 14, 2016
1 parent 9658151 commit c632190
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 30 deletions.
31 changes: 30 additions & 1 deletion src/SheetsTemplater.gs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
REPLACE_TEXT: replaceValue,
FOR_EACH: processForEach,
INSERT_FORMULA: insertFormula,
COMPLETE_CELL: completeCell,
NONE: function (properties) {
return;
}
Expand All @@ -11,7 +12,9 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
var annotationType = {
'=': annotationFunctions.REPLACE_TEXT,
'~': annotationFunctions.FOR_EACH,
'#': annotationFunctions.INSERT_FORMULA
'#': annotationFunctions.INSERT_FORMULA,
'*': annotationFunctions.COMPLETE_CELL

};
var _config = {
folderId: '0B8cJhvYlR-sCcGR4d3VYWGZaYWM',
Expand Down Expand Up @@ -179,6 +182,32 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
sheet.getRange(row, col).setValue(getValueOnJson(json, command.substring(2, command.length - 1)));
};

function completeCell(properties) {
var row = properties.i + 1,
col = properties.j + 1,
command = properties.values[properties.i][properties.j],
sheet = properties.sheet,
json = properties.json,
cellProperties = getValueOnJson(json, command.substring(2, command.length - 1)),
range = sheet.getRange(row, col);
range.setValue(cellProperties.value);
if (cellProperties.backgroundColor) {
range.setBackground(cellProperties.backgroundColor);
}
if (cellProperties.textSize) {
range.setTextSize(cellProperties.textSize);
}
if (cellProperties.color) {
range.setColor(cellProperties.color);
}
if (cellProperties.borderStyle) {
range.setBorderStyle(cellProperties.borderStyle);
}
if (cellProperties.borderColor) {
range.setBorderColor(cellProperties.borderColor);
}
};

function insertFormula(properties) {
var row = properties.i + 1,
col = properties.j + 1,
Expand Down
15 changes: 8 additions & 7 deletions test/annotationsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,35 @@ var jsonMock = {
}
}
};

describe('QuickDrive functions', function () {
describe('get new sheet', function () {
it('it should return sheet with text replaced', function () {
var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations));
var QuickDriveMock = new QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations));
var file = QuickDriveMock.processSheet(jsonMock);
var range = file.sheet.getRange(1,1,2,2).getCells();
var firstCell = range[0][0];
var secondCell = range[0][1];
var thirdCell = range[1][0];
assert.equal('the value', firstCell.getValue());
assert.equal('rgb(100,100,100)', firstCell.getBackgroundColor());
assert.equal('The value', firstCell.getValue());
assert.equal('rgb(100,100,100)', firstCell.getBackground());
assert.equal('#F00', firstCell.getColor());
assert.equal(23, firstCell.getTextSize());
assert.equal('DOTTED', firstCell.getBorderStyle());
assert.equal('#00F', firstCell.getBorderColor());

assert.equal('my second value', secondCell.getValue());
assert.equal('default', secondCell.getBackgroundColor());
assert.equal('default', secondCell.getBackground());
assert.equal('#F00', secondCell.getColor());
assert.equal('default', secondCell.getTextSize());
assert.equal('SOLID', secondCell.getBorderStyle());
assert.equal('default', secondCell.getBorderStyle());
assert.equal('#00F', secondCell.getBorderColor());

assert.equal('', thirdCell.getValue());
assert.equal('default', thirdCell.getBackgroundColor());
assert.equal('default', thirdCell.getBackground());
assert.equal('default', thirdCell.getColor());
assert.equal(10, thirdCell.getTextSize());
assert.equal('SOLID', thirdCell.getBorderStyle());
assert.equal('default', thirdCell.getBorderStyle());
assert.equal('#00F', thirdCell.getBorderColor());
});
});
Expand Down
51 changes: 40 additions & 11 deletions test/mock/SpreadsheetApp/Cell.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@
var Cell = function (firstValue) {
var value = firstValue || '',
backgroundColor = 'white',
borderStyle = 'SOLID';
backgroundColor = 'default',
borderStyle = 'default',
color = 'default',
textSize = 'default',
borderColor = 'default';

var links = {};

this.getValue = function () {
return value;
};
this.setValue = function (newValue) {
value = newValue;
};
this.setFormula = function (newValue) {
value = newValue;
};
this.getValue = function () {
return value;
this.getBackground = function () {
return backgroundColor;
};

this.setBackground = function(newBackground) {
this.setBackground = function (newBackground) {
backgroundColor = newBackground;
};
this._configureLinks = function(newLinks) {
this.getBorderColor = function () {
return borderColor;
};
this.setBorderColor = function (newBorderColor) {
borderColor = newBorderColor;
};
this.getBorderStyle = function () {
return borderStyle;
};
this.setBorderStyle = function (newBorderStyle) {
borderStyle = newBorderStyle;
};
this.getColor = function () {
return color;
};
this.setColor = function (newColor) {
color = newColor;
};
this.getTextSize = function () {
return textSize;
};
this.setTextSize = function (newTextSize) {
textSize = newTextSize;
};
this._configureLinks = function (newLinks) {
links = newLinks;
};
this._left = function() {
this._left = function () {
return links.left;
};
this._bottom = function() {
this._bottom = function () {
return links.bottom;
};
this._right = function() {
this._right = function () {
return links.right;
};
this._top = function() {
this._top = function () {
return links.top;
};
};
Expand Down
33 changes: 22 additions & 11 deletions test/mock/SpreadsheetApp/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ var Range = function (myMatrix) {
return values;
};

this.setValue = function (value) {
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix.length; j++) {
matrix[i][j].setValue(value);
}
}
};

this.setFormula = this.setValue;

this._getCells = function() {
return matrix;
};
Expand All @@ -40,9 +30,30 @@ var Range = function (myMatrix) {
};

this.setBackground = function (background) {
setSomeValue(background, 'Background');
};
this.setValue = function (value) {
setSomeValue(value, 'Value');
};
this.setFormula = function (formula) {
setSomeValue(formula, 'Formula');
};
this.setTextSize = function (textSize) {
setSomeValue(textSize, 'TextSize');
};
this.setColor = function (color) {
setSomeValue(color, 'Color');
};
this.setBorderStyle = function (borderStyle) {
setSomeValue(borderStyle, 'BorderStyle');
};
this.setBorderColor = function (borderColor) {
setSomeValue(borderColor, 'BorderColor');
};
var setSomeValue = function(value, propertie) {
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix[0].length; j++) {
matrix[i][j].setBackground(background);
matrix[i][j]['set' + propertie](value);
}
}
};
Expand Down

0 comments on commit c632190

Please sign in to comment.