From b015a5e3186df1de355f912d3febb03fa37089bc Mon Sep 17 00:00:00 2001 From: dali Date: Wed, 31 Mar 2021 12:33:12 +0200 Subject: [PATCH 1/4] Add operation 'addSheet' to GoogleSheets node --- .../nodes/Google/Sheet/GenericFunctions.ts | 16 ++ .../nodes/Google/Sheet/GoogleSheets.node.ts | 258 +++++++++++++++++- 2 files changed, 273 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts index 21831fc9b774b..eca3ba877ad49 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts @@ -127,3 +127,19 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa //@ts-ignore return this.helpers.request(options); } + +// Hex to RGB +export function hexToRgb(hex: string) { + // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") + var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; + hex = hex.replace(shorthandRegex, function(m, r, g, b) { + return r + r + g + g + b + b; + }); + + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + red: parseInt(result[1], 16), + green: parseInt(result[2], 16), + blue: parseInt(result[3], 16) + } : null; + } \ No newline at end of file diff --git a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts index ac3750e9fa9e4..ef9dcf8be5bed 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts @@ -23,6 +23,7 @@ import { import { googleApiRequest, + hexToRgb, } from './GenericFunctions'; export class GoogleSheets implements INodeType { @@ -111,6 +112,11 @@ export class GoogleSheets implements INodeType { }, }, options: [ + { + name: 'Add', + value: 'add', + description: 'Add a new sheet to a spreadsheet' + }, { name: 'Append', value: 'append', @@ -159,6 +165,11 @@ export class GoogleSheets implements INodeType { 'sheet', ], }, + hide: { + operation: [ + 'add', + ], + }, }, default: '', required: true, @@ -176,6 +187,7 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ + 'add', 'delete', ], }, @@ -185,6 +197,217 @@ export class GoogleSheets implements INodeType { description: 'The table range to read from or to append data to. See the Google documentation for the details.
If it contains multiple sheets it can also be
added like this: "MySheet!A:F"', }, + // ---------------------------------- + // add + // ---------------------------------- + { + displayName: 'Spreadsheet ID', + name: 'spreadsheetId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'sheet', + ], + operation: [ + 'add', + ], + }, + }, + description: 'The ID of the spreadsheet in which the sheet will be added.', + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + resource: [ + 'sheet', + ], + operation: [ + 'add', + ], + }, + }, + options: [ + { + displayName: 'Sheet ID', + name: 'sheetId', + type: 'string', + default: '', + description: 'The Sheet ID.', + }, + { + displayName: 'title', + name: 'title', + type: 'string', + default: '', + description: 'The Sheet name.', + }, + { + displayName: 'Sheet Index', + name: 'index', + type: 'number', + default: 0, + description: 'The index of the sheet within the spreadsheet.', + }, + { + displayName: 'Grid Properties', + name: 'gridProperties', + type: 'collection', + default: '', + options: [ + { + displayName: 'Row Count', + name: 'rowCount', + type: 'number', + default: 0, + description: 'The number of rows in the grid.', + }, + { + displayName: 'Column Count', + name: 'columnCount', + type: 'number', + default: 0, + description: 'The number of columns in the grid.', + }, + { + displayName: 'Frozen Row Count', + name: 'frozenRowCount', + type: 'number', + default: 0, + description: 'The number of rows that are frozen in the grid.', + }, + { + displayName: 'Frozen Column Count', + name: 'frozenColumnCount', + type: 'number', + default: 0, + description: 'The number of columns that are frozen in the grid.', + }, + { + displayName: 'Hide Gridlines', + name: 'hideGridlines', + type: 'boolean', + default: false, + description: 'True if the grid isn\'t showing gridlines in the UI.', + }, + { + displayName: 'Row Group Control After', + name: 'rowGroupControlAfter', + type: 'boolean', + default: false, + description: 'True if the row grouping control toggle is shown after the group.', + }, + { + displayName: 'Column Group Control After', + name: 'columnGroupControlAfter', + type: 'boolean', + default: false, + description: 'True if the column grouping control toggle is shown after the group.', + }, + ], + description: 'The type of the sheet.', + }, + { + displayName: 'Hidden', + name: 'hidden', + type: 'boolean', + default: false, + description: 'True if the sheet is hidden in the UI, false if it\'s visible.' + }, + { + displayName: 'Tab Color', + name: 'tabColor', + type: 'color', + default: '', + description: 'The color of the tab in the UI.' + }, + { + displayName: 'Tab Color Style', + name: 'tabColorStyle', + type: 'collection', + default: '', + options: [ + { + displayName: 'RGB Color', + name: 'rgbColor', + type: 'color', + default: '', + description: 'RGB Color.' + }, + { + displayName: 'Theme Color', + name: 'themeColor', + type: 'options', + default: 0, + options: [ + { + name: 'Text', + value: 'TEXT', + description: 'Represents the primary text color.', + }, + { + name: 'Background', + value: 'BACKGROUND', + description: 'Represents the primary background color.', + }, + { + name: 'Accent1', + value: 'ACCENT1', + description: 'Represents the first accent color.', + }, + { + name: 'Accent2', + value: 'ACCENT2', + description: 'Represents the second accent color.', + }, + { + name: 'Accent3', + value: 'ACCENT3', + description: 'Represents the third accent color.', + }, + { + name: 'Accent4', + value: 'ACCENT4', + description: 'Represents the fourth accent color.', + }, + { + name: 'Accent5', + value: 'ACCENT5', + description: 'Represents the fifth accent color.', + }, + { + name: 'Accent6', + value: 'ACCENT6', + description: 'Represents the sixth accent color.', + }, + { + name: 'Link', + value: 'LINK', + description: 'Represents the color to use for hyperlinks.', + } + ], + + description: 'RGB color.' + } + ], + description: 'The color of the tab in the UI. If tabColor is also set, this field takes precedence.' + }, + { + displayName: 'Right To Left', + name: 'rightToLeft', + type: 'boolean', + default: false, + description: 'True if the sheet is an RTL sheet instead of an LTR sheet.' + } + ] + }, // ---------------------------------- // Delete @@ -391,6 +614,7 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ + 'add', 'append', 'clear', 'delete', @@ -421,6 +645,7 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ + 'add', 'clear', 'delete', ], @@ -596,7 +821,7 @@ export class GoogleSheets implements INodeType { { name: 'Formula', value: 'FORMULA', - description: ' Values will not be calculated. The reply will include the formulas. For example, if A1 is 1.23 and A2 is =A1 and formatted as currency, then A2 would return "=A1".', + description: 'Values will not be calculated. The reply will include the formulas. For example, if A1 is 1.23 and A2 is =A1 and formatted as currency, then A2 would return "=A1".', }, { name: 'Unformatted Value', @@ -835,6 +1060,37 @@ export class GoogleSheets implements INodeType { if (resource === 'sheet') { + if (operation === 'add') { + const spreadsheetId = this.getNodeParameter('spreadsheetId', 0) as string; + const spreadsheet = new GoogleSheet(spreadsheetId, this); + const options = this.getNodeParameter('options', 0, {}) as IDataObject; + let properties = {...options} + + if( options.tabColor){ + const {red,green,blue} = hexToRgb(options.tabColor as string)!; + properties.tabColor = {red:red/255,green:green/255,blue:blue/255}; + } + if( options.tabColorStyle){ + // tabColorStyle take precendens over tabColor + delete properties.tabColor; + + if( (options.tabColorStyle as IDataObject).themeColor){ + properties.tabColorStyle = {"themeColor":(options.tabColorStyle as IDataObject).themeColor as string } + }else{ + const {red,green,blue} = hexToRgb((options.tabColorStyle as IDataObject).rgbColor as string)!; + properties.tabColorStyle = {"rgbColor":{red:red/255,green:green/255,blue:blue/255} } + } + } + const requests = [{ + "addSheet":{ + "properties": properties + } + }]; + + const data = await spreadsheet.spreadsheetBatchUpdate(requests); + + return this.prepareOutputData(this.helpers.returnJsonArray(data)); + } const spreadsheetId = this.getNodeParameter('sheetId', 0) as string; const sheet = new GoogleSheet(spreadsheetId, this); From be429fbce02371129705191150a62c036c830349 Mon Sep 17 00:00:00 2001 From: dali Date: Wed, 31 Mar 2021 12:39:27 +0200 Subject: [PATCH 2/4] lint fixes --- .../nodes/Google/Sheet/GenericFunctions.ts | 16 ++++----- .../nodes/Google/Sheet/GoogleSheets.node.ts | 34 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts index eca3ba877ad49..80526a9ce1e62 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts @@ -131,15 +131,15 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa // Hex to RGB export function hexToRgb(hex: string) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") - var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; - hex = hex.replace(shorthandRegex, function(m, r, g, b) { - return r + r + g + g + b + b; + const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; + hex = hex.replace(shorthandRegex, (m, r, g, b) => { + return r + r + g + g + b + b; }); - var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { - red: parseInt(result[1], 16), - green: parseInt(result[2], 16), - blue: parseInt(result[3], 16) + red: parseInt(result[1], 16), + green: parseInt(result[2], 16), + blue: parseInt(result[3], 16), } : null; - } \ No newline at end of file +} \ No newline at end of file diff --git a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts index ef9dcf8be5bed..7f8bfbb9326b0 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts @@ -115,7 +115,7 @@ export class GoogleSheets implements INodeType { { name: 'Add', value: 'add', - description: 'Add a new sheet to a spreadsheet' + description: 'Add a new sheet to a spreadsheet', }, { name: 'Append', @@ -319,14 +319,14 @@ export class GoogleSheets implements INodeType { name: 'hidden', type: 'boolean', default: false, - description: 'True if the sheet is hidden in the UI, false if it\'s visible.' + description: 'True if the sheet is hidden in the UI, false if it\'s visible.', }, { displayName: 'Tab Color', name: 'tabColor', type: 'color', default: '', - description: 'The color of the tab in the UI.' + description: 'The color of the tab in the UI.', }, { displayName: 'Tab Color Style', @@ -339,7 +339,7 @@ export class GoogleSheets implements INodeType { name: 'rgbColor', type: 'color', default: '', - description: 'RGB Color.' + description: 'RGB Color.', }, { displayName: 'Theme Color', @@ -391,22 +391,22 @@ export class GoogleSheets implements INodeType { name: 'Link', value: 'LINK', description: 'Represents the color to use for hyperlinks.', - } + }, ], - description: 'RGB color.' - } + description: 'RGB color.', + }, ], - description: 'The color of the tab in the UI. If tabColor is also set, this field takes precedence.' + description: 'The color of the tab in the UI. If tabColor is also set, this field takes precedence.', }, { displayName: 'Right To Left', name: 'rightToLeft', type: 'boolean', default: false, - description: 'True if the sheet is an RTL sheet instead of an LTR sheet.' - } - ] + description: 'True if the sheet is an RTL sheet instead of an LTR sheet.', + }, + ], }, // ---------------------------------- @@ -1064,7 +1064,7 @@ export class GoogleSheets implements INodeType { const spreadsheetId = this.getNodeParameter('spreadsheetId', 0) as string; const spreadsheet = new GoogleSheet(spreadsheetId, this); const options = this.getNodeParameter('options', 0, {}) as IDataObject; - let properties = {...options} + const properties = {...options}; if( options.tabColor){ const {red,green,blue} = hexToRgb(options.tabColor as string)!; @@ -1075,16 +1075,16 @@ export class GoogleSheets implements INodeType { delete properties.tabColor; if( (options.tabColorStyle as IDataObject).themeColor){ - properties.tabColorStyle = {"themeColor":(options.tabColorStyle as IDataObject).themeColor as string } + properties.tabColorStyle = {'themeColor':(options.tabColorStyle as IDataObject).themeColor as string }; }else{ const {red,green,blue} = hexToRgb((options.tabColorStyle as IDataObject).rgbColor as string)!; - properties.tabColorStyle = {"rgbColor":{red:red/255,green:green/255,blue:blue/255} } + properties.tabColorStyle = {'rgbColor':{red:red/255,green:green/255,blue:blue/255} }; } } const requests = [{ - "addSheet":{ - "properties": properties - } + 'addSheet':{ + 'properties': properties, + }, }]; const data = await spreadsheet.spreadsheetBatchUpdate(requests); From c8e0a562d5dbe45879fba449fd3990bcdcb1eb24 Mon Sep 17 00:00:00 2001 From: ricardo Date: Fri, 2 Apr 2021 18:43:38 -0400 Subject: [PATCH 3/4] :zap: Improvements --- .../nodes/Google/Sheet/GoogleSheets.node.ts | 526 +++++++++--------- 1 file changed, 271 insertions(+), 255 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts index 7f8bfbb9326b0..e1d1a452397a2 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts @@ -91,6 +91,10 @@ export class GoogleSheets implements INodeType { name: 'Spreadsheet', value: 'spreadsheet', }, + { + name: 'Spreadsheet Sheet', + value: 'spreadsheetSheet', + }, { name: 'Sheet', value: 'sheet', @@ -112,11 +116,6 @@ export class GoogleSheets implements INodeType { }, }, options: [ - { - name: 'Add', - value: 'add', - description: 'Add a new sheet to a spreadsheet', - }, { name: 'Append', value: 'append', @@ -165,11 +164,6 @@ export class GoogleSheets implements INodeType { 'sheet', ], }, - hide: { - operation: [ - 'add', - ], - }, }, default: '', required: true, @@ -197,218 +191,6 @@ export class GoogleSheets implements INodeType { description: 'The table range to read from or to append data to. See the Google documentation for the details.
If it contains multiple sheets it can also be
added like this: "MySheet!A:F"', }, - // ---------------------------------- - // add - // ---------------------------------- - { - displayName: 'Spreadsheet ID', - name: 'spreadsheetId', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'sheet', - ], - operation: [ - 'add', - ], - }, - }, - description: 'The ID of the spreadsheet in which the sheet will be added.', - }, - { - displayName: 'Options', - name: 'options', - type: 'collection', - placeholder: 'Add Option', - default: {}, - displayOptions: { - show: { - resource: [ - 'sheet', - ], - operation: [ - 'add', - ], - }, - }, - options: [ - { - displayName: 'Sheet ID', - name: 'sheetId', - type: 'string', - default: '', - description: 'The Sheet ID.', - }, - { - displayName: 'title', - name: 'title', - type: 'string', - default: '', - description: 'The Sheet name.', - }, - { - displayName: 'Sheet Index', - name: 'index', - type: 'number', - default: 0, - description: 'The index of the sheet within the spreadsheet.', - }, - { - displayName: 'Grid Properties', - name: 'gridProperties', - type: 'collection', - default: '', - options: [ - { - displayName: 'Row Count', - name: 'rowCount', - type: 'number', - default: 0, - description: 'The number of rows in the grid.', - }, - { - displayName: 'Column Count', - name: 'columnCount', - type: 'number', - default: 0, - description: 'The number of columns in the grid.', - }, - { - displayName: 'Frozen Row Count', - name: 'frozenRowCount', - type: 'number', - default: 0, - description: 'The number of rows that are frozen in the grid.', - }, - { - displayName: 'Frozen Column Count', - name: 'frozenColumnCount', - type: 'number', - default: 0, - description: 'The number of columns that are frozen in the grid.', - }, - { - displayName: 'Hide Gridlines', - name: 'hideGridlines', - type: 'boolean', - default: false, - description: 'True if the grid isn\'t showing gridlines in the UI.', - }, - { - displayName: 'Row Group Control After', - name: 'rowGroupControlAfter', - type: 'boolean', - default: false, - description: 'True if the row grouping control toggle is shown after the group.', - }, - { - displayName: 'Column Group Control After', - name: 'columnGroupControlAfter', - type: 'boolean', - default: false, - description: 'True if the column grouping control toggle is shown after the group.', - }, - ], - description: 'The type of the sheet.', - }, - { - displayName: 'Hidden', - name: 'hidden', - type: 'boolean', - default: false, - description: 'True if the sheet is hidden in the UI, false if it\'s visible.', - }, - { - displayName: 'Tab Color', - name: 'tabColor', - type: 'color', - default: '', - description: 'The color of the tab in the UI.', - }, - { - displayName: 'Tab Color Style', - name: 'tabColorStyle', - type: 'collection', - default: '', - options: [ - { - displayName: 'RGB Color', - name: 'rgbColor', - type: 'color', - default: '', - description: 'RGB Color.', - }, - { - displayName: 'Theme Color', - name: 'themeColor', - type: 'options', - default: 0, - options: [ - { - name: 'Text', - value: 'TEXT', - description: 'Represents the primary text color.', - }, - { - name: 'Background', - value: 'BACKGROUND', - description: 'Represents the primary background color.', - }, - { - name: 'Accent1', - value: 'ACCENT1', - description: 'Represents the first accent color.', - }, - { - name: 'Accent2', - value: 'ACCENT2', - description: 'Represents the second accent color.', - }, - { - name: 'Accent3', - value: 'ACCENT3', - description: 'Represents the third accent color.', - }, - { - name: 'Accent4', - value: 'ACCENT4', - description: 'Represents the fourth accent color.', - }, - { - name: 'Accent5', - value: 'ACCENT5', - description: 'Represents the fifth accent color.', - }, - { - name: 'Accent6', - value: 'ACCENT6', - description: 'Represents the sixth accent color.', - }, - { - name: 'Link', - value: 'LINK', - description: 'Represents the color to use for hyperlinks.', - }, - ], - - description: 'RGB color.', - }, - ], - description: 'The color of the tab in the UI. If tabColor is also set, this field takes precedence.', - }, - { - displayName: 'Right To Left', - name: 'rightToLeft', - type: 'boolean', - default: false, - description: 'True if the sheet is an RTL sheet instead of an LTR sheet.', - }, - ], - }, - // ---------------------------------- // Delete // ---------------------------------- @@ -614,7 +396,6 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ - 'add', 'append', 'clear', 'delete', @@ -645,7 +426,6 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ - 'add', 'clear', 'delete', ], @@ -1018,6 +798,214 @@ export class GoogleSheets implements INodeType { }, ], }, + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'spreadsheetSheet', + ], + }, + }, + options: [ + { + name: 'Add', + value: 'add', + description: 'Add a new sheet to a spreadsheet', + }, + { + name: 'Remove', + value: 'remove', + description: 'Remove a sheet from a spreadsheet', + }, + ], + default: 'add', + description: 'The operation to perform.', + }, + + // ---------------------------------- + // add + // ---------------------------------- + { + displayName: 'Spreadsheet ID', + name: 'spreadsheetId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'spreadsheetSheet', + ], + operation: [ + 'add', + 'remove', + ], + }, + }, + description: 'The ID of the spreadsheet in which the sheet will be added.', + }, + { + displayName: 'Simple', + name: 'simple', + type: 'boolean', + default: true, + displayOptions: { + show: { + resource: [ + 'spreadsheetSheet', + ], + operation: [ + 'add', + ], + }, + }, + description: 'When set to true a simplify version of the response will be used else the raw data.', + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + resource: [ + 'spreadsheetSheet', + ], + operation: [ + 'add', + ], + }, + }, + options: [ + { + displayName: 'Grid Properties', + name: 'gridProperties', + type: 'collection', + placeholder: 'Add Property', + default: '', + options: [ + { + displayName: 'Row Count', + name: 'rowCount', + type: 'number', + default: 0, + description: 'The number of rows in the grid.', + }, + { + displayName: 'Column Count', + name: 'columnCount', + type: 'number', + default: 0, + description: 'The number of columns in the grid.', + }, + { + displayName: 'Frozen Row Count', + name: 'frozenRowCount', + type: 'number', + default: 0, + description: 'The number of rows that are frozen in the grid.', + }, + { + displayName: 'Frozen Column Count', + name: 'frozenColumnCount', + type: 'number', + default: 0, + description: 'The number of columns that are frozen in the grid.', + }, + { + displayName: 'Hide Gridlines', + name: 'hideGridlines', + type: 'boolean', + default: false, + description: 'True if the grid isn\'t showing gridlines in the UI.', + }, + { + displayName: 'Row Group Control After', + name: 'rowGroupControlAfter', + type: 'boolean', + default: false, + description: 'True if the row grouping control toggle is shown after the group.', + }, + { + displayName: 'Column Group Control After', + name: 'columnGroupControlAfter', + type: 'boolean', + default: false, + description: 'True if the column grouping control toggle is shown after the group.', + }, + ], + description: 'The type of the sheet.', + }, + { + displayName: 'Hidden', + name: 'hidden', + type: 'boolean', + default: false, + description: 'True if the sheet is hidden in the UI, false if it\'s visible.', + }, + { + displayName: 'Right To Left', + name: 'rightToLeft', + type: 'boolean', + default: false, + description: 'True if the sheet is an RTL sheet instead of an LTR sheet.', + }, + { + displayName: 'Sheet ID', + name: 'sheetId', + type: 'number', + default: 0, + description: 'The ID of the sheet. Must be non-negative. This field cannot be changed once set.', + }, + { + displayName: 'Sheet Index', + name: 'index', + type: 'number', + default: 0, + description: 'The index of the sheet within the spreadsheet.', + }, + { + displayName: 'Tab Color', + name: 'tabColor', + type: 'color', + default: '0aa55c', + description: 'The color of the tab in the UI.', + }, + { + displayName: 'Title', + name: 'title', + type: 'string', + default: '', + description: 'The Sheet name.', + }, + ], + }, + + // ---------------------------------- + // remove + // ---------------------------------- + { + displayName: 'Sheet ID', + name: 'sheetId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'spreadsheetSheet', + ], + operation: [ + 'remove', + ], + }, + }, + description: 'The ID of the sheet to delete.', + }, ], }; @@ -1060,37 +1048,6 @@ export class GoogleSheets implements INodeType { if (resource === 'sheet') { - if (operation === 'add') { - const spreadsheetId = this.getNodeParameter('spreadsheetId', 0) as string; - const spreadsheet = new GoogleSheet(spreadsheetId, this); - const options = this.getNodeParameter('options', 0, {}) as IDataObject; - const properties = {...options}; - - if( options.tabColor){ - const {red,green,blue} = hexToRgb(options.tabColor as string)!; - properties.tabColor = {red:red/255,green:green/255,blue:blue/255}; - } - if( options.tabColorStyle){ - // tabColorStyle take precendens over tabColor - delete properties.tabColor; - - if( (options.tabColorStyle as IDataObject).themeColor){ - properties.tabColorStyle = {'themeColor':(options.tabColorStyle as IDataObject).themeColor as string }; - }else{ - const {red,green,blue} = hexToRgb((options.tabColorStyle as IDataObject).rgbColor as string)!; - properties.tabColorStyle = {'rgbColor':{red:red/255,green:green/255,blue:blue/255} }; - } - } - const requests = [{ - 'addSheet':{ - 'properties': properties, - }, - }]; - - const data = await spreadsheet.spreadsheetBatchUpdate(requests); - - return this.prepareOutputData(this.helpers.returnJsonArray(data)); - } const spreadsheetId = this.getNodeParameter('sheetId', 0) as string; const sheet = new GoogleSheet(spreadsheetId, this); @@ -1328,6 +1285,65 @@ export class GoogleSheets implements INodeType { return [this.helpers.returnJsonArray(returnData)]; } + if (resource === 'spreadsheetSheet') { + + const returnData: IDataObject[] = []; + + let responseData; + + if (operation === 'add') { + + for (let i = 0; i < this.getInputData().length; i++) { + const spreadsheetId = this.getNodeParameter('spreadsheetId', i) as string; + const options = this.getNodeParameter('options', i, {}) as IDataObject; + const simple = this.getNodeParameter('simple', 0) as boolean; + const properties = { ...options }; + + if (options.tabColor) { + const { red, green, blue } = hexToRgb(options.tabColor as string)!; + properties.tabColor = { red: red / 255, green: green / 255, blue: blue / 255 }; + } + + const requests = [{ + addSheet: { + properties, + }, + }]; + + responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); + + if (simple === true) { + Object.assign(responseData, responseData.replies[0].addSheet.properties); + delete responseData.replies; + } + returnData.push(responseData); + } + + return [this.helpers.returnJsonArray(returnData)]; + } + + + if (operation === 'remove') { + + for (let i = 0; i < this.getInputData().length; i++) { + const sheetId = this.getNodeParameter('sheetId', i) as string; + const spreadsheetId = this.getNodeParameter('spreadsheetId', i) as string; + + const requests = [{ + deleteSheet: { + sheetId, + }, + }]; + + responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); + delete responseData.replies; + returnData.push(responseData); + } + + return [this.helpers.returnJsonArray(returnData)]; + } + } + return []; } } From 38e77ecd0619bc3875896fe89c79418b2f0a3e54 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 3 Apr 2021 10:02:28 +0200 Subject: [PATCH 4/4] :zap: Move operations to "Sheet" --- .../nodes/Google/Sheet/GoogleSheets.node.ts | 240 ++++++++---------- 1 file changed, 101 insertions(+), 139 deletions(-) diff --git a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts index e1d1a452397a2..58782e1e15fcf 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts @@ -91,10 +91,6 @@ export class GoogleSheets implements INodeType { name: 'Spreadsheet', value: 'spreadsheet', }, - { - name: 'Spreadsheet Sheet', - value: 'spreadsheetSheet', - }, { name: 'Sheet', value: 'sheet', @@ -126,6 +122,11 @@ export class GoogleSheets implements INodeType { value: 'clear', description: 'Clear data from a sheet', }, + { + name: 'Create', + value: 'create', + description: 'Create a new sheet', + }, { name: 'Delete', value: 'delete', @@ -141,6 +142,11 @@ export class GoogleSheets implements INodeType { value: 'read', description: 'Read data from a sheet', }, + { + name: 'Remove', + value: 'remove', + description: 'Remove a sheet', + }, { name: 'Update', value: 'update', @@ -155,7 +161,7 @@ export class GoogleSheets implements INodeType { // All // ---------------------------------- { - displayName: 'Sheet ID', + displayName: 'Spreadsheet ID', name: 'sheetId', type: 'string', displayOptions: { @@ -167,7 +173,7 @@ export class GoogleSheets implements INodeType { }, default: '', required: true, - description: 'The ID of the Google Sheet.
Found as part of the sheet URL https://docs.google.com/spreadsheets/d/{ID}/', + description: 'The ID of the Google Spreadsheet.
Found as part of the sheet URL https://docs.google.com/spreadsheets/d/{ID}/', }, { displayName: 'Range', @@ -181,8 +187,9 @@ export class GoogleSheets implements INodeType { }, hide: { operation: [ - 'add', + 'create', 'delete', + 'remove', ], }, }, @@ -397,8 +404,10 @@ export class GoogleSheets implements INodeType { hide: { operation: [ 'append', + 'create', 'clear', 'delete', + 'remove', ], rawData: [ true, @@ -427,7 +436,9 @@ export class GoogleSheets implements INodeType { hide: { operation: [ 'clear', + 'create', 'delete', + 'remove', ], rawData: [ true, @@ -798,55 +809,10 @@ export class GoogleSheets implements INodeType { }, ], }, - { - displayName: 'Operation', - name: 'operation', - type: 'options', - displayOptions: { - show: { - resource: [ - 'spreadsheetSheet', - ], - }, - }, - options: [ - { - name: 'Add', - value: 'add', - description: 'Add a new sheet to a spreadsheet', - }, - { - name: 'Remove', - value: 'remove', - description: 'Remove a sheet from a spreadsheet', - }, - ], - default: 'add', - description: 'The operation to perform.', - }, // ---------------------------------- - // add + // sheet:create // ---------------------------------- - { - displayName: 'Spreadsheet ID', - name: 'spreadsheetId', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'spreadsheetSheet', - ], - operation: [ - 'add', - 'remove', - ], - }, - }, - description: 'The ID of the spreadsheet in which the sheet will be added.', - }, { displayName: 'Simple', name: 'simple', @@ -855,10 +821,10 @@ export class GoogleSheets implements INodeType { displayOptions: { show: { resource: [ - 'spreadsheetSheet', + 'sheet', ], operation: [ - 'add', + 'create', ], }, }, @@ -873,10 +839,10 @@ export class GoogleSheets implements INodeType { displayOptions: { show: { resource: [ - 'spreadsheetSheet', + 'sheet', ], operation: [ - 'add', + 'create', ], }, }, @@ -888,13 +854,6 @@ export class GoogleSheets implements INodeType { placeholder: 'Add Property', default: '', options: [ - { - displayName: 'Row Count', - name: 'rowCount', - type: 'number', - default: 0, - description: 'The number of rows in the grid.', - }, { displayName: 'Column Count', name: 'columnCount', @@ -903,11 +862,11 @@ export class GoogleSheets implements INodeType { description: 'The number of columns in the grid.', }, { - displayName: 'Frozen Row Count', - name: 'frozenRowCount', - type: 'number', - default: 0, - description: 'The number of rows that are frozen in the grid.', + displayName: 'Column Group Control After', + name: 'columnGroupControlAfter', + type: 'boolean', + default: false, + description: 'True if the column grouping control toggle is shown after the group.', }, { displayName: 'Frozen Column Count', @@ -916,6 +875,13 @@ export class GoogleSheets implements INodeType { default: 0, description: 'The number of columns that are frozen in the grid.', }, + { + displayName: 'Frozen Row Count', + name: 'frozenRowCount', + type: 'number', + default: 0, + description: 'The number of rows that are frozen in the grid.', + }, { displayName: 'Hide Gridlines', name: 'hideGridlines', @@ -923,6 +889,13 @@ export class GoogleSheets implements INodeType { default: false, description: 'True if the grid isn\'t showing gridlines in the UI.', }, + { + displayName: 'Row Count', + name: 'rowCount', + type: 'number', + default: 0, + description: 'The number of rows in the grid.', + }, { displayName: 'Row Group Control After', name: 'rowGroupControlAfter', @@ -930,13 +903,7 @@ export class GoogleSheets implements INodeType { default: false, description: 'True if the row grouping control toggle is shown after the group.', }, - { - displayName: 'Column Group Control After', - name: 'columnGroupControlAfter', - type: 'boolean', - default: false, - description: 'True if the column grouping control toggle is shown after the group.', - }, + ], description: 'The type of the sheet.', }, @@ -986,18 +953,18 @@ export class GoogleSheets implements INodeType { }, // ---------------------------------- - // remove + // sheet:remove // ---------------------------------- { displayName: 'Sheet ID', - name: 'sheetId', + name: 'id', type: 'string', default: '', required: true, displayOptions: { show: { resource: [ - 'spreadsheetSheet', + 'sheet', ], operation: [ 'remove', @@ -1053,7 +1020,7 @@ export class GoogleSheets implements INodeType { const sheet = new GoogleSheet(spreadsheetId, this); let range = ''; - if (operation !== 'delete') { + if (!['create', 'delete', 'remove'].includes(operation)) { range = this.getNodeParameter('range', 0) as string; } @@ -1091,6 +1058,39 @@ export class GoogleSheets implements INodeType { const items = this.getInputData(); return this.prepareOutputData(items); + + } else if (operation === 'create') { + const returnData: IDataObject[] = []; + + let responseData; + for (let i = 0; i < this.getInputData().length; i++) { + const spreadsheetId = this.getNodeParameter('sheetId', i) as string; + const options = this.getNodeParameter('options', i, {}) as IDataObject; + const simple = this.getNodeParameter('simple', 0) as boolean; + const properties = { ...options }; + + if (options.tabColor) { + const { red, green, blue } = hexToRgb(options.tabColor as string)!; + properties.tabColor = { red: red / 255, green: green / 255, blue: blue / 255 }; + } + + const requests = [{ + addSheet: { + properties, + }, + }]; + + responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); + + if (simple === true) { + Object.assign(responseData, responseData.replies[0].addSheet.properties); + delete responseData.replies; + } + returnData.push(responseData); + } + + return [this.helpers.returnJsonArray(returnData)]; + } else if (operation === 'delete') { // ---------------------------------- // delete @@ -1189,6 +1189,27 @@ export class GoogleSheets implements INodeType { returnData = [{}]; } + return [this.helpers.returnJsonArray(returnData)]; + + } else if (operation === 'remove') { + const returnData: IDataObject[] = []; + + let responseData; + for (let i = 0; i < this.getInputData().length; i++) { + const sheetId = this.getNodeParameter('id', i) as string; + const spreadsheetId = this.getNodeParameter('sheetId', i) as string; + + const requests = [{ + deleteSheet: { + sheetId, + }, + }]; + + responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); + delete responseData.replies; + returnData.push(responseData); + } + return [this.helpers.returnJsonArray(returnData)]; } else if (operation === 'update') { // ---------------------------------- @@ -1285,65 +1306,6 @@ export class GoogleSheets implements INodeType { return [this.helpers.returnJsonArray(returnData)]; } - if (resource === 'spreadsheetSheet') { - - const returnData: IDataObject[] = []; - - let responseData; - - if (operation === 'add') { - - for (let i = 0; i < this.getInputData().length; i++) { - const spreadsheetId = this.getNodeParameter('spreadsheetId', i) as string; - const options = this.getNodeParameter('options', i, {}) as IDataObject; - const simple = this.getNodeParameter('simple', 0) as boolean; - const properties = { ...options }; - - if (options.tabColor) { - const { red, green, blue } = hexToRgb(options.tabColor as string)!; - properties.tabColor = { red: red / 255, green: green / 255, blue: blue / 255 }; - } - - const requests = [{ - addSheet: { - properties, - }, - }]; - - responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); - - if (simple === true) { - Object.assign(responseData, responseData.replies[0].addSheet.properties); - delete responseData.replies; - } - returnData.push(responseData); - } - - return [this.helpers.returnJsonArray(returnData)]; - } - - - if (operation === 'remove') { - - for (let i = 0; i < this.getInputData().length; i++) { - const sheetId = this.getNodeParameter('sheetId', i) as string; - const spreadsheetId = this.getNodeParameter('spreadsheetId', i) as string; - - const requests = [{ - deleteSheet: { - sheetId, - }, - }]; - - responseData = await googleApiRequest.call(this, 'POST', `/v4/spreadsheets/${spreadsheetId}:batchUpdate`, { requests }); - delete responseData.replies; - returnData.push(responseData); - } - - return [this.helpers.returnJsonArray(returnData)]; - } - } - return []; } }