You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
2.6 KiB
132 lines
2.6 KiB
class shoppingFunc {
|
|
|
|
processItems(itemArr, itemLabel) {
|
|
|
|
let tempAr = this.BuildList(this.updateShopIt(itemArr, itemLabel), ",");
|
|
|
|
return "[" + tempAr + "]"
|
|
}
|
|
|
|
updateShopIt(itemArr, itemLabel) {
|
|
|
|
let tempAr = itemArr;
|
|
let num = 0;
|
|
|
|
for (let i = 0; i < tempAr.length; i++) {
|
|
let amount = tempAr[i].split(" ")[0] + " ";
|
|
let radicale = tempAr[i].replace(tempAr[i].split(" ")[0] + " " + tempAr[i].split(" ")[1], "");
|
|
|
|
switch(itemLabel) {
|
|
|
|
case !Boolean(itemLabel):
|
|
amount = amount + num.toString()
|
|
break;
|
|
|
|
default:
|
|
if (radicale.contains(itemLabel)) {
|
|
amount = amount + (parseFloat(tempAr[i].split(" ")[1]) + 1).toString()
|
|
}
|
|
break;
|
|
}
|
|
tempAr[i] = "\"" + amount + radicale + "\""
|
|
|
|
}
|
|
return tempAr
|
|
}
|
|
|
|
BuildList(arg1, construct) {
|
|
|
|
let TempS = ""
|
|
|
|
for (let i = 0; i < arg1.length; i++) {
|
|
if (Boolean(arg1[i])) {
|
|
if (TempS == "") {
|
|
TempS = arg1[i]
|
|
} else {
|
|
TempS = TempS + construct + arg1[i]
|
|
}
|
|
}
|
|
}
|
|
return TempS
|
|
}
|
|
|
|
resetList(args) {
|
|
const {
|
|
that,
|
|
app,
|
|
dv,
|
|
theme,
|
|
listOfIt,
|
|
} = args;
|
|
const { update } = app.plugins.plugins["metaedit"].api
|
|
const { createButton } = app.plugins.plugins["buttons"]
|
|
|
|
const updateSct = listOfIt //this.getSctName(theme) //await dv.suggester(["groceries", "health", "household"], ["groceries", "health", "household"]); //"Groceries" //
|
|
const btnStr = this.getBtnName(theme, updateSct)
|
|
const itemAr = this.getPoint(dv.page("01.02 Home/@Shopping list.md"), updateSct);
|
|
const updateStr = this.processItems(itemAr, false);
|
|
|
|
return dv.el('p',
|
|
createButton({
|
|
app,
|
|
el: that.container,
|
|
args: { name: btnStr, color: 'blue' },
|
|
clickOverride: { click: update, params: [updateSct, updateStr, dv.page("01.02 Home/@Shopping list.md").file.path]}
|
|
}),
|
|
)
|
|
}
|
|
|
|
|
|
|
|
getBtnName(arg1, arg2) {
|
|
let tempresult = "Test";
|
|
switch(arg1) {
|
|
case 'to0':
|
|
tempresult = "Reset " + arg2 + " list"
|
|
break;
|
|
case 'add':
|
|
tempresult = "Add a " + arg2 + " item"
|
|
break;
|
|
}
|
|
return tempresult
|
|
}
|
|
|
|
getPoint(p, datapoint) {
|
|
|
|
let result = null
|
|
|
|
switch(datapoint) {
|
|
case 'Groceries':
|
|
result = p.Groceries
|
|
break;
|
|
case 'Health':
|
|
result = p.Health
|
|
break;
|
|
case 'Household':
|
|
result = p.Household
|
|
break;
|
|
case 'type':
|
|
result = p.DocType
|
|
break;
|
|
case 'createddate':
|
|
result = p.Date
|
|
break;
|
|
case 'tag':
|
|
result = p.Tag
|
|
break;
|
|
case 'hierarchy':
|
|
result = p.Hierarchy
|
|
break;
|
|
case 'alias':
|
|
result = p.Alias
|
|
break;
|
|
case 'location':
|
|
result = p.location
|
|
break;
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
} |