Skip to content

Commit

Permalink
position for duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasPohl committed May 29, 2023
1 parent a621079 commit 94e0226
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Use the available blocks to automatically interact with your spreadsheet.
### 0.0.4

* (Thomas Pohl) Added "duplicate Sheet"

### 0.0.5

* (Thomas Pohl) Position for "suplicate sheet"

<!--
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
Expand Down
17 changes: 13 additions & 4 deletions admin/blocks/duplicateSheet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Blockly.Words["google-spreadsheet_duplicate-sheet_duplicate-in"] = { en: "duplicate in ", de: "dupliziere in" }
Blockly.Words["google-spreadsheet_duplicate-sheet_sheetName"] = { en: "the sheet with the name", de: "das Blatt mit dem Namen" };
Blockly.Words["google-spreadsheet_duplicate-sheet_newSheetName"] = { en: "new name", de: "neuer Name" };
Blockly.Words["google-spreadsheet_duplicate-sheet_newPosition"] = { en: "at position", de: "an Position" };



Expand All @@ -18,6 +19,11 @@ Blockly.Sendto.blocks["google-spreadsheetduplicateSheet"] =
' <field name="TEXT">text</field>' +
' </shadow>' +
' </value>' +
' <value name="NEW_POSITION">' +
' <shadow type="math_number">' +
' <field name="NUM">0</field>' +
' </shadow>' +
' </value>' +
'</block>';


Expand All @@ -38,9 +44,8 @@ Blockly.Blocks["google-spreadsheet.duplicateSheet"] = {
this.appendValueInput("NEW_SHEET_NAME")
.appendField(Blockly.Translate("google-spreadsheet_duplicate-sheet_newSheetName"));

/* if (input && input.connection) {
input.connection._optional = true;
}*/
this.appendValueInput("NEW_POSITION")
.appendField(Blockly.Translate("google-spreadsheet_duplicate-sheet_newPosition"));

this.setInputsInline(false);
this.setPreviousStatement(true, null);
Expand All @@ -54,6 +59,10 @@ Blockly.JavaScript["google-spreadsheet.duplicateSheet"] = function (block) {
var dropdown_instance = block.getFieldValue("INSTANCE");
var source = Blockly.JavaScript.valueToCode(block, "SHEET_NAME", Blockly.JavaScript.ORDER_ATOMIC);
var target = Blockly.JavaScript.valueToCode(block, "NEW_SHEET_NAME", Blockly.JavaScript.ORDER_ATOMIC);
var index = Blockly.JavaScript.valueToCode(block, "NEW_POSITION", Blockly.JavaScript.ORDER_ATOMIC);
if (!index){
index = -1;
}

return 'sendTo("google-spreadsheet' + dropdown_instance + '", "duplicateSheet", {"source": '+source+', "target": '+target+'}' + ");\n";
return 'sendTo("google-spreadsheet' + dropdown_instance + '", "duplicateSheet", {"source": '+source+', "target": '+target+', "index":'+index+'}' + ");\n";
};
6 changes: 5 additions & 1 deletion build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/main.js.map

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"common": {
"name": "google-spreadsheet",
"version": "0.0.4",
"version": "0.0.5",
"news": {
"0.0.1": {
"en": "initial release",
Expand Down Expand Up @@ -54,6 +54,19 @@
"pl": "dodano „duplikat arkusza”",
"uk": "додано \"дублікат аркуша\"",
"zh-cn": "添加了“重复表”"
},
"0.0.5": {
"en": "added position for 'duplicate sheet'",
"de": "Position für „doppeltes Blatt“ hinzugefügt",
"ru": "добавлена ​​позиция для «дубликата листа»",
"pt": "posição adicionada para 'folha duplicada'",
"nl": "positie toegevoegd voor 'blad dupliceren'",
"fr": "position ajoutée pour 'feuille en double'",
"it": "aggiunta posizione per 'foglio duplicato'",
"es": "posición añadida para 'hoja duplicada'",
"pl": "dodano pozycję dla „duplikatu arkusza”",
"uk": "додано позицію для «дублікату аркуша»",
"zh-cn": "为“重复表”添加位置"
}
},
"titleLang": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.google-spreadsheet",
"version": "0.0.4",
"version": "0.0.5",
"description": "Append data to google spreadsheets",
"author": {
"name": "Thomas Pohl",
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,18 @@ class GoogleSpreadsheet extends utils.Adapter {
const sheet = spreadsheet.data.sheets
.find(sheet => sheet.properties && sheet.properties.title == messageData["source"]);
if (sheet && sheet.properties) {
let insertIndex = messageData["index"];
if (insertIndex==-1 || insertIndex == undefined){
insertIndex = spreadsheet.data.sheets.length;
}
sheets.spreadsheets.batchUpdate({
spreadsheetId: this.config.spreadsheetId,
requestBody: {
requests: [{
duplicateSheet: {
sourceSheetId: sheet.properties.sheetId,
newSheetName: messageData["target"],
insertSheetIndex: spreadsheet.data.sheets.length
insertSheetIndex: insertIndex
}
}]
}
Expand Down

0 comments on commit 94e0226

Please sign in to comment.