What I have to say is soo much that I need a video for this
So please ladies, geniuses and gentlemen, watch this 7 min video of what my problem is
here’s my code :
(lol sorry pasting the whole thing which makes it long but you (I personally) never know what the problem is)
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import numeral from "numeral";
let filter1Star = wixData.filter().eq("rating", 1).and(wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id));
let filter2Star = wixData.filter().eq("rating", 2).and(wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id));
let filter3Star = wixData.filter().eq("rating", 3).and(wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id));
let filter4Star = wixData.filter().eq("rating", 4).and(wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id));
let filter5Star = wixData.filter().eq("rating", 5).and(wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id));
let filterSumAmount = wixData.filter().eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id);
function aboutBox() {
$w('#aboutBox').expand()
$w('#reviewsBox').collapse()
$w('#coursesBox').collapse()
$w('#postsBox').collapse()
}
function reviewsBox() {
$w('#reviewsBox').expand()
$w('#aboutBox').collapse()
$w('#coursesBox').collapse()
$w('#postsBox').collapse()
}
function coursesBox() {
$w('#aboutBox').collapse()
$w('#reviewsBox').collapse()
$w('#coursesBox').expand()
$w('#postsBox').collapse()
}
function postsBox () {
$w('#aboutBox').collapse()
$w('#reviewsBox').collapse()
$w('#coursesBox').collapse()
$w('#postsBox').expand()
}
function onestar() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filter1Star)
.sum("rating", "rating")
.run()
.then((results) => {
let x = Number((results.items[0].rating) / 1)
$w('#inputOneStars').value = x;
console.log(results)
$w('#loading').hide()
});
}
function twostars() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filter2Star)
.sum("rating", "rating")
.run()
.then((results) => {
let x = Number((results.items[0].rating) / 2)
$w('#inputTwoStars').value = x;
console.log(results)
$w('#loading').hide()
});
}
function threestars() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filter3Star)
.sum("rating", "rating")
.run()
.then((results) => {
let x = Number((results.items[0].rating) / 3)
$w('#inputThreeStars').value = x;
console.log(results)
$w('#loading').hide()
});
}
function fourstars() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filter4Star)
.sum("rating", "rating")
.run()
.then((results) => {
let x = Number((results.items[0].rating) / 4)
$w('#inputFourStars').value = x;
console.log(results)
$w('#loading').hide()
});
}
function fivestars() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filter5Star)
.sum("rating", "rating")
.run()
.then((results) => {
let x = Number((results.items[0].rating) / 5)
$w('#inputFiveStars').value = x;
console.log(results)
$w('#loading').hide()
});
}
function sumAmount() {
$w('#loading').show()
wixData.aggregate("memberratings")
.filter(filterSumAmount)
.sum("rating", "rating")
.run()
.then((results) => {
$w('#sumAmount').value = results.items[0].rating;
console.log(results)
$w('#loading').hide()
});
function totalRatings() {
$w('#loading').show()
wixData.query("memberratings")
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.count()
.then((num) => {
$w('#totalRatings').value = num;
console.log(num)
$w('#loading').hide()
});
}
function starSlider() {
$w('#loading').show()
let total = Number($w('#totalRatings').value)
let oneData = Number($w('#inputOneStars').value)
let twoData = Number($w('#inputTwoStars').value)
let threeData = Number($w('#inputThreeStars').value)
let fourData = Number($w('#inputFourStars').value)
let fiveData = Number($w('#inputFiveStars').value)
let one = Number((oneData / total) * 100).toFixed(1)
let two = Number((twoData / total) * 100).toFixed(1)
let three = Number((threeData / total) * 100).toFixed(1)
let four = Number((fourData / total) * 100).toFixed(1)
let five = Number((fiveData / total) * 100).toFixed(1)
$w("#repeaterSlider").forEachItem(($item, itemData, index) => {
if ($item('#ratingNumber').text === "5") {
$item('#slider1').value = Number(five)
$item('#ratingPercent').text = Number(five) + "%"
$w('#loading').hide()
}
if ($item('#ratingNumber').text === "4") {
$item('#slider1').value = Number(four)
$item('#ratingPercent').text = Number(four) + "%"
$w('#loading').hide()
}
if ($item('#ratingNumber').text === "3") {
$item('#slider1').value = Number(three)
$item('#ratingPercent').text = Number(three) + "%"
$w('#loading').hide()
}
if ($item('#ratingNumber').text === "2") {
$item('#slider1').value = Number(two)
$item('#ratingPercent').text = Number(two) + "%"
$w('#loading').hide()
}
if ($item('#ratingNumber').text === "1") {
$item('#slider1').value = Number(one)
$item('#ratingPercent').text = Number(one) + "%"
$w('#loading').hide()
}
});
console.log(five)
console.log(four)
console.log(three)
console.log(two)
console.log(one)
}
function calculateRating() {
let sumofAll = Number($w('#sumAmount').value)
let totalofAll = Number($w('#totalRatings').value)
let rating = Number(sumofAll / totalofAll).toFixed(1)
$w('#ratingsDisplay3').rating = Number(rating)
$w('#ratingsDisplay1').rating = Number(rating)
$w('#rating').text = rating
$w("#totalPeopleVoted").label = numeral(totalofAll).format('0,0')
console.log(rating)
console.log("👤 " + numeral(totalofAll).format('0,0') + " total")
}
function filterOneStar() {
$w('#loading').show()
$w('#dataset1').setFilter(
wixData.filter()
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.and(
wixData.filter()
.eq("rating", 1)
)
).then(() => {
$w('#removeFilterButton').expand()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
function filterTwoStar() {
$w('#loading').show()
$w('#dataset1').setFilter(
wixData.filter()
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.and(
wixData.filter()
.eq("rating", 2)
)
).then(() => {
$w('#removeFilterButton').expand()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
function filterThreeStar() {
$w('#loading').show()
$w('#dataset1').setFilter(
wixData.filter()
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.and(
wixData.filter()
.eq("rating", 3)
)
).then(() => {
$w('#removeFilterButton').expand()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
function filterFourStar() {
$w('#loading').show()
$w('#dataset1').setFilter(
wixData.filter()
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.and(
wixData.filter()
.eq("rating", 4)
)
).then(() => {
$w('#removeFilterButton').expand()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
function filterFiveStar() {
$w('#loading').show()
$w('#dataset1').setFilter(wixData.filter()
.eq("ratedMemberId", $w('#dynamicDataset').getCurrentItem()._id)
.and(
wixData.filter()
.eq("rating", 5)
)
).then(() => {
$w('#removeFilterButton').expand()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
export function dynamicDataset_ready() {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
onestar()
twostars()
threestars()
fourstars()
fivestars()
sumAmount()
totalRatings()
setTimeout(() => {
starSlider()
calculateRating()
}, 5000)
}
export function showRatingValues_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#ratingValueBox').expand()
$w('#showRatingValues').hide('fade')
$w('#showRatingValuesInverse').show('fade')
}
export function showRatingValuesInverse_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#ratingValueBox').collapse()
$w('#showRatingValues').show('fade')
$w('#showRatingValuesInverse').hide('fade')
}
export function navigstionButton_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
let $item = $w.at(event.context)
let label = $item('#navigstionButton').label
$w('#navigationRepeater').forEachItem(($item1, itemData, index) => {
if ($item1('#navigstionButton').label === label) {
$item1('#onPageBox').show()
} else {
$item1('#onPageBox').hide()
}
})
$w('#navigationRepeater').forEachItem(($item1, itemData, index) => {
if (label === "About") {
aboutBox()
}
if (label === "Reviews") {
reviewsBox()
}
if (label === "Posts") {
postsBox()
}
if (label === "Courses") {
coursesBox()()
}
})
}
export function ratingNumber_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
let $item = $w.at(event.context)
let rating = $item('#ratingNumber').text
$w("#repeaterSlider").forEachItem(($item1, itemData, index) => {
if (rating === "5") {
filterFiveStar()
}
if (rating === "4") {
filterFourStar()
}
if (rating === "3") {
filterThreeStar()
}
if (rating === "2") {
filterTwoStar()
}
if (rating === "1") {
filterOneStar()
}
});
}
export function totalPeopleVoted_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
filterFiveStar()
}
export function removeFilterButton_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#loading').show()
$w('#dataset1').setFilter(
wixData.filter()
).then(() => {
$w('#removeFilterButton').collapse()
$w('#dataset1').refresh()
$w('#loading').hide()
let totalCount = $w("#dataset1").getTotalCount();
if (totalCount.toString() < "1") {
$w('#noRatingsToShowBox').expand()
} else {
$w('#noRatingsToShowBox').collapse()
}
});
}
export function ratingNumber_dblClick(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
ratingNumber_click()
}
link to the website - https://okeyiwobi6.wixsite.com/my-site/members/dj-bon26
might update my url soon. But anytime I update it I’ll update this post unless it becomes locked
Man someone gotta tell me wassup looked like a gitch to meee
DJ bon26