Alright I have one that I know you guys can improve on. My family owns a small restaurant who is in light of current conditions providing curbside pickup. I created a page to display inside the restaurant when a person arrives to pickup their food. A sign in front of the parking spot tells them to text a phone number linked to Twilio, some black magic gets their information into a collection in Wix that includes Spot# Order# and Name. That collection is that displayed on the site.
Here is where things got a little complicated from a collection and coding perspective. I wanted to be able to show all of the spots in a static order regardless of wether or not someone is actually in the spot ie.
Spot 1 Order # 44658 Name - Apple
Spot 2 Order # ------ Name -
Spot 3 Order # 55467 Name - Smith
etc…
However in a repeater based on a single dataset while I could sort the spots 1-8 I can not statically sent their position. So since customers are welcome to park wherever they would like could potentially get:
Spot 1 Order # 44658 Name - Apple
Spot 3 Order # 55467 Name - Smith
So I had to create a dataset for each spot filtering based on spot number and returning only one result. That forced me to have all of my code essentially copied 8 times one for each spot and dataset. I also wanted to change the background color of the container, green for brand new, yellow for 5 minutes old and red for older than ten.
If anyone has any ideas specifically on two topics I would appreciate it. First, how can I ensure the place holder repeater and text shows up when an dataset is empty? And second, is there a way to consolidate this code down to a single set rather than 8?
Only non visible code is onClick events for each button that calls the corresponding DeleteItem for that container and onitemready to call the corresponding function.
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixLocation from 'wix-location';
import wixData from 'wix-data';
var greenbkg = "https://static.wixstatic.com/media/748ef1_a810775075784013bef638100f30c515~mv2.jpg";
var yellowbkg = "https://static.wixstatic.com/media/748ef1_e480defce92440d7874e533917218c59~mv2.jpg";
var redbkg = "https://static.wixstatic.com/media/748ef1_5c81bb0ab0b049ebad616c15f064827e~mv2.jpg";
$w.onReady(function () {
setInterval(() => {
datarefresh()
}, 8000);
});
export function datarefresh() {
$w('#dataset1').refresh();
$w('#dataset2').refresh();
$w('#dataset3').refresh();
$w('#dataset4').refresh();
$w('#dataset5').refresh();
$w('#dataset6').refresh();
$w('#dataset7').refresh();
$w('#dataset8').refresh();
console.log('Done refreshing Dataset');
}
////Items Ready determine bkg Color
export function itemready1($Container, itemData, index) {
let firstItem = itemData._updatedDate
let now = new Date();
let dif = (now - firstItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container1").background.src = bkg;
}
export function itemready2($Container, itemData, index) {
let secondItem = itemData._updatedDate
let now = new Date();
let dif = (now - secondItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container2").background.src = bkg;
}
export function itemready3($Container, itemData, index) {
let thirdItem = itemData._updatedDate
let now = new Date();
let dif = (now - thirdItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container3").background.src = bkg;
}
export function itemready4($Container, itemData, index) {
let fourthItem = itemData._updatedDate
let now = new Date();
let dif = (now - fourthItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container4").background.src = bkg;
}
export function itemready5($Container, itemData, index) {
let firstItem = itemData._updatedDate
let now = new Date();
let dif = (now - firstItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container5").background.src = bkg;
}
export function itemready6($Container, itemData, index) {
let secondItem = itemData._updatedDate
let now = new Date();
let dif = (now - secondItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container6").background.src = bkg;
}
export function itemready7($Container, itemData, index) {
let thirdItem = itemData._updatedDate
let now = new Date();
let dif = (now - thirdItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container7").background.src = bkg;
}
export function itemready8($Container, itemData, index) {
let fourthItem = itemData._updatedDate
let now = new Date();
let dif = (now - fourthItem);
let timeElapsed = Math.round((dif / 1000) / 60);
let bkg = ""
switch (true) {
case (timeElapsed < 5):
bkg = greenbkg;
break;
case (timeElapsed >= 5 && timeElapsed < 10):
bkg = yellowbkg;
break;
case (timeElapsed >= 10):
bkg = redbkg;
break;
default:
bkg = "";
break;
}
$w("#container8").background.src = bkg;
}
////Button Clicks Delete Items
export function DeleteItem1(event) {
//A wixData.query("CurbsideDisplay", options)
let $item1 = $w.at(event.context);
$item1("#dataset1").remove();
$item1("#dataset1").refresh();
}
export function DeleteItem2(event) {
//A wixData.query("CurbsideDisplay", options)
let $item2 = $w.at(event.context);
$item2("#dataset2").remove();
$item2("#dataset2").refresh();
}
export function DeleteItem3(event) {
//A wixData.query("CurbsideDisplay", options)
let $item3 = $w.at(event.context);
$item3("#dataset3").remove();
$item3("#dataset3").refresh();
}
export function DeleteItem4(event) {
//A wixData.query("CurbsideDisplay", options)
let $item4 = $w.at(event.context);
$item4("#dataset4").remove();
$item4("#dataset4").refresh();
}
export function DeleteItem5(event) {
//A wixData.query("CurbsideDisplay", options)
let $item4 = $w.at(event.context);
$item4("#dataset5").remove();
$item4("#dataset5").refresh();
}
export function DeleteItem6(event) {
//A wixData.query("CurbsideDisplay", options)
let $item4 = $w.at(event.context);
$item4("#dataset6").remove();
$item4("#dataset6").refresh();
}
export function DeleteItem7(event) {
//A wixData.query("CurbsideDisplay", options)
let $item4 = $w.at(event.context);
$item4("#dataset7").remove();
$item4("#dataset7").refresh();
}
export function DeleteItem8(event) {
//A wixData.query("CurbsideDisplay", options)
let $item4 = $w.at(event.context);
$item4("#dataset8").remove();
$item4("#dataset8").refresh();
}