Add ability to hide a product from POS app

See discussion here: https://github.com/btcpayserver/btcpayserver/discussions/2827
This commit is contained in:
Umar Bolatov
2021-09-05 15:19:27 -07:00
committed by Andrew Camilleri
parent 6d667e2d78
commit 403820cf14
6 changed files with 35 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ namespace BTCPayServer.Models.AppViewModels
public string BuyButtonText { get; set; }
public int? Inventory { get; set; } = null;
public string[] PaymentMethods { get; set; }
public bool Hidden { get; set; } = false;
}
public class CurrencyInfoData
@@ -57,4 +58,4 @@ namespace BTCPayServer.Models.AppViewModels
[Display(Name = "Custom CSS Code")]
public string EmbeddedCSS { get; set; }
}
}
}

View File

@@ -290,6 +290,7 @@ namespace BTCPayServer.Services.Apps
itemNode.Add("image", new YamlScalarNode(item.Image));
}
itemNode.Add("custom", new YamlScalarNode(item.Custom.ToStringLowerInvariant()));
itemNode.Add("hidden", new YamlScalarNode(item.Hidden.ToStringLowerInvariant()));
if (item.Inventory.HasValue)
{
itemNode.Add("inventory", new YamlScalarNode(item.Inventory.ToString()));
@@ -337,7 +338,8 @@ namespace BTCPayServer.Services.Apps
Custom = c.GetDetailString("custom") == "true",
BuyButtonText = c.GetDetailString("buyButtonText"),
Inventory = string.IsNullOrEmpty(c.GetDetailString("inventory")) ? (int?)null : int.Parse(c.GetDetailString("inventory"), CultureInfo.InvariantCulture),
PaymentMethods = c.GetDetailStringList("payment_methods")
PaymentMethods = c.GetDetailStringList("payment_methods"),
Hidden = c.GetDetailString("hidden") == "true"
})
.ToArray();
}

View File

@@ -95,6 +95,10 @@
<label class="form-label">Buy Button Text</label>
<input type="text" id="BuyButtonText" class="form-control mb-2" v-model="editingItem.buyButtonText" ref="txtBuyButtonText" />
</div>
<div class="form-group d-flex align-items-center">
<input type="checkbox" id="Hidden" class="btcpay-toggle me-2" v-model="editingItem.hidden" ref="txtHiddenText" />
<label class="form-label mb-0">Hidden</label>
</div>
</div>
</div>
<div class="modal-footer">
@@ -167,7 +171,8 @@ document.addEventListener("DOMContentLoaded", function () {
for (var kl in lines) {
var line = lines[kl], product = line.split("\n"), goingThroughMethods = false,
id = null, price = null, title = null, description = null, image = null,
custom = null, buyButtonText = null, inventory = null, paymentMethods = [];
custom = null, buyButtonText = null, inventory = null, paymentMethods = [],
hidden = false;
for (var kp in product) {
var productProperty = product[kp].trim();
@@ -212,6 +217,9 @@ document.addEventListener("DOMContentLoaded", function () {
if (productProperty.indexOf('payment_methods:') !== -1) {
goingThroughMethods = true;
}
if (productProperty.indexOf('hidden:') !== -1) {
hidden = productProperty.replace('hidden:', '').trim() === "true";
}
}
if (price != null || title != null) {
@@ -225,7 +233,8 @@ document.addEventListener("DOMContentLoaded", function () {
custom: custom === "true",
buyButtonText: buyButtonText,
inventory: isNaN(inventory)? null: inventory,
paymentMethods: paymentMethods
paymentMethods: paymentMethods,
hidden: hidden
});
}
}
@@ -244,7 +253,8 @@ document.addEventListener("DOMContentLoaded", function () {
custom = product.custom,
buyButtonText = product.buyButtonText,
inventory = product.inventory,
paymentMethods = product.paymentMethods;
paymentMethods = product.paymentMethods,
hidden = product.hidden;
template += id + ':\n' +
' price: ' + parseFloat(price).noExponents() + '\n' +
@@ -265,6 +275,9 @@ document.addEventListener("DOMContentLoaded", function () {
if (buyButtonText != null && buyButtonText.length > 0) {
template += ' buyButtonText: ' + buyButtonText + '\n';
}
if (hidden != null) {
template += ' hidden: ' + hidden.toString() + '\n';
}
if(paymentMethods != null && paymentMethods.length > 0){
template+= ' payment_methods:\n';
for (var method of paymentMethods){
@@ -278,7 +291,7 @@ document.addEventListener("DOMContentLoaded", function () {
editItem: function(index){
this.errors = [];
if(index < 0){
this.editingItem = {index:-1, id:"", title: "", price: 0, image: "", description: "", custom: false, inventory: null, paymentMethods: []};
this.editingItem = {index:-1, id:"", title: "", price: 0, image: "", description: "", custom: false, inventory: null, paymentMethods: [], hidden: false};
}else{
this.editingItem = {...this.items[index], index};
}
@@ -369,7 +382,7 @@ document.addEventListener("DOMContentLoaded", function () {
},
unEscape: function(item){
for(var k in item){
if(k !== "paymentMethods" && k!=="id"){
if(k !== "paymentMethods" && k!=="id" && k !== "hidden"){
item[k] = this.unEscapeKey(item[k]);
}
}

View File

@@ -299,6 +299,10 @@
<label class="form-label">Inventory (leave blank to not use inventory feature)</label>
<input type="number" step="1" class="js-product-inventory form-control mb-2" value="{inventory}" />
</div>
<div class="form-group d-flex align-items-center">
<input type="checkbox" class="btcpay-toggle me-2" value="{hidden}" />
<label class="form-label mb-0">Hidden</label>
</div>
</div>
</script>

View File

@@ -216,6 +216,10 @@
var image = item.Image;
var description = item.Description;
@if (item.Hidden) {
continue;
}
<div class="js-add-cart card px-0 card-wrapper" data-index="@index">
@if (!string.IsNullOrWhiteSpace(image))
{

View File

@@ -26,6 +26,10 @@
: item.BuyButtonText)
.Replace("{0}",item.Price.Formatted)
.Replace("{Price}",item.Price.Formatted);
@if (item.Hidden) {
continue;
}
<div class="card px-0" data-id="@x">
@if (!String.IsNullOrWhiteSpace(item.Image))
{