allow multiple rows for template
This commit is contained in:
@ -1,6 +1,23 @@
|
|||||||
import { productTemplate } from "./productTemplate"
|
import { productTemplate } from "./productTemplate"
|
||||||
|
import { toastAndLog } from "./sheetUtils"
|
||||||
|
|
||||||
export function fillProductFromTemplate() {
|
export function fillProductFromTemplate() {
|
||||||
let row = SpreadsheetApp.getCurrentCell().getRow()
|
var sheet = SpreadsheetApp.getActive().getActiveSheet()
|
||||||
productTemplate(row)
|
if (sheet.getName() !== "product_inventory") {
|
||||||
|
console.log("skipping edit on sheet " + sheet.getName())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let selectedRanges = SpreadsheetApp.getActiveRangeList().getRanges()
|
||||||
|
if (selectedRanges == null || selectedRanges.length == 0) {
|
||||||
|
toastAndLog("Select ranges to be updated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (let i = 0; i < selectedRanges.length; i++) {
|
||||||
|
let range = selectedRanges[i]
|
||||||
|
let firstRow = range.getRow()
|
||||||
|
let lastRow = range.getLastRow()
|
||||||
|
for (let row = firstRow; row <= lastRow; row++) {
|
||||||
|
productTemplate(row)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,13 +7,14 @@ import {
|
|||||||
} from "./sheetUtils"
|
} from "./sheetUtils"
|
||||||
|
|
||||||
export function productTemplate(row: number) {
|
export function productTemplate(row: number) {
|
||||||
|
//TODO: just use the columns that exist, if they match
|
||||||
let updateColumns = [
|
let updateColumns = [
|
||||||
"function",
|
"function",
|
||||||
"type",
|
"type",
|
||||||
"category",
|
"category",
|
||||||
"product_type",
|
"product_type",
|
||||||
"tags",
|
"tags",
|
||||||
"price",
|
"base_price",
|
||||||
"shipping",
|
"shipping",
|
||||||
"weight (grams)",
|
"weight (grams)",
|
||||||
]
|
]
|
||||||
@ -21,6 +22,7 @@ export function productTemplate(row: number) {
|
|||||||
let productInventorySheet =
|
let productInventorySheet =
|
||||||
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
|
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
|
||||||
let titleValue = getCellValueByColumnName(productInventorySheet, "title", row)
|
let titleValue = getCellValueByColumnName(productInventorySheet, "title", row)
|
||||||
|
//TODO: Make this *much* faster
|
||||||
for (let i = 0; i < updateColumns.length; i++) {
|
for (let i = 0; i < updateColumns.length; i++) {
|
||||||
let updateColumn = updateColumns[i]
|
let updateColumn = updateColumns[i]
|
||||||
let currentValue = getCellValueByColumnName(
|
let currentValue = getCellValueByColumnName(
|
||||||
@ -43,14 +45,14 @@ export function productTemplate(row: number) {
|
|||||||
)
|
)
|
||||||
if (templateValue != "") {
|
if (templateValue != "") {
|
||||||
console.log(
|
console.log(
|
||||||
"template value for '" +
|
"template value for '" + updateColumn + "' is '" + templateValue + "'"
|
||||||
updateColumn +
|
|
||||||
"' is '" +
|
|
||||||
templateValue +
|
|
||||||
"'"
|
|
||||||
)
|
)
|
||||||
toastAndLog("updating '" + updateColumn + "' to '" + templateValue + "'")
|
toastAndLog("updating '" + updateColumn + "' to '" + templateValue + "'")
|
||||||
let cell = getCellRangeByColumnName(productInventorySheet, updateColumn, row)
|
let cell = getCellRangeByColumnName(
|
||||||
|
productInventorySheet,
|
||||||
|
updateColumn,
|
||||||
|
row
|
||||||
|
)
|
||||||
cell.setValue(templateValue)
|
cell.setValue(templateValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user